Browse Source

Fixing physics

Panagiotis Christopoulos Charitos 13 years ago
parent
commit
bd09e024b0

+ 1 - 1
include/anki/gl/GlState.h

@@ -30,7 +30,7 @@ public:
 	}
 	}
 	bool isEnabled(GLenum flag);
 	bool isEnabled(GLenum flag);
 
 
-	void setViewport(uint x, uint y, uint w, uint h);
+	void setViewport(uint32_t x, uint32_t y, uint32_t w, uint32_t h);
 	/// @}
 	/// @}
 
 
 private:
 private:

+ 32 - 37
include/anki/physics/Character.h

@@ -2,59 +2,54 @@
 #define ANKI_PHYSICS_CHARACTER_H
 #define ANKI_PHYSICS_CHARACTER_H
 
 
 #include "anki/math/Math.h"
 #include "anki/math/Math.h"
-
+#include <memory>
 
 
 class btPairCachingGhostObject;
 class btPairCachingGhostObject;
 class btConvexShape;
 class btConvexShape;
 class btKinematicCharacterController;
 class btKinematicCharacterController;
 class btGhostPairCallback;
 class btGhostPairCallback;
 
 
-
 namespace anki {
 namespace anki {
 
 
-
-class SceneNode;
+class Movable;
 class PhysWorld;
 class PhysWorld;
 class MotionState;
 class MotionState;
 
 
-
 /// Its basically a wrapper around bullet character
 /// Its basically a wrapper around bullet character
 class Character
 class Character
 {
 {
-	friend class PhysWorld;
-
-	public:
-		/// Initializer class
-		struct Initializer
-		{
-			float characterHeight;
-			float characterWidth;
-			float stepHeight;
-			float jumpSpeed;
-			float maxJumpHeight;
-			SceneNode* sceneNode; ///< For the MotionState
-			Transform startTrf;
-
-			Initializer();
-		};
-
-		Character(PhysWorld& masterContainer, const Initializer& init);
-		~Character();
-		void rotate(float angle);
-		void moveForward(float distance);
-		void jump();
-
-	private:
-		PhysWorld& masterContainer; ///< Know your father
-		btPairCachingGhostObject* ghostObject;
-		btConvexShape* convexShape;
-		btKinematicCharacterController* character;
-		btGhostPairCallback* ghostPairCallback;
-		MotionState* motionState;
+friend class PhysWorld;
+
+public:
+	/// Initializer class
+	struct Initializer
+	{
+		float characterHeight;
+		float characterWidth;
+		float stepHeight;
+		float jumpSpeed;
+		float maxJumpHeight;
+		Movable* movable; ///< For the MotionState
+		Transform startTrf;
+
+		Initializer();
+	};
+
+	Character(PhysWorld* masterContainer, const Initializer& init);
+	~Character();
+	void rotate(float angle);
+	void moveForward(float distance);
+	void jump();
+
+private:
+	PhysWorld* masterContainer; ///< Know your father
+	btPairCachingGhostObject* ghostObject;
+	btConvexShape* convexShape;
+	btKinematicCharacterController* character;
+	btGhostPairCallback* ghostPairCallback;
+	std::unique_ptr<MotionState> motionState;
 };
 };
 
 
-
 } // end namespace
 } // end namespace
 
 
-
 #endif
 #endif

+ 31 - 46
include/anki/physics/MotionState.h

@@ -2,66 +2,51 @@
 #define ANKI_PHYSICS_MOTION_STATE_H
 #define ANKI_PHYSICS_MOTION_STATE_H
 
 
 #include <bullet/LinearMath/btMotionState.h>
 #include <bullet/LinearMath/btMotionState.h>
-#include "anki/scene/SceneNode.h"
-
+#include "anki/scene/Movable.h"
 
 
 namespace anki {
 namespace anki {
 
 
-
 /// A custom motion state
 /// A custom motion state
 class MotionState: public btMotionState
 class MotionState: public btMotionState
 {
 {
-	public:
-		MotionState(const Transform& initialTransform, SceneNode* node_);
-		~MotionState() {}
-
-		/// @name Bullet implementation of virtuals
-		/// @{
-		void getWorldTransform(btTransform& worldTrans) const;
-		const btTransform& getWorldTransform() const;
-		void setWorldTransform(const btTransform& worldTrans);
-		/// @}
-
-	private:
-		btTransform worldTransform;
-		SceneNode* node; ///< Pointer cause it may be NULL
-};
-
-
-inline MotionState::MotionState(const Transform& initialTransform,
-	SceneNode* node_)
-:	worldTransform(toBt(initialTransform)),
-	node(node_)
-{}
-
-
-inline void MotionState::getWorldTransform(btTransform& worldTrans) const
-{
-	worldTrans = worldTransform;
-}
+public:
+	MotionState(const Transform& initialTransform, Movable* node_)
+		: worldTransform(toBt(initialTransform)), node(node_)
+	{}
 
 
+	~MotionState() {}
 
 
-inline const btTransform& MotionState::getWorldTransform() const
-{
-	return worldTransform;
-}
-
+	/// @name Bullet implementation of virtuals
+	/// @{
+	void getWorldTransform(btTransform& worldTrans) const
+	{
+		worldTrans = worldTransform;
+	}
 
 
-inline void MotionState::setWorldTransform(const btTransform& worldTrans)
-{
-	worldTransform = worldTrans;
+	const btTransform& getWorldTransform() const
+	{
+		return worldTransform;;
+	}
 
 
-	if(node)
+	void setWorldTransform(const btTransform& worldTrans)
 	{
 	{
-		Transform& nodeTrf = node->getLocalTransform();
-		float originalScale = nodeTrf.getScale();
-		nodeTrf = toAnki(worldTrans);
-		nodeTrf.setScale(originalScale);
+		worldTransform = worldTrans;
+
+		if(node)
+		{
+			Transform& nodeTrf = node->getLocalTransform();
+			float originalScale = nodeTrf.getScale();
+			nodeTrf = toAnki(worldTrans);
+			nodeTrf.setScale(originalScale);
+		}
 	}
 	}
-}
+	/// @}
 
 
+private:
+	btTransform worldTransform;
+	Movable* node; ///< Pointer cause it may be NULL
+};
 
 
 } // end namespace
 } // end namespace
 
 
