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.

Collision system

+6
freakTheMighty
Bazzle
jj
matt
sio2interactive
jlperan
10 posters

Go down

Collision system Empty Collision system

Post  jlperan Thu Oct 16, 2008 5:00 am

First of all I want to congratulate you for this excellent engine.

And then the question. Can you post some instructions to work with the collision system?

I want to execute a code in case a collision has been detected and I´m a little stuck in this.

Thank you very much!

jlperan

Posts : 41
Join date : 2008-10-10

Back to top Go down

Collision system Empty Re: Collision system

Post  sio2interactive Thu Oct 16, 2008 6:05 am

For that you need to use a sensor, actually a tutorial is on the way for this one... but this should be pretty easy to figure it out...

Use this function to create a collision sensor, and link to a callback

Code:

SIO2sensor *sio2SensorInitCollision( char             *_name,
                            SIO2object          *_SIO2object0,
                            SIO2object          *_SIO2object1,
                            SIO2sensorcollision *_SIO2sensorcollision );

If you want this to be executed once, simply destroy the sensor in that callback function.


In example:

Code:


// The collision sensor callback
void touchground( void )
{
   // Destroy the sensor so it will only be executed once.
   SIO2sensor *_SIO2sensor = ( SIO2sensor * )sio2ResourceGet( sio2->_SIO2resource,
                                     SIO2_SENSOR,
                                     "collision_sensor" );
   _SIO2sensor = sio2SensorFree( _SIO2sensor );
   
   //printf("touch_ground\n");
}

In addition make sure that you call sio2ResourceEvaluateSensors inside your rendering loop.
sio2interactive
sio2interactive

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

http://sio2interactive.com

Back to top Go down

Collision system Empty Re: Collision system

Post  jlperan Thu Oct 16, 2008 7:08 am

I´ll give it a try.

Thanks!

jlperan

Posts : 41
Join date : 2008-10-10

Back to top Go down

Collision system Empty Re: Collision system

Post  sio2interactive Thu Oct 16, 2008 8:35 am

No prob, lemme know if everything is allright... another thing is... (that I forgot to mention), collision sensor will of course work with physic... so make sure that you master tutorial06 before trying that one out Wink

Cheers,
sio2interactive
sio2interactive

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

http://sio2interactive.com

Back to top Go down

Collision system Empty Re: Collision system

Post  matt Thu Oct 16, 2008 1:16 pm

We already discussed user data on objects. Now in this case I think it would also be nice if one could provide userdata to a sensor and if the triggering sensor would be handed over to the callback. That way, one could have one callback for multiple sensors but still distinguish them if need-be / take further actions, which would mean maximum flexibility.

Best,
Matt

matt

Posts : 155
Join date : 2008-09-30

http://elfrun.net

Back to top Go down

Collision system Empty Re: Collision system

Post  sio2interactive Thu Oct 16, 2008 4:45 pm

I could always add a void* that should be casted as SIO2sensor, this way you can get back all the data related to this sensor, what do you think?
sio2interactive
sio2interactive

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

http://sio2interactive.com

Back to top Go down

Collision system Empty Re: Collision system

Post  jj Mon Oct 20, 2008 8:04 pm

I'm not sure how you're "linking to a callback" here...

jj

Posts : 77
Join date : 2008-09-24

Back to top Go down

Collision system Empty Re: Collision system

Post  sio2interactive Mon Oct 20, 2008 8:41 pm

Try this pseudo code Wink

...
...

void collision( void *_SIO2sensor )
{

}

...
...

SIO2sensor *_SIO2sensor = sio2SensorInitCollision( "mysensor",
<SIO2object1>,
<SIO2object2>,
collision );

In your rendering loop, and in this example make sure that the physic
state is set to SIO2_PHYSIC_PLAY:

sio2ResourceEvaluateSensors( sio2->_SIO2resource );
sio2interactive
sio2interactive

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

http://sio2interactive.com

Back to top Go down

Collision system Empty Re: Collision system

Post  jj Mon Oct 20, 2008 9:02 pm

got it. I run an NSLog message on the callback, I want a callback everytime the ball bounces.

However, when it bounces 1 time, I get 4 NSlog messages. Is something wrong?

jj

