瀏覽代碼

- Add transform to CollisionShape and every other shape
- Rename a file

Panagiotis Christopoulos Charitos 14 年之前
父節點
當前提交
97d0320a33

+ 6 - 0
anki/collision/Aabb.h

@@ -80,6 +80,12 @@ class Aabb: public CollisionShape
 			return PlaneTests::test(p, *this);
 			return PlaneTests::test(p, *this);
 		}
 		}
 
 
+		/// Overrides CollisionShape::transform
+		void transform(const Transform& trf)
+		{
+			*this = getTransformed(trf);
+		}
+
 		Aabb getTransformed(const Transform& transform) const;
 		Aabb getTransformed(const Transform& transform) const;
 
 
 		/// Get a collision shape that includes this and the given. Its not
 		/// Get a collision shape that includes this and the given. Its not

+ 7 - 0
anki/collision/CollisionShape.h

@@ -3,6 +3,7 @@
 
 
 #include "anki/collision/Forward.h"
 #include "anki/collision/Forward.h"
 #include "anki/collision/PlaneTests.h"
 #include "anki/collision/PlaneTests.h"
+#include "anki/collision/CollisionShapeTransform.h"
 
 
 
 
 namespace anki {
 namespace anki {
@@ -73,6 +74,12 @@ class CollisionShape
 			return PlaneTests::test(p, *this);
 			return PlaneTests::test(p, *this);
 		}
 		}
 
 
+		/// Transform
+		void transform(const Transform& trf)
+		{
+			CollisionShapeTransform::transform(trf, *this);
+		}
+
 	private:
 	private:
 		CollisionShapeType cid;
 		CollisionShapeType cid;
 };
 };

+ 42 - 0
anki/collision/CollisionShapeTransform.cpp

@@ -0,0 +1,42 @@
+#include "anki/collision/CollisionShapeTransform.h"
+#include "anki/collision/Collision.h"
+#include "anki/math/Transform.h"
+
+
+namespace anki {
+
+
+//==============================================================================
+void CollisionShapeTransform::transform(const Transform& trf,
+	CollisionShape& cs)
+{
+	switch(cs.getCollisionShapeType())
+	{
+		case CollisionShape::CST_LINE_SEG:
+			static_cast<LineSegment&>(cs).transform(trf);
+			break;
+		case CollisionShape::CST_RAY:
+			static_cast<Ray&>(cs).transform(trf);
+			break;
+		case CollisionShape::CST_PLANE:
+			static_cast<Plane&>(cs).transform(trf);
+			break;
+		case CollisionShape::CST_SPHERE:
+			static_cast<Sphere&>(cs).transform(trf);
+			break;
+		case CollisionShape::CST_AABB:
+			static_cast<Aabb&>(cs).transform(trf);
+			break;
+		case CollisionShape::CST_OBB:
+			static_cast<Obb&>(cs).transform(trf);
+			break;
+		case CollisionShape::CST_PERSPECTIVE_CAMERA_FRUSTRUM:
+			static_cast<PerspectiveCameraShape&>(cs).transform(trf);
+			break;
+		default:
+			ASSERT(0 && "Forgot something");
+	}
+}
+
+
+} // end namespace

+ 4 - 1
anki/collision/CollisionShapeTransform.h

@@ -2,15 +2,18 @@
 #define ANKI_COLLISION_COLLISION_SHAPE_TRANSFORM_H
 #define ANKI_COLLISION_COLLISION_SHAPE_TRANSFORM_H
 
 
 #include "anki/collision/Forward.h"
 #include "anki/collision/Forward.h"
+#include "anki/math/Forward.h"
 
 
 
 
 namespace anki {
 namespace anki {
 
 
 
 
+/// Transforms a shape
 class CollisionShapeTransform
 class CollisionShapeTransform
 {
 {
 	public:
 	public:
-
+		/// Generic transform
+		static void transform(const Transform& trf, CollisionShape& cs);
 };
 };
 
 
 
 

+ 8 - 2
anki/collision/LineSegment.h

@@ -75,14 +75,20 @@ class LineSegment: public CollisionShape
 			v.visit(*this);
 			v.visit(*this);
 		}
 		}
 
 
