Turns out this is fucking hard. I've found a nice-seeming GL math library called GLM, but it's almost completely devoid of documentation. (No, a list of function names is not documentation.) It's not calculating the intersection point correctly, probably because I have no fucking idea what I'm doing.

**Code:**

typedef struct {

glm::vec4 Colour;

glm::vec3 Position;

} Vertex;

typedef struct {

std::vector<Vertex> Vtx;

glm::vec3 Normal;

} Poly;

//[...]

Vertex V1, V2, V3;

V1.Position = glm::vec3(-1.0f, -1.0f, -4.0f);

V2.Position = glm::vec3( 1.0f, 1.0f, -2.0f);

V1.Colour = glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);

V2.Colour = glm::vec4(1.0f, 1.0f, 1.0f, 1.0f);

Line.Vtx.push_back(V1);

Line.Vtx.push_back(V2);

V1.Position = glm::vec3(-1.0f, 1.0f, -3.0f);

V2.Position = glm::vec3( 0.0f, -1.0f, -3.0f);

V3.Position = glm::vec3( 1.0f, 1.0f, -3.0f);

V1.Colour = glm::vec4(1.0f, 0.0f, 0.0f, 1.0f);

V2.Colour = glm::vec4(0.0f, 1.0f, 0.0f, 1.0f);

V3.Colour = glm::vec4(0.0f, 0.0f, 1.0f, 1.0f);

Tri.Vtx.push_back(V1);

Tri.Vtx.push_back(V2);

Tri.Vtx.push_back(V3);

//[...]

glm::vec3 Intersect, L0, L1, T0, T1, T2, O;

O = glm::vec3(0.0f, 0.0f, 0.0f);

T0 = Tri.Vtx[0].Position;

T1 = Tri.Vtx[1].Position;

T2 = Tri.Vtx[2].Position;

L0 = Line.Vtx[0].Position;

L1 = Line.Vtx[1].Position - Line.Vtx[0].Position;

if(glm::gtx::intersect::intersectLineTriangle<glm::vec3>

(L0, L1, T0, T1, T2, Intersect))

//[...]

Just looking at the numbers you can tell the intersection point should be (0, 0, -3), but the result is (0.5, 0.5, 0.25), which doesn't make any damn sense to me.

Firefox also needs a beating with a cluebat.

_________________

143

HyperNova Software is

now live (but may take a few tries to load) currently down; check out my PSP/DS/Game Boy/Windows/Linux homebrew, ROM hacks, and Gameshark codes!