Ray Testing

View previous topic View next topic Go down

Ray Testing

Post  william on Thu Sep 17, 2009 2:08 am

I've got some objects in my scene and I've got to do a ray test from one object to another and get to know what object has been hit.
I tried th raytest that comes with bullet and this successfully tells me if there was a hit or not, but doesn't tell me with wich object. How can I do this?

ps: I tried to post on the bullets forum, but no one has replied. Maybe someone here knows..

william

Posts : 15
Join date : 2009-09-09

View user profile

Back to top Go down

Re: Ray Testing

Post  sio2interactive on Thu Sep 17, 2009 4:08 am

Search this forum I post how to get the contact points...

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

View user profile http://sio2interactive.com

Back to top Go down

Re: Ray Testing

Post  william on Thu Sep 17, 2009 5:01 am

I did a little research but can't find the topic. Anyway I've see that the
Code:
btCollisionWorld::ClosestRayResultCallback ray( from, to );
has a member named m_hitPointWorld. With this I can search through my objects and find in wich one the hitPointWorld falls. It's strange that in Bullet there isn't a reference to a physic object that I can compare with a sio2 object.

Maybe I'm missing something..

william

Posts : 15
Join date : 2009-09-09

View user profile

Back to top Go down

Contact Points

Post  Francescu on Thu Sep 17, 2009 7:33 am

http://sio2interactive.forumotion.net/sio2-engine-f3/2d-shooter-t610.htm#3389

http://www.bulletphysics.com/mediawiki-1.5.8/index.php?title=Collision_Callbacks_and_Triggers

Francescu

Posts : 136
Join date : 2009-03-18

View user profile

Back to top Go down

Re: Ray Testing

Post  william on Thu Sep 17, 2009 9:10 am

This is good, but too much expensive for what I have to do: all I need is a ray test and if the ray hits something, get the CollisionObject from it.

Here's my solution:
Code:

btCollisionWorld::ClosestRayResultCallback ray( from, to );
sio2->_SIO2physic->_btSoftRigidDynamicsWorld->getCollisionWorld()->rayTest( from, to, ray );   
btCollisionObject* pColObject=ray.m_collisionObject;

//and then for every object
if( pColObject == myRefObject->_SIO2objectphysic->_btRigidBody)
{
  //I've found the sio2object who was hit by the ray
}

Thank you very much Very Happy

william

Posts : 15
Join date : 2009-09-09

View user profile

Back to top Go down

Re: Ray Testing

Post  Francescu on Thu Sep 17, 2009 9:49 am

Well, yes of course it is good enough if you don't need the contact points ;-)

Btw, you can get the SIO2object directly from the btCollisionObject.

( SIO2object * )( ( btRigidBody * )rayCallback.m_collisionObject )->getUserPointer();

Francescu

Posts : 136
Join date : 2009-03-18

View user profile

Back to top Go down

Re: Ray Testing

Post  william on Thu Sep 17, 2009 9:57 am

Yes could be useful but if I can avoid the calling time of the getUserPointer() it's better Wink

william

Posts : 15
Join date : 2009-09-09

View user profile

Back to top Go down

Re: Ray Testing

Post  Francescu on Thu Sep 17, 2009 10:48 am

william wrote:Yes could be useful but if I can avoid the calling time of the getUserPointer() it's better Wink
I'm not sure you would actually save much. In your case, you have to loop through your objects to compare pointers and derefence myRefObject where you can get the object pointer directly with that getter - tradeoffs. But hey, to each their own! Wink

Francescu

Posts : 136
Join date : 2009-03-18

View user profile

Back to top Go down

Re: Ray Testing

Post  william on Fri Sep 18, 2009 4:25 am

The Sio2object is a reference inside an another structure, wich we can call class Player for example, so the loop is necessesary:

Code:

//check raytest, if yes get collision body then..

for each player
if player->sio2object->_sio2objectPhysic == collisionbody
  dosomething

Otherwise yes, your're right!

william

Posts : 15
Join date : 2009-09-09

View user profile

Back to top Go down

Re: Ray Testing

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