瀏覽代碼

Renamed PlaneShape size to half-extent

Jorrit Rouwe 11 月之前
父節點
當前提交
fc2ffbc417
共有 2 個文件被更改,包括 16 次插入16 次删除
  1. 8 8
      Jolt/Physics/Collision/Shape/PlaneShape.cpp
  2. 8 8
      Jolt/Physics/Collision/Shape/PlaneShape.h

+ 8 - 8
Jolt/Physics/Collision/Shape/PlaneShape.cpp

@@ -32,7 +32,7 @@ JPH_IMPLEMENT_SERIALIZABLE_VIRTUAL(PlaneShapeSettings)
 
 
 	JPH_ADD_ATTRIBUTE(PlaneShapeSettings, mPlane)
 	JPH_ADD_ATTRIBUTE(PlaneShapeSettings, mPlane)
 	JPH_ADD_ATTRIBUTE(PlaneShapeSettings, mMaterial)
 	JPH_ADD_ATTRIBUTE(PlaneShapeSettings, mMaterial)
-	JPH_ADD_ATTRIBUTE(PlaneShapeSettings, mSize)
+	JPH_ADD_ATTRIBUTE(PlaneShapeSettings, mHalfExtent)
 }
 }
 
 
 ShapeSettings::ShapeResult PlaneShapeSettings::Create() const
 ShapeSettings::ShapeResult PlaneShapeSettings::Create() const
@@ -57,8 +57,8 @@ void PlaneShape::GetVertices(Vec3 *outVertices) const
 	sPlaneGetOrthogonalBasis(normal, perp1, perp2);
 	sPlaneGetOrthogonalBasis(normal, perp1, perp2);
 
 
 	// Scale basis
 	// Scale basis
-	perp1 *= mSize;
-	perp2 *= mSize;
+	perp1 *= mHalfExtent;
+	perp2 *= mHalfExtent;
 
 
 	// Calculate corners
 	// Calculate corners
 	Vec3 point = -normal * mPlane.GetConstant();
 	Vec3 point = -normal * mPlane.GetConstant();
@@ -74,13 +74,13 @@ void PlaneShape::CalculateLocalBounds()
 	Vec3 vertices[4];
 	Vec3 vertices[4];
 	GetVertices(vertices);
 	GetVertices(vertices);
 
 
-	// Encapsulate the vertices and a point mSize behind the plane
+	// Encapsulate the vertices and a point mHalfExtent behind the plane
 	mLocalBounds = AABox();
 	mLocalBounds = AABox();
 	Vec3 normal = mPlane.GetNormal();
 	Vec3 normal = mPlane.GetNormal();
 	for (const Vec3 &v : vertices)
 	for (const Vec3 &v : vertices)
 	{
 	{
 		mLocalBounds.Encapsulate(v);
 		mLocalBounds.Encapsulate(v);
-		mLocalBounds.Encapsulate(v - mSize * normal);
+		mLocalBounds.Encapsulate(v - mHalfExtent * normal);
 	}
 	}
 }
 }
 
 
