[Newbie] kinematic objects transform and updating

Post Reply
lahabanaroom
Posts: 7
Joined: Mon Jan 11, 2010 11:42 pm

[Newbie] kinematic objects transform and updating

Post by lahabanaroom »

hello,
Firstly i'd like to tell you that I'm not english so please excuse me for the language mistakes I'll surely make and I'm also new to bullet so sorry if those questions look stupid to you...

I'm doing a maze like that http://www.clubic.com/telecharger-fiche ... -lite.html
For the playing field I've made many btBoxShape that are Kinematics (I've checked it) .
At the begining the ball falls on the plate without any problems (it even bounces a little). But when I want to move my field it happens to different things:
- when I use btRigidBody::proceedTransform(btTransform)
the ball just fall whatever the angle of rotation is... and the rendered scene (openGL) doesn't refresh at all...
- when I use btRigidBody::getMotionState()->setWorldTransform(btTransform)
the rendered scene updates perfectly but the ball doesn't move at all...
I think I didn't understand everything about the difference between proceedTransform and setWorldTransform... Could you please explain it to me?
Here are the two functions that may interest you:

Code: Select all

void Objet::addMatrix(const btScalar* _m)// function called when we add a new transform
{
	btTransform tmp;
	tmp.setFromOpenGLMatrix(_m);
	//we get the current matrix
	m_RigidBody->getMotionState()->getWorldTransform(*m_Transfo);
	//add the new transform
	(*m_Transfo)*=tmp;
	//update bullet with this new transform
	m_RigidBody->getMotionState()->setWorldTransform(*m_Transfo);	
	//m_RigidBody->proceedToTransform(*m_Transfo);
	//m_RigidBody->activate(true); 
}
void Objet::getMatrix(btScalar* _m) const// function called to get the transform matrix for drawing the scene
{
	m_RigidBody->getMotionState()->getWorldTransform(*m_Transfo);
	m_Transfo->getOpenGLMatrix(_m);
}
Please tell what you need because I'm not sure to be very clear...
Thank you
lahabanaroom
Posts: 7
Joined: Mon Jan 11, 2010 11:42 pm

Re: [Newbie] kinematic objects transform and updating

Post by lahabanaroom »

Hi,
I've advanced a little bit and it seems that it is the collision reactivation that doesn't work even if i use "m_RigidBody->activate(true); "
Do you know how I can do that??
.jayderyu
Posts: 19
Joined: Sat Jan 17, 2009 10:51 am

Re: [Newbie] kinematic objects transform and updating

Post by .jayderyu »

I'm a newbie too, but my suggestion.

Don't move the field.
Rotate the camera to simulate a tipping world.
Don't kinematic any of your objects
Importantly alter the gravity forces instead.
world.setGravity(0,-10, 0); // balanced
world.setGravity(-2, -10, 0); //tipping
....

If you have a background, rotate the background with the camera so only board looks like it's moving.
lahabanaroom
Posts: 7
Joined: Mon Jan 11, 2010 11:42 pm

Re: [Newbie] kinematic objects transform and updating

Post by lahabanaroom »

this works but the render is not really good for example the ball doesn't roll...
I think I'll use this only if I can't do in any other way.

Thank you for your help!
.jayderyu
Posts: 19
Joined: Sat Jan 17, 2009 10:51 am

Re: [Newbie] kinematic objects transform and updating

Post by .jayderyu »

Could you explain by "doesn't roll"?
Does it not graphically roll?
Just doesn't move?
Was it moving correctly before?

As for the Rendered problem. That's the suggestion I was reading when another person asked a question on how to integrate physics with a graphical api for the same type of game. So i'm only passing it on.

Anyways good luck :)
lahabanaroom
Posts: 7
Joined: Mon Jan 11, 2010 11:42 pm

Re: [Newbie] kinematic objects transform and updating

Post by lahabanaroom »

it graphicaly doesn't roll and I think I see why...
anyway, I've advanced a little bit... I've stopped using setworldtransform and getworldtransform on kinematics objects as recommended here: http://bulletphysics.org/mediawiki-1.5. ... tic_Bodies
Instead I just have a bttransform that I modify each time I move the field...

