Skip to content

Commit

Permalink
Merge branch 'master' of github.com:david-sabata/UniversityRacer
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasKimer committed Dec 12, 2011
2 parents 011ab97 + eeb9027 commit cc60c5b
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 46 deletions.
16 changes: 10 additions & 6 deletions Camera.cpp
Expand Up @@ -13,11 +13,10 @@ Camera::Camera(void): currentSettleTime(0.f) {


void Camera::Reset() {
//eye = glm::vec3(2.78f, 2.73f, -2.5f);

/*eye = glm::vec3(0.0f, 0.0f, -10.0f);
up = glm::vec3(0.0f, 1.0f, 0.0f);
target = glm::vec3(0.0f, 0.0f, 1.0f);*/

eye = glm::vec3(38.435f, 11.41f, -27.451f);
up = glm::vec3(0.0f, 1.0f, 0.0f);
target = glm::vec3(-0.623f, -0.124f, 0.772f);
Expand Down Expand Up @@ -114,11 +113,16 @@ void Camera::toggleObserve() {
*/


// portnuto z TrueAxis Physics SDK - demo Cars
/**
* Kod naportovan z True Axis Physics SDK (http://trueaxis.com/physics/index.html)
* Konkretne ze souboru DemoCars/DemoCars.cpp z archivu http://trueaxis.com/physics/downloadDemosSource.html
* A to konkretne z funkce "void UpdateCamera(float fDt)"
* Pridana nezavislost pohybu kamery na FPS a upravy hodnot konstant aby sedeli pro nase meritko.
*/
void Camera::Follow(glm::mat4 & targetMat, glm::vec3 targetVelocity, const GameTime & gameTime)
{
const glm::vec3 lookAtPos(0, 1, 0);
const glm::vec3 lookFromPos(0, 1, 1); //0, 3, -2 0,4,4
const glm::vec3 lookFromPos(0, 1, 1); // 0, 3, -2
float viewDistance = 2.5f; // 10.f
const float settleTime = 2.f;

Expand All @@ -128,7 +132,7 @@ void Camera::Follow(glm::mat4 & targetMat, glm::vec3 targetVelocity, const GameT
// Using statics here because of lazy programming
static glm::vec3 lastBaseLookFromPos = targetPos - targetRot[2] * 20.f;
static float facing = 1.f;
//static float actSettleTime = 0.f;
//static float currentSettleTime = 0.f;

// camera intro
if (currentSettleTime < settleTime)
Expand Down Expand Up @@ -191,7 +195,7 @@ void Camera::Follow(glm::mat4 & targetMat, glm::vec3 targetVelocity, const GameT

currentLookFromPos += lookFromPos * m;
glm::vec3 currentLookAtPos = lookDirection;
// glm::vec3 currentLookAtPos = targetPos + lookAtPos * m;
// glm::vec3 currentLookAtPos = targetPos + lookAtPos * m;

eye = currentLookFromPos;
target = currentLookAtPos;
Expand Down
10 changes: 6 additions & 4 deletions FpsCounter.h
Expand Up @@ -6,6 +6,11 @@

#include "GameTime.h"

/**
* Pocita FPS a udrzuje nejlepsi, nejhorsi a prumerne hodnoty.
* Inspirovano podle knihovny OGRE (http://www.ogre3d.org/)
* Konkretne tridou RenderTarget (http://www.ogre3d.org/docs/api/html/classOgre_1_1RenderTarget.html)
*/
class FpsCounter
{
public:
Expand Down Expand Up @@ -36,8 +41,6 @@ class FpsCounter
m_totalFrames++;
}

//void Reset();

float Current() const { return m_current; }
float Average() const { return m_average; }
float Best() const { return m_best; }
Expand All @@ -53,9 +56,8 @@ class FpsCounter

private:
float m_current, m_average, m_best, m_worst;
unsigned int m_totalFrames;
unsigned int m_frameCount, m_totalFrames;
TimeSpan m_totalElapsedTime;
unsigned int m_frameCount;
};

#endif
6 changes: 6 additions & 0 deletions GameTime.h
Expand Up @@ -4,6 +4,9 @@
#include <ostream>
#include <iomanip>

/**
* Trida reprezentujici casovy udaj.
*/
class TimeSpan
{
public:
Expand Down Expand Up @@ -43,6 +46,9 @@ class TimeSpan
unsigned int m_ms;
};

/**
* Reprezentuje herni cas. Na jeho zaklade lze provadet akce nezavisle na FPS ci mereni casu.
*/
class GameTime
{
public:
Expand Down
8 changes: 5 additions & 3 deletions Physics.cpp
@@ -1,5 +1,4 @@


#include "Physics.h"


Expand Down Expand Up @@ -36,7 +35,7 @@ void Physics::Initialize()
m_checkpoint.Initialize(m_dynamicsWorld);
}

void Physics::Deinitialize() //cleanup in the reverse order of creation/initialization
void Physics::Deinitialize()
{
//remove the rigidbodies from the dynamics world and delete them
for (int i = m_dynamicsWorld->getNumCollisionObjects() - 1; i >= 0; i--)
Expand All @@ -54,12 +53,15 @@ void Physics::Deinitialize() //cleanup in the reverse order of creation/initial
// delete m_collisionShapes[j];

if (m_car)
{
m_car->Deinitialize();
delete m_car;
}

//m_checkpoint.Deinitialize();

delete m_debugDraw;
delete m_dynamicsWorld;
delete m_debugDraw;
delete m_constraintSolver;
delete m_overlappingPairCache;
delete m_dispatcher;
Expand Down
17 changes: 11 additions & 6 deletions Physics.h
Expand Up @@ -10,9 +10,15 @@
#include "PhysicsDebugDraw.h"
#include "BaseModel.h"

#define MAX_SIMULATION_SUBSTEPS 10
#define FIXED_SIMULATION_TIMESTEP 1/120.f
#define FIXED_SIMULATION_TIMESTEP 1/120.f /// pevny simulacni krok
#define MAX_SIMULATION_SUBSTEPS 10 /// maximum simulacnich podkroku

/**
* Zapouzdruje veskerou praci s fyzikalni simulaci pomoci knihovny Bullet Physics (http://bulletphysics.org/).
* Cerpano z Bullet 2.79 Physics SDK Manual a Bullet demos, konkretne VehicleDemo.
* Oboji lze nalezt v archivu http://code.google.com/p/bullet/downloads/detail?name=bullet-2.79-rev2440.zip
* Dale vyuzity stranky knihovny, konkretne wiki a fora.
*/
class Physics
{
public:
Expand All @@ -26,7 +32,7 @@ class Physics
btRigidBody * AddRigidBody(float mass, const btTransform & startTransform, btCollisionShape * shape);

void DebugDrawWorld() { m_dynamicsWorld->debugDrawWorld(); }
void AddCollisionShape(btCollisionShape * shape) { m_collisionShapes.push_back(shape); }
// void AddCollisionShape(btCollisionShape * shape) { m_collisionShapes.push_back(shape); }

static btCollisionShape * CreateStaticCollisionShape(Mesh * mesh, const btVector3 & scale = btVector3(1,1,1));
static std::vector<btCollisionShape *> CreateStaticCollisionShapes(BaseModel * model, const btVector3 & scale);
Expand All @@ -40,8 +46,7 @@ class Physics
PhysicsDebugDraw *GetDebugDrawer() { return m_debugDraw; }
btDiscreteDynamicsWorld * GetDynamicsWorld() { return m_dynamicsWorld; }

void AddCar(const btTransform & trans) { (m_car = new PhysicsCar())->Initialize(m_dynamicsWorld, trans); }

void AddCar(const btTransform & trans) { (m_car = new PhysicsCar())->Initialize(m_dynamicsWorld, trans); }

private:

Expand All @@ -51,7 +56,7 @@ class Physics
btDefaultCollisionConfiguration* m_collisionConfiguration;

btDiscreteDynamicsWorld *m_dynamicsWorld;
btAlignedObjectArray<btCollisionShape*> m_collisionShapes;
//btAlignedObjectArray<btCollisionShape*> m_collisionShapes;

PhysicsCar *m_car;
PhysicsCheckpoint m_checkpoint;
Expand Down
12 changes: 1 addition & 11 deletions PhysicsCar.cpp
Expand Up @@ -3,14 +3,6 @@
#include <cmath>
#include <vector>

PhysicsCar::PhysicsCar(void): m_engineForce(0.f), m_breakingForce(0.f), m_vehicleSteering(0.f), m_turned(false)
{
}

PhysicsCar::~PhysicsCar(void)
{
}

#define CRB CAR_RAISE_BOTTOM

btCollisionShape* PhysicsCar::CreateVehicleShape()
Expand Down Expand Up @@ -143,14 +135,12 @@ void PhysicsCar::Reset(const btTransform & trans)
{
m_vehicle->resetSuspension();
for (int i = 0; i < m_vehicle->getNumWheels(); i++)
m_vehicle->updateWheelTransform(i, true); //synchronize the wheels with the (interpolated) chassis worldtransform
m_vehicle->updateWheelTransform(i, true); // synchronize the wheels with the (interpolated) chassis worldtransform
}
}

void PhysicsCar::Update(btScalar timeStep)
{
//btScalar t

// engine
m_vehicle->applyEngineForce(m_engineForce, WHEEL_REARLEFT);
m_vehicle->applyEngineForce(m_engineForce, WHEEL_REARRIGHT);
Expand Down
15 changes: 12 additions & 3 deletions PhysicsCar.h
Expand Up @@ -8,19 +8,28 @@
#include "PhysicsCarConfig.h"
#include "PhysicsUtils.h"

/**
* Fyzikalni simulace auta.
* Cerpano z dokumentu Bullet 2.79 Physics SDK Manual a Vehicle Simulation With Bullet (http://tinyurl.com/ydfb7lm).
* Dale cerpano z VehicleDemo, z nehoz byla vyuzita zakladni kostra kodu.
* VehicleDemo a Bullet 2.79 Physics SDK Manual jsou obsazeny v archivu http://code.google.com/p/bullet/downloads/detail?name=bullet-2.79-rev2440.zip
*/
class PhysicsCar
{
public:
enum WHEELID { // z pohledu ridice
/**
* Identifikatory kol auta; z pohledu ridice.
*/
enum WHEELID {
WHEEL_FRONTLEFT = 0,
WHEEL_FRONTRIGHT,
WHEEL_REARLEFT,
WHEEL_REARRIGHT,
WHEEL_COUNT // zarazka
};

PhysicsCar(void);
~PhysicsCar(void);
PhysicsCar(void): m_engineForce(0.f), m_breakingForce(0.f), m_vehicleSteering(0.f), m_turned(false) {}
~PhysicsCar(void) {}

btCollisionShape* CreateVehicleShape();

Expand Down
19 changes: 12 additions & 7 deletions PhysicsCarConfig.h
Expand Up @@ -3,9 +3,13 @@

#include <btBulletDynamicsCommon.h>

#define CAR_SCALE 0.25f
#define CAR_RAISE_BOTTOM 0.1f // zvyseni spodku kolizniho telesa auta
#define CAR_SCALE 0.25f /// meritko auta
#define CAR_RAISE_BOTTOM 0.1f /// zvyseni spodku kolizniho telesa auta

/**
* Konfigurace vlastnosti a chovani auta.
* Popis hodnot prevzan z dokumentu Vehicle Simulation With Bullet (http://tinyurl.com/ydfb7lm)
*/
struct CarConfig
{
CarConfig(): mass(5.0f),
Expand All @@ -19,13 +23,14 @@ struct CarConfig
/// Maximum speed clamp (km/h)
maxSpeedClamp(60.f),

steeringIncrement(0.025f), // 0.03
/// Steering settings
steeringIncrement(0.025f),
steeringDecrement(0.1f),
steeringClamp(0.50f), // 0.75
steeringClamp(0.50f),

// chasis damping
linearDamping(0.25f), // 0.3
angularDamping(0.0f), // 0.1
/// Chasis damping
linearDamping(0.25f), // 0.3
angularDamping(0.0f),

/// The direction of ray cast (chassis space). The wheel moves relative to the chassis in this direction, and the suspension force acts along this direction.
wheelDirectionCS(0.f, -1.f, 0.f),
Expand Down
7 changes: 3 additions & 4 deletions PhysicsCheckpoint.cpp
Expand Up @@ -5,8 +5,7 @@
void PhysicsCheckpoint::Initialize(btDiscreteDynamicsWorld *refWorld)
{
m_ghostPairCallback = new btGhostPairCallback();
refWorld->getPairCache()->setInternalGhostPairCallback(m_ghostPairCallback);
// refWorld->getBroadphase()->getOverlappingPairCache()->setInternalGhostPairCallback(m_ghostPairCallback);
refWorld->getPairCache()->setInternalGhostPairCallback(m_ghostPairCallback);

m_ghostObject = new btGhostObject();

Expand All @@ -19,8 +18,7 @@
}

void PhysicsCheckpoint::Deinitialize()
{
delete m_ghostObject;
{
delete m_checkpointShape;
delete m_ghostPairCallback;
}
Expand Down Expand Up @@ -58,6 +56,7 @@ void PhysicsCheckpoint::Add(const btTransform & trans)
{
if (m_transforms.size() == 0)
m_ghostObject->setWorldTransform(trans);

m_transforms.push_back(trans);
}

Expand Down
7 changes: 7 additions & 0 deletions PhysicsCheckpoint.h
Expand Up @@ -6,14 +6,21 @@

#include "GameTime.h"

/// meritko kolizniho telesa checkpointu
#define CHECKPOINT_SCALE 0.1f

/// rozmery kolizniho telesa checkpointu
#define CHECKPOINT_SIZE_X 5.5f * CHECKPOINT_SCALE
#define CHECKPOINT_SIZE_Y 4.f * CHECKPOINT_SCALE
#define CHECKPOINT_SIZE_Z .5f * CHECKPOINT_SCALE

/// pocet kol
#define MAX_ROUNDS 1

/**
* Sprava checkpointu s detekci kolizi a pocitanim casu.
* Prace s btGhostObject na zaklade http://bulletphysics.org/mediawiki-1.5.8/index.php/Collision_Callbacks_and_Triggers#btGhostObject
*/
class PhysicsCheckpoint
{
public:
Expand Down
7 changes: 5 additions & 2 deletions PhysicsDebugDraw.h
Expand Up @@ -7,6 +7,9 @@

#include <btBulletDynamicsCommon.h>

/**
* Pomocna trida pro debug vykresleni koliznich teles pouzitych v simulaci; kresleni pouze pomoci car.
*/
class PhysicsDebugDraw : public btIDebugDraw
{
public:
Expand All @@ -21,8 +24,8 @@ class PhysicsDebugDraw : public btIDebugDraw
PhysicsDebugDraw(void): m_debugMode(1) {}
~PhysicsDebugDraw(void) {}

virtual void drawLine(const btVector3& from,const btVector3& to,const btVector3& color);
virtual void drawContactPoint(const btVector3& PointOnB,const btVector3& normalOnB,btScalar distance,int lifeTime,const btVector3& color) {}
virtual void drawLine(const btVector3& from, const btVector3& to, const btVector3& color);
virtual void drawContactPoint(const btVector3& PointOnB, const btVector3& normalOnB, btScalar distance, int lifeTime, const btVector3& color) {}
virtual void drawTriangle(const btVector3 & a, const btVector3 & b, const btVector3 & c, const btVector3 & color, btScalar alpha) {}

void reportErrorWarning(const char * warningString) { std::cout << "Physics debugger warning: " << warningString << std::endl; }
Expand Down

0 comments on commit cc60c5b

Please sign in to comment.