Browse Source

Adding collision algorithms back

Panagiotis Christopoulos Charitos 11 years ago
parent
commit
37dbb99898

+ 10 - 21
include/anki/collision/Aabb.h

@@ -20,27 +20,22 @@ class Aabb: public ConvexShape
 public:
 	using Base = ConvexShape;
 
-	/// @name Constructors
-	/// @{
 	Aabb()
-		: Base(Type::AABB)
+	:	Base(Type::AABB)
 	{}
 
 	Aabb(const Vec4& min, const Vec4& max)
-		: Base(Type::AABB), m_min(min), m_max(max)
+	:	Base(Type::AABB), m_min(min), m_max(max)
 	{
 		ANKI_ASSERT(m_min.xyz() < m_max.xyz());
 	}
 
 	Aabb(const Aabb& b)
-		: Base(Type::AABB)
+	:	Base(Type::AABB)
 	{
 		operator=(b);
 	}
-	/// @}
 
-	/// @name Accessors
-	/// @{
 	const Vec4& getMin() const
 	{
 		return m_min;
@@ -66,10 +61,8 @@ public:
 	{
 		m_max = x;
 	}
-	/// @}
 
-	/// @name Operators
-	/// @{
+	/// Copy.
 	Aabb& operator=(const Aabb& b)
 	{
 		Base::operator=(b);
@@ -77,36 +70,35 @@ public:
 		m_max = b.m_max;
 		return *this;
 	}
-	/// @}
 
 	/// Implements CollisionShape::accept
-	void accept(MutableVisitor& v)
+	void accept(MutableVisitor& v) override
 	{
 		v.visit(*this);
 	}
 	/// Implements CollisionShape::accept
-	void accept(ConstVisitor& v) const
+	void accept(ConstVisitor& v) const override
 	{
 		v.visit(*this);
 	}
 
 	/// Implements CollisionShape::testPlane
-	F32 testPlane(const Plane& p) const;
+	F32 testPlane(const Plane& p) const override;
 
 	/// Implements CollisionShape::transform
-	void transform(const Transform& trf)
+	void transform(const Transform& trf) override
 	{
 		*this = getTransformed(trf);
 	}
 
 	/// Implements CollisionShape::computeAabb
-	void computeAabb(Aabb& b) const
+	void computeAabb(Aabb& b) const override
 	{
 		b = *this;
 	}
 
 	/// Implements CompoundShape::computeSupport
-	Vec4 computeSupport(const Vec4& dir) const;
+	Vec4 computeSupport(const Vec4& dir) const override;
 
 	/// It uses a nice trick to avoid unwanted calculations 
 	Aabb getTransformed(const Transform& transform) const;
@@ -120,11 +112,8 @@ public:
 		const void* buff, U count, PtrSize stride, PtrSize buffSize);
 
 private:
-	/// @name Data
-	/// @{
 	Vec4 m_min;
 	Vec4 m_max;
-	/// @}
 };
 /// @}
 

+ 3 - 9
include/anki/collision/ConvexShape.h

@@ -19,32 +19,26 @@ class ConvexShape: public CollisionShape
 public:
 	using Base = CollisionShape;
 
-	/// @name Constructors & destructor
-	/// @{
 	ConvexShape(Type cid)
-		: Base(cid)
+	:	Base(cid)
 	{}
 
 	ConvexShape(const ConvexShape& b)
-		: Base(b)
+	:	Base(b)
 	{
 		operator=(b);
 	}
-	/// @}
 
-	/// @name Operators
-	/// @{
+	/// Copy.
 	ConvexShape& operator=(const ConvexShape& b)
 	{
 		Base::operator=(b);
 		return *this;
 	}
-	/// @}
 
 	/// Get a support vector for the GJK algorithm
 	virtual Vec4 computeSupport(const Vec4& dir) const = 0;
 };
-
 /// @}
 
 } // end namespace anki

+ 23 - 0
include/anki/collision/Tests.h

@@ -0,0 +1,23 @@
+// Copyright (C) 2014, Panagiotis Christopoulos Charitos.
+// All rights reserved.
+// Code licensed under the BSD License.
+// http://www.anki3d.org/LICENSE
+
+#ifndef ANKI_COLLISION_TESTS_H
+#define ANKI_COLLISION_TESTS_H
+
+#include "anki/collision/Common.h"
+
+namespace anki {
+
+/// @addtogroup collision
+/// @{
+
+/// Test if two collision shapes collide.
+Bool testCollisionShapes(const CollisionShape& a, const CollisionShape& b);
+/// @}
+
+} // end namespace anki
+
+#endif
+

+ 7 - 0
src/collision/Tests.cpp

@@ -0,0 +1,7 @@
+// Copyright (C) 2014, Panagiotis Christopoulos Charitos.
+// All rights reserved.
+// Code licensed under the BSD License.
+// http://www.anki3d.org/LICENSE
+
+#include "anki/collision/Tests.h"
+

+ 1 - 1
testapp/Main.cpp

@@ -399,7 +399,7 @@ Error mainLoopExtra(App& app, void*, Bool& quit)
 		BodyComponent* bodyc = l.tryGetComponent<BodyComponent>();
 		if(bodyc)
 		{
-			Vec4 pos(randRange(0, 10), 10, randRange(-4, 4), 0);
+			Vec4 pos(randRange(-2, 10), 10, randRange(-6, 6), 0);
 
 			bodyc->setTransform(
 				Transform(pos, Mat3x4::getIdentity(), 1.0));