FORUM CLOSED, PLEASE REGISTER AT FORUM.SIO2INTERACTIVE.COM
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Help With Custom Function in sio2_physic.cc

3 posters

Go down

Help With Custom Function in sio2_physic.cc Empty Help With Custom Function in sio2_physic.cc

Post  jj Wed Nov 19, 2008 5:01 am

Hey,

So I'm about 80% into completing, but running into problem.

I have added the following function inside of sio2_physic.cc in order to reposition a physic object originally (in Blender) set to a static triangle mesh ON THE FLY:

Code:

void sio2PhysicRepositionStaticObject( SIO2physic *_SIO2physic,
                       SIO2object *_SIO2object )
{
   int i = 0;
   
   while( i != _SIO2physic->_btDiscreteDynamicsWorld->getNumCollisionObjects() )
   {
      btCollisionObject *_btCollisionObject = _SIO2physic->_btDiscreteDynamicsWorld->getCollisionObjectArray()[ i ];
      btRigidBody *_btRigidBody = btRigidBody::upcast( _btCollisionObject );
      
      if( _btRigidBody == _SIO2object->_btRigidBody )
      {
         btTransform _btTransformer;
         
         _btTransformer.setFromOpenGLMatrix( ( btScalar * )_SIO2object->mat );
         
         _SIO2object->_btRigidBody->setMotionState( new btDefaultMotionState( _btTransformer ));
   
         break;
      }
      
      ++i;
   }
}

I'm running into a problem, however, when I try to call this function a 2ND TIME (or 3RD TIME).

Is there anything you see that would cause the physicObject->_btRigidBody to NOT update its location (based on the graphics OpenGL object->pos) a 2ND TIME (or 3RD TIME) ???

Any help or insight would be greatly appreciated! Thanks in advance...

jj

Posts : 77
Join date : 2008-09-24

Back to top Go down

Help With Custom Function in sio2_physic.cc Empty Re: Help With Custom Function in sio2_physic.cc

Post  sio2interactive Wed Nov 19, 2008 5:32 am

Actually take a look at: sio2PhysicReset function, but that makes me think that maybe I should provide this function on an individual object basis...

What do you think?
sio2interactive
sio2interactive

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

http://sio2interactive.com

Back to top Go down

Help With Custom Function in sio2_physic.cc Empty Re: Help With Custom Function in sio2_physic.cc

Post  jj Wed Nov 19, 2008 5:39 am

Ya, perhaps man,

After looking at the bullet physics library, Erwin comments that an object flagged as STATIC does NOT update it's motionState like an object that is "dynamic" or "kinematic".

SOMEHOW, I figured out how to UPDATE the location (position:x, y, z) of the physics collision object that came out of Blender as a STATIC body (with the function I wrote above).

However, it APPEARS that when I call this function a 2ND TIME, something does not update correctly (as it did the 1ST time I call this). The GLmatrix DOES UPDATE in the graphical world no matter how many times I update, but the physics world does NOT seem to stay in SYNC.

This might be because of other programming I have going on... I'm looking into this now...

Let me know your thoughts. Many thanks...

jj

Posts : 77
Join date : 2008-09-24

Back to top Go down

Help With Custom Function in sio2_physic.cc Empty Re: Help With Custom Function in sio2_physic.cc

Post  jj Wed Nov 19, 2008 5:52 am

Hmm... ok, upon closer inspection, it appears that this function DOES work each time that it is called...

I will repost a reply here if it turns out that indeed my custom function does not work when called more than 1x

I have posted another topic which seems to be another 5% Smile

jj

Posts : 77
Join date : 2008-09-24

Back to top Go down

Help With Custom Function in sio2_physic.cc Empty Re: Help With Custom Function in sio2_physic.cc

Post  jj Wed Nov 19, 2008 6:14 am

Damn,

It still looks like there's a collision object problem with calling my Custom RepositionStaticObject function a 2ND TIME.

I will look at my other logic and see if the problem is in there... I assume it's in the Bullet calls, because the graphics world updates accordingly, but the physics object don't seem to be repositioned in the places I expect based on my Custom function...

jj

Posts : 77
Join date : 2008-09-24

Back to top Go down

Help With Custom Function in sio2_physic.cc Empty Re: Help With Custom Function in sio2_physic.cc

