A place to discuss everything related to Newton Dynamics.
Moderators: Sascha Willems, walaber
by Slick » Thu Dec 05, 2013 7:24 pm
If I derive a class from OgreNewtonRayCast am I supposed to get a callback to OnRayHit for multiple hits on a body along the path of the ray?
I do get callbacks but it appears just to be one callback.
-
Slick
-
- Posts: 330
- Joined: Sat Feb 07, 2004 7:24 pm
- Location: LA last and France now
by Julio Jerez » Thu Dec 05, 2013 7:46 pm
that class is wriiet to get teh closet hit, that faste possible way. for all hit you need to overload OnRayHit
the current inmplementation is this
- Code: Select all
dFloat OnRayHit (const dNewtonBody* const body, const dNewtonCollision* const shape, const dFloat* const contact, const dFloat* const normal, dLong collisionID, dFloat intersectParam)
{
if (intersectParam < m_param) {
m_bodyHit = (dNewtonBody*) body;
m_param = intersectParam;
m_shapeId = collisionID;
m_normal = Vector3 (normal[0], normal[1], normal[2]);
m_contact = Vector3 (contact[0], contact[1], contact[2]);
}
return intersectParam;
}
- Code: Select all
dFloat OnRayHit (const dNewtonBody* const body, const dNewtonCollision* const shape, const dFloat* const contact, const dFloat* const normal, dLong collisionID, dFloat intersectParam)
{
if (intersectParam < m_param) {
// save the bodies in some contaner, teh wil lonel hold tteh most close body
m_bodyHit = (dNewtonBody*) body;
m_param = intersectParam;
m_shapeId = collisionID;
m_normal = Vector3 (normal[0], normal[1], normal[2]);
m_contact = Vector3 (contact[0], contact[1], contact[2]);
}
// return 1.0 so tha tthe ray key scanning more objects
return 1.0;
}
this will continue scanning, yo unee to sav eth vodies as the are picke by the ray,
Maybe it will be good to add another RayCastAll call teh impelmne the container.
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Slick » Thu Dec 05, 2013 8:08 pm
Ah thanks I will try that. I thought my ray was ok but was confused by the callback.
-
Slick
-
- Posts: 330
- Joined: Sat Feb 07, 2004 7:24 pm
- Location: LA last and France now
by Slick » Fri Dec 06, 2013 1:45 pm
I just tried returning 1.0f from my class derived from OgreNewtonRayCast and it doesn't appear to return more hits. The hits would be with the same body potentially but that should still be ok. I think my code is ok but i am still just getting one hit in the callback.
-
Slick
-
- Posts: 330
- Joined: Sat Feb 07, 2004 7:24 pm
- Location: LA last and France now
by Slick » Fri Dec 06, 2013 1:55 pm
I started to do some debugging and the base class appears to be getting some callbacks after the derived class with other values. Hmm. Maybe this is something I am confused with on a C++ level?
-
Slick
-
- Posts: 330
- Joined: Sat Feb 07, 2004 7:24 pm
- Location: LA last and France now
by Julio Jerez » Fri Dec 06, 2013 3:47 pm
I will write a class for that.
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Slick » Sat Dec 07, 2013 12:03 am
I debugged it a bit more I can't see how 1.0f would make it return more results but maybe I didn't dig deep enough. My best thought for now is to do another raycast from the point of impact of the first cast.
Am I missing something and it will return multiple hits already?
-
Slick
-
- Posts: 330
- Joined: Sat Feb 07, 2004 7:24 pm
- Location: LA last and France now
by Julio Jerez » Sat Dec 07, 2013 1:32 am
I check in a ray cask class that collect all hits. it look like this
- Code: Select all
class OgreNewtonRayHitBody
{
public:
OgreNewtonRayHitBody(){}
OgreNewtonRayHitBody (const dNewtonBody* const bodyHit, const Vector3& normal, const Vector3& contact, dLong shapeId, Real param)
:m_normal(normal)
,m_contact(contact)
,m_bodyHit(bodyHit)
,m_shapeId(shapeId)
,m_param(param)
{
}
Vector3 m_normal;
Vector3 m_contact;
const dNewtonBody* m_bodyHit;
dLong m_shapeId;
Real m_param;
};
class OGRE_NEWTON_API OgreNewtonAllHitRayCast: public dNewtonRayCast, public std::vector<OgreNewtonRayHitBody>
{
public:
OgreNewtonAllHitRayCast(dNewton* const world, dLong collisionMask);
void CastRay (const dFloat* const p0, const dFloat* const p1, int threadIndex = 0);
dFloat OnRayHit (const dNewtonBody* const body, const dNewtonCollision* const shape, const dFloat* const contact, const dFloat* const normal, dLong collisionID, dFloat intersectParam);
};
you use the same way you are using the first one. and it will colleen all hit bodies long the path of the ray.
I did not test it by I believe is should work.
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Slick » Mon Dec 09, 2013 8:55 pm
This still doesn't appear to be working for me. If using OgreNewtonRayCast Is returning 1.0f or 1.2f the correct value? Way down into the newton class it mentions 1.0f.
The size of my OgreNewtonAllHitRayCast returns 1 if I try using that instead of OgreNewtonRayCast.
If there are multiple hits with one body for example the scenebody that should return multiple hits right?
-
Slick
-
- Posts: 330
- Joined: Sat Feb 07, 2004 7:24 pm
- Location: LA last and France now
by Julio Jerez » Mon Dec 09, 2013 9:13 pm
I will test it tonight.
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Slick » Tue Dec 10, 2013 1:01 pm
Did you get a chance to test. I can try creating different bodies to test I just don't know the expected behaviour. I am getting one hit for a ray that goes through a scenebody multiple times.
-
Slick
-
- Posts: 330
- Joined: Sat Feb 07, 2004 7:24 pm
- Location: LA last and France now
by Julio Jerez » Tue Dec 10, 2013 2:29 pm
It should return all all bodies tah the ray intersect, teh bodieswill not be in order.
I just did a quick test, but castin te jenga and it collect three bodies.
I will add and option to show the hit bodies.
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Slick » Tue Dec 10, 2013 3:06 pm
ok sounds good. If it hits a body more than once how many hits are returned?
-
Slick
-
- Posts: 330
- Joined: Sat Feb 07, 2004 7:24 pm
- Location: LA last and France now
by Julio Jerez » Tue Dec 10, 2013 3:31 pm
bodies can only be hit once. there should not be duplicates.In the list of bodies coleceted by the ray
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Slick » Tue Dec 10, 2013 3:33 pm
ah ok that might explain why I was struggling. I had a ray going through a scenebody and thought I would get more hits.
-
Slick
-
- Posts: 330
- Joined: Sat Feb 07, 2004 7:24 pm
- Location: LA last and France now
Return to General Discussion
Who is online
Users browsing this forum: No registered users and 1 guest