Newton 2.0 - RayCast bug

Report any bugs here and we'll post fixes

Moderators: Sascha Willems, Thomas

Newton 2.0 - RayCast bug

Postby sea » Thu Oct 30, 2008 3:44 pm

I discovered a bug (I'm definitely sure that this is not my fault) in NewtonWorldRayCast function. This stuff works almost good except some angles. The angle I mean is not measured between the normal of "hit" body and the ray. It's just the shooting ray angle. I realized, that the ray is going through all bodies when it's vector is nearly vertical (z = 0, x is almost 0, y is almost -1). Unfortunately this is not a special angle (I think), I use Newton for 2D simulation, but I'm absolutely sure, that the ray is able to hit the bodies. And it's not any mistake with tree collision because all kind of objects are ignored. I tried to fix the problem by going around it, so I determined the Z coordinate to be -maxdepth/2 at shooting point and +maxdepth/2 at the end. The maxdepth variable is the z-dimension of all my bodies, just to simulate 2D physics. So, I fixed the problem temporarily, but not at all. The bug exists, but it appears when I shot my ray in other angle (it's much harder to discover). If I wrote something not understandable, just tell me, I'll try to explain my thoughts again. I hope you'll look at ray-casting code in Newton and fix the bug.
sea
 
Posts: 19
Joined: Mon Dec 17, 2007 5:20 pm

Re: Newton 2.0 - RayCast bug

Postby Julio Jerez » Fri Oct 31, 2008 8:39 am

I am confused, does this happens with 2.0?
can you post a test for debugging?
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Newton 2.0 - RayCast bug

Postby sea » Fri Oct 31, 2008 1:21 pm

Yes, it happens with 2.0. I'll try doing some tests and I'll edit this post when I got results.

EDIT: So, here you are. I written everything in console, so you can determine precise values of ray points and normal vectors. Just look at the marked (*) entries. The ray was definitely intersecting the object, so even if we changed the value a bit the ray should stop on it. It's weird, isn't it?

Code: Select all
NewtonWorldRayCast call:
p0 = (8.07129, -1.7134, 0)
p1 = (8.07129, -1.8144, 0)
RayCastFilter:
normal =(0.213829, 0.976871, 0)
Found object!

*) NewtonWorldRayCast call:
p0 = (8.07129, -1.6634, 0)
p1 = (8.04628, -3.1684, 0)
RayCastFilter:
normal =(0.213829, 0.976871, 0)
Found object!

*) NewtonWorldRayCast call:
p0 = (8.07129, -1.6634, 0)
p1 = (8.04628, -3.1684, 0)
RayCastFilter:
normal =(0.213829, 0.976871, 0)
Found object!

NewtonWorldRayCast call:
p0 = (8.07129, -1.71341, 0)
p1 = (8.07129, -1.8144, 0)
RayCastFilter:
normal =(0.213829, 0.976871, 0)
Found object!

*) NewtonWorldRayCast call:
p0 = (8.07129, -1.66341, 0)
p1 = (8.04629, -3.1684, 0)
Object not found!

*) NewtonWorldRayCast call:
p0 = (8.07129, -1.66341, 0)
p1 = (8.04629, -3.1684, 0)
Object not found!
sea
 
Posts: 19
Joined: Mon Dec 17, 2007 5:20 pm

Re: Newton 2.0 - RayCast bug

Postby JernejL » Fri Oct 31, 2008 5:02 pm

And what is the object and it's matrix?
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1578
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: Newton 2.0 - RayCast bug

Postby sea » Fri Oct 31, 2008 6:32 pm

In this case it was simple tree collision with default initial matrix, but believe me, this happens also for primitives with any matrix (I tested it for randomly rotated boxes). Remember, that the Z-coordinate is set to 0 because of 2D simulation... I suggest Julio to set the exact values of according variables and test it by himself.

I would add I'm working mainly with Newton 2.0 for Linux. Just take a look. I post some screenshots showing both situations (normal and abnormal):

ImageImage

Look at the first image. We see the white ray shooting from the characters' head. White colour means that the ray hit the object. In the next picture we see the red ray, which shows the bug.

This bug happens every time and depends only on ray direction, I observed... Maybe it will be helpful.
sea
 
Posts: 19
Joined: Mon Dec 17, 2007 5:20 pm

Re: Newton 2.0 - RayCast bug

Postby Aphex » Wed Dec 17, 2008 4:36 am

I've noticed some Newton2 rays fail to hit just recently. Needed to narrow down the exact conditions and verify it isn't game-side though...
Aphex
 
Posts: 144
Joined: Fri Jun 18, 2004 6:08 am
Location: UK

Re: Newton 2.0 - RayCast bug

Postby Julio Jerez » Wed Dec 17, 2008 10:48 am

Sea never posted the test, just some results.
There could be a bug but I do not see how to reproduce it without a test, all of my test seems to work fine.
if you can make a scene where is happen please send me a test so that I can fix it.

note:
notice that if you teleport a body, and you do a ray cast the cast will fail on teh body you just teleported, because the scene manage only organize tteh space partion after an update.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Newton 2.0 - RayCast bug

