Commit d5b14441 authored by bbguimaraes's avatar bbguimaraes
Browse files

sms: & to * on sms interface

parent 06daa005
......@@ -23,8 +23,8 @@ class SpringMassSystem {
{this->m_springs = s;}
void set_gravity(const Vector & g) {this->m_gravity = g;}
const std::vector<Mass *> & masses() const {return this->m_masses;}
const std::vector<Spring *> & springs() const {return this->m_springs;}
const std::vector<Mass *> * masses() const {return &this->m_masses;}
const std::vector<Spring *> * springs() const {return &this->m_springs;}
Vector gravity() const {return this->m_gravity;}
static void link(Mass * mass0, Mass * mass1, Spring * spring);
......
......@@ -16,7 +16,7 @@ void SpringMassSystem::link(Mass * mass0, Mass * mass1, Spring * spring) {
}
void SpringMassSystem::update(float interval) {
for(auto mass : this->masses()) {
for(auto mass : *this->masses()) {
if(mass->fixed())
continue;
Vector total_force = mass->force() + (this->m_gravity * mass->mass());
......@@ -29,6 +29,6 @@ void SpringMassSystem::update(float interval) {
mass->set_speed(speed);
mass->set_position(mass->position() + speed * interval);
}
for(auto spring : this->springs())
for(auto spring : *this->springs())
spring->update_force();
}
......@@ -104,7 +104,7 @@ void Display::select(Vector click) {
glPushName(0);
this->draw_masses(system, GL_SELECT);
if(glRenderMode(GL_RENDER) != 0) {
selected = system->masses()[select_buffer[3]];
selected = (*system->masses())[select_buffer[3]];
break;
}
}
......@@ -194,7 +194,7 @@ void Display::draw_springs_non_textured(SpringMassSystem * system) {
glLineWidth(5.0f);
glColor3f(0.0f, 1.0f, 0.0f);
glBegin(GL_LINES);
for(auto spring : system->springs()) {
for(auto spring : *system->springs()) {
auto p0 = spring->mass0()->position();
auto p1 = spring->mass1()->position();
glVertex3f(p0.x(), p0.y(), p0.z());
......@@ -211,7 +211,7 @@ void Display::draw_springs_textured(SpringMassSystem * system) {
const float WIDTH_F = static_cast<float>(WIDTH);
auto point = [WIDTH, WIDTH_F, masses](int x, int y) {
glTexCoord2f(x / WIDTH_F, y / WIDTH_F);;
auto p = masses[y * WIDTH + x]->position();
auto p = (*masses)[y * WIDTH + x]->position();
glVertex3f(p.x(), p.y(), p.z());;
};
glEnable(GL_TEXTURE_2D);
......@@ -219,7 +219,7 @@ void Display::draw_springs_textured(SpringMassSystem * system) {
glColor3f(1.0f, 1.0f, 1.0f);
glBindTexture(GL_TEXTURE_2D, this->m_texture);
glBegin(GL_TRIANGLES);
for(unsigned int y = 0; y < masses.size() / WIDTH - 1; ++y)
for(unsigned int y = 0; y < masses->size() / WIDTH - 1; ++y)
for(unsigned int x = 0; x < WIDTH - 1; ++x) {
point(x , y );
point(x , y + 1);
......@@ -238,7 +238,7 @@ void Display::draw_masses(SpringMassSystem * system, GLenum mode) {
this->m_quadric = gluNewQuadric();
glPushAttrib(GL_CURRENT_BIT);
unsigned int index = 0;
for(auto mass : system->masses()) {
for(auto mass : *system->masses()) {
if(mode == GL_SELECT)
glLoadName(index++);
glPushMatrix();
......
......@@ -20,9 +20,9 @@ int main(int argc, char ** argv) {
SpringMassSystem sms0, sms1;
init_sm_system3(&sms0);
init_sm_system3(&sms1);
for(auto mass : sms0.masses())
for(auto mass : *sms0.masses())
mass->set_position(mass->position() + Vector(-10.0f));
for(auto mass : sms1.masses())
for(auto mass : *sms1.masses())
mass->set_position(mass->position() + Vector(10.0f));
Display display;
display.makeCurrent();
......@@ -60,7 +60,7 @@ void init_sm_system0(SpringMassSystem * system) {
"# spring k constant\n"
"0.25\n");
SMSCreator::read_from_file(system, &input);
system->masses()[0]->set_fixed(true);
(*system->masses())[0]->set_fixed(true);
}
void init_sm_system1(SpringMassSystem * system) {
......@@ -69,7 +69,7 @@ void init_sm_system1(SpringMassSystem * system) {
Vector(),
Vector(5.0f, 0.0f, 0.0f),
10, 1, 1);
system->masses()[0]->set_fixed(true);
(*system->masses())[0]->set_fixed(true);
}
void init_sm_system2(SpringMassSystem * system) {
......@@ -79,8 +79,8 @@ void init_sm_system2(SpringMassSystem * system) {
Vector(-5.0f, 10.0f), Vector(5.0f, 0.0f),
W, 5,
1.0f, 10.0f);
system->masses()[0]->set_fixed(true);
system->masses()[W - 1]->set_fixed(true);
(*system->masses())[0]->set_fixed(true);
(*system->masses())[W - 1]->set_fixed(true);
}
void init_sm_system3(SpringMassSystem * system) {
......@@ -90,8 +90,8 @@ void init_sm_system3(SpringMassSystem * system) {
Vector(-5.0f, 10.0f), Vector(5.0f, 0.0f),
W, 5,
1.0f, 10.0f);
system->masses()[0]->set_fixed(true);
system->masses()[W - 1]->set_fixed(true);
(*system->masses())[0]->set_fixed(true);
(*system->masses())[W - 1]->set_fixed(true);
}
GLuint load_texture(const std::string & filename) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment