Using Newton to check if an object is in line of sight.

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Delee
Posts: 18
Joined: Sat Apr 14, 2007 8:36 am

Using Newton to check if an object is in line of sight.

Post by Delee »

Hi again everyone. My goal is to determine if an object is in line of sight of another object. For example, if there is a tree impeding the camera's view of the character. I thought this is something that could be done with NewtonCollisionRayCast, but if anyone knows of another way I am all ears. :)

Most notedly, I do not quite understand the function NewtonCollisionRayCast. I have read the specification, but I have some questions.

Code: Select all

float NewtonCollisionRayCast(
const NewtonCollision* collision,
const float* p0,
const float* p1,
float* normal,
int* attribute);
With p0 and p1, I do not understand what it means by representing the local space of the geometry. Does it mean the collision geometry?

If so, what exactly does p1 require? If p0 is the exact center of the object and I wanted the ray to shoot directly down/up, would (X = 0, Y = 1, Z = 0) be sufficient? Or do I have to suggest distance as well?

Any advice on how to proceed would be most appreciated.
My thanks in advance!
Luben
Posts: 568
Joined: Sun Oct 09, 2005 10:12 am
Location: #irrlicht @freenode

Post by Luben »

p0 and p1 are the vectors that define the line. p0 is the start of the line, and p1 is the en of the line.

But you probably want to use NewtonWorldRayCast instead. NewtonCollisionRayCast only checks for collision against one collision, which is positioned at 0,0,0. So you'd have to repeat the check for each thing you'd like to test with, and transform the line to object-local coordinates. You dont have to with NewtonWorldRayCast.

From the Newton docs
void NewtonWorldRayCast(
const NewtonWorld* newtonWorld,
const dFloat* p0,
const dFloat* p1,
NewtonWorldRayFilterCallback filter,
void* userData,
NewtonWorldRayPrefilterCallback prefilter)
Shoot a ray from p0 to p1 and call the application callback with each ray intersection.

Parameters
const NewtonWorld *newtonWorld - is the pointer to the world.
const dFloat *p0 - pointer to an array of at least three floats containing the beginning of the ray in global space.

const dFloat *p1 - pointer to an array of at least three floats containing the end of the ray in global space.

NewtonWorldRayFilterCallback filter - user define function to be called for each body hit during the ray scan.

void *userData - user data to be passed to the filter callback.

NewtonWorldRayPrefilterCallback prefilter - user define function to be called for each body before intesection.




Return
nothing

Remarks
The ray cast function will call the application with each body intersecting the line segment. By writing the callback filter function in different ways the application can implement different flavors of ray casting. For example an all body ray cast can be easily implemented by having the filter function always returning 1.0, and copying each rigid body into an array of pointers; a closest hit ray cast can be implemented by saving the body with the smaller intersection parameter and returning the parameter t; and a report the first body hit can be implemented by having the filter function returning zero after the first call and saving the pointer to the rigid body.

Remarks
The most common use for the ray cast function is the closest body hit, In this case it is important, for performance reasons, that the filter function returns the intersection parameter. If the filter function returns a value of zero the ray cast will terminate immediately.

Remarks
if prefilter is not NULL, Newton will call the application right before executing the intersections between the ray and the primitive. if the function returns zero the Newton will not raycast the primitive. passing a NULL pointer will raycast the. The application can use this implement faster or smarter filters when implementing complex logic, otherwise for normal all ray cast this parameter could be NULL.

Remarks
The ray cast function is provided as an utility function, this means that even thought the function is very high performance by function standards, it can not by batched and therefore it can not be an incremental function. For example the cost of calling 1000 ray cast is 1000 times the cost of calling one ray cast. This is much different than the collision system where the cost of calculating collision for 1000 pairs in much, much less that the 1000 times the cost of one pair. Therefore this function must be used with care, as excessive use of it can degrade performance.
If you don't have anything nice to say, don't say anything at all.
roxaz
Posts: 575
Joined: Tue Jan 23, 2007 8:35 pm
Location: LT

Post by roxaz »

btw wrong forum. newton forum is here :)
Delee
Posts: 18
Joined: Sat Apr 14, 2007 8:36 am

Post by Delee »

Thanks for your help Luben. :) And I did post on the Newton forums, but they are usually so slow to reply and often do not. People on Irrlicht are always very helpful, and once again I appreciate it very much. Again, my thanks!
roxaz
Posts: 575
Joined: Tue Jan 23, 2007 8:35 pm
Location: LT

Post by roxaz »

Yes... Newton guys are not so helpful :)
Post Reply