Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualWerner291

Posted 27 November 2012 - 11:50 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)

#1Werner291

Posted 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); 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