How to improve the rotation speed of rigid body

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

How to improve the rotation speed of rigid body

Post by water »

I set up a rigid body with a mass of 0 and change its rotation by changing the Euler angle

Code: Select all

	
	btCollisionShape* groundShape = new btBvhTriangleMeshShape(tMesh, useQuantization); 
        btTransform groundTransform	
	groundTransform.setIdentity();
	groundTransform.setOrigin(btVector3(0, 0, 0));
	compound->addChildShape(groundTransform, groundShape);
	btQuaternion quaternion = btQuaternion(m_yaw * RADIANS_PER_DEGREE, m_pich * RADIANS_PER_DEGREE, m_roll* RADIANS_PER_DEGREE);
	groundTransform.setRotation(quaternion);
	btScalar mass(0);

Code: Select all

	for (int j = mp_btDynamicsWorld->getNumCollisionObjects() - 1; j >= 0; j--)
	{
		int m = 1;
		btCollisionObject* obj = mp_btDynamicsWorld->getCollisionObjectArray()[j];
		btRigidBody* body = btRigidBody::upcast(obj);
		
		body->getCenterOfMassPosition();
	
		btQuaternion qua = body->getOrientation();
		btVector3 angul(1, 1, 1);
		
		btTransform trans;
		btMatrix3x3 matrix33 = trans.getBasis();
		btVector3 angularVelocity(0, 0, 0);
		trans.setIdentity();
		btQuaternion quaternion = btQuaternion(m_yaw * RADIANS_PER_DEGREE, m_pich * RADIANS_PER_DEGREE, m_roll* RADIANS_PER_DEGREE);
	
		if (body && body->getMotionState())

		{
			body->getMotionState()->getWorldTransform(trans);

		}
		else
		{
			trans = obj->getWorldTransform();
		}
	
		m_trajectory[m_tra++].setValue(float(trans.getOrigin().getX()), float(trans.getOrigin().getY()), float(trans.getOrigin().getZ()));

		if (j == mp_btDynamicsWorld->getNumCollisionObjects() - 1)
		{

			trans.setRotation(quaternion);
			body->setCenterOfMassTransform(trans);
			glPushMatrix();
			glRotatef(m_yaw, 0.0, 1.0, 0.0);
			glRotatef(m_pich, 1.0, 0.0, 0.0);
			glRotatef(m_roll, 0.0, 0.0, 1.0);
			DrawMesh();
			glPopMatrix();


		}

Code: Select all

switch (event->key())
	{
	case Qt::Key_Escape:                             
		close();
		update();
		break;
	case Qt::Key_PageUp:                              
		m_yaw -= 0.2f;
		update();
		break;

The rotation angle can be increased through keyboard events. I hope the rigid body can rotate faster. In addition to increasing the degree of yaw, what else can I do? Thank you very much.
Post Reply