瀏覽代碼

Added accessors for tapered cylinder shape

Fixes #1247
Jorrit Rouwe 1 年之前
父節點
當前提交
5122d4f0ea
共有 2 個文件被更改,包括 18 次插入0 次删除
  1. 12 0
      Jolt/Physics/Collision/Shape/TaperedCylinderShape.h
  2. 6 0
      UnitTests/Physics/TaperedCylinderShapeTests.cpp

+ 12 - 0
Jolt/Physics/Collision/Shape/TaperedCylinderShape.h

@@ -39,6 +39,18 @@ public:
 							TaperedCylinderShape() : ConvexShape(EShapeSubType::TaperedCylinder) { }
 							TaperedCylinderShape(const TaperedCylinderShapeSettings &inSettings, ShapeResult &outResult);
 
+	/// Get top radius of the tapered cylinder
+	inline float			GetTopRadius() const													{ return mTopRadius; }
+
+	/// Get bottom radius of the tapered cylinder
+	inline float			GetBottomRadius() const													{ return mBottomRadius; }
+
+	/// Get convex radius of the tapered cylinder
+	inline float			GetConvexRadius() const													{ return mConvexRadius; }
+
+	/// Get half height of the tapered cylinder
+	inline float			GetHalfHeight() const													{ return 0.5f * (mTop - mBottom); }
+
 	// See Shape::GetCenterOfMass
 	virtual Vec3			GetCenterOfMass() const override										{ return Vec3(0, -0.5f * (mTop + mBottom), 0); }
 

+ 6 - 0
UnitTests/Physics/TaperedCylinderShapeTests.cpp

@@ -25,6 +25,12 @@ TEST_SUITE("TaperedCylinderShapeTests")
 		RefConst<TaperedCylinderShape> cylinder1 = StaticCast<TaperedCylinderShape>(settings1.Create().Get());
 		RefConst<TaperedCylinderShape> cylinder2 = StaticCast<TaperedCylinderShape>(settings2.Create().Get());
 
+		// Check accessors
+		CHECK(cylinder1->GetTopRadius() == cRadius);
+		CHECK(cylinder1->GetBottomRadius() == 0.0f);
+		CHECK(cylinder1->GetConvexRadius() == 0.0f);
+		CHECK_APPROX_EQUAL(cylinder1->GetHalfHeight(), 0.5f * cHeight);
+
 		MassProperties m1 = cylinder1->GetMassProperties();
 		MassProperties m2 = cylinder2->GetMassProperties();