diff --git a/configure.py b/configure.py index f06f5a5f..7b69047a 100755 --- a/configure.py +++ b/configure.py @@ -28,6 +28,7 @@ COMPLETE_OBJECTS = [ "MetroidPrime/HUD/CHUDMemoParms", "MetroidPrime/ScriptObjects/CScriptDebugCameraWaypoint", "Weapons/IWeaponRenderer", + "Collision/CMRay", "Kyoto/Basics/CStopwatch", "Kyoto/Basics/COsContextDolphin", "Kyoto/Basics/CSWDataDolphin", diff --git a/include/Collision/CMRay.hpp b/include/Collision/CMRay.hpp new file mode 100644 index 00000000..cf252c7b --- /dev/null +++ b/include/Collision/CMRay.hpp @@ -0,0 +1,22 @@ +#ifndef __CMRAY_HPP__ +#define __CMRAY_HPP__ + +#include "Kyoto/Math/CVector3f.hpp" + +class CTransform4f; +class CMRay { +public: + CMRay(const CVector3f& start, const CVector3f& end, float, float); + CMRay(const CVector3f& start, const CVector3f& end, float); + CMRay GetInvUnscaledTransformRay(const CTransform4f&) const; + +private: + CVector3f mStart; + CVector3f mEnd; + CVector3f mDelta; + float mLength; + float mInvLength; + CVector3f mDir; +}; + +#endif // __CMRAY_HPP__ diff --git a/obj_files.mk b/obj_files.mk index 5caff98a..fd9bedb6 100644 --- a/obj_files.mk +++ b/obj_files.mk @@ -415,7 +415,7 @@ COLLISION :=\ $(BUILD_DIR)/asm/Collision/CCollidableSphere.o\ $(BUILD_DIR)/asm/Collision/CMaterialFilter.o\ $(BUILD_DIR)/asm/Collision/COBBox.o\ - $(BUILD_DIR)/asm/Collision/CMRay.o\ + $(BUILD_DIR)/src/Collision/CMRay.o\ KYOTO_1 :=\ $(BUILD_DIR)/asm/Kyoto/Basics/CBasics.o\ diff --git a/src/Collision/CMRay.cpp b/src/Collision/CMRay.cpp new file mode 100644 index 00000000..3eb97a7e --- /dev/null +++ b/src/Collision/CMRay.cpp @@ -0,0 +1,25 @@ +#include "Collision/CMRay.hpp" +#include "Kyoto/Math/CTransform4f.hpp" + +CMRay::CMRay(const CVector3f& start, const CVector3f& end, float length, float invLength) +: mStart(start) +, mEnd(end) +, mDelta(mEnd - mStart) +, mLength(length) +, mInvLength(invLength) +, mDir(mInvLength * mDelta) { +} + +CMRay::CMRay(const CVector3f& start, const CVector3f& dir, float length) +: mStart(start) +, mEnd(start + length * dir) +, mDelta(mEnd - mStart) +, mLength(length) +, mInvLength(1.f / length) +, mDir(dir) {} + + +CMRay CMRay::GetInvUnscaledTransformRay(const CTransform4f& xf) const { + CTransform4f invXf = xf.GetQuickInverse(); + return CMRay(invXf * mStart, invXf * mEnd, mLength, mInvLength); +}