-
 #endif
 #endif

+ 29 - 31
include/anki/physics/RigidBody.h

@@ -2,50 +2,48 @@
 #define ANKI_PHYSICS_RIGID_BODY_H
 #define ANKI_PHYSICS_RIGID_BODY_H
 
 
 #include "anki/math/Math.h"
 #include "anki/math/Math.h"
-#include <boost/scoped_ptr.hpp>
+#include <memory>
 #include <bullet/btBulletDynamicsCommon.h>
 #include <bullet/btBulletDynamicsCommon.h>
 #include <bullet/btBulletCollisionCommon.h>
 #include <bullet/btBulletCollisionCommon.h>
 
 
-
 namespace anki {
 namespace anki {
 
 
-
-class SceneNode;
+class Movable;
 class MotionState;
 class MotionState;
 class PhysWorld;
 class PhysWorld;
 
 
-
 /// Wrapper for rigid body
 /// Wrapper for rigid body
 class RigidBody: public btRigidBody
 class RigidBody: public btRigidBody
 {
 {
-	public:
-		/// Initializer class
-		struct Initializer
-		{
-			float mass;
-			Transform startTrf;
-			btCollisionShape* shape;
-			SceneNode* sceneNode;
-			int group;
-			int mask;
-
-			Initializer();
-		};
-
-		/// Init and register
-		RigidBody(PhysWorld& masterContainer, const Initializer& init);
-
-		/// Unregister
-		~RigidBody();
-
-	private:
-		PhysWorld& masterContainer; ///< Know your father
-		/// Keep it here for garbage collection
-		boost::scoped_ptr<MotionState> motionState;
+public:
+	/// Initializer class
+	struct Initializer
+	{
+		float mass;
+		Transform startTrf;
+		btCollisionShape* shape;
+		Movable* movable;
+		int group;
+		int mask;
+
+		Initializer()
+			: mass(0.0), startTrf(Transform::getIdentity()),
+				shape(nullptr), movable(nullptr), group(-1), mask(-1)
+		{}
+	};
+
+	/// Init and register
+	RigidBody(PhysWorld* masterContainer, const Initializer& init);
+
+	/// Unregister
+	~RigidBody();
+
+private:
+	PhysWorld* masterContainer; ///< Know your father
+	/// Keep it here for garbage collection
+	std::unique_ptr<MotionState> motionState;
 };
 };
 
 
-
 } // end namespace
 } // end namespace
 
 
-
 #endif
 #endif

+ 4 - 5
include/anki/scene/Movable.h

@@ -4,13 +4,10 @@
 #include "anki/util/Object.h"
 #include "anki/util/Object.h"
 #include "anki/math/Math.h"
 #include "anki/math/Math.h"
 
 
-
 namespace anki {
 namespace anki {
 
 
-
 class PropertyMap;
 class PropertyMap;
 
 
-
 /// @addtogroup Scene
 /// @addtogroup Scene
 /// @{
 /// @{
 
 
@@ -43,6 +40,10 @@ public:
 	{
 	{
 		return lTrf;
 		return lTrf;
 	}
 	}
+	Transform& getLocalTransform()
+	{
+		return lTrf;
+	}
 	void setLocalTransform(const Transform& x)
 	void setLocalTransform(const Transform& x)
 	{
 	{
 		lTrf = x;
 		lTrf = x;
@@ -157,8 +158,6 @@ protected:
 };
 };
 /// @}
 /// @}
 
 
-
 } // end namespace
 } // end namespace
 
 
-
 #endif
 #endif

+ 8 - 18
include/anki/util/Variant.h

@@ -6,12 +6,8 @@
 #include <iosfwd>
 #include <iosfwd>
 #include <memory>
 #include <memory>
 
 
