Skip to content
Browse files

Merge branch 'master' of github.com:david-sabata/UniversityRacer

  • Loading branch information...
2 parents 011ab97 + eeb9027 commit cc60c5ba219dd63baa5bc911d6b34e61f0e0e28d @TomasKimer TomasKimer committed Dec 12, 2011
Showing with 78 additions and 46 deletions.
  1. +10 −6 Camera.cpp
  2. +6 −4 FpsCounter.h
  3. +6 −0 GameTime.h
  4. +5 −3 Physics.cpp
  5. +11 −6 Physics.h
  6. +1 −11 PhysicsCar.cpp
  7. +12 −3 PhysicsCar.h
  8. +12 −7 PhysicsCarConfig.h
  9. +3 −4 PhysicsCheckpoint.cpp
  10. +7 −0 PhysicsCheckpoint.h
  11. +5 −2 PhysicsDebugDraw.h
View
16 Camera.cpp
@@ -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);
@@ -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;
@@ -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)
@@ -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;
View
10 FpsCounter.h
@@ -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:
@@ -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; }
@@ -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
View
6 GameTime.h
@@ -4,6 +4,9 @@
#include <ostream>
#include <iomanip>
+/**
+ * Trida reprezentujici casovy udaj.
+ */
class TimeSpan
{
public:
@@ -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:
View
8 Physics.cpp
@@ -1,5 +1,4 @@
-
#include "Physics.h"
@@ -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--)
@@ -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;
View
17 Physics.h
@@ -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:
@@ -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);
@@ -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:
@@ -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;
View
12 PhysicsCar.cpp
@@ -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()
@@ -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);
View
15 PhysicsCar.h
@@ -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();
View
19 PhysicsCarConfig.h
@@ -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),
@@ -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),
View
7 PhysicsCheckpoint.cpp
@@ -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();
@@ -19,8 +18,7 @@
}
void PhysicsCheckpoint::Deinitialize()
-{
- delete m_ghostObject;
+{
delete m_checkpointShape;
delete m_ghostPairCallback;
}
@@ -58,6 +56,7 @@ void PhysicsCheckpoint::Add(const btTransform & trans)
{
if (m_transforms.size() == 0)
m_ghostObject->setWorldTransform(trans);
+
m_transforms.push_back(trans);
}
View
7 PhysicsCheckpoint.h
@@ -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:
View
7 PhysicsDebugDraw.h
@@ -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:
@@ -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; }

0 comments on commit cc60c5b

Please sign in to comment.
Something went wrong with that request. Please try again.