Line | |
---|
1 | // Ripped from Paul Bourke |
---|
2 | |
---|
3 | #include "Include\dRay.h" |
---|
4 | #include "dxRay.h" |
---|
5 | |
---|
6 | int dCollidePR(dxGeom* RayGeom, dxGeom* PlaneGeom, int Flags, dContactGeom* Contact, int Stride){ |
---|
7 | dVector3 Plane; |
---|
8 | dGeomPlaneGetParams(PlaneGeom, Plane); |
---|
9 | |
---|
10 | dVector3 Origin, Direction; |
---|
11 | dGeomRayGet(RayGeom, Origin, Direction); |
---|
12 | |
---|
13 | dReal Length = dGeomRayGetLength(RayGeom); |
---|
14 | |
---|
15 | dReal Denom = Plane[0] * Direction[0] + Plane[1] * Direction[1] + Plane[2] * Direction[2]; |
---|
16 | if (dFabs(Denom) < 0.00001f){ |
---|
17 | return 0; // Ray never hits |
---|
18 | } |
---|
19 | |
---|
20 | float T = -(Plane[3] + Plane[0] * Origin[0] + Plane[1] * Origin[1] + Plane[2] * Origin[2]) / Denom; |
---|
21 | |
---|
22 | if (T < 0 || T > Length){ |
---|
23 | return 0; // Ray hits but not within boundaries |
---|
24 | } |
---|
25 | |
---|
26 | Contact->pos[0] = Origin[0] + T * Direction[0]; |
---|
27 | Contact->pos[1] = Origin[1] + T * Direction[1]; |
---|
28 | Contact->pos[2] = Origin[2] + T * Direction[2]; |
---|
29 | Contact->pos[3] = REAL(0.0); |
---|
30 | //Contact->normal = 0; |
---|
31 | Contact->depth = 0.0f; |
---|
32 | Contact->g1 = RayGeom; |
---|
33 | Contact->g2 = PlaneGeom; |
---|
34 | return 1; |
---|
35 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.