-#error "The file is experimental. Dont include"
-
-
 namespace anki {
 namespace anki {
 
 
-
 // Forwards
 // Forwards
 template<typename Data, typename VariantBase>
 template<typename Data, typename VariantBase>
 class VariantDerived;
 class VariantDerived;
@@ -19,17 +15,16 @@ class VariantDerived;
 template<typename... Types>
 template<typename... Types>
 class VariantBase;
 class VariantBase;
 
 
-
 /// The variant base class
 /// The variant base class
 template<typename... Types>
 template<typename... Types>
 class VariantBase:
 class VariantBase:
 	public Visitable<VariantDerived<Types, VariantBase<Types...>>...>
 	public Visitable<VariantDerived<Types, VariantBase<Types...>>...>
 {
 {
 public:
 public:
-	typedef Visitable<VariantDerived<Types, VariantBase<Types...>>...> BaseType;
-	typedef VariantBase<Types...> SelfType;
-	typedef typename BaseType::ConstVisitorType ConstVisitorType;
-	typedef typename BaseType::MutableVisitorType MutableVisitorType;
+	typedef Visitable<VariantDerived<Types, VariantBase<Types...>>...> Base;
+	typedef VariantBase<Types...> Self;
+	typedef typename BaseType::ConstVisitor ConstVisitor;
+	typedef typename BaseType::MutableVisitor MutableVisitor;
 
 
 	static const int TEMPLATE_PARAMETERS_NUM = sizeof...(Types);
 	static const int TEMPLATE_PARAMETERS_NUM = sizeof...(Types);
 
 
@@ -77,7 +72,7 @@ public:
 	/// Print
 	/// Print
 	friend std::ostream& operator<<(std::ostream& s, const SelfType& x)
 	friend std::ostream& operator<<(std::ostream& s, const SelfType& x)
 	{
 	{
-		PrintVisitorType v(s);
+		PrintVisitor v(s);
 		x.accept(v);
 		x.accept(v);
 		return s;
 		return s;
 	}
 	}
@@ -117,7 +112,7 @@ private:
 		}
 		}
 	};
 	};
 
 
-	typedef PrintVisitor<VariantDerived<Types, SelfType>...> PrintVisitorType;
+	using PrintVisitor = PrintVisitor<VariantDerived<Types, SelfType>...>;
 
 
 	uint typeId; ///< type ID
 	uint typeId; ///< type ID
 
 
@@ -134,10 +129,8 @@ private:
 	}
 	}
 };
 };
 
 
-
-/// VariantDerived template class
-///
-/// Using the @a TData and the @a TVariantBase it constructs a variant class
+/// VariantDerived template class. Using the @a TData and the @a TVariantBase 
+/// it constructs a variant class
 template<typename TData, typename TVariantBase>
 template<typename TData, typename TVariantBase>
 class VariantDerived: public TVariantBase
 class VariantDerived: public TVariantBase
 {
 {
@@ -228,7 +221,6 @@ private:
 	DataType data; ///< The data
 	DataType data; ///< The data
 };
 };
 
 
-
 /// XXX
 /// XXX
 /// @note It is no possible to have default constructor because we cannot have
 /// @note It is no possible to have default constructor because we cannot have
 /// template default constructor
 /// template default constructor
@@ -346,8 +338,6 @@ private:
 	std::unique_ptr<VariantBaseType> ptr;
 	std::unique_ptr<VariantBaseType> ptr;
 };
 };
 
 
-
 } // end namespace
 } // end namespace
 
 
-
 #endif
 #endif

+ 21 - 22
include/anki/util/Visitor.h

@@ -4,19 +4,19 @@
 #ifndef ANKI_UTIL_VISITOR_H
 #ifndef ANKI_UTIL_VISITOR_H
 #define ANKI_UTIL_VISITOR_H
 #define ANKI_UTIL_VISITOR_H
 
 
-#error "The file is experimental. Dont include"
-
-
 namespace anki {
 namespace anki {
 
 
+/// @addtogroup util
+/// @{
 
 
+//==============================================================================
+// ConstVisitor                                                                =
 //==============================================================================
 //==============================================================================
 
 
 // Forward declaration
 // Forward declaration
 template<typename... Types>
 template<typename... Types>
 struct ConstVisitor;
 struct ConstVisitor;
 
 
-
 // Specialized for one and many
 // Specialized for one and many
 template<typename First, typename... Types>
 template<typename First, typename... Types>
 struct ConstVisitor<First, Types...>: ConstVisitor<Types...>
 struct ConstVisitor<First, Types...>: ConstVisitor<Types...>
@@ -25,7 +25,6 @@ struct ConstVisitor<First, Types...>: ConstVisitor<Types...>
 	virtual void visit(const First&) = 0;
 	virtual void visit(const First&) = 0;
 };
 };
 
 
-
 // Specialized for one
 // Specialized for one
 template<typename First>
 template<typename First>
 struct ConstVisitor<First>
 struct ConstVisitor<First>
@@ -33,14 +32,14 @@ struct ConstVisitor<First>
 	virtual void visit(const First&) = 0;
 	virtual void visit(const First&) = 0;
 };
 };
 
 
