Panagiotis Christopoulos Charitos пре 13 година
родитељ
комит
c58d847cb8
4 измењених фајлова са 56 додато и 78 уклоњено
  1. 32 42
      include/anki/physics/PhysWorld.h
  2. 12 11
      include/anki/scene/Scene.h
  3. 10 23
      src/physics/PhysWorld.cpp
  4. 2 2
      src/physics/RigidBody.cpp

+ 32 - 42
include/anki/physics/PhysWorld.h

@@ -7,62 +7,52 @@
 #include <btBulletCollisionCommon.h>
 #include <btBulletDynamicsCommon.h>
 
-
 class btIDebugDraw;
 
-
 namespace anki {
 
-
 class Character;
 class RigidBody;
 
-
 /// The master container for all physics related stuff.
 class PhysWorld
 {
 	friend class Character; ///< For registering and unregistering
 	friend class RigidBody;  ///< For registering and unregistering
 
-	public:
-		/// Collision groups
-		enum CollisionGroup
-		{
-			CG_NOTHING = 0,
-			CG_MAP = 1,
-			CG_PARTICLE = 2,
-			CG_ALL = CG_MAP | CG_PARTICLE
-		};
-
-	public:
-		PhysWorld();
-		~PhysWorld();
-
-		/// @name Accessors
-		/// @{
-		btDiscreteDynamicsWorld& getWorld() {return *dynamicsWorld;}
-		void setDebugDrawer(btIDebugDraw* newDebugDrawer);
-		/// @}
-
-		/// Time as always in sec
-		void update(float prevUpdateTime, float crntTime);
-
-	private:
-		/// Container for rigid bodied and constraints
-		btDiscreteDynamicsWorld* dynamicsWorld;
-		btDefaultCollisionConfiguration* collisionConfiguration;
-		/// Contains the algorithms of collision
-		btCollisionDispatcher* dispatcher;
-		btBroadphaseInterface* broadphase;
-		btSequentialImpulseConstraintSolver* sol;
-		/// Keep here for garbage collection
-		std::unique_ptr<btIDebugDraw> debugDrawer;
-		float defaultContactProcessingThreshold;
-		Vector<Character*> characters;
+public:
+	/// Collision groups
+	enum CollisionGroup
+	{
+		CG_NOTHING = 0,
+		CG_MAP = 1,
+		CG_PARTICLE = 2,
+		CG_ALL = CG_MAP | CG_PARTICLE
+	};
+
+public:
+	PhysWorld();
+	~PhysWorld();
+
+	void setDebugDrawer(btIDebugDraw* newDebugDrawer);
+
+	/// Time as always in sec
+	void update(F32 prevUpdateTime, F32 crntTime);
+
+private:
+	/// Container for rigid bodied and constraints
+	btDiscreteDynamicsWorld* dynamicsWorld;
+	btDefaultCollisionConfiguration* collisionConfiguration;
+	/// Contains the algorithms of collision
+	btCollisionDispatcher* dispatcher;
+	btBroadphaseInterface* broadphase;
+	btSequentialImpulseConstraintSolver* sol;
+	/// Keep here for garbage collection
+	std::unique_ptr<btIDebugDraw> debugDrawer;
+	F32 defaultContactProcessingThreshold;
+	Vector<Character*> characters;
 };
 
-
-} // end namespace
-
+} // end namespace anki
 
 #endif

+ 12 - 11
include/anki/scene/Scene.h

@@ -21,6 +21,8 @@ class Renderer;
 /// XXX Add physics
 class Scene
 {
+	friend class SceneNode;
+
 public:
 	template<typename T>
 	struct Types
@@ -94,10 +96,6 @@ public:
 	}
 	/// @}
 
-	/// Put a node in the appropriate containers
-	void registerNode(SceneNode* node);
-	void unregisterNode(SceneNode* node);
-
 	void update(float prevUpdateTime, float crntTime, Renderer& renderer);
 
 	SceneNode* findSceneNode(const char* name)
@@ -109,16 +107,22 @@ public:
 	PtrVector<Sector> sectors;
 
 private:
-	Types<SceneNode>::Container nodes;
-	Types<SceneNode>::NameToItemMap nameToNode;
 	Vec3 ambientCol = Vec3(1.0); ///< The global ambient color
 	U32 ambiendColorUpdateTimestamp = Timestamp::getTimestamp();
 	Camera* mainCam = nullptr;
 	U32 activeCameraChangeTimestamp = Timestamp::getTimestamp();
