Daniele Bartolini před 13 roky
rodič
revize
2f8fda7303
6 změnil soubory, kde provedl 0 přidání a 618 odebrání
  1. 0 108
      src/PhysicNode.cpp
  2. 0 80
      src/PhysicNode.h
  3. 0 136
      src/PhysicsManager.cpp
  4. 0 101
      src/PhysicsManager.h
  5. 0 136
      src/PhysicsSystem.cpp
  6. 0 57
      src/PhysicsSystem.h

+ 0 - 108
src/PhysicNode.cpp

@@ -1,108 +0,0 @@
-/*
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#include "PhysicNode.h"
-#include "PhysicsManager.h"
-
-namespace crown
-{
-
-PhysicNode::PhysicNode(const Vec3& position, const Angles& axis, bool visible, int collisionGroupId) :
-	mVelocity(0.0, 0.0, 0.0),
-	mInverseMass(1.0),
-	mShape(NULL),
-	mCollisionGroupId(collisionGroupId)
-{
-	//creator->GetPhysicsManager()->Register(this, mCollisionGroupId);
-}
-
-PhysicNode::~PhysicNode()
-{
-	//GetCreator()->GetPhysicsManager()->Unregister(this);
-	if (mShape)
-	{
-		delete mShape;
-	}
-}
-
-const Vec3& PhysicNode::GetVelocity() const
-{
-	return mVelocity;
-}
-
-void PhysicNode::SetVelocity(const Vec3 velocity)
-{
-	mVelocity = velocity;
-}
-
-real PhysicNode::GetInverseMass() const
-{
-	return mInverseMass;
-}
-
-void PhysicNode::SetInverseMass(real inverseMass)
-{
-	mInverseMass = inverseMass;
-}
-
-Shape* PhysicNode::GetShape() const
-{
-	return mShape;
-}
-
-void PhysicNode::SetShape(Shape* shape)
-{
-	if (mShape)
-	{
-		delete mShape;
-	}
-	mShape = shape;
-	if (mShape)
-	{
-		mShape->SetPosition(mPosition.ToVec2());
-	}
-}
-
-void PhysicNode::Update(real dt)
-{
-	//Integrates the velocity
-	mPosition += mVelocity * dt;
-	if (mShape)
-	{
-		mShape->SetPosition(mPosition.ToVec2());
-	}
-}
-
-void PhysicNode::Collision(PhysicNode* other)
-{
-
-}
-
-int PhysicNode::GetCollisionGroupId() const
-{
-	return mCollisionGroupId;
-}
-
-}

+ 0 - 80
src/PhysicNode.h

@@ -1,80 +0,0 @@
-/*
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#pragma once
-
-#include "Shape.h"
-#include "Vec3.h"
-#include "Angles.h"
-
-namespace crown
-{
-
-class PhysicNode
-{
-public:
-	//! Constructor
-	PhysicNode(const Vec3& position, const Angles& axis, bool visible, int collisionGroupId);
-
-	//! Destructor
-	virtual ~PhysicNode();
-
-	//! Gets the velocity
-	const Vec3& GetVelocity() const;
-
-	//! Sets the velocity
-	void SetVelocity(const Vec3 velocity);
-
-	//! Gets the inverse mass
-	real GetInverseMass() const;
-
-	//! Sets the inverse mass
-	void SetInverseMass(real inverseMass);
-
-	//! Gets the shape
-	Shape* GetShape() const;
-
-	//! Sets the shape
-	void SetShape(Shape* shape);
-
-	//! Update that applies the velocity
-	virtual void Update(real dt);
-
-	//! Called when a collision occours
-	virtual void Collision(PhysicNode* other);
-
-	//! Returns the collision group id
-	int GetCollisionGroupId() const;
-
-private:
-
-	Vec3 mPosition;
-	Vec3 mVelocity;
-	real mInverseMass;
-	Shape* mShape;
-	int mCollisionGroupId;
-};
-
-}

+ 0 - 136
src/PhysicsManager.cpp

@@ -1,136 +0,0 @@
-/*
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#include "PhysicsManager.h"
-
-namespace crown
-{
-
-//PhysicsManager::PhysicsManager()
-//{
-
-//}
-
-//PhysicsManager::~PhysicsManager()
-//{
-//	CollisionGroupDictionary::Enumerator e = mCollisionGroups.getBegin();
-//	while (e.next())
-//	{
-//		delete e.current().value;
-//	}
-//}
-
-//void PhysicsManager::Register(PhysicNode* node, int collisionGroupId)
-//{
-//	if (mPhysicNodes.Find(node) == -1)
-//	{
-//		mPhysicNodes.Append(node);
-//		List<PhysicNode*>* list;
-//		if (mCollisionGroups.Contains(collisionGroupId))
-//		{
-//			list = mCollisionGroups[collisionGroupId];
-//		}
-//		else
-//		{
-//			list = new List<PhysicNode*>();
-//			mCollisionGroups[collisionGroupId] = list;
-//		}
-//		list->Append(node);
-//	}
-//}
-
-//void PhysicsManager::Unregister(PhysicNode* node)
-//{
-//	int nodeIndex = mPhysicNodes.Find(node);
-//	if (nodeIndex != -1)
-//	{
-//		mPhysicNodes.Remove(nodeIndex);
-//		List<PhysicNode*>* list;
-//		list = mCollisionGroups[node->GetCollisionGroupId()];
-//		list->Remove(list->Find(node));
-//	}
-//}
-
-//void PhysicsManager::AddGroupPairCollisionCheck(int groupId1, int groupId2)
-//{
-//	if (mGroupIdPairsToCollide.Find(CollisionGroupPair(groupId1, groupId2)) == -1)
-//	{
-//		mGroupIdPairsToCollide.Append(CollisionGroupPair(groupId1, groupId2));
-//	}
-//}
-
-//void PhysicsManager::Update(real dt)
-//{
-//	for(int i = 0; i < mGroupIdPairsToCollide.GetSize(); i++)
-//	{
-//		CollideGroups(dt, mGroupIdPairsToCollide[i].collisionGroup1Id, mGroupIdPairsToCollide[i].collisionGroup2Id);
-//	}
-//}
-
-//void PhysicsManager::CollideGroups(real dt, int groupId1, int groupId2)
-//{
-//	if (!mCollisionGroups.Contains(groupId1) || !mCollisionGroups.Contains(groupId2))
-//	{
-//		return;
-//	}
-
-//	List<PhysicNode*>* listGroup1 = mCollisionGroups[groupId1];
-//	List<PhysicNode*>* listGroup2 = mCollisionGroups[groupId2];
-
-//	for(int i = 0; i < listGroup1->GetSize(); i++)
-//	{
-//		PhysicNode* node1 = listGroup1->GetElement(i);
-//		Shape* shapeI = node1->GetShape();
-//		if (shapeI != NULL)
-//		{
-//			int j = 0;
-//			//Initilization of the j loop variable separated, because it has to be i+1 if the group is the same, to avoid double checks
-//			if (groupId1 == groupId2)
-//			{
-//				j = i + 1;
-//			}
-//			for(; j < listGroup2->GetSize(); j++)
-//			{
-//				PhysicNode* node2 = listGroup2->GetElement(j);
-//				Shape* shapeJ = node2->GetShape();
-//				Vec2 penetration(0.0, 0.0);
-//				if (shapeJ != NULL && shapeI->Overlaps(shapeJ, penetration))
-//				{
-//					real imI = node1->GetInverseMass();
-//					real imJ = node2->GetInverseMass();
-//					Vec2 imp = penetration / (imI + imJ);
-//					Vec3 imp3 = Vec3(imp.x, imp.y, 0.0);
-//					node1->SetPosition(node1->GetPosition() + imp3 * imI);
-//					node2->SetPosition(node2->GetPosition() - imp3 * imJ);
-//					
-//					node1->Collision(node2);
-//					node2->Collision(node1);
-//				}
-//			}
-//		}
-//	}
-//}
-
-}

+ 0 - 101
src/PhysicsManager.h

@@ -1,101 +0,0 @@
-/*
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#pragma once
-
-//#include "Config.h"
-//#include "PhysicNode.h"
-//#include "Dictionary.h"
-
-//namespace crown
-//{
-
-//class Scene;
-//class SceneNode;
-
-//struct CollisionGroupPair
-//{
-//	CollisionGroupPair():
-//		collisionGroup1Id(0), collisionGroup2Id(0)
-//	{
-//	}
-
-//	CollisionGroupPair(int Id1, int Id2):
-//		collisionGroup1Id(Id1), collisionGroup2Id(Id2)
-//	{
-//	}
-
-//	CollisionGroupPair(const CollisionGroupPair& other)
-//	{
-//		collisionGroup1Id = other.collisionGroup1Id;
-//		collisionGroup2Id = other.collisionGroup2Id;
-//	}
-
-//	int collisionGroup1Id;
-//	int collisionGroup2Id;
-
-//	bool operator==(const CollisionGroupPair& other) const
-//	{
-//		return (collisionGroup1Id == other.collisionGroup1Id && collisionGroup2Id == other.collisionGroup2Id);
-//	}
-//};
-
-//class PhysicsManager
-//{
-//private:
-//	typedef Dictionary<int, List<PhysicNode*>* > CollisionGroupDictionary;
-
-//public:
-//	//! Constructor
-//	PhysicsManager();
-
-//	//! Destructor
-//	~PhysicsManager();
-
-//	//! Registers the node for collision. The node shape will be used for collision checking and collisions will be reported
-//	void Register(PhysicNode* node, int collisionGroupId);
-
-//	//! Removes the node from the physic system
-//	void Unregister(PhysicNode* node);
-
-//	//! Register a group pair to perform collision detection
-//	void AddGroupPairCollisionCheck(int groupId1, int groupId2);
-
-//	//! Updates the physic system
-//	void Update(real dt);
-
-//private:
-//	List<PhysicNode*> mPhysicNodes;
-//	CollisionGroupDictionary mCollisionGroups;
-//	List<CollisionGroupPair> mGroupIdPairsToCollide;
-
-//	void CollideGroups(real dt, int groupId1, int groupId2);
-
-//	// Disable copying
-//	PhysicsManager(const PhysicsManager&);
-//	PhysicsManager& operator=(const PhysicsManager&);
-//};
-
-//}

+ 0 - 136
src/PhysicsSystem.cpp

@@ -1,136 +0,0 @@
-/*
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#include "PhysicsManager.h"
-
-namespace crown
-{
-
-PhysicsManager::PhysicsManager()
-{
-
-}
-
-PhysicsManager::~PhysicsManager()
-{
-	CollisionGroupDictionary::Enumerator e = mCollisionGroups.getBegin();
-	while (e.next())
-	{
-		delete e.current().value;
-	}
-}
-
-void PhysicsManager::Register(PhysicNode* node, int collisionGroupId)
-{
-	if (mPhysicNodes.Find(node) == -1)
-	{
-		mPhysicNodes.Append(node);
-		List<PhysicNode*>* list;
-		if (mCollisionGroups.Contains(collisionGroupId))
-		{
-			list = mCollisionGroups[collisionGroupId];
-		}
-		else
-		{
-			list = new List<PhysicNode*>();
-			mCollisionGroups[collisionGroupId] = list;
-		}
-		list->Append(node);
-	}
-}
-
-void PhysicsManager::Unregister(PhysicNode* node)
-{
-	int nodeIndex = mPhysicNodes.Find(node);
-	if (nodeIndex != -1)
-	{
-		mPhysicNodes.Remove(nodeIndex);
-		List<PhysicNode*>* list;
-		list = mCollisionGroups[node->GetCollisionGroupId()];
-		list->Remove(list->Find(node));
-	}
-}
-
-void PhysicsManager::AddGroupPairCollisionCheck(int groupId1, int groupId2)
-{
-	if (mGroupIdPairsToCollide.Find(CollisionGroupPair(groupId1, groupId2)) == -1)
-	{
-		mGroupIdPairsToCollide.Append(CollisionGroupPair(groupId1, groupId2));
-	}
-}
-
-void PhysicsManager::Update(real dt)
-{
-	for(int i = 0; i < mGroupIdPairsToCollide.GetSize(); i++)
-	{
-		CollideGroups(dt, mGroupIdPairsToCollide[i].collisionGroup1Id, mGroupIdPairsToCollide[i].collisionGroup2Id);
-	}
-}
-
-void PhysicsManager::CollideGroups(real dt, int groupId1, int groupId2)
-{
-	if (!mCollisionGroups.Contains(groupId1) || !mCollisionGroups.Contains(groupId2))
-	{
-		return;
-	}
-
-	List<PhysicNode*>* listGroup1 = mCollisionGroups[groupId1];
-	List<PhysicNode*>* listGroup2 = mCollisionGroups[groupId2];
-
-	for(int i = 0; i < listGroup1->GetSize(); i++)
-	{
-		PhysicNode* node1 = listGroup1->GetElement(i);
-		Shape* shapeI = node1->GetShape();
-		if (shapeI != NULL)
-		{
-			int j = 0;
-			//Initilization of the j loop variable separated, because it has to be i+1 if the group is the same, to avoid double checks
-			if (groupId1 == groupId2)
-			{
-				j = i + 1;
-			}
-			for(; j < listGroup2->GetSize(); j++)
-			{
-				PhysicNode* node2 = listGroup2->GetElement(j);
-				Shape* shapeJ = node2->GetShape();
-				Vec2 penetration(0.0, 0.0);
-				if (shapeJ != NULL && shapeI->Overlaps(shapeJ, penetration))
-				{
-					real imI = node1->GetInverseMass();
-					real imJ = node2->GetInverseMass();
-					Vec2 imp = penetration / (imI + imJ);
-					Vec3 imp3 = Vec3(imp.x, imp.y, 0.0);
-					node1->SetPosition(node1->GetPosition() + imp3 * imI);
-					node2->SetPosition(node2->GetPosition() - imp3 * imJ);
-					
-					node1->Collision(node2);
-					node2->Collision(node1);
-				}
-			}
-		}
-	}
-}
-
-}

+ 0 - 57
src/PhysicsSystem.h

@@ -1,57 +0,0 @@
-/*
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#pragma once
-
-#include "Types.h"
-#include "Shape.h"
-
-namespace crown
-{
-
-struct PhysicBody
-{
-	Vec3 	mVelocity;
-	real	mMass;
-
-	Shape*	mShape;
-};
-
-class PhysicsSystem
-{
-
-public:
-
-	PhysicsSystem();
-	~PhysicsSystem();
-
-	void Update(real dt);
-
-private:
-
-};
-
-} // namespace crown
-