Postby sea » Fri Jan 16, 2009 5:59 pm

Well, I thought that my results was enough. I just used these coordinates (and code):

Code: Select all
float p0[] = {8.07129, -1.66341, 0};
float p1[] = {8.04629, -3.1684, 0};
NewtonWorldRayCast(nworld, p0, p1, RayCastFilter, NULL, RayCastPrefilter);


These settings would show the bug, because ray cast didn't work with any object. I have no time to write an application showing the problem, just try this construction. I noticed, that the problem exists just only for this angle (or somewhere around float precision), so I can modify coordinates freely by adding a value to them (the same for both points of course):

Code: Select all
float p0[] = {8.07129+x, -1.66341+y, z};
float p1[] = {8.04629+x, -3.1684+y, z};


I computed that the angle is 89 (exactly 89,04832407) degrees.
And this doesn't work with any objects in my scene, moving or not, primitives, convex hulls, tree collisions etc. If it's a bug you should have the same results I had.
sea
 
Posts: 19
Joined: Mon Dec 17, 2007 5:20 pm

Re: Newton 2.0 - RayCast bug

Postby Julio Jerez » Sat Jan 17, 2009 2:25 pm

float p0[] = {8.07129+x, -1.66341+y, z};
float p1[] = {8.04629+x, -3.1684+y, z};

what do I do with that?
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Newton 2.0 - RayCast bug

Postby agi_shi » Sat Jan 17, 2009 2:50 pm

I believe he means that any ray cast with those coefficients fails for him, regardless of the x/y offset.
agi_shi
 
Posts: 263
Joined: Fri Aug 17, 2007 6:54 pm

Re: Newton 2.0 - RayCast bug

Postby Julio Jerez » Sat Jan 17, 2009 4:33 pm

that is correct, I just pasted into teh find floor funtion of teh SDK and is does fail


Code: Select all
dFloat FindFloor (const NewtonWorld* world, dFloat x, dFloat z)
{
   dFloat parameter;

float q0[] = {8.07129, -1.66341 - 1.5, 0};
float q1[] = {8.04629, -3.1684  - 1.5, 0};
NewtonWorldRayCast(world, q0, q1, RayCastPlacement, &parameter, NULL);



   // shot a vertical ray from a high altitude and collect the intersection parameter.
   dVector p0 (x, 1000.0f, z);
   dVector p1 (x, -1000.0f, z);

   parameter = 1.2f;
   NewtonWorldRayCast (world, &p0[0], &p1[0], RayCastPlacement, &parameter, NULL);
   //_ASSERTE (parameter < 1.0f);

   // the intersection is the interpolated value
   return 1000.0f - 2000.0f * parameter;
//return 0.0f;
}


the floor is at -4.0 and teh ray cast return not found.
thank you. I am fix it now.
julio
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Newton 2.0 - RayCast bug

Postby JernejL » Sat Jan 17, 2009 10:06 pm

I have never paid much attention to raycasting functionality in my top down game until today when i tried weapons systems again, i do get a similar bug, the raycasts sometimes return as if they hit something even if it's not there, this seems to depend on where in the world the character stands, so it could be a trimesh related bug in beta19 or something related to the bug that sea had.

Now this probably explains why my pedesterian AI was so weird lately and kept confused :lol:
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1578
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: Newton 2.0 - RayCast bug

Postby Julio Jerez » Sat Jan 17, 2009 11:12 pm

In that case we have no choice but to fix it.
We cannot have bugs willy-nilly running around in the engine, out of control.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Newton 2.0 - RayCast bug

Postby sea » Sun Jan 18, 2009 12:06 am

Well, I temporarily fixed this bug by myself just by changing useless (for me) z-coord, just like that:
Code: Select all
float p0[] = {x1, y1, -somedepth};
float p1[] = {x2, y2, somedepth};
NewtonWorldRayCast(nworld, p0, p1, RayCastFilter, NULL, RayCastPrefilter);


That would fix it for 2D physics (somedepth is a constant depth of my 2D objects). But I'm looking forward your solution.
sea
 
Posts: 19
Joined: Mon Dec 17, 2007 5:20 pm

Re: Newton 2.0 - RayCast bug

Postby JernejL » Sun Jan 18, 2009 9:06 am

I created a test in my game, which performs a 1 unit long raycast around the player character in all 360 degrees on the ground plane, and here are results, if raycast hits something i use that location as hit point, otherwise i use the 1 distance vector into that direction:

Image
Image

Image
Image

You can see that sometimes there are hits reported which are on a totally different location than the direction the way was heading into,
it looks as if the raycast.. went into negative direction (reverse) and hit walls around the source of ray from the outside (look at picture 2, the ray hit locations go around outside of the wall), this looks like a bug in something in raycast system in general, it happens on trimeshes and convex hulls from my tests so far, it's in beta 19 but i didnt test any earlier versions, if you need i will pack a demo of the game with this visual test so you can debug it.
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1578
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Next

Return to Bugs and Fixes

Who is online

Users browsing this forum: No registered users and 11 guests

cron