+
+	Types<SceneNode>::Container nodes;
+	Types<SceneNode>::NameToItemMap nameToNode;
+
 	VisibilityTester vtester;
 
 	void doVisibilityTests(Camera& cam, Renderer& r);
 
+	/// Put a node in the appropriate containers
+	void registerNode(SceneNode* node);
+	void unregisterNode(SceneNode* node);
+
 	/// Add to a container
 	template<typename T>
 	void addC(typename Types<T>::Container& c, T* ptr)
@@ -131,11 +135,8 @@ private:
 	template<typename T>
 	void addDict(typename Types<T>::NameToItemMap& d, T* ptr)
 	{
-		if(d.find(ptr->getName().c_str()) != d.end())
-		{
-			throw ANKI_EXCEPTION("Item with same name already exists: "
-				+ ptr->getName());
-		}
+		ANKI_ASSERT(d.find(ptr->getName().c_str()) == d.end()
+			&& "Item with same name already exists");
 
 		d[ptr->getName().c_str()] = ptr;
 	}

+ 10 - 23
src/physics/PhysWorld.cpp

@@ -3,38 +3,29 @@
 #include "anki/physics/MotionState.h"
 #include <BulletCollision/CollisionDispatch/btGhostObject.h>
 
-
 namespace anki {
 
-
-//==============================================================================
-// Constructor                                                                 =
 //==============================================================================
-PhysWorld::PhysWorld():
-	defaultContactProcessingThreshold(BT_LARGE_FLOAT)
+PhysWorld::PhysWorld()
+	: defaultContactProcessingThreshold(BT_LARGE_FLOAT)
 {
 	collisionConfiguration = new btDefaultCollisionConfiguration();
 	dispatcher = new btCollisionDispatcher(collisionConfiguration);
-	broadphase = new btAxisSweep3(btVector3(-1000, -1000, -1000),
+	broadphase = new btAxisSweep3(
+		btVector3(-1000, -1000, -1000),
 		btVector3(1000, 1000, 1000));
 	sol = new btSequentialImpulseConstraintSolver;
-	dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher, broadphase, sol,
-		collisionConfiguration);
+	dynamicsWorld = new btDiscreteDynamicsWorld(
+		dispatcher, broadphase, sol, collisionConfiguration);
 	dynamicsWorld->setGravity(btVector3(0,-10, 0));
 }
 
-
-//==============================================================================
-// Destructor                                                                  =
 //==============================================================================
 PhysWorld::~PhysWorld()
 {
-	/// @todo
+	/// XXX
 }
 
-
-//==============================================================================
-// setDebugDrawer                                                              =
 //==============================================================================
 void PhysWorld::setDebugDrawer(btIDebugDraw* newDebugDrawer)
 {
@@ -43,21 +34,17 @@ void PhysWorld::setDebugDrawer(btIDebugDraw* newDebugDrawer)
 	debugDrawer->setDebugMode(btIDebugDraw::DBG_DrawWireframe);
 }
 
-
 //==============================================================================
-// update                                                                      =
-//==============================================================================
-void PhysWorld::update(float prevUpdateTime, float crntTime)
+void PhysWorld::update(F32 prevUpdateTime, F32 crntTime)
 {
 	dynamicsWorld->stepSimulation(crntTime - prevUpdateTime);
 
 	// updateNonRigidBodiesMotionStates
-	for(uint i = 0; i < characters.size(); i++)
+	for(U i = 0; i < characters.size(); i++)
 	{
 		characters[i]->motionState->setWorldTransform(
 			characters[i]->ghostObject->getWorldTransform());
 	}
 }
 
-
-} // end namespace
+} // end namespace anki

+ 2 - 2
src/physics/RigidBody.cpp

@@ -28,8 +28,8 @@ RigidBody::RigidBody(PhysWorld* masterContainer_, const Initializer& init)
 
 	motionState = MotionState(init.startTrf, init.movable);
 
-	btRigidBody::btRigidBodyConstructionInfo cInfo(init.mass,
-		&motionState, init.shape, localInertia);
+	btRigidBody::btRigidBodyConstructionInfo cInfo(
+		init.mass, &motionState, init.shape, localInertia);
 
 	setupRigidBody(cInfo);