Page 1 of 1
How to solve the problem of the ball penetrating the cuboid
Posted: Mon Jun 22, 2020 10:24 am
by water
Code: Select all
btQuaternion quaternion = btQuaternion(yaw,pich,roll);
quaternion.setEuler(yaw, pitch, roll);
groundTransform.setRotation(quaternion);
I want to rotate the rigid body by setting the Euler angle, but there is an error. Can you help me to see how to write it?
Re: How to solve the problem of the ball penetrating the cuboid
Posted: Mon Jun 22, 2020 2:30 pm
by drleviathan
The code looks ok. What is the error?
The angles you are using... they are in radians (not degrees) right?
Re: How to solve the problem of the ball penetrating the cuboid
Posted: Tue Jun 23, 2020 3:42 am
by water
I want to change the Euler angle in real time through the keyboard and display it through OpenGL,I put the initialization of the model in InitObjectground();But the model doesn't move when I press the key to change yaw roll
Code: Select all
glPushMatrix();
glTranslated(float(trans.getOrigin().getX()), float(trans.getOrigin().getY()), float(trans.getOrigin().getZ()));
DrawBulletObject();
glPopMatrix();
Code: Select all
void MyWindow::initializeGL()
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glEnable(GL_DEPTH_TEST);
glShadeModel(GL_SMOOTH);
glEnable(GL_AUTO_NORMAL);
glEnable(GL_NORMALIZE);
InitObject();
InitObjectground();
}
Code: Select all
void MyWindow::paintGL()
{
Display();
}
Re: How to solve the problem of the ball penetrating the cuboid
Posted: Tue Jun 23, 2020 1:33 pm
by drleviathan
I see. You have a logic error rather than a question about Euler angles and quaternions. The good news is: I don't see the fault of the code you posted. The bad news would be: your bug is somewhere else. Maybe post your full code up on github? Good luck.
Re: How to solve the problem of the ball penetrating the cuboid
Posted: Wed Jun 24, 2020 12:50 am
by water
Thank you very much for your reply. I found that initobjectground() in my code was initialized only once, so btquaternion quaternion = btquaternion (yaw, pich, roll); it was also called only once, resulting in unable to change the Euler angle of the model. Can I ask if there is any way to control the Euler angle of the rigid body in the bullet to realize the rotation of the rigid body?
Re: How to solve the problem of the ball penetrating the cuboid
Posted: Wed Jun 24, 2020 6:21 am
by drleviathan
The simple way to do it is to use:
btCollisionObject::setWorldTransform()
So the code might look like this:
Code: Select all
btTransform t = body->getWorldTransform();
t.setRotation(btQuaternion(roll, pitch, yaw));
body->setWorldTransform(t);
Re: How to solve the problem of the ball penetrating the cuboid
Posted: Wed Jun 24, 2020 7:28 am
by water