When I create my field (made of many boxobjets) i use that btRigidBody::translate(btVector3(m_x,m_y,m_z)); in order they move correctly with only one transform...
do you thing my bug could happen from here??

It's really farfetching me! I don't understand why it doesn't work I've tried many things...
.jayderyu
Posts: 19
Joined: Sat Jan 17, 2009 10:51 am

Re: [Newbie] kinematic objects transform and updating

Post by .jayderyu »

It's a bad idea to use YourMotionState.get/setWorldTransform. Those function are for the internal physics step. Not so much for external use. Pretty much stick with cycling through MotionState.setKinematic(), it covers all the rotation and position setting you need. don't use RigidBody.translate(). From my understanding that once objects are in play you shouldn't be altering positional or rotational values by the RigidBody. It should be done by in the MotionState.getWorldTransform(). OgreMotionState fortunatly has this implemented with the setKinematic. Lucky you :) (mini rant)I'm using JPCT and have to write the entire thing manually with numerous conflicting issues. YZ are inverted and JPCT uses Matrix4f while jBullet produces only a Matrix3f to work with :\. So it's a bit awkward until I iron it all out.

I would also suggest just testing with a single box that composes of the ground. Then build the walls on the way up.

Is your ball kinematic?

edit:
Just a thought. Since your going to use a tilting board than tilting camera. I would suggest(if possible|) to bind non kinematic walls to the kinematic ground. That way you can just rotate the ground and the rest of the objects will move with it. You can avoid cycling through your OgreMotionStates for each object. I think a basic Generic6DofConstraint should work. Everything is locked on creation(which is what you want with
non moving walls). Maybe you already do this, but I read your post in a manner that your manually rotating and positioning everything.
lahabanaroom
Posts: 7
Joined: Mon Jan 11, 2010 11:42 pm

Re: [Newbie] kinematic objects transform and updating

Post by lahabanaroom »

No my ball is not kinematic...
Thank you for the help but I don't use ogre at all . Moreover as there is holes in the field I can't build the full ground at once...
After many tests I think I will go as it was recommended to me at the beginning( use gravity modification)
but I've got a question about that: I get a transformation matrix from previous steps do you know how I can extract the gravity modifications from the matrix?
.jayderyu
Posts: 19
Joined: Sat Jan 17, 2009 10:51 am

Re: [Newbie] kinematic objects transform and updating

Post by .jayderyu »

Sorry.
When you linked to the OgreMotionState I thought you were using Ogre3d. Gotcha, you using your own and used OgreMotionState as a template.

" I get a transformation matrix from previous steps do you know how I can extract the gravity modifications from the matrix?"

Any effects of gravity from a btDiscreateDynamicWorld.stepSimulation() your MotionState.setWorldTransform() will be notified by being called from the internal process. So once you put your RigidBody into word.addRigidBody(ballRigidBody). you should be completly leaving set/getWorldTransofrm() alone and letting the stepSimulation do the work. so when stepSimulation occurs. your graphical update is called done for you

YoutMotionState.setWorldTransform(btTransform trans){
// any effect from gravity effects is in trans. the simulation will update trans as needed.
ballGfx.pos.x += trans.origin.x;
ballGfx.pos.y += trans.origin.y;
ballGfx.pos.z += trans.origin.z;
// also rotate the graphic. from trans.basis or Qaunternion trans.getRotation
}

if you don't mind could you post your ball creation code, stepSimulation loop and your MotionState?

I've had to to muddle through getting jBullet working jPCT. So i'm familiar with my graphical objects not moving, but seeing the code I can visualize why it's not moving as you mentioned.
lahabanaroom
Posts: 7
Joined: Mon Jan 11, 2010 11:42 pm

Re: [Newbie] kinematic objects transform and updating

Post by lahabanaroom »

Here's my full project for the moment:
http://digilibre.com/files/prj.zip
There is still the btRigidBody::translate and the setTransform...
Could you please precisly tell me what is wrong?

Do you mean I should do my own motion state?
I might wrong in many parts of my job.... "Ho god I think I in the wrong way"^^

