فهرست منبع

- Moving a few files to new dir
- OBB

Panagiotis Christopoulos Charitos 15 سال پیش
والد
کامیت
89d1bfd9b6

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 0 - 1
build/debug/Makefile


+ 69 - 0
src/Collision/Obb.cpp

@@ -15,6 +15,31 @@ Obb Obb::getTransformed(const Transform& transform) const
 }
 
 
+//======================================================================================================================
+// getCompoundShape                                                                                                    =
+//======================================================================================================================
+Obb Obb::getCompoundShape(const Obb& b) const
+{
+	Obb out;
+
+	boost::array<Vec3, 8> points0;
+	boost::array<Vec3, 8> points1;
+
+	getExtremePoints(points0);
+	b.getExtremePoints(points1);
+
+	boost::array<Vec3, 16> points;
+	for(uint i = 0; i < 8; i++)
+	{
+		points[i] = points0[i];
+		points[i + 8] = points1[i];
+	}
+
+	out.set(points);
+	return out;
+}
+
+
 //======================================================================================================================
 // testPlane                                                                                                           =
 //======================================================================================================================
@@ -41,3 +66,47 @@ float Obb::testPlane(const Plane& plane) const
 		return d - r;
 	}
 }
+
+
+//======================================================================================================================
+// getExtremePoints                                                                                                    =
+//======================================================================================================================
+void Obb::getExtremePoints(boost::array<Vec3, 8>& points) const
+{
+	// L: left, R: right, T: top, B: bottom, F: front, B: back
+	enum
+	{
+		RTF,
+		LTF,
+		LBF,
+		RBF,
+		RTB,
+		LTB,
+		LBB,
+		RBB
+	};
+
+	Vec3 er = rotation * extends; // extend rotated
+
+	points[RTF] = er;
+	points[LBB] = -er;
+
+	Vec3 xAxis = rotation.getColumn(0);
+	Vec3 yAxis = rotation.getColumn(1);
+	Vec3 zAxis = rotation.getColumn(2);
+
+	// Reflection: x1' = x1 - 2n|x1.n|
+
+	points[RBB] = er - 2.0 * er.dot(xAxis) * xAxis;
+	points[LTB] = er - 2.0 * er.dot(yAxis) * yAxis;
+	points[LBF] = er - 2.0 * er.dot(zAxis) * zAxis;
+
+	points[LTF] = points[LBB] - 2.0 * points[LBB].dot(-xAxis) * -xAxis;
+	points[RTB] = points[LTF] - 2.0 * points[LTF].dot(yAxis) * yAxis;
+	points[RBF] = points[LTF] - 2.0 * points[LTF].dot(zAxis) * zAxis;
+
+	BOOST_FOREACH(Vec3& point, points)
+	{
+		point += center;
+	}
+}

+ 8 - 1
src/Collision/Obb.h

@@ -1,6 +1,7 @@
 #ifndef OBB_H
 #define OBB_H
 
+#include <boost/array.hpp>
 #include "CollisionShape.h"
 #include "Math.h"
 
@@ -33,6 +34,9 @@ class Obb: public CollisionShape
 
 		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;
+
 		/// @see CollisionShape::testPlane
 		float testPlane(const Plane& plane) const;
 
@@ -45,8 +49,11 @@ class Obb: public CollisionShape
 		/// @{
 		Vec3 center;
 		Mat3 rotation;
-		Vec3 extends;
+		Vec3 extends; ///< With identity rotation this points to max (front, right, top in our case)
 		/// @}
+
+		/// Get extreme points in 3D space
+		void getExtremePoints(boost::array<Vec3, 8>& points) const;
 };
 
 

+ 26 - 0
src/Collision/Sphere.cpp

@@ -21,6 +21,32 @@ Sphere Sphere::getCompoundSphere(const Sphere& b) const
 {
 	const Sphere& a = *this;
 
+	/// @todo test this
+	/*
+	Vec3 centerDiff = b.center - a.center;
+	float radiusDiff = b.radius - a.radius;
+	Vec3 radiusDiffSqr = radiusDiff * radiusDiff;
+	float lenSqr = centerDiff.getLengthSquared();
+
+	if(radiusDiffSqrt >= 0.0)
+	{
+		if(radiusDiff >= 0.0)
+		{
+			return b;
+		}
+		else
+		{
+			return a;
+		}
+	}
+	else
+	{
+		float l = sqrt(lenSqr);
+		float t = (l + b.radius - a.radius) / (2.0 * l);
+		return Sphere(a.center + t * centerDiff, (l + a.radius + b.radius) / 2.0);
+	}
+	*/
+
 	Vec3 c = b.getCenter() - a.getCenter(); // vector from one center to the other
 	float cLen = c.getLength();
 

+ 0 - 0
src/Renderer/PhyDbgDrawer.cpp → src/Renderer/Drawers/PhyDbgDrawer.cpp


+ 0 - 0
src/Renderer/PhyDbgDrawer.h → src/Renderer/Drawers/PhyDbgDrawer.h


+ 0 - 0
src/Renderer/SceneDbgDrawer.cpp → src/Renderer/Drawers/SceneDbgDrawer.cpp


+ 0 - 0
src/Renderer/SceneDbgDrawer.h → src/Renderer/Drawers/SceneDbgDrawer.h


+ 0 - 0
src/Renderer/SceneDrawer.cpp → src/Renderer/Drawers/SceneDrawer.cpp


+ 0 - 0
src/Renderer/SceneDrawer.h → src/Renderer/Drawers/SceneDrawer.h


+ 3 - 0
src/Scene/SceneNode.h

@@ -4,6 +4,7 @@
 #include <memory>
 #include "Math.h"
 #include "Object.h"
+#include "Obb.h"
 
 
 class Material;
@@ -16,6 +17,8 @@ class SceneNode: private Object
 	friend class Scene;
 
 	public:
+		typedef Obb VisibilityCollisionShape;
+
 		enum SceneNodeType
 		{
 			SNT_GHOST,

برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است