Browse Source

Collision

Panagiotis Christopoulos Charitos 14 years ago
parent
commit
105dad1c1c

+ 6 - 0
anki/collision/Aabb.h

@@ -81,6 +81,12 @@ public:
 		*this = getTransformed(trf);
 	}
 
+	/// Implements CollisionShape::getAabb
+	void getAabb(Aabb& b) const
+	{
+		b = *this;
+	}
+
 	Aabb getTransformed(const Transform& transform) const;
 
 	/// Get a collision shape that includes this and the given. Its not

+ 3 - 0
anki/collision/CollisionShape.h

@@ -70,6 +70,9 @@ public:
 	/// Transform
 	virtual void transform(const Transform& trf) = 0;
 
+	/// Get the AABB
+	virtual void getAabb(Aabb&) const = 0;
+
 	virtual void accept(MutableVisitor&) = 0;
 	virtual void accept(ConstVisitor&) const = 0;
 

+ 13 - 1
anki/collision/Frustum.h

@@ -200,6 +200,12 @@ public:
 	/// Implements Frustum::calculateProjectionMatrix
 	Mat4 calculateProjectionMatrix() const;
 
+	/// Implements CollisionShape::getAabb
+	void getAabb(Aabb& b) const
+	{
+		/// XXX
+	}
+
 private:
 	/// @name Shape
 	/// @{
@@ -309,9 +315,15 @@ public:
 	/// Implements CollisionShape::testPlane
 	float testPlane(const Plane& p) const;
 
-	/// Re-implements Frustum::transform
+	/// Override Frustum::transform
 	void transform(const Transform& trf);
 
+	/// Implements CollisionShape::getAabb
+	void getAabb(Aabb& b) const
+	{
+		/// XXX
+	}
+
 	/// Implements Frustum::calculateProjectionMatrix
 	Mat4 calculateProjectionMatrix() const;
 

+ 21 - 0
anki/collision/LineSegment.cpp

@@ -51,4 +51,25 @@ LineSegment LineSegment::getTransformed(const Transform& transform) const
 }
 
 
+//==============================================================================
+void LineSegment::getAabb(Aabb& out) const
+{
+	Vec3 min = pls.getOrigin();
+	Vec3 max = pls.getOrigin() + ls.getDirection();
+
+	for(uint i = 0; i < 3; ++i)
+	{
+		if(max[i] < min[i])
+		{
+			float tmp = max[i];
+			max[i] = min[i];
+			min[i] = tmp;
+		}
+	}
+
+	out.setMin(min);
+	out.setMax(max);
+}
+
+
 } // end namespace

+ 3 - 0
anki/collision/LineSegment.h

@@ -80,6 +80,9 @@ public:
 		*this = getTransformed(trf);
 	}
 
+	/// Implements CollisionShape::getAabb
+	void getAabb(Aabb& b) const;
+
 	LineSegment getTransformed(const Transform& transform) const;
 
 private:

+ 6 - 0
anki/collision/Obb.h

@@ -89,6 +89,12 @@ public:
 		*this = getTransformed(trf);
 	}
 
+	/// Implements CollisionShape::getAabb
+	void getAabb(Aabb& b) const
+	{
+		/// XXX
+	}
+
 	Obb getTransformed(const Transform& transform) const;
 
 	/// Get a collision shape that includes this and the given. Its not

+ 7 - 0
anki/collision/Plane.cpp

@@ -81,4 +81,11 @@ Plane Plane::getTransformed(const Transform& trf) const
 }
 
 
+//==============================================================================
+void Plane::getAabb(Aabb&) const
+{
+	ANKI_ASSERT(0 && "Can't do that");
+}
+
+
 } // end namespace

+ 3 - 0
anki/collision/Plane.h

@@ -93,6 +93,9 @@ public:
 		*this = getTransformed(trf);
 	}
 
+	/// Implements CollisionShape::getAabb
+	void getAabb(Aabb& b) const;
+
 	/// Return the transformed
 	Plane getTransformed(const Transform& trf) const;
 

+ 7 - 0
anki/collision/Ray.cpp