Thank you for your precious help
.jayderyu
Posts: 19
Joined: Sat Jan 17, 2009 10:51 am

Re: [Newbie] kinematic objects transform and updating

Post by .jayderyu »

Ok i'm going to look over. In the mean time heres some suggestions

I couldn't find where you add Bille to the DiscreateWorld. I coudln't find the main game loop. I'm not saying they are not there, but just to make sure.

Make sure all RigidBodies are added to the world.
Make sure DiscreatWorld.stepSimulation() is called before every graphical update.

Here is what I found that might help Bille. Make sure to do with with your field.
I am passing Monde to Bille so that the Ball can be added to the Physics World.
I could be wrong, but from my understanding of MotionState you don't pass values into Set/GetWorldTransform. They are values your supposed to work with if your using a custom MotionState. I hacked draw() a bit so that you can what objects are used to update your graphics.

Code: Select all

Bille::Bille(Monde monde, float X,float Y,float Z, unsigned int mass,float taille):Objet(X,Y,Z,taille,taille,'3'),m_Mass(mass),m_Taille(taille)
{
	m_Shape = new btSphereShape(btScalar(m_Taille));
	btVector3 fall(0,0,0);//inertie		
	btVector3 fallInertia(0,0,0);
	m_Shape->calculateLocalInertia(mass,fallInertia);
	btRigidBody::btRigidBodyConstructionInfo fallRigidBodyCI(m_Mass,m_MotionState,m_Shape,btVector3(0,0,0));
	m_RigidBody = new btRigidBody(fallRigidBodyCI);
	m_RigidBody->translate(btVector3(m_x,m_y,m_z));
	
	monde->ajouterObjet(m_RigidBody)
}
void Bille::draw() const
{
  btTransform tmp = m_RigidBody->getMotionState()->m_graphicsWorldTrans;
  Vector3f pos = tmp->getOrigin(); // this is your position  Vector3f
  btMatrix3x3 rot = tmp->getBasis(); // this is your rotation
  // or use
  btQaunternion qRot = tmp->getRotation();
  // update your bille postion and rotation

	btScalar matrice[16];
	getMatrix(matrice);
	glColor3f(1.0,0.0,0.0);
	glPushMatrix();
	glMultMatrixf(matrice);
	gluSphere( gluNewQuadric(),0.25,10,10);
	glPopMatrix();
}
void Bille::addMatrix(const btScalar* _m)
{
  // if you need to altar the rigid body, I think this method is used
  m_RigidBody->proceedToTranform(btTransform);
  
	btTransform tmp;
	tmp.setFromOpenGLMatrix(_m);
	//on récupère la matrice de transfo actuelle
	//m_RigidBody->getMotionState()->getWorldTransform(*m_Transfo);
	
	//on y ajoute la nouvelle transfo
	(*m_Transfo)*=tmp;
	//on met à jour bullet avec la nouvelle transfo
	//m_RigidBody->getMotionState()->setWorldTransform(*m_Transfo);	
	
	//m_RigidBody->proceedToTransform(*m_Transfo);
	//std::cout<<"active:"<<colObj->getActivationState()<<std::endl;
	reactivate();
}
void Bille::getMatrix(btScalar* _m) const
{
  // this method getWorld... is used by stepSimulation to update
  // the RigidBody in the physics engine
	//m_RigidBody->getMotionState()->getWorldTransform(*m_Transfo);
	
	m_Transfo->getOpenGLMatrix(_m);
}
I might have missed something. So let me know if there is nothing more happening and I'll continue to look.
lahabanaroom
Posts: 7
Joined: Mon Jan 11, 2010 11:42 pm

Re: [Newbie] kinematic objects transform and updating

Post by lahabanaroom »

the game loop is the display function in the main called by the glutmainloopfunction() and the idle func does a glutpostredisplay() the stepsimulation() is directly in the rendering function (display()) so it's sure that it happens every time...
I've added all my bodies to the world in the init func of the main.cc file...
I'll have a look to your suggests but I have to finish this project in a week and I've found how to deal with the gravity transform so I think I'll use that to finish it and after I'll try in the good way (with bttransform...)

Thank you very much for your help
Post Reply