Posts : 77
Join date : 2008-09-24

Back to top Go down

Collision system Empty Re: Collision system

Post  sio2interactive Mon Oct 20, 2008 9:39 pm

Good question, I don't know im simply wrapping around Bullets callback here... checkout the Bullet specs. on that... and keep me posted... Wink
sio2interactive
sio2interactive

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

http://sio2interactive.com

Back to top Go down

Collision system Empty Re: Collision system

Post  jlperan Thu Oct 23, 2008 9:36 am

So if I have 100 objects in the scene that could have a collision, should I have to create a sensor for each combination of pairs of objects?

jlperan

Posts : 41
Join date : 2008-10-10

Back to top Go down

Collision system Empty Re: Collision system

Post  sio2interactive Thu Oct 23, 2008 6:24 pm

Well in your case I would suggest you to override the sio2PhysicCollisionCallback and replace it by your own, and tag your objects that you want to have callbacks from manually using: _btRigidBody->setCollisionFlags( btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK );

There's a new sensor called SIO2sensorcontact, that return the SIO2object pointer of 2 objects previously marked to receive CF_CUSTOM_MATERIAL_CALLBACK, but its going to be out with the next revision...
sio2interactive
sio2interactive

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

http://sio2interactive.com

Back to top Go down

Collision system Empty tutorial is on the way for this one...

Post  Bazzle Mon Feb 23, 2009 4:56 pm

Hi. Given that the tutorial is not out yet for utilizing SIO2sensor within the collision system, could you kindly give us more code examples. Thanks!

Bazzle

Posts : 1
Join date : 2009-02-16

Back to top Go down

Collision system Empty Re: Collision system

Post  sio2interactive Mon Feb 23, 2009 5:33 pm

Got it, I add it in my TODO list Wink
sio2interactive
sio2interactive

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

http://sio2interactive.com

Back to top Go down

Collision system Empty second that

Post  freakTheMighty Thu Apr 09, 2009 12:19 am

Can anyone contribute more examples of implementing sensors?

freakTheMighty

Posts : 12
Join date : 2009-03-05

Back to top Go down

Collision system Empty Collision sensors

Post  Bobshrak Fri Jun 26, 2009 4:09 am

Hi everyone,

I'm trying to get Collision Sensors working in my project but I'm having some difficulties...

I can't find sio2ResourceEvaluateSensors(). It seems that it's not in the framework anymore. Instead I used sio2SensorEvaluate() inside my rendering loop but the callback method is never called...

I set the physic, I set the object in Blender on Static, I initialized the Collision Sensor... Do I need to do something else ?

Can someone post some code working or explain how to use Collision Sensors in the actual revision ?

Thanks.

Bobshrak

Posts : 2
Join date : 2009-06-22

Back to top Go down

Collision system Empty Re: Collision system

Post  yarri Fri Jun 26, 2009 10:36 pm

Hi, I'm using collision and distance sensors with SIO2 1.3.5. I'm a little worried about the performance impact of using a dozen or so of these in my game and wonder if there's a better way?

Using the template.mm as a base, in the templateLoading() function add the sensors like this:
Code:

SIO2object *player = sio2ResourceGetObject( sio2->_SIO2resource, "object/player" );
SIO2object *target = sio2ResourceGetObject( sio2->_SIO2resource, "object/target" );
SIO2object *bogie = sio2ResourceGetObject( sio2->_SIO2resource, "object/bogie" );

// Set up a distance sensor on the target
sio2SensorInitDistance("target_dist", player, target, 4.0f, mySIO2sensordistance);

// Set up a collision sensor on the target
sio2SensorInitCollision("bogie_colide", player, bogie, mySIO2sensorcollision);

And my callback functions are defined like this:
Code:

void mySIO2sensordistance ( void *_ptr ,float _dist)
{
   SIO2sensor *sender = (SIO2sensor *)_ptr;
   if (!sio2StringCmp(sender->name, "target_dist")){
      printf("Sensor target_dist!\n");
   }
}

And:
Code:

void mySIO2sensorcollision ( void *_ptr )
{
   SIO2sensor *sender = (SIO2sensor *)_ptr;
   if (!sio2StringCmp(sender->name, "bogie_colide")){
      printf("Sensor bogie_collied!\n");
   }
}