@@ -88,7 +88,7 @@ PlaneShape::PlaneShape(const PlaneShapeSettings &inSettings, ShapeResult &outRes
 	Shape(EShapeType::Plane, EShapeSubType::Plane, inSettings, outResult),
 	Shape(EShapeType::Plane, EShapeSubType::Plane, inSettings, outResult),
 	mPlane(inSettings.mPlane),
 	mPlane(inSettings.mPlane),
 	mMaterial(inSettings.mMaterial),
 	mMaterial(inSettings.mMaterial),
-	mSize(inSettings.mSize)
+	mHalfExtent(inSettings.mHalfExtent)
 {
 {
 	if (!mPlane.GetNormal().IsNormalized())
 	if (!mPlane.GetNormal().IsNormalized())
 	{
 	{
@@ -502,7 +502,7 @@ void PlaneShape::SaveBinaryState(StreamOut &inStream) const
 	Shape::SaveBinaryState(inStream);
 	Shape::SaveBinaryState(inStream);
 
 
 	inStream.Write(mPlane);
 	inStream.Write(mPlane);
-	inStream.Write(mSize);
+	inStream.Write(mHalfExtent);
 }
 }
 
 
 void PlaneShape::RestoreBinaryState(StreamIn &inStream)
 void PlaneShape::RestoreBinaryState(StreamIn &inStream)
@@ -510,7 +510,7 @@ void PlaneShape::RestoreBinaryState(StreamIn &inStream)
 	Shape::RestoreBinaryState(inStream);
 	Shape::RestoreBinaryState(inStream);
 
 
 	inStream.Read(mPlane);
 	inStream.Read(mPlane);
-	inStream.Read(mSize);
+	inStream.Read(mHalfExtent);
 
 
 	CalculateLocalBounds();
 	CalculateLocalBounds();
 }
 }

+ 8 - 8
Jolt/Physics/Collision/Shape/PlaneShape.h

@@ -22,7 +22,7 @@ public:
 									PlaneShapeSettings() = default;
 									PlaneShapeSettings() = default;
 
 
 	/// Create a plane shape.
 	/// Create a plane shape.
-									PlaneShapeSettings(const Plane &inPlane, const PhysicsMaterial *inMaterial = nullptr, float inSize = cDefaultSize) : mPlane(inPlane), mMaterial(inMaterial), mSize(inSize) { }
+									PlaneShapeSettings(const Plane &inPlane, const PhysicsMaterial *inMaterial = nullptr, float inHalfExtent = cDefaultHalfExtent) : mPlane(inPlane), mMaterial(inMaterial), mHalfExtent(inHalfExtent) { }
 
 
 	// See: ShapeSettings
 	// See: ShapeSettings
 	virtual ShapeResult				Create() const override;
 	virtual ShapeResult				Create() const override;
@@ -31,13 +31,13 @@ public:
 
 
 	RefConst<PhysicsMaterial>		mMaterial;													///< Surface material of the plane
 	RefConst<PhysicsMaterial>		mMaterial;													///< Surface material of the plane
 
 
-	static constexpr float			cDefaultSize = 1000.0f;										///< Default size of the plane
+	static constexpr float			cDefaultHalfExtent = 1000.0f;								///< Default half-extent of the plane (total size along 1 axis will be 2 * half-extent)
 
 
-	float							mSize = cDefaultSize;										///< The bounding box of this plane will run from [-size, size]. Keep this as low as possible for better broad phase performance.
+	float							mHalfExtent = cDefaultHalfExtent;							///< The bounding box of this plane will run from [-half_extent, half_extent]. Keep this as low as possible for better broad phase performance.
 };
 };
 
 
 /// A plane shape. The negative half space is considered solid. Planes cannot be dynamic objects, only static or kinematic.
 /// A plane shape. The negative half space is considered solid. Planes cannot be dynamic objects, only static or kinematic.
-/// The plane is considered an infinite shape, but testing collision outside of its bounding box (defined by the size parameter) will not return a collision result.
+/// The plane is considered an infinite shape, but testing collision outside of its bounding box (defined by the half-extent parameter) will not return a collision result.
 /// At the edge of the bounding box collision with the plane will be inconsistent. If you need something of a well defined size, a box shape may be better.
 /// At the edge of the bounding box collision with the plane will be inconsistent. If you need something of a well defined size, a box shape may be better.
 class JPH_EXPORT PlaneShape final : public Shape
 class JPH_EXPORT PlaneShape final : public Shape
 {
 {
@@ -46,14 +46,14 @@ public:
 
 
 	/// Constructor
 	/// Constructor
 									PlaneShape() : Shape(EShapeType::Plane, EShapeSubType::Plane) { }
 									PlaneShape() : Shape(EShapeType::Plane, EShapeSubType::Plane) { }
-									PlaneShape(const Plane &inPlane, const PhysicsMaterial *inMaterial = nullptr, float inSize = PlaneShapeSettings::cDefaultSize) : Shape(EShapeType::Plane, EShapeSubType::Plane), mPlane(inPlane), mMaterial(inMaterial), mSize(inSize) { CalculateLocalBounds(); }
+									PlaneShape(const Plane &inPlane, const PhysicsMaterial *inMaterial = nullptr, float inHalfExtent = PlaneShapeSettings::cDefaultHalfExtent) : Shape(EShapeType::Plane, EShapeSubType::Plane), mPlane(inPlane), mMaterial(inMaterial), mHalfExtent(inHalfExtent) { CalculateLocalBounds(); }
 									PlaneShape(const PlaneShapeSettings &inSettings, ShapeResult &outResult);
 									PlaneShape(const PlaneShapeSettings &inSettings, ShapeResult &outResult);
 
 
 	/// Get the plane
 	/// Get the plane
 	const Plane &					GetPlane() const											{ return mPlane; }
 	const Plane &					GetPlane() const											{ return mPlane; }
 
 
-	/// Get the size of the bounding box of the plane
-	float							GetSize() const												{ return mSize; }
+	/// Get the half-extent of the bounding box of the plane
+	float							GetHalfExtent() const												{ return mHalfExtent; }
 
 
 	// See Shape::MustBeStatic
 	// See Shape::MustBeStatic
 	virtual bool					MustBeStatic() const override								{ return true; }
 	virtual bool					MustBeStatic() const override								{ return true; }
@@ -136,7 +136,7 @@ private:
 
 
 	Plane							mPlane;
 	Plane							mPlane;
 	RefConst<PhysicsMaterial>		mMaterial;
 	RefConst<PhysicsMaterial>		mMaterial;
-	float							mSize;
+	float							mHalfExtent;
 	AABox							mLocalBounds;
 	AABox							mLocalBounds;
 };
 };