Post  sio2interactive Wed Nov 19, 2008 6:42 am

errrrrrrrrr not cool... keep me posted if you find the cause of the problem...


Cheers,
sio2interactive
sio2interactive

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

http://sio2interactive.com

Back to top Go down

Help With Custom Function in sio2_physic.cc Empty Re: Help With Custom Function in sio2_physic.cc

Post  jj Wed Nov 19, 2008 7:07 am

Could it be because I appear to be allocating a "new" btMotionState, and not freeing it?

When I change my code to the following, I get a fatal error:

Code:

void sio2PhysicRepositionStaticObject( SIO2physic *_SIO2physic,
                       SIO2object *_SIO2object )
{
   int i = 0;
   
   while( i != _SIO2physic->_btDiscreteDynamicsWorld->getNumCollisionObjects() )
   {
      btCollisionObject *_btCollisionObject = _SIO2physic->_btDiscreteDynamicsWorld->getCollisionObjectArray()[ i ];
      btRigidBody *_btRigidBody = btRigidBody::upcast( _btCollisionObject );
      
      if( _btRigidBody == _SIO2object->_btRigidBody )
      {
         btTransform _btTransformer;
         
         _btTransformer.setFromOpenGLMatrix( ( btScalar * )_SIO2object->mat );
         
         btDefaultMotionState *_myMotionState = new btDefaultMotionState( _btTransformer );
         
         _SIO2object->_btRigidBody->setMotionState( _myMotionState );
         
         delete _myMotionState; //attempts to fix
         _myMotionState = NULL; // these two lines give a CRASH
   
         break;
      }
      
      ++i;
   }
}

Do I need to somehow tell Bullet engine to "forget" the btTransform, btMotionState in this function once I set the physics->_btRigidBody to a new x, y, z ?? so that when this is called again, an entirely new transform/motionState takes place?

I guess I'm a little confused with the C++ and Bullet calls here...and the difference between btTransforms, worldTransforms, motionStates, etc...

jj

Posts : 77
Join date : 2008-09-24

Back to top Go down

Help With Custom Function in sio2_physic.cc Empty Re: Help With Custom Function in sio2_physic.cc

Post  matt Wed Nov 19, 2008 1:50 pm

I am successfully placing static objects with the following function:

Code:
void Mesh::setPosition( const v3f& pos ) {
   if( sio2IsEnabled( object->flags, SIO2_OBJECT_ACTOR ) ) {
      // Bullet has control over the objects transformation, so only the objects matrix is correctly filled.
      // Create a btTransform object from the matrix:
      btTransform transform;
      transform.setFromOpenGLMatrix( object->mat );
      // Update the origin:
      btVector3 origin;
      origin.setX( pos.x );
      origin.setY( pos.y );
      origin.setZ( pos.z );
      transform.setOrigin( origin );
      // Update the object's transformation:
      object->_btRigidBody->setWorldTransform( transform );
      // And move this updated matrix back into the SIO2 matrix:
      transform.getOpenGLMatrix( object->mat );
      // Keep SIO2s transformation attributes updated too so that e.g. culling keeps working:
      object->pos->x = pos.x;
      object->pos->y = pos.y;
      object->pos->z = pos.z;
      btQuaternion rot = transform.getRotation();
      object->rot->x = rot.x();
      object->rot->y = rot.y();
      object->rot->z = rot.z();
   } else {
      // Bullet not involved, simply update the position on the SIO2object:
      object->pos->x = pos.x;
      object->pos->y = pos.y;
      object->pos->z = pos.z;
      sio2ObjectBindMatrix( object );
   }
}

HTH
Matt

matt

Posts : 155
Join date : 2008-09-30

http://elfrun.net

Back to top Go down

Help With Custom Function in sio2_physic.cc Empty Re: Help With Custom Function in sio2_physic.cc

Post  jj Wed Nov 19, 2008 2:58 pm

Matt,

Does

// Update the object's transformation:
object->_btRigidBody->setWorldTransform( transform );

work for a static body? According to Erwin's comments, it appears not.

But I'll give your code a try. Thanks!

jj

Posts : 77
Join date : 2008-09-24

Back to top Go down

Help With Custom Function in sio2_physic.cc Empty Re: Help With Custom Function in sio2_physic.cc

Post  Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

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