Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Bullet Physics Changing RigidBody Position


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Medo3337   Members   -  Reputation: 680

Like
0Likes
Like

Posted 23 October 2012 - 06:04 PM

I'm trying to change the position of a RigidBody in Bullet Physics, here is the code that I am using for rendering:

dynamicsWorld->stepSimulation(1.f/60.f,10);

  //print positions of all objects
  for (int j=dynamicsWorld->getNumCollisionObjects()-1; j>=0 ;j--)
  {
   // -- For each RigidBody
   btCollisionObject* obj = dynamicsWorld->getCollisionObjectArray()[j];
   btRigidBody* body = btRigidBody::upcast(obj);
   if (body && body->getMotionState())
   {
	btTransform trans;
	body->getMotionState()->getWorldTransform(trans);
	model[j]->X = float(trans.getOrigin().getX());
	model[j]->Y = float(trans.getOrigin().getY());
	model[j]->Z = float(trans.getOrigin().getZ());


	//printf("world pos = %f,%f,%f\n",float(trans.getOrigin().getX()),float(trans.getOrigin().getY()),float(trans.getOrigin().getZ()));
   }

I want to be able to change the position (x, y, z), I tried the following but it doesn't work:
float newX = // Any new X value here
float newY = // Any new Y value here
float newZ = // Any new Z value here
int modelId = 1;
btCollisionObject* obj = dynamicsWorld->getCollisionObjectArray()[modelId];
btRigidBody* body = btRigidBody::upcast(obj);
if (body && body->getMotionState())
{
  btTransform trans;
  // -- Set new transform
  trans.setOrigin(btVector3(newX, newY, newZ));
  body->getMotionState()->setWorldTransform(trans);
}


Sponsor:

#2 zacaj   Members   -  Reputation: 643

Like
0Likes
Like

Posted 23 October 2012 - 06:34 PM

void translateBody(btRigidBody *body)
{
	    body->activate(true);
body->translate(d);
}
I use this in my engine to translate (note: not the same as just set) the positions of rigid bodies. To go to a specific position, I assume you'd just have to retrieve the original position first

#3 Medo3337   Members   -  Reputation: 680

Like
0Likes
Like

Posted 23 October 2012 - 08:26 PM

I tried that, but it doesn't transform correctly as expected.

Here is what I have tried:
float newX = // Any new X value here
float newY = // Any new Y value here
float newZ = // Any new Z value here
int modelId = 1;
btCollisionObject* obj = dynamicsWorld->getCollisionObjectArray()[modelId];
btRigidBody* body = btRigidBody::upcast(obj);
if (body && body->getMotionState())
{
  body->translate(btVector3(newX, newY, newZ));
  body->activate(true);
}

Edited by Medo3337, 23 October 2012 - 08:28 PM.


#4 erwincoumans   Members   -  Reputation: 272

Like
0Likes
Like

Posted 26 October 2012 - 11:10 AM

Instead of directly changing the position, it is better to change the velocity.

Here is some sample code to show how this can work
http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?p=29081#p29081




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS