How to refer to collision objects

View previous topic View next topic Go down

How to refer to collision objects

Post  Don Jaffa on Fri May 15, 2009 4:14 am

I was wondering if anyone knew how to refer to 'object0' and 'object1' in a collision callback? I have tried the original name of the SIO2object, but as the callback has to be declared before the sensor this doesn't work, I have tried
Code:

_SIO2sensor->_SIO2object1->name
and
Code:

_SIO2sensor->_SIO2object->_SIO2object1

...etc, but just can't work out how to properly call this. Anyone able to help?

Don Jaffa

Posts : 49
Join date : 2009-02-19

View user profile

Back to top Go down

Re: How to refer to collision objects

Post  sio2interactive on Fri May 15, 2009 4:33 am

its the _SIO2object->_btRigidBody handle...

_________________
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 : 37
Location : Shanghai

View user profile http://sio2interactive.com

Back to top Go down

Re: How to refer to collision objects

Post  Don Jaffa on Fri May 15, 2009 5:43 am

Sorry if I'm being incredibly stupid but I still can't work it out. my code atm is as follows:

Code:

void collision( void *_SIO2sensor )
{
   void **_SIO2object;
   SIO2object *obj;
   
   ++TEST_VAL;
   
   obj = ?????????????

   if( sio2IsEnabled( obj->flags, SIO2_OBJECT_ACTOR ) )
   {
      sio2PhysicRemoveObject( sio2->_SIO2physic, obj );
   }
   // SIO2object *_SIO2object;
   sio2ObjectFree( obj );
}

What would I need to put in the "????" section to remove object0?

Also a completely unrelated note: for the indie certificate it says you can still buy it if your application doesn't have a name - but can you buy it if you may well be using a different application as your final first game? I have had to port over all my code to new projects several times when i have done something that breaks the project, and the only reason I haven't bought the license yet is in case I have to do that again.

Thanks a lot Very Happy

Don Jaffa

Posts : 49
Join date : 2009-02-19

View user profile

Back to top Go down

Re: How to refer to collision objects

Post  Francescu on Fri May 15, 2009 8:55 am

The sensor structure has 2 placeholders for the 2 objects in collision:

SIO2object *_SIO2object0;
SIO2object *_SIO2object1;

So to refer to them in your callback:

obj = ((SIO2sensor) _SIO2sensor)->_SIO2object0; // object 0

or/and

obj = ((SIO2sensor) _SIO2sensor)->_SIO2object1; // object 1

The callback is called during collision so I'm not sure why you can't access the 2 SIO2 objects as you mentioned in your first post?


Last edited by Francescu on Fri May 15, 2009 11:15 am; edited 1 time in total

Francescu

Posts : 136
Join date : 2009-03-18

View user profile

Back to top Go down

Re: How to refer to collision objects

Post  Don Jaffa on Fri May 15, 2009 9:03 am

Hmm, well I can't put the callback within TemplateRender, as you 'cant have a function definition here' so I can't use the SIO2object name I gave it, And if I try the 'obj = _SIO2sensor->_SIO2object0;' one it get 'void is not a valid pointer-to-object type' :S

Don Jaffa

Posts : 49
Join date : 2009-02-19

View user profile

Back to top Go down

Re: How to refer to collision objects

Post  Francescu on Fri May 15, 2009 11:15 am

templateRender() is a function by itself - the callback is a function as well - of course, you can't have the callback function defined in templateRender() as this is not C legal. These 2 functions are defined separately in the same file at different placeholder...like templateLoading() is and others, etc...

As far as the (void *) compile error - you just have to cast the passed-in void *
to a type of SIO2sensor such as:

obj = ((SIO2sensor) _SIO2sensor)->_SIO2object0;

Francescu

Posts : 136
Join date : 2009-03-18

View user profile

Back to top Go down

Re: How to refer to collision objects

Post  Don Jaffa on Fri May 15, 2009 12:50 pm

