aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/ode-0.9/contrib/dRay/dRay_Plane.cpp
blob: cf03c5b3c7b7928b3762c3ad7c477f9cf12f28f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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;
}