Răsfoiți Sursa

- Compiled SDL_image in ubuntu 9.10. I will compile everything in older linux
- PhyCharacter WIP

Panagiotis Christopoulos Charitos 15 ani în urmă
părinte
comite
5e253e0058

Fișier diff suprimat deoarece este prea mare
+ 397 - 431
build/debug/Makefile


BIN
extern/lib-x86-64-linux/libSDL_image-1.2.so.0.8.2


BIN
extern/lib-x86-64-linux/libSDL_image.a


+ 1 - 1
extern/lib-x86-64-linux/libSDL_image.la

@@ -38,4 +38,4 @@ dlopen=''
 dlpreopen=''
 
 # Directory that this library needs to be installed in:
-libdir='/home/godlike/src/SDL_image/install/lib'
+libdir='/users/panoscc/src/SDL_image/install/lib'

+ 3 - 8
src/Main.cpp

@@ -228,7 +228,7 @@ void mainLoop()
 	float secs = 0.0;
 	do
 	{
-		int ticks_ = App::getTicks();
+		float crntTime = App::getTicks() / 1000.0;
 		I::handleEvents();
 
 		float dist = 0.2;
@@ -284,12 +284,7 @@ void mainLoop()
 
 		mover->getLocalTransform().getRotation().reorthogonalize();
 
-		//static_cast<btRigidBody*>(dynamicsWorld->getCollisionObjectArray()[1])->getMotionState()->setWorldTransform(toBt(point_lights[0]->transformationWspace));
-		//dynamicsWorld->getCollisionObjectArray()[3]->setWorldTransform(toBt(point_lights[0]->transformationWspace));
-
-		secs = app->getTicks() / 1000.0 - secs;
-
-		app->getScene()->getPhysics()->getDynamicsWorld()->stepSimulation(secs);
+		app->getScene()->getPhysics()->update(crntTime);
 
 		app->getScene()->updateAllControllers();
 		app->getScene()->updateAllWorldStuff();
@@ -302,7 +297,7 @@ void mainLoop()
 		Ui::setColor(Vec4(1.0, 1.0, 1.0, 1.0));
 		Ui::setPos(-0.98, 0.95);
 		Ui::setFontWidth(0.03);
-		Ui::printf("frame:%d fps:%dms\n", app->getMainRenderer()->getFramesNum(), (App::getTicks()-ticks_));
+		//Ui::printf("frame:%d fps:%dms\n", app->getMainRenderer()->getFramesNum(), (App::getTicks()-ticks_));
 		//Ui::print("Movement keys: arrows,w,a,s,d,q,e,shift,space\nSelect objects: keys 1 to 5\n");
 		/*Ui::printf("Mover: Pos(%.2f %.2f %.2f) Angs(%.2f %.2f %.2f)", mover->translationWspace.x, mover->translationWspace.y, mover->translationWspace.z,
 								 toDegrees(Euler(mover->rotationWspace).x), toDegrees(Euler(mover->rotationWspace).y), toDegrees(Euler(mover->rotationWspace).z));*/

+ 25 - 5
src/Physics/PhyCharacter.cpp

@@ -4,15 +4,19 @@
 #include <BulletDynamics/Character/btKinematicCharacterController.h>
 #include "PhyCharacter.h"
 #include "Physics.h"
+#include "MotionState.h"
 
 
 //======================================================================================================================
 // Contructor                                                                                                          =
 //======================================================================================================================
-PhyCharacter::PhyCharacter(Physics& physics, const Initializer& init)
+PhyCharacter::PhyCharacter(Physics& physics_, const Initializer& init):
+	physics(physics_)
 {
 	ghostObject = new btPairCachingGhostObject();
 
+	motionState = new MotionState(toBt(init.startTrf), init.sceneNode);
+
 	btAxisSweep3* sweepBp = dynamic_cast<btAxisSweep3*>(physics.broadphase);
 	DEBUG_ERR(sweepBp == NULL);
 
@@ -23,10 +27,7 @@ PhyCharacter::PhyCharacter(Physics& physics, const Initializer& init)
 
 	ghostObject->setCollisionShape(convexShape);
 	//ghostObject->setCollisionFlags(btCollisionObject::CF_CHARACTER_OBJECT);
-	btTransform trf;
-	trf.setIdentity();
-	trf.setOrigin(btVector3(0.0, 40.0, 0.0));
-	ghostObject->setWorldTransform(trf);
+	ghostObject->setWorldTransform(toBt(init.startTrf));
 
 	character = new btKinematicCharacterController(ghostObject, convexShape, init.stepHeight);
 
@@ -38,4 +39,23 @@ PhyCharacter::PhyCharacter(Physics& physics, const Initializer& init)
 																						btBroadphaseProxy::StaticFilter|btBroadphaseProxy::DefaultFilter);
 
 	physics.dynamicsWorld->addAction(character);
+
+	physics.characters.push_back(this);
+}
+
+
+//======================================================================================================================
+// Destructor                                                                                                          =
+//======================================================================================================================
+PhyCharacter::~PhyCharacter()
+{
+	physics.characters.erase(std::find(physics.characters.begin(), physics.characters.end(), this));
+	physics.dynamicsWorld->removeAction(character);
+	physics.dynamicsWorld->removeCollisionObject(ghostObject);
+
+	delete character;
+	delete convexShape;
+	delete ghostPairCallback;
+	delete ghostObject;
+	delete motionState;
 }

