Camera Collision Sensor
2 posters
Camera Collision Sensor
I'm trying to add a sensor for my camera and a certain object but when a collision happens there is no register. Here's the code I'm using:
SIO2object *block, *player;
block = ( SIO2object * )sio2ResourceGet( sio2->_SIO2resource, SIO2_OBJECT, "object/Block" );
player = ( SIO2object * )sio2ResourceGet( sio2->_SIO2resource, SIO2_CAMERA, "camera/Camera" );
sio2SensorInitCollision("hit block", player, block, checkBlockSensorCollision);
I know that I'm casting the camera to an object but I thought that would work because the camera class contains the btRigidBody class.
What's the correct way to do this?
SIO2object *block, *player;
block = ( SIO2object * )sio2ResourceGet( sio2->_SIO2resource, SIO2_OBJECT, "object/Block" );
player = ( SIO2object * )sio2ResourceGet( sio2->_SIO2resource, SIO2_CAMERA, "camera/Camera" );
sio2SensorInitCollision("hit block", player, block, checkBlockSensorCollision);
I know that I'm casting the camera to an object but I thought that would work because the camera class contains the btRigidBody class.
What's the correct way to do this?
calebcohoon- Posts : 15
Join date : 2009-07-25
Re: Camera Collision Sensor
No you can't do that... If you want to do something like that... modify the source to receive rigidbody instead of object....
Re: Camera Collision Sensor
Well I figured out a way to do it but it's a hack. Since I'm only going to have sensors for my camera this should work okay. I commented out some code in the sio2_physic.cc file:
This is probably not the best solution but it works. Thanks for your help.
- Code:
bool sio2PhysicCollisionCallback( btManifoldPoint &cp,
const btCollisionObject *colObj0,int partId0, int index0,
const btCollisionObject *colObj1,int partId1, int index1 )
{
unsigned int i = 0;
while( i != sio2->_SIO2resource->n_sensor )
{
SIO2sensor *_SIO2sensor = ( SIO2sensor * )sio2->_SIO2resource->_SIO2sensor[ i ];
if( _SIO2sensor->_SIO2sensorcollision )
{
/*if( ( _SIO2sensor->_SIO2object0->_btRigidBody == btRigidBody::upcast( colObj0 ) ||
_SIO2sensor->_SIO2object0->_btRigidBody == btRigidBody::upcast( colObj1 ) )
&&
( _SIO2sensor->_SIO2object1->_btRigidBody == btRigidBody::upcast( colObj0 ) ||
_SIO2sensor->_SIO2object1->_btRigidBody == btRigidBody::upcast( colObj1 ) ) )
{ _SIO2sensor->_SIO2sensorcollision( _SIO2sensor ); }*/
// just execute the sensor
_SIO2sensor->_SIO2sensorcollision( _SIO2sensor );
}
else if( _SIO2sensor->_SIO2sensorcontact )
{
_SIO2sensor->_SIO2object0 = ( SIO2object * )btRigidBody::upcast( colObj0 )->getUserPointer();
_SIO2sensor->_SIO2object1 = ( SIO2object * )btRigidBody::upcast( colObj1 )->getUserPointer();
_SIO2sensor->_SIO2sensorcontact( _SIO2sensor );
_SIO2sensor->_SIO2object0 = NULL;
_SIO2sensor->_SIO2object1 = NULL;
}
++i;
}
return false;
}
This is probably not the best solution but it works. Thanks for your help.
calebcohoon- Posts : 15
Join date : 2009-07-25
Re: Camera Collision Sensor
Hehe, no prob... that's why the source code is available so you can tweak it and adjust it to meet your requirements... However... I do think looking back at that function (which as been written like ages ago) that it would be more convenient to pass btRigidBody / btSoftBody handle more than the SIO2object...
I mark it down and will change it for the next version
Cheers,
I mark it down and will change it for the next version
Cheers,
Re: Camera Collision Sensor
Sounds good, thanks!
Btw, I got rid of the hack I previously posted and wrote a couple methods for checking object collision and object distance with the camera. Here's what I wrote:
Btw, I got rid of the hack I previously posted and wrote a couple methods for checking object collision and object distance with the camera. Here's what I wrote:
- Code:
SIO2sensor *sio2CameraSensorInitCollision( char *_name,
SIO2object *_SIO2object,
SIO2sensorcollision *_SIO2sensorcollision )
{
SIO2camera *currentCamera = sio2->_SIO2camera;
SIO2object *newObject = ( SIO2object * ) calloc( 1, sizeof( SIO2object ) );
// Set the new object's tranform, rigid, rad and name to the camera's
sio2StringCpy(newObject->name, currentCamera->name);
newObject->_SIO2transform = currentCamera->_SIO2transform;
newObject->_btRigidBody = currentCamera->_btRigidBody;
newObject->rad = currentCamera->rad;
SIO2sensor *_SIO2sensor = ( SIO2sensor * ) calloc( 1, sizeof( SIO2sensor ) );
sio2StringCpy( _SIO2sensor->name, _name );
_SIO2sensor->_SIO2object0 = newObject;
_SIO2sensor->_SIO2object1 = _SIO2object;
sio2ObjectEnableObjectCollisionCallback( newObject );
sio2ObjectEnableObjectCollisionCallback( _SIO2object );
_SIO2sensor->_SIO2sensorcollision = _SIO2sensorcollision;
sio2ResourceAdd( sio2->_SIO2resource,
SIO2_SENSOR,
( void * )_SIO2sensor );
return _SIO2sensor;
}
SIO2sensor *sio2CameraSensorInitDistance( char *_name,
SIO2object *_SIO2object,
float _threshold,
SIO2sensordistance *_SIO2sensordistance )
{
SIO2camera *currentCamera = sio2->_SIO2camera;
SIO2object *newObject = ( SIO2object * ) calloc( 1, sizeof( SIO2object ) );
// Set the new object's tranform and name to the camera's
sio2StringCpy(newObject->name, currentCamera->name);
newObject->_SIO2transform = currentCamera->_SIO2transform;
SIO2sensor *_SIO2sensor = ( SIO2sensor * ) calloc( 1, sizeof( SIO2sensor ) );
sio2StringCpy( _SIO2sensor->name, _name );
_SIO2sensor->_SIO2object0 = newObject;
_SIO2sensor->_SIO2object1 = _SIO2object;
_SIO2sensor->threshold = _threshold;
_SIO2sensor->_SIO2sensordistance = _SIO2sensordistance;
sio2ResourceAdd( sio2->_SIO2resource,
SIO2_SENSOR,
( void * )_SIO2sensor );
return _SIO2sensor;
}
calebcohoon- Posts : 15
Join date : 2009-07-25
Similar topics
» Simple Collision Sensor
» Close Camera Collision
» No intended collision with camera
» Sensor again
» Contact Sensor
» Close Camera Collision
» No intended collision with camera
» Sensor again
» Contact Sensor
Permissions in this forum:
You cannot reply to topics in this forum