-
+//==============================================================================
+// MutableVisitor                                                              =
 //==============================================================================
 //==============================================================================
 
 
 // Forward declaration
 // Forward declaration
 template<typename... Types>
 template<typename... Types>
 struct MutableVisitor;
 struct MutableVisitor;
 
 
-
 // Specialized for one and many
 // Specialized for one and many
 template<typename First, typename... Types>
 template<typename First, typename... Types>
 struct MutableVisitor<First, Types...>: MutableVisitor<Types...>
 struct MutableVisitor<First, Types...>: MutableVisitor<Types...>
@@ -49,7 +48,6 @@ struct MutableVisitor<First, Types...>: MutableVisitor<Types...>
 	virtual void visit(First&) = 0;
 	virtual void visit(First&) = 0;
 };
 };
 
 
-
 // Specialized for one
 // Specialized for one
 template<typename First>
 template<typename First>
 struct MutableVisitor<First>
 struct MutableVisitor<First>
@@ -57,7 +55,8 @@ struct MutableVisitor<First>
 	virtual void visit(First&) = 0;
 	virtual void visit(First&) = 0;
 };
 };
 
 
-
+//==============================================================================
+// GetTypeIdVisitor                                                            =
 //==============================================================================
 //==============================================================================
 
 
 /// Visitor for getting the type id
 /// Visitor for getting the type id
@@ -95,7 +94,8 @@ struct GetTypeIdVisitor
 	typedef Helper<Types...> Type;
 	typedef Helper<Types...> Type;
 };
 };
 
 
-
+//==============================================================================
+// DummyVisitor                                                                =
 //==============================================================================
 //==============================================================================
 
 
 /// Implements the visit() function. The new visit() does nothing
 /// Implements the visit() function. The new visit() does nothing
@@ -125,14 +125,14 @@ struct DummyVisitor
 	typedef Helper<Types...> Type;
 	typedef Helper<Types...> Type;
 };
 };
 
 
-
+//==============================================================================
+// GetVisitableId                                                              =
 //==============================================================================
 //==============================================================================
 
 
 // Forward
 // Forward
 template<typename Type, typename... Types>
 template<typename Type, typename... Types>
 struct GetVisitableId;
 struct GetVisitableId;
 
 
-
 /// A smart struct that given a @a Type and a list of types defines a const
 /// A smart struct that given a @a Type and a list of types defines a const
 /// integer indicating the @a Type's position from the back of the list. The
 /// integer indicating the @a Type's position from the back of the list. The
 /// integer is named ID
 /// integer is named ID
@@ -145,7 +145,6 @@ template<typename Type, typename First, typename... Types>
 struct GetVisitableId<Type, First, Types...>: GetVisitableId<Type, Types...>
 struct GetVisitableId<Type, First, Types...>: GetVisitableId<Type, Types...>
 {};
 {};
 
 
-
 // Specialized
 // Specialized
 template<typename Type, typename... Types>
 template<typename Type, typename... Types>
 struct GetVisitableId<Type, Type, Types...>
 struct GetVisitableId<Type, Type, Types...>
@@ -153,22 +152,23 @@ struct GetVisitableId<Type, Type, Types...>
 	static const int ID = sizeof...(Types);
 	static const int ID = sizeof...(Types);
 };
 };
 
 
-
+//==============================================================================
+// Visitable                                                                   =
 //==============================================================================
 //==============================================================================
 
 
 /// Visitable class
 /// Visitable class
 template<typename... Types>
 template<typename... Types>
 struct Visitable
 struct Visitable
 {
 {
-	typedef MutableVisitor<Types...> MutableVisitorType;
-	typedef ConstVisitor<Types...> ConstVisitorType;
-	typedef typename GetTypeIdVisitor<Types...>::Type GetTypeIdVisitorType;
-	typedef typename DummyVisitor<Types...>::Type DummyVisitorType;
+	using MutableVisitor = MutableVisitor<Types...>;
+	using ConstVisitor = ConstVisitor<Types...>;
+	using GetTypeIdVisitor = typename GetTypeIdVisitor<Types...>::Type;
+	using DummyVisitor = typename DummyVisitor<Types...>::Type;
 
 
 	/// Visitor accept
 	/// Visitor accept
-	virtual void accept(MutableVisitorType& v) = 0;
+	virtual void accept(MutableVisitor& v) = 0;
 	/// Visitor accept
 	/// Visitor accept
-	virtual void accept(ConstVisitorType& v) const = 0;
+	virtual void accept(ConstVisitor& v) const = 0;
 
 
 	/// Using the GetVisitableId get the id of the @a T
 	/// Using the GetVisitableId get the id of the @a T
 	template<typename T>
 	template<typename T>
@@ -177,9 +177,8 @@ struct Visitable
 		return sizeof...(Types) - GetVisitableId<T, Types...>::ID - 1;
 		return sizeof...(Types) - GetVisitableId<T, Types...>::ID - 1;
 	}
 	}
 };
 };
-
+/// @}
 
 
 } // end namespace
 } // end namespace
 
 
-
 #endif
 #endif

+ 3 - 3
src/gl/GlState.cpp

@@ -66,10 +66,10 @@ void GlState::sync()
 }
 }
 
 
 //==============================================================================
 //==============================================================================
