Ray Testing
Page 1 of 1 • Share •
Ray Testing
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..
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
Re: Ray Testing
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

sio2interactive- Posts: 1524
Join date: 2008-08-26
Age: 30
Location: Shanghai

Re: Ray Testing
I did a little research but can't find the topic. Anyway I've see that the
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..
- 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
Re: Ray Testing
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:
Thank you very much
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
william- Posts: 15
Join date: 2009-09-09
Re: Ray Testing
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();
Btw, you can get the SIO2object directly from the btCollisionObject.
( SIO2object * )( ( btRigidBody * )rayCallback.m_collisionObject )->getUserPointer();
Francescu- Posts: 136
Join date: 2009-03-18
Re: Ray Testing
Yes could be useful but if I can avoid the calling time of the getUserPointer() it's better 
william- Posts: 15
Join date: 2009-09-09
Re: Ray Testing
william wrote:Yes could be useful but if I can avoid the calling time of the getUserPointer() it's better
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!
Francescu- Posts: 136
Join date: 2009-03-18
Re: Ray Testing
The Sio2object is a reference inside an another structure, wich we can call class Player for example, so the loop is necessesary:
Otherwise yes, your're right!
- 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
Permissions of this forum:
You cannot reply to topics in this forum




