Physics Simulation Forum

 

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Fri Aug 04, 2017 9:04 pm 
Offline

Joined: Sat Jul 29, 2017 9:19 pm
Posts: 21
I am having a bit of an issue with rotation, I want to spin a character on the spot to allow him to choose his direction of travel, but from the point of his creation as a rigidBody, I can find no methods to alter his orientation once created.

The btMotionstate allows me to gain access to the report data after a Physics step has occurred so I can comfortably alter his visual position and orientation for render, but as far as physics is concerned he still exists and points at the values he was given on creation.

Is there no other way to spin a character other than applying torque or setting Angular Velocity until orientation is where you want it?


Top
 Profile  
 
PostPosted: Sat Aug 05, 2017 4:10 am 
Offline

Joined: Thu Apr 14, 2016 3:44 pm
Posts: 44
use btCollisionObject::setWorldTransform if you want to alter position or orientation, example:
Code:
btQuaternion newrotation(0,0,0,1);
object->setWorldTransform(btTransform( newrotation, object->getWorldTransform().getOrigin()));


Top
 Profile  
 
PostPosted: Sat Aug 05, 2017 2:32 pm 
Offline

Joined: Sat Jul 29, 2017 9:19 pm
Posts: 21
thank you I'll try that.

Edit...thank you that worked a treat I have now created 2 small utility functions in my Physics Object class to make it a little cleaner to use in game.

As I found this hard to locate in a search I will post this here for any others like me who are new to Bullet.




Code:
// couple of useful utility methods to simplify the rotate and position of our physics objects
// these act on the Rigid body and therefore will re-position/orient an object while it is
// in the physics world, useful for restarting or teleporting.
   inline void SetOrientation(btQuaternion Rotation)
   {
      GetRigidBody()->setWorldTransform(btTransform(Rotation, GetRigidBody()->getWorldTransform().getOrigin()));
   }

   inline void SetPosition(btVector3 Position)
   {
      GetRigidBody()->setWorldTransform(btTransform(GetRigidBody()->getOrientation(), Position));
   }



Keywords Position, Rotation, Orientation.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: Exabot [Bot], Google [Bot] and 16 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group