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.

Ray Testing

3 posters

Go down

Ray Testing Empty Ray Testing

Post  william 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

Back to top Go down

Ray Testing Empty Re: Ray Testing

Post  sio2interactive Thu Sep 17, 2009 4:08 am

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

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

http://sio2interactive.com

Back to top Go down

Ray Testing Empty Re: Ray Testing

Post  william 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

Back to top Go down

Ray Testing Empty Re: Ray Testing

Post  william 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

Back to top Go down

Ray Testing Empty Re: Ray Testing

Post  Francescu 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

Back to top Go down

Ray Testing Empty Re: Ray Testing

Post  william 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

Back to top Go down

Ray Testing Empty Re: Ray Testing

Post  Francescu 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

Back to top Go down

Ray Testing Empty Re: Ray Testing

Post  william 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

Back to top Go down

Ray Testing Empty Re: Ray Testing

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