chances / slimmath

Automatically exported from code.google.com/p/slimmath
0 stars 0 forks source link

RayIntersectsPlane #15

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
It seemed the function 

bool RayIntersectsPlane(ref Ray ray, ref Plane plane, out float distance)

in Collision.cs is incorrect.

It should be

...
distance = (-plane.D - position) / direction; 
...

Please check it And thank for great work.  :)

Original issue reported on code.google.com by Jumping....@gmail.com on 9 Mar 2011 at 9:02

GoogleCodeExporter commented 9 years ago
Using the code below I get a distance of 20.0 which appears to be correct. This 
is before I made the change you suggested. I'm not an expect though, so more 
input would be nice.

Plane plane = new Plane(new Vector3(0, -1, 0), 10);
Ray ray = new Ray(new Vector3(0, 10, 0), new Vector3(0, -1, 0));

float distance;
Collision.RayIntersectsPlane(ref ray, ref plane, out distance);

Original comment by Jorgy...@gmail.com on 26 Mar 2011 at 6:45

GoogleCodeExporter commented 9 years ago
The exemple you have gived seemed also mistake.

Plane plane = new Plane(new Vector3(0, -1, 0), 10);
Ray ray = new Ray(new Vector3(0, 10, 0), new Vector3(0, -1, 0));

The distance should be 0 not 20 , The plane cross (0, 10, 0), which the start 
point of the ray.

Try below:

Ray ray = new Ray(new Vector3(0, 10, 0), new Vector3(0, -1, 0));
Plane plane = new Plane(new Vector3(0, 1, 0), 20); 

result = SlimMath.Collision.RayIntersectsPlane(ref ray, ref plane, out 
distance);

Now the result is false. The correct result is true and disantce is 30.

Original comment by Jumping....@gmail.com on 27 Mar 2011 at 11:37

GoogleCodeExporter commented 9 years ago
I committed your fix in r46. Thank you!

Original comment by Jorgy...@gmail.com on 27 Mar 2011 at 7:32