And just make sure that you enable the sensors in templateRender() function:
Code:

sio2ResourceRender( sio2->_SIO2resource, sio2->_SIO2window, sio2->_SIO2camera,
         SIO2_RENDER_SOLID_OBJECT | SIO2_RENDER_CLIPPED_OBJECT | SIO2_EVALUATE_SENSOR );

--yarri

yarri

Posts : 81
Join date : 2009-04-10

Back to top Go down

Collision system Empty Re: Collision system

Post  calebcohoon Sun Jul 26, 2009 4:44 pm

Thanks yarri for the code example. Smile

calebcohoon

Posts : 15
Join date : 2009-07-25

Back to top Go down

Collision system Empty Re: Collision system

Post  Bobshrak Sun Jul 26, 2009 4:59 pm

Yeah, I forgot to thank you and your code example was really helpful Smile

Thanks a lot.

Bobshrak

Posts : 2
Join date : 2009-06-22

Back to top Go down

Collision system Empty Re: Collision system

Post  vikthered Thu Aug 06, 2009 5:40 pm

Hi,

I have a terrain object with hills/slopes and a player object (car) in third person camera mode. I set the player to be a Rigid Body. I want to rotate my player object whenever it comes in contact with a hill so that it would appear as though the car is going upslope. (and similarly for downslope).

My doubt is, if i set up a sensor to detect collisions between the terrain object and the player object is there a way for me to find out that player has collided with a hill/slope? Or do i have to model the hill/slope as a separate object?

What i thought is, if i could somehow manage to get the angle at which the collision occurred, i could perhaps do the rotation/transformation of my player object. I dont know if this is the right way. Maybe you guys could point me to the right direction

Thanks Smile

vikthered

Posts : 25
Join date : 2009-06-25

Back to top Go down

Collision system Empty Re: Collision system

Post  sio2interactive Thu Aug 06, 2009 5:42 pm

Just get the normal of the contact point(s)... I already post the code on the forum...
sio2interactive
sio2interactive

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

http://sio2interactive.com

Back to top Go down

Collision system Empty Re: Collision system

Post  vikthered Fri Aug 07, 2009 12:28 am

I'm really sorry to trouble you but can you post the link where you've written the code. I couldnt find it

vikthered

Posts : 25
Join date : 2009-06-25

Back to top Go down

Collision system Empty Re: Collision system

Post  vikthered Fri Aug 07, 2009 1:26 am


vikthered

Posts : 25
Join date : 2009-06-25

Back to top Go down

Collision system Empty Re: Collision system

Post  vikthered Fri Aug 07, 2009 2:29 pm

Hi,

This is what i'm trying to do. After i get the normals of all the contact points, i'm calculating the average normal and checking the angle between the average normal and the current orientation of the btRigidBody object (car). I dont know if this is the right way. Also, since i dont have an iPhone, i'm concerned if these calculations will be expensive on the device!?

Code:

void mySIO2sensorcollision ( void *_ptr )
{
   btRigidBody *_btRigidBody = NULL;
   btVector3 avgNormal(0,0,0);
   
   unsigned int i = 0,
   j;
   
   while( i != sio2->_SIO2physic->_btSoftRigidDynamicsWorld->getDispatcher()->getNumManifolds() )
   {
      btPersistentManifold *_btPersistentManifold = sio2->_SIO2physic->_btSoftRigidDynamicsWorld->getDispatcher()->getManifoldByIndexInternal( i );
      
      j = 0;
      while( j != _btPersistentManifold->getNumContacts() )
      {
                      _btRigidBody = ( btRigidBody * )_btPersistentManifold->getBody0();
         
         _btPersistentManifold->getContactPoint(j).m_localPointA.normalize();
         
            avgNormal += _btPersistentManifold->getContactPoint(j).m_localPointA;
         
         ++j;
      }
      
      
      avgNormal /= j;
      
      
      ++i;
   }
   
   
   printf("\nAngle = %d", _btRigidBody->getOrientation().getAxis().angle(avgNormal));
   
}

vikthered

Posts : 25
Join date : 2009-06-25

Back to top Go down

Collision system Empty Re: Collision system

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