Browse Source

Collision fixes

Panagiotis Christopoulos Charitos 11 years ago
parent
commit
441f5201c3

+ 1 - 2
include/anki/renderer/DebugDrawer.h

@@ -128,8 +128,7 @@ public:
 
 
 	void visit(const Aabb&);
 	void visit(const Aabb&);
 
 
-	void visit(const CompoundShape&)
-	{}
+	void visit(const CompoundShape&);
 
 
 	void visit(const ConvexHullShape&);
 	void visit(const ConvexHullShape&);
 
 

+ 6 - 6
src/collision/Tests.cpp

@@ -275,17 +275,17 @@ static Bool tpx(const CollisionShape& a, const CollisionShape& b)
 }
 }
 
 
 /// Compound shape.
 /// Compound shape.
-Bool tcx(const CollisionShape& a, const CollisionShape& b)
+static Bool tcx(const CollisionShape& a, const CollisionShape& b)
 {
 {
-	Bool inside = true;
+	Bool inside = false;
 	const CompoundShape& c = dcast<const CompoundShape&>(a);
 	const CompoundShape& c = dcast<const CompoundShape&>(a);
 
 
 	// Use the error to stop the loop
 	// Use the error to stop the loop
 	Error err = c.iterateShapes([&](const CollisionShape& cs)
 	Error err = c.iterateShapes([&](const CollisionShape& cs)
 	{
 	{
-		if(!testCollisionShapes(cs, b))
+		if(testCollisionShapes(cs, b))
 		{
 		{
-			inside = false;
+			inside = true;
 			return ErrorCode::FUNCTION_FAILED;
 			return ErrorCode::FUNCTION_FAILED;
 		}
 		}
 
 
@@ -297,7 +297,7 @@ Bool tcx(const CollisionShape& a, const CollisionShape& b)
 }
 }
 
 
 /// Compound shape.
 /// Compound shape.
-Bool txc(const CollisionShape& a, const CollisionShape& b)
+static Bool txc(const CollisionShape& a, const CollisionShape& b)
 {
 {
 	return tcx(b, a);
 	return tcx(b, a);
 }
 }
@@ -324,7 +324,7 @@ Bool testCollisionShapes(const CollisionShape& a, const CollisionShape& b)
 	ANKI_ASSERT(matrix[ai][bi] != nullptr && "Collision algorithm is missing");
 	ANKI_ASSERT(matrix[ai][bi] != nullptr && "Collision algorithm is missing");
 	ANKI_ASSERT(ai < COUNT && bi < COUNT && "Out of range");
 	ANKI_ASSERT(ai < COUNT && bi < COUNT && "Out of range");
 
 
-	return matrix[ai][bi](a, b);
+	return matrix[bi][ai](a, b);
 }
 }
 
 
 } // end namespace anki
 } // end namespace anki

+ 14 - 12
src/renderer/Dbg.cpp

@@ -146,9 +146,8 @@ Error Dbg::run(GlCommandBufferHandle& cmdb)
 	}
 	}
 #endif
 #endif
 
 
-#if 0
+#if 1
 	{
 	{
-		ConvexHullShape hull;
 		Vec4 storage[] = {
 		Vec4 storage[] = {
 			Vec4(1.0, 1.0, 1.0, 0.0),
 			Vec4(1.0, 1.0, 1.0, 0.0),
 			Vec4(1.0, 1.0, -1.0, 0.0),
 			Vec4(1.0, 1.0, -1.0, 0.0),
@@ -159,16 +158,23 @@ Error Dbg::run(GlCommandBufferHandle& cmdb)
 		SceneNode& sn = scene.findSceneNode("horse");
 		SceneNode& sn = scene.findSceneNode("horse");
 		MoveComponent& move = sn.getComponent<MoveComponent>();
 		MoveComponent& move = sn.getComponent<MoveComponent>();
 
 
+		ConvexHullShape hull;
 		hull.initStorage(storage, 4);
 		hull.initStorage(storage, 4);
+		
+		Sphere s(Vec4(1.0, 0.0, 0.0, 0), 1.0);
 
 
-		Sphere s(Vec4(0.0), 1.0);
+		Aabb aabb(Vec4(-1.0, -1, -1, 0), Vec4(2, 3, 5, 0));
 
 
-		hull.transform(move.getWorldTransform());
+		Obb obb(Vec4(0.0), Mat3x4::getIdentity(), Vec4(1.0, 2.0, 1.0, 0.0));
 
 
-		Gjk gjk;
-		Bool collide = gjk.intersect(s, hull);
+		CompoundShape comp;
+		comp.addShape(&obb);
+		comp.addShape(&s);
+		comp.addShape(&abb);
 
 
-		if(collide)
+		comp.transform(move.getWorldTransform());
+
+		if(testCollisionShapes(aabb, comp))
 		{
 		{
 			m_drawer->setColor(Vec4(1.0, 0.0, 0.0, 1.0));
 			m_drawer->setColor(Vec4(1.0, 0.0, 0.0, 1.0));
 		}
 		}
@@ -180,12 +186,8 @@ Error Dbg::run(GlCommandBufferHandle& cmdb)
 		m_drawer->setModelMatrix(Mat4::getIdentity());
 		m_drawer->setModelMatrix(Mat4::getIdentity());
 		CollisionDebugDrawer cd(m_drawer);
 		CollisionDebugDrawer cd(m_drawer);
 
 
-		cd.visit(hull);
-		cd.visit(s);
-
-		Aabb aabb;
-		hull.computeAabb(aabb);
 		cd.visit(aabb);
 		cd.visit(aabb);
+		cd.visit(comp);
 	}
 	}
 #endif
 #endif
 
 

+ 12 - 0
src/renderer/DebugDrawer.cpp

@@ -453,6 +453,18 @@ void CollisionDebugDrawer::visit(const Frustum& f)
 	}
 	}
 }
 }
 
 
+//==============================================================================
+void CollisionDebugDrawer::visit(const CompoundShape& cs)
+{
+	CollisionDebugDrawer* self = this;
+	Error err = cs.iterateShapes([&](const CollisionShape& a) -> Error 
+	{
+		a.accept(*self);
+		return ErrorCode::NONE;
+	});
+	(void) err;
+}
+
 //==============================================================================
 //==============================================================================
 void CollisionDebugDrawer::visit(const ConvexHullShape& hull)
 void CollisionDebugDrawer::visit(const ConvexHullShape& hull)
 {
 {

+ 3 - 3
testapp/Main.cpp

@@ -231,7 +231,7 @@ Error init()
 	}
 	}
 #endif
 #endif
 
 
-#if 0
+#if 1
 	// horse
 	// horse
 	err = scene.newSceneNode<ModelNode>("horse", horse, 
 	err = scene.newSceneNode<ModelNode>("horse", horse, 
 		"models/horse/horse.ankimdl");
 		"models/horse/horse.ankimdl");
@@ -247,7 +247,7 @@ Error init()
 	}
 	}
 #endif
 #endif
 
 
-	if(0)
+	if(1)
 	{
 	{
 		err = scene.newSceneNode<PointLight>("plight0", point);
 		err = scene.newSceneNode<PointLight>("plight0", point);
 		if(err) return err;
 		if(err) return err;
@@ -261,7 +261,7 @@ Error init()
 		move->setLocalOrigin(Vec4(2.0, 1.4, 0.6, 0.0));
 		move->setLocalOrigin(Vec4(2.0, 1.4, 0.6, 0.0));
 	}
 	}
 
 
-#if 1
+#if 0
 	{
 	{
 		ScriptResourcePointer script;
 		ScriptResourcePointer script;