Does anyone have code for ray and convex polygon intersection? I have ray-triangle, but the code goes a little over my head partially.
http://code.google.com/p/nxpascal/so...Math3D.pas#428
We can assume a few things...
Header:
Code:
TWordArray = array[0..0] of word;
PWordArray = ^TWordArray;
function RayPolyIntersect(const rayStart, rayDirection: TVector;
const vi: PWordArray; Count: integer; BothSided: boolean;
intersect: PVector; intersectNormal: PVector): Boolean;
- vi[] is index array to face vertices.
- Polygon is flat. If it's really not, it will still be treated as flat. Function can estimate it close enough.
- Polygon is convex. It is the only type of polygon you will see on 3D-models, ever.
On little theory, i would assume it go like this:
- We can get the intersection point, something like ray-plane intersect.
- Then somehow with crossproduct and dotproduct, we would determine if intersection point is outside the polygon.
Bookmarks