I have been struggling with this problem for a few days, but I can't seem to find the reason.
I've created a container class for the Box2D world and a "Map" class that is redundant but haven't gotten around to merging it (wanted to get Box2D to work first)
I've been trying to get a body to move in every way possible but it just won't....
Where I am applying the force:
Where I do the step():
Creating the body:
I am really confused. Can someone help me?
I've created a container class for the Box2D world and a "Map" class that is redundant but haven't gotten around to merging it (wanted to get Box2D to work first)
I've been trying to get a body to move in every way possible but it just won't....
Where I am applying the force:
Code:
void Box2D_Handler::addbforce(long id, double x, double y) { // x, y and id are not broken
bodies[id]->ApplyForce(b2Vec2(x, y), bodies[id]->GetWorldCenter());
//Guess what time it is... 3.2.1. DEBUG TIME!
//bodies[id]->SetAwake(true);
//bodies[id]->SetLinearVelocity(b2Vec2(x, y));
}
bodies[id]->ApplyForce(b2Vec2(x, y), bodies[id]->GetWorldCenter());
//Guess what time it is... 3.2.1. DEBUG TIME!
//bodies[id]->SetAwake(true);
//bodies[id]->SetLinearVelocity(b2Vec2(x, y));
}
Where I do the step():
Code:
void Map::updateall() {
long i;
Object *crt;
for(i = 0, crt = this->x; i < this->nrobj; i++) {
crt->update();
crt = crt->next;
}
_std_hand.world->Step(_std_hand.timestep, _std_hand.velIt, _std_hand.pozIt); //timestep, velIt and pozIt are not broken
for(i = 0, crt = this->x; i < this->nrobj; i++) {
crt->checkUpdate();
crt = crt->next;
}
}
long i;
Object *crt;
for(i = 0, crt = this->x; i < this->nrobj; i++) {
crt->update();
crt = crt->next;
}
_std_hand.world->Step(_std_hand.timestep, _std_hand.velIt, _std_hand.pozIt); //timestep, velIt and pozIt are not broken
for(i = 0, crt = this->x; i < this->nrobj; i++) {
crt->checkUpdate();
crt = crt->next;
}
}
Creating the body:
Code:
void Box2D_Handler::addbody(double x, double y, double sizex, double sizey, long &id) {
b2BodyDef bodyDef;
//bodyDef.allowsleep = true;
bodyDef.awake = true;
bodyDef.type = b2_dynamicBody;
bodyDef.position.Set(x, y);
b2Body *body = world->CreateBody(&bodyDef);
b2PolygonShape dynamicBox;
dynamicBox.SetAsBox(sizex, sizey);
b2FixtureDef fixtureDef;
fixtureDef.shape = &dynamicBox;
fixtureDef.density = 1.0f;
fixtureDef.friction = 0.0f;
body->CreateFixture(&fixtureDef);
id = bodies.size();
bodies.push_back(body);
}
b2BodyDef bodyDef;
//bodyDef.allowsleep = true;
bodyDef.awake = true;
bodyDef.type = b2_dynamicBody;
bodyDef.position.Set(x, y);
b2Body *body = world->CreateBody(&bodyDef);
b2PolygonShape dynamicBox;
dynamicBox.SetAsBox(sizex, sizey);
b2FixtureDef fixtureDef;
fixtureDef.shape = &dynamicBox;
fixtureDef.density = 1.0f;
fixtureDef.friction = 0.0f;
body->CreateFixture(&fixtureDef);
id = bodies.size();
bodies.push_back(body);
}
I am really confused. Can someone help me?