NewtonWorldRayCast

From Newton Wiki
Revision as of 08:02, 10 June 2019 by WikiSysop (talk | contribs) (1 revision imported)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

NewtonWorldRayCast

Syntax:

void NewtonWorldRayCast (const NewtonWorld* const newtonWorld, const dFloat* const p0, const dFloat* const p1, NewtonWorldRayFilterCallback filter, void* const userData, NewtonWorldRayPrefilterCallback prefilter, int threadIndex)

Usage

Shoots a ray from p0 to p1 and calls the application callback whenever the ray hits a body.

Parameters

  • const NewtonWorld *newtonWorld - is the pointer to the world.
  • const dFloat *p0 - pointer to the first element of an array of at least three floats containing the beginning of the ray in global space.
  • const dFloat *p1 - pointer to the first element of an array of at least three floats containing the end of the ray in global space.
  • NewtonWorldRayFilterCallback filter - user defined 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 when the ray hits the AABB of the body (potentional hit), can be used to tell newton to ignore bodies before checking weither they actually intresect with the ray.
  • int threadIndex threadIndex Index of thread that called this function (zero if called form outsize a newton update).

Description

Raycasting is a very useful feature, usually used for game AI such as scanning the world for presence of obstacles.

Remarks

  • Raycast 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.
  • 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.
  • 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.
  • 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.
  • 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.

See also

NewtonWorldConvexCast NewtonCollisionRayCast