Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

Werner291

Member Since 25 Jun 2012
Offline Last Active Nov 30 2012 10:13 AM

#5004583 Does the projection of a point onto a plane belong to a triangle in that plan...

Posted by Werner291 on 27 November 2012 - 11:45 AM

I took your second solution, it works excellently!

Here's the resulting code:
[source lang="cpp"]Ogre::Vector3 vectorOA = wallStrip[itr-2];                Ogre::Vector3 vectorOB = wallStrip[itr-1];                Ogre::Vector3 vectorOC = wallStrip[itr];                Ogre::Vector3 vectorAB(vectorOB - vectorOA);                Ogre::Vector3 vectorBC(vectorOC - vectorOB);                Ogre::Vector3 vectorCA(vectorOA - vectorOC);                Ogre::Vector3 faceNormal = vectorAB.crossProduct(vectorCA) * (itr%2==0 ? 1.0 : -1.0); // It's a triangle strip                if (vectorOA.dotProduct(faceNormal) > 0){                    Ogre::Vector3 ABNormal = vectorAB.crossProduct(faceNormal);                    if (vectorOA.dotProduct(ABNormal) > 0) continue;                    Ogre::Vector3 BCNormal = vectorBC.crossProduct(faceNormal);                    if (vectorOB.dotProduct(BCNormal) > 0) continue;                    Ogre::Vector3 CANormal = vectorCA.crossProduct(faceNormal);                    if (vectorOA.dotProduct(CANormal) > 0) continue;                    // The projection falls within the triangle                }[/source]

It also checks wether the point is on a specific side of the triangle, it's also inside a loop iterating through a vector of these triangles.
The point that I'm testing is actually the origin in this case, that's why you don't actually see it in the code.

It actually even worked the first time! (That was very unlikely, I'm a champion at typos Posted Image)


PARTNERS