Kodewerx

Our culture has advanced beyond all that you could possibly comprehend with one hundred percent of your brain.
It is currently Sun Dec 08, 2024 8:47 am

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Mon Nov 16, 2009 10:35 pm 
Offline
Komrade
Komrade
User avatar

Joined: Tue Mar 27, 2007 6:23 pm
Posts: 1354
Location: Mario Raceway, 1509.831, 217.198, -564.429
Title: Mario Kart 64 Hacker
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.

_________________
Image 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!


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group