Help With Custom Function in sio2_physic.cc
3 posters
Help With Custom Function in sio2_physic.cc
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:
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...
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
Re: Help With Custom Function in sio2_physic.cc
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?
What do you think?
Re: Help With Custom Function in sio2_physic.cc
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...
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
Re: Help With Custom Function in sio2_physic.cc
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%
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%
jj- Posts : 77
Join date : 2008-09-24
Re: Help With Custom Function in sio2_physic.cc
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...
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
Re: Help With Custom Function in sio2_physic.cc
errrrrrrrrr not cool... keep me posted if you find the cause of the problem...
Cheers,
Cheers,
Re: Help With Custom Function in sio2_physic.cc
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:
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...
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
Re: Help With Custom Function in sio2_physic.cc
I am successfully placing static objects with the following function:
HTH
Matt
- 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
Re: Help With Custom Function in sio2_physic.cc
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!
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
Similar topics
» Custom resources
» Tutorial 4 with custom model, lighting not right
» Tutorial#2 - Custom model doesn't respond to touch input
» Tutorial 4 with custom model, lighting not right
» Tutorial#2 - Custom model doesn't respond to touch input
Permissions in this forum:
You cannot reply to topics in this forum