A place to discuss everything related to Newton Dynamics.
Moderators: Sascha Willems, walaber
by Leadwerks » Tue May 12, 2009 9:04 pm
I was advised long ago it was best to perform triangle-mesh raycasting by going through my own scenegraph, finding the relevant meshes, and performing a raycast on the collision object for those meshes. Before that I had been storing one Newton body for every LOD level of every mesh in the scene, and it was very slow and memory-intensive. I switched to the current method and have been using that for maybe six months without problems.
I also requested a raycast radius a while back, and the response was the more flexible convex cast. I always figured I would use this at some point in the future when I add a radius value to my raycast routine; I would just use a temporary sphere collision shape and calculate the convex cast that way.
Now I am ready to add the radius parameter, but I realized the convex cast is only provided as NewtonWorldConvex cast, which goes through all the bodies in the world. This is what I was told to avoid back when I was storing one newton body for every LOD mesh in the scene. This leaves me with a problem. I need something that will perform a volumetric raycast on a single newton collision object.
I think the best solution would be an optional radius parameter in the NewtonCollisionRayCast
function:
NewtonCollisionRayCast(newtonCollision,p0,p1,normal,attribute,radius)
Alternatively, a convex cast function to work on newton collision objects would also work.
-

Leadwerks
-
- Posts: 569
- Joined: Fri Oct 27, 2006 2:54 pm
by Julio Jerez » Tue May 12, 2009 10:37 pm
the convex cast is not efficent for long rays, the ray cast with ratio may be a better solution.
I have to figure out the math for that,
The problems I can see is if the radio makes a cylinder of a sphere. I sound a triviality but it is actually complex
I guess it will be a special case of the Convex cast plus some optimization.
why a convex cast with a small sphere or a cylinder does no works?
It looks to me that adding ConvexCast on per shape should work.
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Leadwerks » Tue May 12, 2009 11:03 pm
Convex cast per shape would work.
I would prefer a ray with a radius (forming a cylinder shape). The reason for this is a convex cast sphere would hit points beyond the end points of the ray. A cylinder shape could be created to simulate this volume, but then you have the problem of the different transformation matrices. It is trivial to transform the two end points of a ray to the coordinate system of a mesh, but it is not feasible to create a temporary collision shape for every mesh that gets tested.
My raycast function works like this, basically:
- Code: Select all
raycastworld(p0,p1) {
for every mesh in the world (for all practical purposes in this discussion) {
if (mesh.aabb.overlapsray(p0,p1)) {
//Transform ray to mesh coordinate system and cast
temp_p0=TFormPoint(p0,mesh)
temp_p1=TFormPoint(p1,mesh)
NewtonRaycast( mesh.newtonCollision, temp_p0,temp_p1 )
}
}
}
Sorry I am whining so much today. I sound like some of my users.
Last edited by
Leadwerks on Wed May 13, 2009 12:30 am, edited 1 time in total.
-

Leadwerks
-
- Posts: 569
- Joined: Fri Oct 27, 2006 2:54 pm
by Julio Jerez » Tue May 12, 2009 11:25 pm
So in that loop chnging Raycast to ConveCast, will so the trick for you
something like this.
- Code: Select all
for every mesh in the world (for all practical purposes in this discussion) {
if (mesh.aabb.overlapsray(p0,p1)) {
//Transform ray to mesh coordinate system and cast
temp_p0=TFormPoint(p0,mesh)
temp_p1=TFormPoint(p1,mesh)
NewtonConvexcast( mesh.newtonCollision, shape, .... )
}
}
If this is OK with you, I can release a new Beta thisi weekend end.
There are few othe bug fixed I nee to realse too, and some stuff I have to undo with, But this should be very very simple to get going.
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Leadwerks » Wed May 13, 2009 12:30 am
Yes, that would be a great solution.
-

Leadwerks
-
- Posts: 569
- Joined: Fri Oct 27, 2006 2:54 pm
by Julio Jerez » Wed May 20, 2009 1:14 pm
Hey Leadwerk
I was looking at this and I knew we have a way to do this already, but since it had being so long I did no remember how, but when I try to write the function I immediately figured out.
Convex Cast of tow shape is a special case of continue collision, in fact the convex cast function I the engine using the same collide continues function, the only difference is tha is uses and DDDA function to cast the AABB of the shape alone the word grid.
The make the cats efficient for long ray, but inefficient fo medium to short rays, your idea of using the World AABB and the having you own Convex Cast is more flexible.
The good news is the solution is already in the engine, no update necessary
Here is a function that will do what you want
- Code: Select all
int ConvexCast (const NewtonWorld* newtonWorld, int maxSize,
const NewtonCollision* collisionA, const Matrix* matrixA, const dVcetor* posit,
const NewtonCollision* collisionB, const Matrix* matrixB,
dFloat* timeOfImpact, dFloat* contacts, dFloat* normals, dFloat* penetration, int threadIndex)
{
Vector veloc (0, 0, 0, 0)
Vector velocA (posit - matrixA.Posit)
return NewtonCollisionCollideContinue (newtonWorld, int maxSize, 1.0f,
collisionA, matrixA, velocA, veloc,
collisionB, matrixB, veloc, veloc,
timeOfImpact, contacts, normals, penetration, threadIndex);
}
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Leadwerks » Sat May 23, 2009 3:09 pm
How is velocity used? If I want a raycast length of ten, what would I set the velocity to?
-

Leadwerks
-
- Posts: 569
- Joined: Fri Oct 27, 2006 2:54 pm
by Julio Jerez » Sat May 23, 2009 10:53 pm
I jus wroet eth funtin for you
- Code: Select all
int ConvexCast (const NewtonWorld* newtonWorld, int maxSize,
const NewtonCollision* collisionA, const Matrix* matrixA, const dVcetor* posit,
const NewtonCollision* collisionB, const Matrix* matrixB,
dFloat* timeOfImpact, dFloat* contacts, dFloat* normals, dFloat* penetration, int threadIndex)
you do not have to worrie abou the velocity.
but if you wan to know, the velocity fo shape A is the target position minus the position o fteh shapeA.
the secund velocity is zero.
the function will return the time of impact as a variable from zero to one, just like a ray cast funtion
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
Return to General Discussion
Who is online
Users browsing this forum: No registered users and 1 guest