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.

Problems solved with object duplication

3 posters

Go down

Problems solved with object duplication Empty Problems solved with object duplication

Post  iphoniac Mon Jan 12, 2009 2:35 am

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.

  • 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.

iphoniac

Posts : 62
Join date : 2008-12-11

http://thecaveaniphonegame.blogspot.com/

Back to top Go down

Problems solved with object duplication Empty Re: Problems solved with object duplication

Post  sio2interactive Mon Jan 12, 2009 2:55 am

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 Wink


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 Wink


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 ) )

sio2interactive
sio2interactive

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

http://sio2interactive.com

Back to top Go down

Problems solved with object duplication Empty Re: Problems solved with object duplication

Post  iphoniac Mon Jan 12, 2009 3:59 am

>> 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"

iphoniac

Posts : 62
Join date : 2008-12-11

http://thecaveaniphonegame.blogspot.com/

Back to top Go down

Problems solved with object duplication Empty Re: Problems solved with object duplication

Post  sio2interactive Mon Jan 12, 2009 4:19 am

Dude Im working on a pretty limited budget here that's why Im using a free forum solution Wink

Please notice the "Contribution" button at the bottom of this page Wink

Cheers,
sio2interactive
sio2interactive

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

http://sio2interactive.com

Back to top Go down

Problems solved with object duplication Empty Re: Problems solved with object duplication

Post  iphoniac Mon Jan 12, 2009 6:35 am

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?

iphoniac

Posts : 62
Join date : 2008-12-11

http://thecaveaniphonegame.blogspot.com/

Back to top Go down

Problems solved with object duplication Empty Re: Problems solved with object duplication

Post  meteors Mon Jan 12, 2009 7:27 am

The search does work if you choose advanced search, and select the search terms button.


Best,
-joshua
meteors
meteors

Posts : 241
Join date : 2008-11-08
Location : Sunny Florida

Back to top Go down

Problems solved with object duplication Empty Re: Problems solved with object duplication

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