@@ -47,4 +47,11 @@ float Ray::testPlane(const Plane& p) const
 }
 
 
+//==============================================================================
+void Ray::getAabb(Aabb&) const
+{
+	ANKI_ASSERT(0 && "Can't do that");
+}
+
+
 } // end namespace

+ 3 - 0
anki/collision/Ray.h

@@ -84,6 +84,9 @@ public:
 		*this = getTransformed(trf);
 	}
 
+	/// Implements CollisionShape::getAabb
+	void getAabb(Aabb& b) const;
+
 	Ray getTransformed(const Transform& transform) const;
 
 private:

+ 8 - 0
anki/collision/Sphere.cpp

@@ -95,4 +95,12 @@ Sphere Sphere::getCompoundShape(const Sphere& b) const
 }
 
 
+//==============================================================================
+void Sphere::getAabb(Aabb& aabb) const
+{
+	aabb.setMin(s.getCenter() - radius);
+	aabb.setMax(s.getCenter() + radius);
+}
+
+
 } // end namespace

+ 3 - 0
anki/collision/Sphere.h

@@ -83,6 +83,9 @@ public:
 		*this = getTransformed(trf);
 	}
 
+	/// Implements CollisionShape::getAabb
+	void getAabb(Aabb& b) const;
+
 	Sphere getTransformed(const Transform& transform) const;
 
 	/// Get the sphere that includes this sphere and the given. See a

+ 0 - 74
anki/collision/ToAabb.cpp

@@ -1,74 +0,0 @@
-#include "anki/collision/ToAabb.h"
-#include "anki/collision/Collision.h"
-#include "anki/util/Assert.h"
-
-
-namespace anki {
-
-
-//=============================================================================
-void ToAbb::visit(LineSegment& ls)
-{
-	Vec3 min = pls.getOrigin();
-	Vec3 max = pls.getOrigin() + ls.getDirection();
-
-	for(uint i = 0; i < 3; ++i)
-	{
-		if(max[i] < min[i])
-		{
-			float tmp = max[i];
-			max[i] = min[i];
-			min[i] = tmp;
-		}
-	}
-
-	aabb.setMax(max);
-	aabb.setMin(min);
-}
-
-
-//=============================================================================
-void ToAbb::visit(Obb& obb)
-{
-	// XXX
-}
-
-
-//=============================================================================
-void ToAbb::visit(Frustum&)
-{
-	/// XXX
-}
-
-
-//=============================================================================
-void ToAbb::visit(Plane&)
-{
-	ANKI_ASSERT(0 && "Can't do that");
-}
-
-
-//=============================================================================
-void ToAbb::visit(Ray&)
-{
-	ANKI_ASSERT(0 && "Can't do that");
-}
-
-
-//=============================================================================
-void ToAbb::visit(Sphere& s)
-{
-	Vec3 r = Vec3(s.getRadius());
-	aabb.setMin(s.getCenter() - r);
-	aabb.setMax(s.getCenter() + r);
-}
-
-
-//=============================================================================
-void ToAbb::visit(Aabb& b)
-{
-	aabb = b;
-}
-
-
-} // end namespace anki

+ 0 - 41
anki/collision/ToAabb.h

@@ -1,41 +0,0 @@
-#ifndef ANKI_COLLISION_TO_AABB_H
-#define ANKI_COLLISION_TO_AABB_H
-
-#include "anki/collision/Forward.h"
-#include "anki/collision/CollisionShape.h"
-#include "anki/collision/Aabb.h"
-
-
-namespace anki {
-
-
-/// @addtogroup Collision
-/// @{
-
-/// XXX
-class ToAbb: public CollisionShape::ConstVisitor
-{
-public:
-	void visit(LineSegment&);
-	void visit(Obb&);
-	void visit(Frustum&);
-	void visit(Plane&);
-	void visit(Ray&);
-	void visit(Sphere&);
-	void visit(Aabb&);
-
-	const Aabb& getAabb() const
-	{
-		return aabb;
-	}
-
-private:
-	Aabb aabb;
-};
-/// @}
-
-
-} // end namespace anki
-
-
-#endif