rotate a physics object?

View previous topic View next topic Go down

rotate a physics object?

Post  arrogantb on Sun Aug 02, 2009 3:30 am

I'm trying to duplicate - and then both scale and rotate a "static" physics object with box bounds.

(The larger scale goal is to define some basic objects in blender - then programatically create a new scene using them)

The following code seems to work for me as far as scaling the duplicate object:

Code:


      SIO2object *selection = ( SIO2object * )sio2ResourceGet( sio2->_SIO2resource,
                                                SIO2_OBJECT,
                                                "object/floor1" );
      

      selection->_SIO2transform->loc->x += 180.0f;

      selection->_SIO2transform->scl->x = .6f;


      btRigidBody            *_btRigidBody;
      btCollisionShape      *_btCollisionShape;
      btDefaultMotionState  *_btDefaultMotionState;
      btTransform            _btTransform;
      btMatrix3x3            _btMatrix3x3;
      
      btVector3            inertia( 0.0, 0.0, 0.0 );
      
      _btCollisionShape = new btBoxShape( btVector3( selection->dim->x * selection->_SIO2transform->scl->x,
       selection->dim->y * selection->_SIO2transform->scl->y,
       selection->dim->z * selection->_SIO2transform->scl->z ) );
      
      _btTransform.setIdentity();
      
      _btTransform.setOrigin( btVector3( selection->_SIO2transform->loc->x,
                                selection->_SIO2transform->loc->y,
                                selection->_SIO2transform->loc->z ) );
      
      _btDefaultMotionState = new btDefaultMotionState( _btTransform );
      
      _btCollisionShape->calculateLocalInertia( (btScalar)selection->mass, inertia );
      
      _btRigidBody = new btRigidBody( (btScalar)selection->mass,
                             _btDefaultMotionState,
                             _btCollisionShape,
                             inertia );
      
      _btRigidBody->setAngularFactor( (btScalar)0.0 );
            
      sio2->_SIO2physic->_btSoftRigidDynamicsWorld->addRigidBody( _btRigidBody );

      selection->_btRigidBody = _btRigidBody;
      
      selection = sio2ObjectDuplicate( selection,
                              selection->_SIO2transform,
                              new_object, 1 );


But whenever I try to introduce rotation - I get strange results. It seems I can get the rotation - or the scaling to work in physics - but not both.

Is there a "right" way to do this? Am I barking up the wrong tree? Any help appreciated.

Currently using sio2 1.35.

arrogantb

Posts : 5
Join date : 2009-02-05

View user profile

Back to top Go down

Re: rotate a physics object?

Post  sio2interactive on Sun Aug 02, 2009 7:41 am

Check tutorial061...

_________________
SIO2 Interactive
Free Open Source 3D Game Engine for iPhone and iPod Touch
http://sio2interactive.com
avatar
sio2interactive

Posts : 1526
Join date : 2008-08-26
Age : 38
Location : Shanghai

View user profile http://sio2interactive.com

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum