How to solve the problem of the ball penetrating the cuboid

Post Reply
water
Posts: 33
Joined: Fri Jun 05, 2020 8:36 am

How to solve the problem of the ball penetrating the cuboid

Post 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?
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: How to solve the problem of the ball penetrating the cuboid

Post by drleviathan »

The code looks ok. What is the error?

The angles you are using... they are in radians (not degrees) right?
water
Posts: 33
Joined: Fri Jun 05, 2020 8:36 am

Re: How to solve the problem of the ball penetrating the cuboid

Post 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();
}

User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: How to solve the problem of the ball penetrating the cuboid

Post 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.
water
Posts: 33
Joined: Fri Jun 05, 2020 8:36 am

Re: How to solve the problem of the ball penetrating the cuboid

Post 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?
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: How to solve the problem of the ball penetrating the cuboid

Post 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);
water
Posts: 33
Joined: Fri Jun 05, 2020 8:36 am

Re: How to solve the problem of the ball penetrating the cuboid

Post by water »

drleviathan wrote: Wed Jun 24, 2020 6:21 am 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);

Thank you very much
Post Reply