Various strange behavious relating to movement + rotation

genericController
Posts: 4
Joined: Mon Jul 08, 2013 11:10 am

Various strange behavious relating to movement + rotation

Post by genericController »

I have been experimenting as so far I have not been able to achieve non-static objects falling, reacting to another object and rotating in relation.
So far I have only been able to update the position of the collision object(box) with the object(cube), but have only been able to either receive collisions, and the collision shape conforms to the alignment of the box (non-rotating), or tracks with the position of the object, but only the collision shape rotates,not the object.

The second behavior I achieved, was all collision shapes would align perfectly with their respective objects, but would not update movement, position or rotation from the physics engine, only by directly setting their respective x,y,z positions.

A common problem I witnessed, was the lack of setting the local inertia, which I have done. In my update, I assign setEulerZYX() from the rotation x,y and z to my btQuaternion, then because I am using glm as my math library, I assign the btQuaternion x,y,z,w to the glm quarternion x,y,z,w(I need to do this to glm::mat4_cast() to my local rotate matrix)

After this I assign the btTransform x,y,z to the glm::vec3 position x,y,z (which I use in my local translate matrix), then I call setRotation() on my btTransform by parsing in my btQuaternion, and finally call setCenterOfMassTransform() on the rigid body, parsing in the btTransform.

If I remove the call to setCenterOfMassTransform(), the collision shapes ignore their respective objects, and I can view the collision shapes behaving as expected and reacting to each other with the debug view activated.

I want the objects to react to the physics and the collision shapes to align to the orientation and track their positions, with users enabled the ability to move them if so desired, any thoughts on what I am doing wrong here or any further insights would be greatly appreciated.

Code exert from my update call:

Code: Select all

           
        //Set the euler angles from the user-input x,y,z to orientate the object
        qOrientation.setEulerZYX(rotZ, rotY, rotX);
        
        //Assign the quartonian for use with glm matrices
        orientation.x = qOrientation.x();
        orientation.y = qOrientation.y();
        orientation.z = qOrientation.z();
        orientation.w = qOrientation.w();
        
        /********************************************
        //Test code to assign collision shape position to the object
        btVector3 point;
        point = rigidBody->getCenterOfMassPosition();
            
        positon.x = trans.getOrigin().getX();
        positon.y = trans.getOrigin().getY();
        positon.z = trans.getOrigin().getZ();
            
        trans.setOrigin(point);
        *********************************************/

        trans.setRotation(qOrientation);
            
        rigidBody->setCenterOfMassTransform(trans);
            
        //Combine the matrices together
	    model = worldTranslate * localRotate * localScale;
       
	    worldTranslate = localTranslate;
        
        //Cast orientation to the matrix for use
        localRotate = glm::mat4_cast(orientation);
        
        localScale = glm::scale(glm::mat4(1.0f), glm::vec3(scale.x,scale.y,scale.z));
        localTranslate = glm::translate(glm::mat4(1.0f),glm::vec3(positon.x,positon.y,positon.z));
genericController
Posts: 4
Joined: Mon Jul 08, 2013 11:10 am

Re: Various strange behavious relating to movement + rotatio

Post by genericController »

I've made further progress, it seems typing the problem out helped me analyse potential issues. As I suspected, it was an issue relation to the btQuaternion, the objects now rotate and update in relation to their respective collision shapes, which is fantastic. However, I am unable to assign my own rotations, without completely overriding the physics.

How can I allow the physics engine to take into account user-defined rotations without overriding the entire system?

This is my new update code as a reference to anyone else who might see this with a similar issue:

Code: Select all

            btVector3 point;
            btQuaternion rot;
            
            point = rigidBody->getCenterOfMassPosition();
            rot  = rigidBody->getOrientation();
            
            /**********************************
            //This overrides the physics
            rot.setEulerZYX(rotZ, rotY, rotX);
            **********************************/
            
            trans.setOrigin(point);
            trans.setRotation(rot);
            
            rigidBody->setCenterOfMassTransform(trans);
            
            positon.x = trans.getOrigin().getX();
            positon.y = trans.getOrigin().getY();
            positon.z = trans.getOrigin().getZ();
            
            orientation.x = rot.x();
            orientation.y = rot.y();
            orientation.z = rot.z();
            orientation.w = rot.w();
genericController
Posts: 4
Joined: Mon Jul 08, 2013 11:10 am

Re: Various strange behavious relating to movement + rotatio

Post by genericController »

Solution:

It appears this was more of a design issue relating to my complete lack of understanding of how the Bullet Physics engine works.
For me to successfully populate a world with static and non-static(physics) objects, during the update I needed to identify what was a static object(no physics applied) and update them unrelated to the physics operations, in other words, I was trying to move a physics object like a static object, without using methods like applyCentralForce().

It is seemingly obvious now, but with no prior experience with this kind of thing, it isn't initially.
STTrife
Posts: 109
Joined: Tue May 01, 2012 10:42 am

Re: Various strange behavious relating to movement + rotatio

Post by STTrife »

I thought reading the manual (completly) was a great help when first learn Bullet. It's quite short but it handles most important aspects.
genericController
Posts: 4
Joined: Mon Jul 08, 2013 11:10 am

Re: Various strange behavious relating to movement + rotatio

Post by genericController »

No absolutely, I appreciate that. I seemingly failed to grasp some concepts for lack of understanding the material, this method of thinking is rather new to me(graphics programmer), but now I understand the difference, the manual is very straightforward. My post my appear seemingly pointless, but the act of typing everything out enabled me to see clearly the concepts I did not grasp and visualise how the elements of Bullet interact and should interact with my existing code base.