-void GlState::setViewport(uint x, uint y, uint w, uint h)
+void GlState::setViewport(uint32_t x, uint32_t y, uint32_t w, uint32_t h)
 {
 {
-	if(x != (uint)viewportX || y != (uint)viewportY 
-		|| w != (uint)viewportW || h != (uint)viewportH)
+	if(x != (uint32_t)viewportX || y != (uint32_t)viewportY 
+		|| w != (uint32_t)viewportW || h != (uint32_t)viewportH)
 	{
 	{
 		glViewport(x, y, w, h);
 		glViewport(x, y, w, h);
 		viewportX = x;
 		viewportX = x;

+ 1 - 1
src/gl/ShaderProgram.cpp

@@ -23,7 +23,7 @@ ShaderProgramVariable::ShaderProgramVariable(
 {
 {
 	name.shrink_to_fit();
 	name.shrink_to_fit();
 	ANKI_ASSERT(loc == 
 	ANKI_ASSERT(loc == 
-		getUniformLocation(fatherSProg->getGlId(), name.c_str()));
+		glGetUniformLocation(fatherSProg->getGlId(), name.c_str()));
 }
 }
 
 
 //==============================================================================
 //==============================================================================

+ 27 - 39
src/physics/Character.cpp

@@ -9,38 +9,39 @@
 #include <bullet/BulletCollision/CollisionDispatch/btGhostObject.h>
 #include <bullet/BulletCollision/CollisionDispatch/btGhostObject.h>
 #include <bullet/BulletDynamics/Character/btKinematicCharacterController.h>
 #include <bullet/BulletDynamics/Character/btKinematicCharacterController.h>
 
 
-
 namespace anki {
 namespace anki {
 
 
-
 //==============================================================================
 //==============================================================================
-// Contructor                                                                  =
+// Character::Initializer                                                      = 
 //==============================================================================
 //==============================================================================
-inline Character::Initializer::Initializer():
-	characterHeight(2.0),
-	characterWidth(0.75),
-	stepHeight(1.0),
-	jumpSpeed(10.0),
-	maxJumpHeight(0.0),
-	sceneNode(NULL),
-	startTrf(Transform::getIdentity())
-{}
 
 
+//==============================================================================
+inline Character::Initializer::Initializer()
+	: characterHeight(2.0),
+		characterWidth(0.75),
+		stepHeight(1.0),
+		jumpSpeed(10.0),
+		maxJumpHeight(0.0),
+		movable(nullptr),
+		startTrf(Transform::getIdentity())
+{}
 
 
 //==============================================================================
 //==============================================================================
-// Contructor                                                                  =
+// Character                                                                   = 
+//==============================================================================
+
 //==============================================================================
 //==============================================================================
-Character::Character(PhysWorld& masterContainer_,
+Character::Character(PhysWorld* masterContainer_,
 	const Initializer& init)
 	const Initializer& init)
-:	masterContainer(masterContainer_)
+	: masterContainer(masterContainer_)
 {
 {
 	ghostObject = new btPairCachingGhostObject();
 	ghostObject = new btPairCachingGhostObject();
 
 
-	motionState = new MotionState(init.startTrf, init.sceneNode);
+	motionState.reset(new MotionState(init.startTrf, init.movable));
 
 
 	btAxisSweep3* sweepBp =
 	btAxisSweep3* sweepBp =
-		dynamic_cast<btAxisSweep3*>(masterContainer.broadphase);
-	ANKI_ASSERT(sweepBp != NULL);
+		dynamic_cast<btAxisSweep3*>(masterContainer->broadphase);
+	ANKI_ASSERT(sweepBp != nullptr);
 
 
 	ghostPairCallback = new btGhostPairCallback();
 	ghostPairCallback = new btGhostPairCallback();
 	sweepBp->getOverlappingPairCache()->setInternalGhostPairCallback(
 	sweepBp->getOverlappingPairCache()->setInternalGhostPairCallback(
@@ -61,26 +62,23 @@ Character::Character(PhysWorld& masterContainer_,
 	character->setMaxJumpHeight(init.maxJumpHeight);
 	character->setMaxJumpHeight(init.maxJumpHeight);
 
 
 	// register
 	// register
-	masterContainer.dynamicsWorld->addCollisionObject(ghostObject,
+	masterContainer->dynamicsWorld->addCollisionObject(ghostObject,
 		btBroadphaseProxy::CharacterFilter,
 		btBroadphaseProxy::CharacterFilter,
 		btBroadphaseProxy::StaticFilter|btBroadphaseProxy::DefaultFilter);
 		btBroadphaseProxy::StaticFilter|btBroadphaseProxy::DefaultFilter);
 
 
-	masterContainer.dynamicsWorld->addAction(character);
+	masterContainer->dynamicsWorld->addAction(character);
 
 
-	masterContainer.characters.push_back(this);
+	masterContainer->characters.push_back(this);
 }
 }
 
 
-
-//==============================================================================
-// Destructor                                                                  =
 //==============================================================================
 //==============================================================================
 Character::~Character()
 Character::~Character()
 {
 {
-	masterContainer.characters.erase(std::find(
-		masterContainer.characters.begin(),
-		masterContainer.characters.end(), this));
-	masterContainer.dynamicsWorld->removeAction(character);
-	masterContainer.dynamicsWorld->removeCollisionObject(ghostObject);
+	masterContainer->characters.erase(std::find(
+		masterContainer->characters.begin(),
+		masterContainer->characters.end(), this));
+	masterContainer->dynamicsWorld->removeAction(character);
+	masterContainer->dynamicsWorld->removeCollisionObject(ghostObject);
 
 
 	delete character;
 	delete character;
 	delete convexShape;
 	delete convexShape;
@@ -88,9 +86,6 @@ Character::~Character()
 	delete ghostObject;
 	delete ghostObject;
 }
 }
 
 
-
-//==============================================================================
-// rotate                                                                      =
 //==============================================================================
 //==============================================================================
 void Character::rotate(float angle)
 void Character::rotate(float angle)
 {
 {
@@ -99,9 +94,6 @@ void Character::rotate(float angle)
 	ghostObject->getWorldTransform().setBasis(rot);
 	ghostObject->getWorldTransform().setBasis(rot);
 }
 }
 
 
-
-//==============================================================================
-// moveForward                                                                 =
 //==============================================================================
 //==============================================================================
 void Character::moveForward(float distance)
 void Character::moveForward(float distance)
 {
 {
@@ -110,14 +102,10 @@ void Character::moveForward(float distance)
 	character->setWalkDirection(forward * distance);
 	character->setWalkDirection(forward * distance);
 }
 }
 
 
-
-//==============================================================================
-// jump                                                                        =
 //==============================================================================
 //==============================================================================
 void Character::jump()
 void Character::jump()
 {
 {
 	character->jump();
 	character->jump();
 }
 }
 
 
-
 } // end namespace
 } // end namespace

+ 11 - 32
src/physics/RigidBody.cpp

@@ -3,34 +3,17 @@
 #include "anki/scene/Scene.h"
 #include "anki/scene/Scene.h"
 #include "anki/physics/MotionState.h"
 #include "anki/physics/MotionState.h"
 
 
-
 namespace anki {
 namespace anki {
 
 
-
-//==============================================================================
-// Constructor                                                                 =
-//==============================================================================
-RigidBody::Initializer::Initializer():
-	mass(0.0),
-	startTrf(Transform::getIdentity()),
-	shape(NULL),
-	sceneNode(NULL),
-	group(-1),
-	mask(-1)
-{}
-
-
-//==============================================================================
-// Constructor                                                                 =
 //==============================================================================
 //==============================================================================
-RigidBody::RigidBody(PhysWorld& masterContainer_,
+RigidBody::RigidBody(PhysWorld* masterContainer_,
 	const Initializer& init)
 	const Initializer& init)
-:	btRigidBody(btRigidBody::btRigidBodyConstructionInfo(0.0, NULL, NULL,
-		btVector3(0.0, 0.0, 0.0))), // dummy init
-	masterContainer(masterContainer_)
+	: btRigidBody(btRigidBody::btRigidBodyConstructionInfo(0.0, nullptr, 
+		nullptr, btVector3(0.0, 0.0, 0.0))), // dummy init
+		masterContainer(masterContainer_)
 {
 {
-	ANKI_ASSERT(init.shape != NULL &&
-		init.shape->getShapeType() != INVALID_SHAPE_PROXYTYPE);
+	ANKI_ASSERT(init.shape != nullptr 
+		&& init.shape->getShapeType() != INVALID_SHAPE_PROXYTYPE);
 
 
 	bool isDynamic = (init.mass != 0.0);
 	bool isDynamic = (init.mass != 0.0);
 
 
@@ -44,7 +27,7 @@ RigidBody::RigidBody(PhysWorld& masterContainer_,
 		localInertia = btVector3(0.0, 0.0, 0.0);
 		localInertia = btVector3(0.0, 0.0, 0.0);
 	}
 	}
 
 
-	motionState.reset(new MotionState(init.startTrf, init.sceneNode));
+	motionState.reset(new MotionState(init.startTrf, init.movable));
 
 
 	btRigidBody::btRigidBodyConstructionInfo cInfo(init.mass,
 	btRigidBody::btRigidBodyConstructionInfo cInfo(init.mass,
 		motionState.get(), init.shape, localInertia);
 		motionState.get(), init.shape, localInertia);
@@ -52,30 +35,26 @@ RigidBody::RigidBody(PhysWorld& masterContainer_,
 	setupRigidBody(cInfo);
 	setupRigidBody(cInfo);
 
 
 	setContactProcessingThreshold(
 	setContactProcessingThreshold(
-		masterContainer.defaultContactProcessingThreshold);
+		masterContainer->defaultContactProcessingThreshold);
 
 
 	forceActivationState(ISLAND_SLEEPING);
 	forceActivationState(ISLAND_SLEEPING);
 
 
 	// register
 	// register
 	if(init.mask == -1 || init.group == -1)
 	if(init.mask == -1 || init.group == -1)
 	{
 	{
-		masterContainer.dynamicsWorld->addRigidBody(this);
+		masterContainer->dynamicsWorld->addRigidBody(this);
 	}
 	}
 	else
 	else
 	{
 	{
-		masterContainer.dynamicsWorld->addRigidBody(this, init.group,
+		masterContainer->dynamicsWorld->addRigidBody(this, init.group,
 			init.mask);
 			init.mask);
 	}
 	}
 }
 }
 
 
-
-//==============================================================================
-// Destructor                                                                  =
 //==============================================================================
 //==============================================================================
 RigidBody::~RigidBody()
 RigidBody::~RigidBody()
 {
 {
-	masterContainer.dynamicsWorld->removeRigidBody(this);
+	masterContainer->dynamicsWorld->removeRigidBody(this);
 }
 }
 
 
-
 } // end namespace
 } // end namespace

+ 0 - 23
src/resource/Material.cpp

@@ -14,10 +14,8 @@
 #include <boost/lexical_cast.hpp>
 #include <boost/lexical_cast.hpp>
 #include <algorithm>
 #include <algorithm>
 
 
-
 namespace anki {
 namespace anki {
 
 
-
 //==============================================================================
 //==============================================================================
 // MaterialVariable                                                            =
 // MaterialVariable                                                            =
 //==============================================================================
 //==============================================================================
@@ -26,21 +24,18 @@ namespace anki {
 MaterialVariable::~MaterialVariable()
 MaterialVariable::~MaterialVariable()
 {}
 {}
 
 
-
 //==============================================================================
 //==============================================================================
 GLenum MaterialVariable::getGlDataType() const
 GLenum MaterialVariable::getGlDataType() const
 {
 {
 	return oneSProgVar->getGlDataType();
 	return oneSProgVar->getGlDataType();
 }
 }
 
 
-
 //==============================================================================
 //==============================================================================
 const std::string& MaterialVariable::getName() const
 const std::string& MaterialVariable::getName() const
 {
 {
 	return oneSProgVar->getName();
 	return oneSProgVar->getName();
 }
 }
 
 
-
 //==============================================================================
 //==============================================================================
 void MaterialVariable::init(const char* shaderProgVarName,
 void MaterialVariable::init(const char* shaderProgVarName,
 	const PassLevelToShaderProgramHashMap& sProgs)
 	const PassLevelToShaderProgramHashMap& sProgs)
@@ -87,7 +82,6 @@ void MaterialVariable::init(const char* shaderProgVarName,
 	}
 	}
 }
 }
 
 
-
 //==============================================================================
 //==============================================================================
 // Material                                                                    =
 // Material                                                                    =
 //==============================================================================
 //==============================================================================
@@ -117,12 +111,10 @@ ConstCharPtrHashMap<GLenum>::Type Material::txtToBlengGlEnum =
 Material::Material()
 Material::Material()
 {}
 {}
 
 
-
 //==============================================================================
 //==============================================================================
 Material::~Material()
 Material::~Material()
 {}
 {}
 
 
-
 //==============================================================================
 //==============================================================================
 void Material::load(const char* filename)
 void Material::load(const char* filename)
 {
 {
@@ -140,18 +132,15 @@ void Material::load(const char* filename)
 	}
 	}
 }
 }
 
 
-
 //==============================================================================
 //==============================================================================
 void Material::parseMaterialTag(const boost::property_tree::ptree& pt)
 void Material::parseMaterialTag(const boost::property_tree::ptree& pt)
 {
 {
 	using namespace boost::property_tree;
 	using namespace boost::property_tree;
 
 
-	//
 	// renderingStage
 	// renderingStage
 	//
 	//
 	renderingStage = pt.get<int>("renderingStage");
 	renderingStage = pt.get<int>("renderingStage");
 
 
-	//
 	// passes
 	// passes
 	//
 	//
 	boost::optional<std::string> pass =
 	boost::optional<std::string> pass =
@@ -166,7 +155,6 @@ void Material::parseMaterialTag(const boost::property_tree::ptree& pt)
 		passes.push_back("DUMMY");
 		passes.push_back("DUMMY");
 	}
 	}
 
 
-	//
 	// levelsOfDetail
 	// levelsOfDetail
 	//
 	//
 	boost::optional<int> lod = pt.get_optional<int>("levelsOfDetail");
 	boost::optional<int> lod = pt.get_optional<int>("levelsOfDetail");
@@ -180,7 +168,6 @@ void Material::parseMaterialTag(const boost::property_tree::ptree& pt)
 		levelsOfDetail = 1;
 		levelsOfDetail = 1;
 	}
 	}
 
 
-	//
 	// shadow
 	// shadow
 	//
 	//
 	boost::optional<int> sw = pt.get_optional<int>("shadow");
 	boost::optional<int> sw = pt.get_optional<int>("shadow");
@@ -190,7 +177,6 @@ void Material::parseMaterialTag(const boost::property_tree::ptree& pt)
 		shadow = sw.get();
 		shadow = sw.get();
 	}
 	}
 
 
-	//
 	// blendFunctions
 	// blendFunctions
 	//
 	//
 	boost::optional<const ptree&> blendFuncsTree =
 	boost::optional<const ptree&> blendFuncsTree =
@@ -230,7 +216,6 @@ void Material::parseMaterialTag(const boost::property_tree::ptree& pt)
 		}
 		}
 	}
 	}
 
 
