I'm currently working on a extension for a GameEngine at my university, that is using bullet, and it works, mostly.
I'm having issues with the following code:
Code: Select all
DynamicBody* db;
list<Key> keysPressed;
void Handle(ProcessEventArg arg)
{
//Pushed here the body moves
// keysPressed.push_back(KEY_w);
list<Key>::iterator key;
for(key=keysPressed.begin(); key != keysPressed.end(); ++key)
HandleDown(*key);
}
void Handle(KeyboardEventArg arg)
{
//Pushed here it doesn't
//keysPressed.push_back(KEY_w);
}
void HandleDown(Key key)
{
db->ApplyForce(Vector<3,float>(1,0,0));
}
The issues is that once I push keys into the list, from within Handle(Keyboard) the code doesn't work, if I push a key from within Handle(ProcessEvent), then it works. - That would be perfectly understandable if the call to Handle(Keyboard) never happend, however it does, and the call to db->ApplyForce() happens in both cases, however it only works on one of them.
The call to ApplyForces, simply pushes the force into a list of forces, that affects the body, and these are applied using the following code (inside the engine extension):
Code: Select all
btBody.clearForces();
btBody.applyTorque(toBtVec(dynBody.GetTorque()));
for(list<DynamicBody::ForceAtPosition>::iterator it = dynBody.GetForces().begin(); it != dynBody.GetForces().end(); it++)
{
DynamicBody::ForceAtPosition & f = *it;
btBody.applyForce(toBtVec(f.get<0>()), toBtVec(f.get<1>()));
}
dynBody.ResetForces();
'toBtVec' translates our vector type, to the bullet one, dynBody.GetForces(), returns a list of forces.
ResetForces() clears the list of forces.
The forces, in the list is of type: 'boost::tuple<const Vector<3,float>, const Vector<3,float> >'.
The physics plugin, handles the dynamic bodies, by applying forces, with the above code (among with something else), then a call to stepSimulation(), followed by an updating of the rendering data, for the body.
Anyone see, where the issue would be? - I've tried like everything, and what bugs me, is that running a debugger. I can see that the same code gets executed, no matter where I'm pushing the keypressed from.
If you require any other code or test, please let me know, and I'll supply and test.
Note: The code is compiled using GCC 4.5.1 (MinGW under Windows 7).
Note: Compiling for x86-32