Ty for the help, though I'm now getting a 'no matching function for call' error - seems to me that it can't recognize the sensor that called it (though i know it is being activated as TEST_VAL goes up during collision).

Due to the fact that all the possible collision objects are all duplicates I'm having to create the sensor during the duplication process of the objects, deep inside the template render process. Would this affect it at all?

Don Jaffa

Posts : 49
Join date : 2009-02-19

View user profile

Back to top Go down

Re: How to refer to collision objects

Post  Francescu on Fri May 15, 2009 1:31 pm

It would be helpful if you could post the code you have where you create the sensors, etc

Otherwise it is hard to see what's going on - maybe you have some race condition happening somewhere - hard to tell...Obviously you have to create separate sensors (SIO2sensor objects) for the object pairs you want collision to be reported back...

Francescu

Posts : 136
Join date : 2009-03-18

View user profile

Back to top Go down

Re: How to refer to collision objects

Post  Don Jaffa on Fri May 15, 2009 1:59 pm

Right, my code for the object duplication (and sensor creation) is as follows:

Code:

      if((COUNTER % 4) == 0)
      {   
         static unsigned int i = 0;
         
         char name[ SIO2_MAX_CHAR ];
         
         duplicate_object = !duplicate_object;
         
         // Create a name for our new object
         sprintf( name, "%s_%d", obstacle->name, i );
            
         // choose the spawn location
         obstacle->_SIO2transform->loc->x = ( (tmp_pos.x - 50) + (100 * (rand() / ((double)RAND_MAX + 1))));
         obstacle->_SIO2transform->loc->y = ( tmp_pos.y + 150);
         
         // Select the new object created...
         obstacle = sio2ObjectDuplicate( obstacle, obstacle->_SIO2transform, name, 1);
         
         SIO2sensor *_SIO2sensor = sio2SensorInitCollision( "sensor", obstacle, player, collision );
         
         ++i;
      }

On top of the 'no matching function for call' error in the callback (which is placed in front on TemplateRender, if I place it after I get errors on the sensor creation) I also get a warning 'unused variable 'SIO2sensor' - I assume this has something to do with it.

Don Jaffa

Posts : 49
Join date : 2009-02-19

View user profile

Back to top Go down

Re: How to refer to collision objects

Post  Francescu on Fri May 15, 2009 6:49 pm

Don Jaffa wrote:Right, my code for the object duplication (and sensor creation) is as follows:

Code:

      if((COUNTER % 4) == 0)
      {   
         static unsigned int i = 0;
         
         char name[ SIO2_MAX_CHAR ];
         
         duplicate_object = !duplicate_object;
         
         // Create a name for our new object
         sprintf( name, "%s_%d", obstacle->name, i );
            
         // choose the spawn location
         obstacle->_SIO2transform->loc->x = ( (tmp_pos.x - 50) + (100 * (rand() / ((double)RAND_MAX + 1))));
         obstacle->_SIO2transform->loc->y = ( tmp_pos.y + 150);
         
         // Select the new object created...
         obstacle = sio2ObjectDuplicate( obstacle, obstacle->_SIO2transform, name, 1);
         
         SIO2sensor *_SIO2sensor = sio2SensorInitCollision( "sensor", obstacle, player, collision );
         
         ++i;
      }

On top of the 'no matching function for call' error in the callback (which is placed in front on TemplateRender, if I place it after I get errors on the sensor creation) I also get a warning 'unused variable 'SIO2sensor' - I assume this has something to do with it.
Not really, the warning is legit as _SIO2sensor is not used - you're just initializing it in that code block and that's it...In fact, you don't need to set this variable at all apparently.

The sensor init name ("sensor") is always the same and I don't know if that can cause issues at runtime...

Francescu

Posts : 136
Join date : 2009-03-18

View user profile

Back to top Go down

Re: How to refer to collision objects

Post  Sponsored content


Sponsored content


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