Help, Question about Moving Rigidbody Object

Post Reply
srapro
Posts: 1
Joined: Wed Jan 07, 2015 7:32 pm

Help, Question about Moving Rigidbody Object

Post by srapro »

hi,
I tried to animate 'particles on moving screen'.
but, the movement of particles looks very strange.
the particles does not move with the moving screen.

Please check my code / attached files and let me know how to solve it.

Thanks :P

Code: Select all

 // Moving Screen

	for (int i=1; i<bar_numX+bar_numY+1;i++)    {

   btCollisionObject* colObj = m_dynamicsWorld->getCollisionObjectArray()[i];
   btRigidBody*	body=btRigidBody::upcast(colObj);

  btTransform trans;
  
   btVector3 p1;   
  p1 = body->getCenterOfMassPosition();

  trans.setIdentity();
  trans.setOrigin(btVector3(p1.getX()+0.01,p1.getY(),p1.getZ()));
  
  body->getMotionState()->setWorldTransform(trans);
  body->setCenterOfMassTransform(trans);
 
   } 
Image
Attachments
OreAnalyseB_Code.zip
code full
(7.21 KiB) Downloaded 219 times
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: Help, Question about Moving Rigidbody Object

Post by drleviathan »

Distance = Rate * Time

After looking at the code snippet my first theory is that you aren't computing the correct position step. The distance to move all of the objects depends on the real timeStep of your frame which depends on your frame rate. For a steady drift at 1.0 m/sec along the x-direction your code would look more like this:

Code: Select all

    // Moving Screen
    btVector3 driftVelocity(1.0f, 0.0f, 0.0f);
    btVector3 deltaPosition = timeStep * driftVelocity;

    for (int i=1; i<bar_numX+bar_numY+1;i++)    {
        btCollisionObject* colObj = m_dynamicsWorld->getCollisionObjectArray()[i];
        btRigidBody*   body=btRigidBody::upcast(colObj);

        btTransform trans;
        trans.setIdentity();
        trans.setOrigin(body->getCenterOfMassPosition() + deltaPosition);
 
        body->setWorldTransform(trans);
    } 
Note, unless you're doing something fancy with the body's MotionState (i.e. using a derived class with special handling) I don't think you need to set the body's transform through it -- you can just call btCollisionObject::setWorldTransform().

Note: I don't understand what you're doing with bar_numX + bar_numY + 1, but I assume you do.
Post Reply