-		LineSegment getTransformed(const Transform& transform) const;
-
 		/// Overrides CollisionShape::testPlane
 		/// Overrides CollisionShape::testPlane
 		float testPlane(const Plane& p) const
 		float testPlane(const Plane& p) const
 		{
 		{
 			return PlaneTests::test(p, *this);
 			return PlaneTests::test(p, *this);
 		}
 		}
 
 
+		/// Overrides CollisionShape::transform
+		void transform(const Transform& trf)
+		{
+			*this = getTransformed(trf);
+		}
+
+		LineSegment getTransformed(const Transform& transform) const;
+
 	private:
 	private:
 		/// @name Data
 		/// @name Data
 		/// @{
 		/// @{

+ 14 - 6
anki/collision/Obb.h

@@ -21,7 +21,9 @@ class Obb: public CollisionShape
 		Obb()
 		Obb()
 		:	CollisionShape(CST_OBB)
 		:	CollisionShape(CST_OBB)
 		{}
 		{}
+
 		Obb(const Obb& b);
 		Obb(const Obb& b);
+
 		Obb(const Vec3& center, const Mat3& rotation, const Vec3& extends);
 		Obb(const Vec3& center, const Mat3& rotation, const Vec3& extends);
 		/// @}
 		/// @}
 
 
@@ -78,18 +80,24 @@ class Obb: public CollisionShape
 			v.visit(*this);
 			v.visit(*this);
 		}
 		}
 
 
-		Obb getTransformed(const Transform& transform) const;
-
-		/// Get a collision shape that includes this and the given. Its not
-		/// very accurate
-		Obb getCompoundShape(const Obb& b) const;
-
 		/// Overrides CollisionShape::testPlane
 		/// Overrides CollisionShape::testPlane
 		float testPlane(const Plane& p) const
 		float testPlane(const Plane& p) const
 		{
 		{
 			return PlaneTests::test(p, *this);
 			return PlaneTests::test(p, *this);
 		}
 		}
 
 
+		/// Overrides CollisionShape::transform
+		void transform(const Transform& trf)
+		{
+			*this = getTransformed(trf);
+		}
+
+		Obb getTransformed(const Transform& transform) const;
+
+		/// Get a collision shape that includes this and the given. Its not
+		/// very accurate
+		Obb getCompoundShape(const Obb& b) const;
+
 		/// Calculate from a set of points
 		/// Calculate from a set of points
 		template<typename Container>
 		template<typename Container>
 		void set(const Container& container);
 		void set(const Container& container);

+ 6 - 0
anki/collision/PerspectiveCameraShape.h

@@ -57,6 +57,12 @@ class PerspectiveCameraShape: public CollisionShape
 			return PlaneTests::test(p, *this);
 			return PlaneTests::test(p, *this);
 		}
 		}
 
 
+		/// Overrides CollisionShape::transform
+		void transform(const Transform& trf)
+		{
+			*this = getTransformed(trf);
+		}
+
 		PerspectiveCameraShape getTransformed(const Transform& trf) const;
 		PerspectiveCameraShape getTransformed(const Transform& trf) const;
 
 
 		/// Set all
 		/// Set all

+ 12 - 6
anki/collision/Plane.h

@@ -84,6 +84,18 @@ class Plane: public CollisionShape
 			v.visit(*this);
 			v.visit(*this);
 		}
 		}
 
 