-	//
 	// depthTesting
 	// depthTesting
 	//
 	//
 	boost::optional<int> dp = pt.get_optional<int>("depthTesting");
 	boost::optional<int> dp = pt.get_optional<int>("depthTesting");
@@ -240,7 +225,6 @@ void Material::parseMaterialTag(const boost::property_tree::ptree& pt)
 		depthTesting = dp.get();
 		depthTesting = dp.get();
 	}
 	}
 
 
-	//
 	// wireframe
 	// wireframe
 	//
 	//
 	boost::optional<int> wf = pt.get_optional<int>("wireframe");
 	boost::optional<int> wf = pt.get_optional<int>("wireframe");
@@ -250,7 +234,6 @@ void Material::parseMaterialTag(const boost::property_tree::ptree& pt)
 		wireframe = wf.get();
 		wireframe = wf.get();
 	}
 	}
 
 
-	//
 	// shaderProgram
 	// shaderProgram
 	//
 	//
 	MaterialShaderProgramCreator mspc(pt.get_child("shaderProgram"));
 	MaterialShaderProgramCreator mspc(pt.get_child("shaderProgram"));
@@ -284,7 +267,6 @@ void Material::parseMaterialTag(const boost::property_tree::ptree& pt)
 	populateVariables(pt.get_child("shaderProgram"));
 	populateVariables(pt.get_child("shaderProgram"));
 }
 }
 
 
