A place to discuss everything related to Newton Dynamics.
Moderators: Sascha Willems, walaber
by armokal » Sat Nov 29, 2008 11:58 pm
I would like to cast a ray and find the closest hit point and NewtonWorldRayCast seems to be what I need except I'm not sure about the required callback.
void NewtonWorldRayCast(
const NewtonWorld* newtonWorld,
const dFloat* p0,
const dFloat* p1,
NewtonWorldRayFilterCallback filter,
void* userData,
NewtonWorldRayPrefilterCallback prefilter)
How do I find out what is the closest hit point? I would also like to know what is the normal vector. Is it also possible to know which polygon was hit on the particular BODY in question?
The first 2 are more important.
-
armokal
-
- Posts: 22
- Joined: Fri Oct 27, 2006 10:03 pm
- Location: Canada
by martinsm » Sun Nov 30, 2008 9:44 am
Have you at least read documentation of NewtonWorldRayCast function?
Remarks section there explains how to find closest body that ray intersects.
Also page on
NewtonWorldRayFilterCallback function shows few cases how to do implement callback function.
-
martinsm
-
- Posts: 86
- Joined: Mon Dec 19, 2005 3:15 pm
- Location: Latvia
by JulBaxter » Fri May 21, 2010 10:51 am
I wonder why NewtonWorldRayFilterCallback calls during a NewtonWorldRayCast are ordered from end to begin ray ?
-
JulBaxter
-
- Posts: 23
- Joined: Wed Mar 10, 2010 6:56 am
by Julio Jerez » Fri May 21, 2010 10:57 am
in a loose way teh are ordered from begin to end.
bacisally raycast scan the mutigrid cell, each laye is scaned for begion to end, but if a cell have more tan one body, it will scane then at randon.
if you fiter you must controll the order by collecting the t value and returning the value if you do not want object beyond the corrent time to be tested.
doing that speed up raycasting significanlly when you only want the first ray teh object hit.
if you return 1.0 or larger in the filter than the ray cast will continue be called for all object the ray hit.
-
Julio Jerez
- Moderator

-
- Posts: 12452
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by JulBaxter » Fri May 21, 2010 11:04 am
Humm. Ok
So if I want all bodies from begin to end(ordered), I must return 1 and sort bodies according their T ?
-
JulBaxter
-
- Posts: 23
- Joined: Wed Mar 10, 2010 6:56 am
by Julio Jerez » Fri May 21, 2010 11:38 am
yes that is correct. But remenber the will not be perfect sorted, they will be loselly sorted.
if you want then sorted form begin to end, you can make on one pass insertion sort, in the filter callbak
basically it is something like this
- Code: Select all
int count = 0
float times[n];
body* bodyarray[n];
float filter (time, body, ...)
{
// do teh filter stuff
...
int i;
for (i = count; (i > 0) && times[i - 1] < time; i --) {
times[i] = times[i - 1 ];
bodyarray[i] = bodyarray[i - 1];
}
times[i] = time;
bodyarray[i] = body];
count ++;
return 1.0
}
-
Julio Jerez
- Moderator

-
- Posts: 12452
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by JulBaxter » Fri May 21, 2010 12:14 pm
Ok. Thank you for this clarification.
-
JulBaxter
-
- Posts: 23
- Joined: Wed Mar 10, 2010 6:56 am
Return to General Discussion
Who is online
Users browsing this forum: No registered users and 398 guests