Problems solved with object duplication
3 posters
Problems solved with object duplication
I just wanted to share my thoughs and discoveries about object duplication in SIO2. The truth is SIO2ObjectDuplicate works fine but I didnīt understand the process so I was failing in my implementation. Worst of all is solutions were dispersed in the forums and after reading a lot I want to put it together and apologize for my post asking for a solution.
I Hope this useful to someone.
Cheers.
- When you duplicate an object, the process has to be the following:
- Code:
// Select the object to copy
SIO2object *_ObjectOrigin = ( SIO2object * )sio2ResourceGet( sio2->_SIO2resource, SIO2_OBJECT, ObjectName );
// Duplication
SIO2object *_Object = sio2ObjectDuplicate(_ObjectOrigin, NewObjectName);
// Position, rotation, etc modifications should be here.
_Object->pos->x = 0.0;
_Object->pos->y = 0.0;
_Object->pos->z = 0.0;
// Do not forget this after you apply a change to the object before physics.
sio2ObjectBindMatrix( _Object );
// Add it to physics simulation.
if( sio2ObjectMapBuffer( _ObjectOrigin ) )
{
_Object->buf = _ObjectOrigin->buf;
sio2PhysicAddRigidBody( sio2->_SIO2physic,
_Object );
_Object->buf = NULL;
sio2ObjectUnmapBuffer( _ObjectOrigin );
}
The order is important. After you add an object to the physics simulation, the position and movement is controlled by physics so any change to pos, rot or anything will be invalid. - Any change you want to apply to the object should be done through bullet. Examples are: _Object->_btRigidBody->applyImpulse(_impulse, _rel_pos) or _Object->_btRigidBody->setLinearVelocity(_impulse)
Donīt try to change the position through _Object->pos->x = 0.0, that will not work. - sio2ObjectBindMatrix( _Object ) shoud be executed after a change to the object but that will be invalid if youīve added it to the physics simulation.
- If you want to change the position of an object after physics, probably the best way is by deleting it from physics, change the position, executing sio2ObjectBindMatrix( _Object ) and adding it again to the physics simulation.
- Activation State. You have to set the status of an object in physics. I donīt understand this but if you set it to DISABLE_DEACTIVATION the object will not move so before apply an impulse use _Object->_btRigidBody->forceActivationState(true) or _Object->_btRigidBody->setActivationState(ACTIVE_TAG). The first one will force the activation state, so be carefull.
I Hope this useful to someone.
Cheers.
Re: Problems solved with object duplication
When you duplicate an object, the process has to be the following:
>> I post similar code somewhere on the forum a while ago... I don't understand how come people still have problem with that... anyway tks for refreshing our memory
Any change you want to apply to the object should be done through bullet. Examples are: _Object->_btRigidBody->applyImpulse(_impulse, _rel_pos) or _Object->_btRigidBody->setLinearVelocity(_impulse)
>> I suggest to use setLinearVelocity more than applyImpulse, as applyImpulse will ignore the gravitational vector.
Donīt try to change the position through _Object->pos->x = 0.0, that will not work.
>> Bullet is handling the matrix
sio2ObjectBindMatrix( _Object ) shoud be executed after a change to the object but that will be invalid if youīve added it to the physics simulation.
>> Im using the current matrix in order to pass the right information (the origin matrix) to Bullet instead the matrix will be blank and unexpected results will follow...
Activation State. You have to set the status of an object in physics. I donīt understand this but if you set it to DISABLE_DEACTIVATION the object will not move so before apply an impulse use _Object->_btRigidBody->forceActivationState(true) or _Object->_btRigidBody->setActivationState(ACTIVE_TAG). The first one will force the activation state, so be carefull.
>> Ok that might be a bug, I see this behavior before inside sio2ObjectRender make sure that you have the following lines:
>> I post similar code somewhere on the forum a while ago... I don't understand how come people still have problem with that... anyway tks for refreshing our memory
Any change you want to apply to the object should be done through bullet. Examples are: _Object->_btRigidBody->applyImpulse(_impulse, _rel_pos) or _Object->_btRigidBody->setLinearVelocity(_impulse)
>> I suggest to use setLinearVelocity more than applyImpulse, as applyImpulse will ignore the gravitational vector.
Donīt try to change the position through _Object->pos->x = 0.0, that will not work.
>> Bullet is handling the matrix
sio2ObjectBindMatrix( _Object ) shoud be executed after a change to the object but that will be invalid if youīve added it to the physics simulation.
>> Im using the current matrix in order to pass the right information (the origin matrix) to Bullet instead the matrix will be blank and unexpected results will follow...
Activation State. You have to set the status of an object in physics. I donīt understand this but if you set it to DISABLE_DEACTIVATION the object will not move so before apply an impulse use _Object->_btRigidBody->forceActivationState(true) or _Object->_btRigidBody->setActivationState(ACTIVE_TAG). The first one will force the activation state, so be carefull.
>> Ok that might be a bug, I see this behavior before inside sio2ObjectRender make sure that you have the following lines:
- Code:
else if( !_SIO2object->_btRigidBody->isStaticObject() &&
( _SIO2object->_btRigidBody->getActivationState() == DISABLE_DEACTIVATION ||
_SIO2object->_btRigidBody->getActivationState() == ACTIVE_TAG ) )
Re: Problems solved with object duplication
>> I post similar code somewhere on the forum a while ago... I don't understand how come people still have problem with that... anyway tks for refreshing our memory Wink
Thatīs probably because search in forum is not working. To search here I use google: "sio2DuplicateObject site:forum.sio2interactive.com"
Re: Problems solved with object duplication
Dude Im working on a pretty limited budget here that's why Im using a free forum solution
Please notice the "Contribution" button at the bottom of this page
Cheers,
Please notice the "Contribution" button at the bottom of this page
Cheers,
Re: Problems solved with object duplication
No problem, thatīs not your fault. Itīs forumotionīs.
Perhaps I can provide you with the hosting. How many bandwidth do you use per month?
Perhaps I can provide you with the hosting. How many bandwidth do you use per month?
Re: Problems solved with object duplication
The search does work if you choose advanced search, and select the search terms button.
Best,
-joshua
Best,
-joshua
meteors- Posts : 241
Join date : 2008-11-08
Location : Sunny Florida
Similar topics
» Testing and failing Object duplication
» md2 duplication
» Fading an object at runtime
» Bitmap Font Generator
» Can't run sio2 powered apps on device
» md2 duplication
» Fading an object at runtime
» Bitmap Font Generator
» Can't run sio2 powered apps on device
Permissions in this forum:
You cannot reply to topics in this forum