Jump to content
  • Advertisement
Sign in to follow this  
coollofty

ray and obb intersect test problem!

This topic is 5456 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

class OBB { public: Vector3 mDiamesions;//dimensions along local axes, x, y, z Vector3 mTrans; //translate Quaternion mOrientation; } ; class Ray { public: Vector3 mOrigin; Vector3 mDirection; } ; //ÅжÏÉäÏßÓëOBBÊÇ·ñÏཻ inline bool RAY_OBB_CLIP(float fDenom, float fNumer, float *pfT0) { if (fDenom > 0.0f) { if (fNumer > (fDenom * (*pfT0))) *pfT0 = fNumer / fDenom; return true; } else if (fDenom < 0.0f) { if (fNumer > (fDenom * (*pfT0))) return false; return true; } return (fNumer <= 0.0f); } bool isRayAndOBBIntersect(const Ray& ray, const OBB& obb) { Vector3 kDiff, kOrigin, kDirection, kTmp; Matrix3 kRot; V3Subtract(&kDiff, &ray.mOrigin, &obb.mTrans); obb.mOrientation.toRotationMatrix(kRot); kRot.getColumn(0, &kTmp); V3DotProduct(&kOrigin.x, &kDiff, &kTmp); V3DotProduct(&kDirection.x, &ray.mDirection, &kTmp); kRot.getColumn(1, &kTmp); V3DotProduct(&kOrigin.y, &kDiff, &kTmp); V3DotProduct(&kDirection.y, &ray.mDirection, &kTmp); kRot.getColumn(2, &kTmp); V3DotProduct(&kOrigin.z, &kDiff, &kTmp); V3DotProduct(&kDirection.z, &ray.mDirection, &kTmp); float fT0 = 0.0f; const Vector3& vDiam = obb.mDiamesions; bool bNotEntirelyClipped = RAY_OBB_CLIP(+kDirection.x, -kOrigin.x - vDiam.x, &fT0) && RAY_OBB_CLIP(-kDirection.x, +kOrigin.x - vDiam.x, &fT0) && RAY_OBB_CLIP(+kDirection.y, -kOrigin.y - vDiam.y, &fT0) && RAY_OBB_CLIP(-kDirection.y, +kOrigin.y - vDiam.y, &fT0) && RAY_OBB_CLIP(+kDirection.z, -kOrigin.z - vDiam.z, &fT0) && RAY_OBB_CLIP(-kDirection.z, +kOrigin.z - vDiam.z, &fT0); if (bNotEntirelyClipped && (fT0 != 0.0f)) return true; return false; } This is my ray and obb intersect test code, copy and modify from neo-engine. But the code test result is not correct. Who can help me to find out the errors? Thx.

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!