瀏覽代碼

Plane/Quat: Added functions to convert from and to Float4

Jorrit Rouwe 3 周之前
父節點
當前提交
2945ec8f0e
共有 3 個文件被更改,包括 13 次插入1 次删除
  1. 3 0
      Jolt/Geometry/Plane.h
  2. 5 1
      Jolt/Math/Quat.h
  3. 5 0
      Jolt/Math/Quat.inl

+ 3 - 0
Jolt/Geometry/Plane.h

@@ -32,6 +32,9 @@ public:
 	float			GetConstant() const														{ return mNormalAndConstant.GetW(); }
 	void			SetConstant(float inConstant)											{ mNormalAndConstant.SetW(inConstant); }
 
+	/// Store as 4 floats
+	void			StoreFloat4(Float4 *outV) const											{ mNormalAndConstant.StoreFloat4(outV); }
+
 	/// Offset the plane (positive value means move it in the direction of the plane normal)
 	Plane			Offset(float inDistance) const											{ return Plane(mNormalAndConstant - Vec4(Vec3::sZero(), inDistance)); }
 

+ 5 - 1
Jolt/Math/Quat.h

@@ -40,6 +40,7 @@ public:
 								Quat(const Quat &inRHS) = default;
 	Quat &						operator = (const Quat &inRHS) = default;
 	inline						Quat(float inX, float inY, float inZ, float inW)				: mValue(inX, inY, inZ, inW) { }
+	inline explicit				Quat(const Float4 &inV)											: mValue(Vec4::sLoadFloat4(&inV)) { }
 	inline explicit				Quat(Vec4Arg inV)												: mValue(inV) { }
 	///@}
 
@@ -241,9 +242,12 @@ public:
 	/// Load 3 floats from memory (X, Y and Z component and then calculates W) reads 32 bits extra which it doesn't use
 	static JPH_INLINE Quat		sLoadFloat3Unsafe(const Float3 &inV);
 
-	/// Store 3 as floats to memory (X, Y and Z component)
+	/// Store as 3 floats to memory (X, Y and Z component). Ensures that W is positive before storing.
 	JPH_INLINE void				StoreFloat3(Float3 *outV) const;
 
+	/// Store as 4 floats
+	JPH_INLINE void				StoreFloat4(Float4 *outV) const;
+
 	/// To String
 	friend ostream &			operator << (ostream &inStream, QuatArg inQ)					{ inStream << inQ.mValue; return inStream; }
 

+ 5 - 0
Jolt/Math/Quat.inl

@@ -391,6 +391,11 @@ void Quat::StoreFloat3(Float3 *outV) const
 	EnsureWPositive().GetXYZ().StoreFloat3(outV);
 }
 
+void Quat::StoreFloat4(Float4 *outV) const
+{
+	mValue.StoreFloat4(outV);
+}
+
 Quat Quat::sLoadFloat3Unsafe(const Float3 &inV)
 {
 	Vec3 v = Vec3::sLoadFloat3Unsafe(inV);