From 79eca25c945a535a7a0325999034bae17da92412 Mon Sep 17 00:00:00 2001 From: dan miller Date: Fri, 19 Oct 2007 05:15:33 +0000 Subject: resubmitting ode --- libraries/ode-0.9/contrib/dRay/dRay_Plane.cpp | 35 +++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 libraries/ode-0.9/contrib/dRay/dRay_Plane.cpp (limited to 'libraries/ode-0.9/contrib/dRay/dRay_Plane.cpp') diff --git a/libraries/ode-0.9/contrib/dRay/dRay_Plane.cpp b/libraries/ode-0.9/contrib/dRay/dRay_Plane.cpp new file mode 100644 index 0000000..cf03c5b --- /dev/null +++ b/libraries/ode-0.9/contrib/dRay/dRay_Plane.cpp @@ -0,0 +1,35 @@ +// Ripped from Paul Bourke + +#include "Include\dRay.h" +#include "dxRay.h" + +int dCollidePR(dxGeom* RayGeom, dxGeom* PlaneGeom, int Flags, dContactGeom* Contact, int Stride){ + dVector3 Plane; + dGeomPlaneGetParams(PlaneGeom, Plane); + + dVector3 Origin, Direction; + dGeomRayGet(RayGeom, Origin, Direction); + + dReal Length = dGeomRayGetLength(RayGeom); + + dReal Denom = Plane[0] * Direction[0] + Plane[1] * Direction[1] + Plane[2] * Direction[2]; + if (dFabs(Denom) < 0.00001f){ + return 0; // Ray never hits + } + + float T = -(Plane[3] + Plane[0] * Origin[0] + Plane[1] * Origin[1] + Plane[2] * Origin[2]) / Denom; + + if (T < 0 || T > Length){ + return 0; // Ray hits but not within boundaries + } + + Contact->pos[0] = Origin[0] + T * Direction[0]; + Contact->pos[1] = Origin[1] + T * Direction[1]; + Contact->pos[2] = Origin[2] + T * Direction[2]; + Contact->pos[3] = REAL(0.0); + //Contact->normal = 0; + Contact->depth = 0.0f; + Contact->g1 = RayGeom; + Contact->g2 = PlaneGeom; + return 1; +} \ No newline at end of file -- cgit v1.1