Collision system
+6
freakTheMighty
Bazzle
jj
matt
sio2interactive
jlperan
10 posters
Collision system
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!
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
Re: Collision system
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
If you want this to be executed once, simply destroy the sensor in that callback function.
In example:
In addition make sure that you call sio2ResourceEvaluateSensors inside your rendering loop.
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.
Re: Collision system
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
Cheers,
Cheers,
Re: Collision system
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
Best,
Matt
Re: Collision system
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?
Re: Collision system
I'm not sure how you're "linking to a callback" here...
jj- Posts : 77
Join date : 2008-09-24
Re: Collision system
Try this pseudo code
...
...
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 );
...
...
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 );
Re: Collision system
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?
However, when it bounces 1 time, I get 4 NSlog messages. Is something wrong?
jj- Posts : 77
Join date : 2008-09-24
Re: Collision system
Good question, I don't know im simply wrapping around Bullets callback here... checkout the Bullet specs. on that... and keep me posted...
Re: Collision system
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
Re: Collision system
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...
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...
tutorial is on the way for this one...
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
second that
Can anyone contribute more examples of implementing sensors?
freakTheMighty- Posts : 12
Join date : 2009-03-05
Collision sensors
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.
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
Re: Collision system
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:
And my callback functions are defined like this:
And:
And just make sure that you enable the sensors in templateRender() function:
--yarri
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
Re: Collision system
Yeah, I forgot to thank you and your code example was really helpful
Thanks a lot.
Thanks a lot.
Bobshrak- Posts : 2
Join date : 2009-06-22
Re: Collision system
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
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
vikthered- Posts : 25
Join date : 2009-06-25
Re: Collision system
Just get the normal of the contact point(s)... I already post the code on the forum...
Re: Collision system
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
Re: Collision system
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!?
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
Similar topics
» Outstanding System
» 28 FPS with particle system added to Tutorial06?
» How many animated objects can I have with the new animation system?
» Simple Transform Animation System
» Particles System with a little memory leak...
» 28 FPS with particle system added to Tutorial06?
» How many animated objects can I have with the new animation system?
» Simple Transform Animation System
» Particles System with a little memory leak...
Permissions in this forum:
You cannot reply to topics in this forum