Page 1 of 1

Help, Question about Moving Rigidbody Object

Posted: Wed Jan 07, 2015 7:58 pm
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

Re: Help, Question about Moving Rigidbody Object

Posted: Thu Jan 08, 2015 7:51 pm
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.