+ 13 - 2
src/Physics/PhyCharacter.h

@@ -3,6 +3,7 @@
 
 #include "Common.h"
 #include "Physics.h"
+#include "Math.h"
 
 
 class Physics;
@@ -10,6 +11,7 @@ class btPairCachingGhostObject;
 class btConvexShape;
 class btKinematicCharacterController;
 class btGhostPairCallback;
+class MotionState;
 
 
 /**
@@ -17,6 +19,8 @@ class btGhostPairCallback;
  */
 class PhyCharacter
 {
+	friend class Physics;
+
 	public:
 		/**
 		 * Initializer class
@@ -28,21 +32,25 @@ class PhyCharacter
 			float stepHeight;
 			float jumpSpeed;
 			float maxJumpHeight;
+			SceneNode* sceneNode;
+			Transform startTrf;
 
 			Initializer();
 		};
 
-		PhyCharacter(Physics& physics, const Initializer& init);
+		PhyCharacter(Physics& physics_, const Initializer& init);
 		~PhyCharacter();
 		void rotate(float angle);
 		void moveForward(float distance);
 		void jump();
 
 	private:
+		Physics& physics;
 		btPairCachingGhostObject* ghostObject;
 		btConvexShape* convexShape;
 		btKinematicCharacterController* character;
 		btGhostPairCallback* ghostPairCallback;
+		MotionState* motionState;
 };
 
 
@@ -51,7 +59,10 @@ inline PhyCharacter::Initializer::Initializer():
 	characterWidth(0.75),
 	stepHeight(1.0),
 	jumpSpeed(10.0),
-	maxJumpHeight(.0)
+	maxJumpHeight(0.0),
+	sceneNode(NULL),
+	startTrf(Transform::getIdentity())
 {}
 
+
 #endif

+ 21 - 1
src/Physics/Physics.cpp

@@ -1,4 +1,5 @@
 #include "Physics.h"
+#include "PhyCharacter.h"
 
 
 
@@ -6,7 +7,8 @@
 // Constructor                                                                                                         =
 //======================================================================================================================
 Physics::Physics():
-	defaultContactProcessingThreshold(BT_LARGE_FLOAT)
+	defaultContactProcessingThreshold(BT_LARGE_FLOAT),
+	time(0.0)
 {
 	collisionConfiguration = new btDefaultCollisionConfiguration();
 	dispatcher = new	btCollisionDispatcher(collisionConfiguration);
@@ -19,3 +21,21 @@ Physics::Physics():
 	dynamicsWorld->setDebugDrawer(debugDrawer);
 	dynamicsWorld->getDebugDrawer()->setDebugMode(btIDebugDraw::DBG_DrawWireframe);
 }
+
+
+//======================================================================================================================
+// update                                                                                                              =
+//======================================================================================================================
+void Physics::update(float crntTime)
+{
+	float dt = crntTime - time;
+	time = crntTime;
+
+	dynamicsWorld->stepSimulation(dt);
+
+	// updateNonRigidBodiesMotionStates
+	for(uint i=0; i<characters.size(); i++)
+	{
+		characters[i]->motionState->setWorldTransform(characters[i]->ghostObject->getWorldTransform());
+	}
+}

+ 9 - 1
src/Physics/Physics.h

@@ -7,12 +7,15 @@
 #include "DebugDrawer.h"
 
 
+class PhyCharacter;
+
+
 /**
  * The master container for all physics related stuff.
  */
 class Physics
 {
-	friend class PhyCharacter;
+	friend class PhyCharacter; ///< For registering and unregistering
 
 	public:
 		/**
@@ -37,6 +40,11 @@ class Physics
 		DebugDrawer* debugDrawer;
 
 		Physics();
+		void update(float crntTime);
+
+	private:
+		Vec<PhyCharacter*> characters;
+		float time; ///< Time of prev update
 };
 
 #endif

Unele fișiere nu au fost afișate deoarece prea multe fișiere au fost modificate în acest diff