-
 //==============================================================================
 //==============================================================================
 std::string Material::createShaderProgSourceToCache(const std::string& source)
 std::string Material::createShaderProgSourceToCache(const std::string& source)
 {
 {
@@ -316,7 +298,6 @@ std::string Material::createShaderProgSourceToCache(const std::string& source)
 	return newfPathName.string();
 	return newfPathName.string();
 }
 }
 
 
-
 //==============================================================================
 //==============================================================================
 void Material::populateVariables(const boost::property_tree::ptree& pt)
 void Material::populateVariables(const boost::property_tree::ptree& pt)
 {
 {
@@ -382,7 +363,6 @@ void Material::populateVariables(const boost::property_tree::ptree& pt)
 		}
 		}
 	}
 	}
 
 
-	//
 	// Now combine
 	// Now combine
 	//
 	//
 	std::map<std::string, GLenum>::const_iterator it = allVarNames.begin();
 	std::map<std::string, GLenum>::const_iterator it = allVarNames.begin();
@@ -487,7 +467,6 @@ void Material::populateVariables(const boost::property_tree::ptree& pt)
 	}
 	}
 }
 }
 
 
-
 //==============================================================================
 //==============================================================================
 template<typename Type, size_t n>
 template<typename Type, size_t n>
 Type Material::setMathType(const char* str)
 Type Material::setMathType(const char* str)
