problem with bullet`s transformation matrices

Post Reply
Manish Bista
Posts: 6
Joined: Wed Feb 11, 2015 2:04 am

problem with bullet`s transformation matrices

Post by Manish Bista »

I am using OpenGLSL along with bullet physics engine to create rigid bodies connected in hinge. I had done so using opengl`s built-in transformation, and a function to add and render a sphere is as given, which produces the desired output:

Code: Select all

    btRigidBody* rag::addSphere(float rad,float x,float y,float z,float mass)
    {
	btTransform t;
	t.setIdentity();
	t.setOrigin(btVector3(x,y,z));
	btSphereShape* sphere=new btSphereShape(rad);
	btVector3 inertia(0,0,0);
	if(mass!=0.0)
		sphere->calculateLocalInertia(mass,inertia);
	
	btMotionState* motion=new btDefaultMotionState(t);
	btRigidBody::btRigidBodyConstructionInfo info(mass,motion,sphere,inertia);
	btRigidBody* body=new btRigidBody(info);
	world->addRigidBody(body);
	bodies.push_back(body);
	return body;
    }

    void rag::renderSphere(btRigidBody* sphere)
    {
	    if(sphere->getCollisionShape()->getShapeType()!=SPHERE_SHAPE_PROXYTYPE)
		return;
	glColor3f(1,0,0);
	float r=((btSphereShape*)sphere->getCollisionShape())->getRadius();
	btTransform t;
	sphere->getMotionState()->getWorldTransform(t);
	float mat[16];
	t.getOpenGLMatrix(mat);
	glPushMatrix();
		glMultMatrixf(mat);	//translation,rotation times mat
		gluSphere(quad,r,20,20);
	glPopMatrix();
    }
I put the initial plane at a certain height and let it fall to collide with the ground. The function produces the desired output. But, I needed to use user-defined matrices, pass it into the shaders and compute. To achieve that, I changed the above function as:

Code: Select all

 void rag::renderSphere(btRigidBody* sphere, matrices& pipeline, unsigned int programObject)
    {
	    if(sphere->getCollisionShape()->getShapeType()!=SPHERE_SHAPE_PROXYTYPE)
		return;
	glColor3f(1,0,0);
	float r=((btSphereShape*)sphere->getCollisionShape())->getRadius();
	btTransform t;
	sphere->getMotionState()->getWorldTransform(t);
	float mat[16];
	t.getOpenGLMatrix(mat);
	physx = getMatrix(mat);   //getMatrix function changes array of float to matrix form
	pipeline.pushMatrix();
		pipeline.getModelViewProjectionMatrix() = physx * pipeline.getModelViewProjectionMatrix();
		pipeline.updateMatrices(programObject);  //changes the value of matrix to be passed to shader
		gluSphere(quad,r,20,20);
	pipeline.popMatrix();
    }
The getModelViewProjectionMatrix() function returns matrix by reference. The final output is that the sphere is centered at the origin as if there has been
no effect of physics transformation at all. Also, I am unsure about the order in which the two transformation matrices are multiplied. What could be the problem?
Post Reply