Browse Source

Added accessors for tapered cylinder shape

Fixes #1247
Jorrit Rouwe 1 year ago
parent
commit
5122d4f0ea

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

@@ -39,6 +39,18 @@ public:
 							TaperedCylinderShape() : ConvexShape(EShapeSubType::TaperedCylinder) { }
 							TaperedCylinderShape() : ConvexShape(EShapeSubType::TaperedCylinder) { }
 							TaperedCylinderShape(const TaperedCylinderShapeSettings &inSettings, ShapeResult &outResult);
 							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
 	// See Shape::GetCenterOfMass
 	virtual Vec3			GetCenterOfMass() const override										{ return Vec3(0, -0.5f * (mTop + mBottom), 0); }
 	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> cylinder1 = StaticCast<TaperedCylinderShape>(settings1.Create().Get());
 		RefConst<TaperedCylinderShape> cylinder2 = StaticCast<TaperedCylinderShape>(settings2.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 m1 = cylinder1->GetMassProperties();
 		MassProperties m2 = cylinder2->GetMassProperties();
 		MassProperties m2 = cylinder2->GetMassProperties();