@@ -504,7 +483,6 @@ Type Material::setMathType(const char* str)
 	return out;
 	return out;
 }
 }
 
 
-
 //==============================================================================
 //==============================================================================
 const MaterialVariable& Material::findVariableByName(const char* name) const
 const MaterialVariable& Material::findVariableByName(const char* name) const
 {
 {
@@ -517,5 +495,4 @@ const MaterialVariable& Material::findVariableByName(const char* name) const
 	return *(it->second);
 	return *(it->second);
 }
 }
 
 
-
 } // end namespace
 } // end namespace

+ 0 - 5
src/scene/Movable.cpp

@@ -2,10 +2,8 @@
 #include "anki/scene/Property.h"
 #include "anki/scene/Property.h"
 #include <boost/foreach.hpp>
 #include <boost/foreach.hpp>
 
 
-
 namespace anki {
 namespace anki {
 
 
-
 //==============================================================================
 //==============================================================================
 Movable::Movable(uint flags_, Movable* parent, PropertyMap& pmap)
 Movable::Movable(uint flags_, Movable* parent, PropertyMap& pmap)
 	: Base(this, parent), flags(flags_)
 	: Base(this, parent), flags(flags_)
@@ -16,7 +14,6 @@ Movable::Movable(uint flags_, Movable* parent, PropertyMap& pmap)
 		new ReadPointerProperty<Transform>("worldTransform", &wTrf));
 		new ReadPointerProperty<Transform>("worldTransform", &wTrf));
 }
 }
 
 
-
 //==============================================================================
 //==============================================================================
 void Movable::update()
 void Movable::update()
 {
 {
@@ -26,7 +23,6 @@ void Movable::update()
 	}
 	}
 }
 }
 
 
-
 //==============================================================================
 //==============================================================================
 void Movable::updateWorldTransform()
 void Movable::updateWorldTransform()
 {
 {
@@ -66,5 +62,4 @@ void Movable::updateWorldTransform()
 	}
 	}
 }
 }
 
 
-
 } // namespace anki
 } // namespace anki