+		/// Overrides CollisionShape::testPlane
+		float testPlane(const Plane& p) const
+		{
+			return PlaneTests::test(p, *this);
+		}
+
+		/// Overrides CollisionShape::transform
+		void transform(const Transform& trf)
+		{
+			*this = getTransformed(trf);
+		}
+
 		/// Return the transformed
 		/// Return the transformed
 		Plane getTransformed(const Transform& trf) const;
 		Plane getTransformed(const Transform& trf) const;
 
 
@@ -108,12 +120,6 @@ class Plane: public CollisionShape
 			return point - normal * test(point);
 			return point - normal * test(point);
 		}
 		}
 
 
-		/// Overrides CollisionShape::testPlane
-		float testPlane(const Plane& p) const
-		{
-			return PlaneTests::test(p, *this);
-		}
-
 		/// Test a CollisionShape
 		/// Test a CollisionShape
 		template<typename T>
 		template<typename T>
 		float testShape(const T& x) const
 		float testShape(const T& x) const

+ 8 - 2
anki/collision/Ray.h

@@ -70,14 +70,20 @@ class Ray: public CollisionShape
 			v.visit(*this);
 			v.visit(*this);
 		}
 		}
 
 
-		Ray getTransformed(const Transform& transform) const;
-
 		/// Overrides CollisionShape::testPlane
 		/// Overrides CollisionShape::testPlane
 		float testPlane(const Plane& p) const
 		float testPlane(const Plane& p) const
 		{
 		{
 			return PlaneTests::test(p, *this);
 			return PlaneTests::test(p, *this);
 		}
 		}
 
 
+		/// Overrides CollisionShape::transform
+		void transform(const Transform& trf)
+		{
+			*this = getTransformed(trf);
+		}
+
+		Ray getTransformed(const Transform& transform) const;
+
 	private:
 	private:
 		Vec3 origin;
 		Vec3 origin;
 		Vec3 dir;
 		Vec3 dir;

+ 12 - 6
anki/collision/Sphere.h

@@ -70,18 +70,24 @@ class Sphere: public CollisionShape
 			v.visit(*this);
 			v.visit(*this);
 		}
 		}
 
 
-		Sphere getTransformed(const Transform& transform) const;
-
-		/// Get the sphere that includes this sphere and the given. See a
-		/// drawing in the docs dir for more info about the algorithm
-		Sphere getCompoundShape(const Sphere& b) const;
-
 		/// Overrides CollisionShape::testPlane
 		/// Overrides CollisionShape::testPlane
 		float testPlane(const Plane& p) const
 		float testPlane(const Plane& p) const
 		{
 		{
 			return PlaneTests::test(p, *this);
 			return PlaneTests::test(p, *this);
 		}
 		}
 
 
+		/// Overrides CollisionShape::transform
+		void transform(const Transform& trf)
+		{
+			*this = getTransformed(trf);
+		}
+
+		Sphere getTransformed(const Transform& transform) const;
+
+		/// Get the sphere that includes this sphere and the given. See a
+		/// drawing in the docs dir for more info about the algorithm
+		Sphere getCompoundShape(const Sphere& b) const;
+
 		/// Calculate from a set of points
 		/// Calculate from a set of points
 		template<typename Container>
 		template<typename Container>
 		void set(const Container& container);
 		void set(const Container& container);

+ 2 - 2
anki/math/MathForward.h → anki/math/Forward.h

@@ -1,5 +1,5 @@
-#ifndef ANKI_MATH_MATH_FORWARD_H
-#define ANKI_MATH_MATH_FORWARD_H
+#ifndef ANKI_MATH_FORWARD_H
+#define ANKI_MATH_FORWARD_H
 
 
 #include <iosfwd>
 #include <iosfwd>
 
 

+ 1 - 1
anki/math/MathCommonIncludes.h

@@ -1,3 +1,3 @@
-#include "anki/math/MathForward.h"
+#include "anki/math/Forward.h"
 #include "anki/math/MathSimd.h"
 #include "anki/math/MathSimd.h"
 #include <boost/array.hpp>
 #include <boost/array.hpp>