1) Removed the old m_curr_pos sg* data structure from kart.
2) Replaced several sg* data structures and function parameters with plib independent data structures. 3) Some code cleanup, updated gpl license to 3 in a file or two. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@2132 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
@@ -69,8 +69,8 @@ void Attachment::hitGreenHerring()
|
||||
float leftover_time = 0.0f;
|
||||
switch(getType()) // If there already is an attachment, make it worse :)
|
||||
{
|
||||
case ATTACH_BOMB: projectile_manager->newExplosion(m_kart->getPos());
|
||||
m_kart->handleExplosion(m_kart->getPos(), /*direct_hit*/ true);
|
||||
case ATTACH_BOMB: projectile_manager->newExplosion(m_kart->getXYZ());
|
||||
m_kart->handleExplosion(m_kart->getXYZ(), /*direct_hit*/ true);
|
||||
clear();
|
||||
random_attachment = rand()%3;
|
||||
break;
|
||||
@@ -139,8 +139,8 @@ void Attachment::update(float dt)
|
||||
case ATTACH_MAX: break;
|
||||
case ATTACH_BOMB: if(m_time_left<=0.0)
|
||||
{
|
||||
projectile_manager->newExplosion(m_kart->getPos());
|
||||
m_kart->handleExplosion(m_kart->getPos(),
|
||||
projectile_manager->newExplosion(m_kart->getXYZ());
|
||||
m_kart->handleExplosion(m_kart->getXYZ(),
|
||||
/*direct_hit*/ true);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -28,8 +28,8 @@ class AutoKart : public Kart
|
||||
{
|
||||
public:
|
||||
AutoKart(const std::string& kart_name, int position,
|
||||
sgCoord init_pos) :
|
||||
Kart(kart_name, position, init_pos) { Kart::reset(); }
|
||||
const btTransform& init_pos) :
|
||||
Kart(kart_name, position, init_pos) {}
|
||||
|
||||
int isPlayerKart() const {return 0;}
|
||||
};
|
||||
|
||||
@@ -34,7 +34,7 @@ Camera::Camera(int camera_index, const Kart* kart)
|
||||
m_context = new ssgContext ;
|
||||
m_distance = kart->getKartProperties()->getCameraDistance();
|
||||
m_kart = kart;
|
||||
m_xyz = kart->getPos();
|
||||
m_xyz = kart->getXYZ();
|
||||
m_hpr = Vec3(0,0,0);
|
||||
|
||||
// FIXME: clipping should be configurable for slower machines
|
||||
@@ -121,7 +121,7 @@ void Camera::reset()
|
||||
{
|
||||
setMode(CM_NORMAL);
|
||||
m_last_pitch = 0.0f;
|
||||
m_xyz = m_kart->getPos();
|
||||
m_xyz = m_kart->getXYZ();
|
||||
m_hpr = Vec3(0,0,0);
|
||||
} // reset
|
||||
|
||||
@@ -142,7 +142,7 @@ void Camera::update (float dt)
|
||||
else
|
||||
{
|
||||
kart = m_kart;
|
||||
kart_hpr = kart->getRotation();
|
||||
kart_hpr = kart->getHPR();
|
||||
// Use the terrain pitch to avoid the camera following a wheelie the kart is doing
|
||||
kart_hpr.setPitch( m_kart->getTerrainPitch(kart_hpr.getHeading()) );
|
||||
kart_hpr.setRoll(0.0f);
|
||||
@@ -159,7 +159,7 @@ void Camera::update (float dt)
|
||||
kart_hpr.setPitch(m_last_pitch);
|
||||
} // dt>0.0
|
||||
} // m_mode!=CM_LEADER_MODE
|
||||
kart_xyz = kart->getPos();
|
||||
kart_xyz = kart->getXYZ();
|
||||
if(m_mode==CM_SIMPLE_REPLAY) kart_hpr.setHeading(0.0f);
|
||||
|
||||
// Set the camera position relative to the kart
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// as published by the Free Software Foundation; either version 3
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
@@ -58,9 +58,11 @@ public:
|
||||
setSgCoord();
|
||||
} // Coord
|
||||
// ------------------------------------------------------------------------
|
||||
const sgCoord& toSgCoord() const { return m_coord; }
|
||||
const Vec3& getXYZ() const { return m_xyz; }
|
||||
const Vec3& getHPR() const { return m_hpr; }
|
||||
const sgCoord& toSgCoord() const { return m_coord; }
|
||||
const Vec3& getXYZ() const { return m_xyz; }
|
||||
const Vec3& getHPR() const { return m_hpr; }
|
||||
void setHPR(const Vec3& a) { m_hpr = a; setSgCoord(); }
|
||||
void setXYZ(const Vec3& a) { m_xyz = a; setSgCoord(); }
|
||||
}; // Coord
|
||||
|
||||
#endif
|
||||
|
||||
@@ -76,7 +76,7 @@ void Flyable::createPhysics(float y_offset, const btVector3 velocity,
|
||||
trans.getBasis()[2][1]);
|
||||
float heading=atan2(-direction.getX(), direction.getY());
|
||||
|
||||
TerrainInfo::update(m_owner->getPos());
|
||||
TerrainInfo::update(m_owner->getXYZ());
|
||||
float pitch = getTerrainPitch(heading);
|
||||
|
||||
btMatrix3x3 m;
|
||||
@@ -187,15 +187,6 @@ void Flyable::update (float dt)
|
||||
|
||||
Moveable::update(dt);
|
||||
} // update
|
||||
// -----------------------------------------------------------------------------
|
||||
void Flyable::placeModel()
|
||||
{
|
||||
btTransform t=getTrans();
|
||||
float m[4][4];
|
||||
t.getOpenGLMatrix((float*)&m);
|
||||
sgSetCoord(&m_curr_pos, m);
|
||||
Moveable::placeModel();
|
||||
} // placeModel
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
void Flyable::explode(Kart *kart_hit, MovingPhysics* moving_physics)
|
||||
@@ -213,7 +204,7 @@ void Flyable::explode(Kart *kart_hit, MovingPhysics* moving_physics)
|
||||
scene->remove(m);
|
||||
|
||||
// The explosion is a bit higher in the air
|
||||
btVector3 pos_explosion=getPos();
|
||||
Vec3 pos_explosion=getXYZ();
|
||||
pos_explosion.setZ(pos_explosion.getZ()+1.2f);
|
||||
world->getPhysics()->removeBody(getBody());
|
||||
m_exploded=true;
|
||||
@@ -227,7 +218,7 @@ void Flyable::explode(Kart *kart_hit, MovingPhysics* moving_physics)
|
||||
if(m_owner!=kart || m_owner==kart_hit)
|
||||
{
|
||||
// Set a flag it if was a direct hit.
|
||||
kart->handleExplosion(getPos(), kart==kart_hit);
|
||||
kart->handleExplosion(getXYZ(), kart==kart_hit);
|
||||
}
|
||||
}
|
||||
callback_manager->handleExplosion(pos_explosion, moving_physics);
|
||||
|
||||
@@ -66,12 +66,10 @@ public:
|
||||
CollectableType type);
|
||||
virtual void update (float);
|
||||
|
||||
void placeModel ();
|
||||
virtual void hitTrack () {};
|
||||
void explode (Kart* kart, MovingPhysics* moving_physics=NULL);
|
||||
bool hasHit () { return m_has_hit_something; }
|
||||
void reset () { Moveable::reset();
|
||||
sgCopyCoord(&m_last_pos,&m_reset_pos ); }
|
||||
void reset () { Moveable::reset(); }
|
||||
}; // Flyable
|
||||
|
||||
#endif
|
||||
|
||||
@@ -292,27 +292,25 @@ void RaceGUI::drawMap ()
|
||||
|
||||
for ( unsigned int i = 0 ; i < race_manager->getNumKarts() ; i++ )
|
||||
{
|
||||
sgCoord *c ;
|
||||
|
||||
Kart* kart = world->getKart(i);
|
||||
if(kart->isEliminated()) continue; // don't draw eliminated kart
|
||||
glColor3fv ( kart->getColor().toFloat());
|
||||
c = kart->getCoord () ;
|
||||
const Vec3& xyz = kart->getXYZ();
|
||||
|
||||
/* If it's a player, draw a bigger sign */
|
||||
if (kart -> isPlayerKart ())
|
||||
{
|
||||
world -> m_track->glVtx ( c->xyz, (float)xLeft+3, (float)yTop+3);
|
||||
world -> m_track->glVtx ( c->xyz, (float)xLeft-2, (float)yTop+3);
|
||||
world -> m_track->glVtx ( c->xyz, (float)xLeft-2, (float)yTop-2);
|
||||
world -> m_track->glVtx ( c->xyz, (float)xLeft+3, (float)yTop-2);
|
||||
world -> m_track->glVtx ( xyz.toFloat(), (float)xLeft+3, (float)yTop+3);
|
||||
world -> m_track->glVtx ( xyz.toFloat(), (float)xLeft-2, (float)yTop+3);
|
||||
world -> m_track->glVtx ( xyz.toFloat(), (float)xLeft-2, (float)yTop-2);
|
||||
world -> m_track->glVtx ( xyz.toFloat(), (float)xLeft+3, (float)yTop-2);
|
||||
}
|
||||
else
|
||||
{
|
||||
world -> m_track->glVtx ( c->xyz, (float)xLeft+2, (float)yTop+2);
|
||||
world -> m_track->glVtx ( c->xyz, (float)xLeft-1, (float)yTop+2);
|
||||
world -> m_track->glVtx ( c->xyz, (float)xLeft-1, (float)yTop-1);
|
||||
world -> m_track->glVtx ( c->xyz, (float)xLeft+2, (float)yTop-1);
|
||||
world -> m_track->glVtx ( xyz.toFloat(), (float)xLeft+2, (float)yTop+2);
|
||||
world -> m_track->glVtx ( xyz.toFloat(), (float)xLeft-1, (float)yTop+2);
|
||||
world -> m_track->glVtx ( xyz.toFloat(), (float)xLeft-1, (float)yTop-1);
|
||||
world -> m_track->glVtx ( xyz.toFloat(), (float)xLeft+2, (float)yTop-1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,37 +17,31 @@
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#include "vec3.hpp"
|
||||
#include "world.hpp"
|
||||
#include "herring.hpp"
|
||||
#include "kart.hpp"
|
||||
#include "scene.hpp"
|
||||
#include "coord.hpp"
|
||||
|
||||
Herring::Herring(herringType _type, sgVec3* xyz, ssgEntity* model)
|
||||
Herring::Herring(herringType type, const Vec3& xyz, ssgEntity* model)
|
||||
: m_coord(xyz, Vec3(0, 0, 0))
|
||||
{
|
||||
sgSetVec3(m_coord.hpr, 0.0f, 0.0f, 0.0f);
|
||||
|
||||
sgCopyVec3(m_coord.xyz, *xyz);
|
||||
m_root = new ssgTransform();
|
||||
m_type = type;
|
||||
m_eaten = false;
|
||||
m_time_to_return = 0.0f; // not strictly necessary, see isEaten()
|
||||
m_root = new ssgTransform();
|
||||
m_root->ref();
|
||||
m_root->setTransform(&m_coord);
|
||||
|
||||
m_rotate = new ssgTransform();
|
||||
m_rotate->ref();
|
||||
m_rotate->addKid(model);
|
||||
m_root->addKid(m_rotate);
|
||||
m_root->setTransform(const_cast<sgCoord*>(&m_coord.toSgCoord()));
|
||||
m_root->addKid(model);
|
||||
scene->add(m_root);
|
||||
|
||||
m_type = _type;
|
||||
m_eaten = false;
|
||||
m_rotation = 0.0f;
|
||||
m_time_to_return = 0.0f; // not strictly necessary, see isEaten()
|
||||
} // Herring
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
Herring::~Herring()
|
||||
{
|
||||
ssgDeRefDelete(m_root);
|
||||
ssgDeRefDelete(m_rotate);
|
||||
} // ~Herring
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -55,13 +49,13 @@ void Herring::reset()
|
||||
{
|
||||
m_eaten = false;
|
||||
m_time_to_return = 0.0f;
|
||||
m_root->setTransform(&m_coord);
|
||||
m_root->setTransform(const_cast<sgCoord*>(&m_coord.toSgCoord()));
|
||||
} // reset
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
int Herring::hitKart(Kart* kart)
|
||||
{
|
||||
return sgDistanceSquaredVec3 ( kart->getCoord()->xyz, m_coord.xyz ) < 0.8f;
|
||||
return (kart->getXYZ()-m_coord.getXYZ()).length2()<0.8f;
|
||||
} // hitKart
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -72,26 +66,24 @@ void Herring::update(float delta)
|
||||
const float T = m_time_to_return - world->getTime();
|
||||
if ( T > 0 )
|
||||
{
|
||||
sgVec3 hell;
|
||||
sgCopyVec3(hell, m_coord.xyz);
|
||||
Vec3 hell(m_coord.getXYZ());
|
||||
|
||||
hell[2] = ( T > 1.0f ) ? -1000000.0f : m_coord.xyz[2] - T / 2.0f;
|
||||
m_root -> setTransform(hell);
|
||||
hell.setZ( (T>1.0f) ? -1000000.0f : m_coord.getXYZ().getZ() - T / 2.0f);
|
||||
m_root->setTransform(hell.toFloat());
|
||||
}
|
||||
else
|
||||
{
|
||||
m_eaten = false;
|
||||
m_rotation = 0.0f;
|
||||
m_root -> setTransform(&m_coord);
|
||||
m_eaten = false;
|
||||
m_coord.setHPR(Vec3(0.0f));
|
||||
m_root->setTransform(const_cast<sgCoord*>(&m_coord.toSgCoord()));
|
||||
} // T>0
|
||||
|
||||
}
|
||||
else
|
||||
{ // not m_eaten
|
||||
sgCoord c = { { 0.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0 } } ;
|
||||
c.hpr[0] = m_rotation;
|
||||
m_rotation += 180.0f*delta;
|
||||
m_rotate -> setTransform ( &c ) ;
|
||||
Vec3 rotation(delta*M_PI, 0, 0);
|
||||
m_coord.setHPR(m_coord.getHPR()+rotation);
|
||||
m_root->setTransform(const_cast<sgCoord*>(&m_coord.toSgCoord()));
|
||||
}
|
||||
} // update
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#define HEADER_HERRING_H
|
||||
|
||||
#include <plib/sg.h>
|
||||
#include "coord.hpp"
|
||||
|
||||
class Kart;
|
||||
class ssgTransform;
|
||||
@@ -34,24 +35,22 @@ class Herring
|
||||
{
|
||||
private:
|
||||
herringType m_type; // Herring type
|
||||
bool m_eaten; // true if herring was eaten & is not displayed
|
||||
bool m_eaten; // true if herring was eaten & is not displayed
|
||||
float m_time_to_return; // world->clock when an eaten herring reappears
|
||||
sgCoord m_coord; // Original coordinates, used mainly when
|
||||
// eaten herrings reappear.
|
||||
Coord m_coord; // Original coordinates, used mainly when
|
||||
// eaten herrings reappear.
|
||||
ssgTransform* m_root; // The actual root of the herring
|
||||
ssgTransform* m_rotate; // Just below root is a node only rotating
|
||||
float m_rotation; // Amount of rotation
|
||||
|
||||
public:
|
||||
Herring (herringType type, sgVec3* xyz, ssgEntity* model);
|
||||
~Herring ();
|
||||
void update (float delta);
|
||||
bool wasEaten () {return m_eaten;}
|
||||
void isEaten ();
|
||||
herringType getType () {return m_type;}
|
||||
int hitKart (Kart* kart );
|
||||
void reset ();
|
||||
Herring (herringType type, const Vec3& xyz, ssgEntity* model);
|
||||
~Herring ();
|
||||
void update (float delta);
|
||||
void isEaten ();
|
||||
int hitKart (Kart* kart );
|
||||
void reset ();
|
||||
ssgTransform* getRoot () const {return m_root;}
|
||||
herringType getType () const {return m_type;}
|
||||
bool wasEaten() const {return m_eaten;}
|
||||
}
|
||||
; // class Herring
|
||||
|
||||
|
||||
@@ -195,7 +195,7 @@ void HerringManager::setDefaultHerringStyle()
|
||||
} // setDefaultHerringStyle
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
Herring* HerringManager::newHerring(herringType type, sgVec3* xyz)
|
||||
Herring* HerringManager::newHerring(herringType type, const Vec3& xyz)
|
||||
{
|
||||
Herring* h = new Herring(type, xyz, m_herring_model[type]);
|
||||
m_all_herrings.push_back(h);
|
||||
|
||||
@@ -57,7 +57,7 @@ public:
|
||||
~HerringManager();
|
||||
void loadDefaultHerrings();
|
||||
void loadHerringStyle(const std::string filename);
|
||||
Herring* newHerring (herringType type, sgVec3* xyz);
|
||||
Herring* newHerring (herringType type, const Vec3& xyz);
|
||||
void update (float delta);
|
||||
void hitHerring (Kart* kart);
|
||||
void cleanup ();
|
||||
|
||||
138
src/kart.cpp
138
src/kart.cpp
@@ -48,8 +48,8 @@
|
||||
#endif
|
||||
|
||||
|
||||
Kart::Kart (const std::string& kart_name, int position_ ,
|
||||
sgCoord init_pos)
|
||||
Kart::Kart (const std::string& kart_name, int position,
|
||||
const btTransform& init_transform)
|
||||
: TerrainInfo(1),
|
||||
#if defined(WIN32) && !defined(__CYGWIN__)
|
||||
// Disable warning for using 'this' in base member initializer list
|
||||
@@ -61,8 +61,8 @@ Kart::Kart (const std::string& kart_name, int position_ ,
|
||||
#endif
|
||||
{
|
||||
m_kart_properties = kart_properties_manager->getKart(kart_name);
|
||||
m_grid_position = position_;
|
||||
m_initial_position = position_;
|
||||
m_grid_position = position;
|
||||
m_initial_position = position;
|
||||
m_num_herrings_gobbled = 0;
|
||||
m_eliminated = false;
|
||||
m_finished_race = false;
|
||||
@@ -74,7 +74,9 @@ Kart::Kart (const std::string& kart_name, int position_ ,
|
||||
m_skidmark_left = NULL;
|
||||
m_skidmark_right = NULL;
|
||||
m_track_sector = Track::UNKNOWN_SECTOR;
|
||||
sgCopyCoord(&m_reset_pos, &init_pos);
|
||||
|
||||
// Set position and heading:
|
||||
m_reset_transform = init_transform;
|
||||
|
||||
// Neglecting the roll resistance (which is small for high speeds compared
|
||||
// to the air resistance), maximum speed is reached when the engine
|
||||
@@ -97,6 +99,7 @@ Kart::Kart (const std::string& kart_name, int position_ ,
|
||||
m_wheel_rear_r = NULL;
|
||||
m_lap_start_time = -1.0f;
|
||||
loadData();
|
||||
reset();
|
||||
} // Kart
|
||||
|
||||
// -----------------------------------------------------------------------------v
|
||||
@@ -288,7 +291,6 @@ void Kart::reset()
|
||||
{
|
||||
world->getPhysics()->addKart(this, m_vehicle);
|
||||
}
|
||||
Moveable::reset();
|
||||
|
||||
m_attachment.clear();
|
||||
m_collectable.reset();
|
||||
@@ -306,17 +308,19 @@ void Kart::reset()
|
||||
m_wheel_rotation = 0;
|
||||
m_wheelie_angle = 0.0f;
|
||||
|
||||
m_controls.lr = 0.0f;
|
||||
m_controls.accel = 0.0f;
|
||||
m_controls.brake = false;
|
||||
m_controls.wheelie = false;
|
||||
m_controls.jump = false;
|
||||
m_controls.fire = false;
|
||||
m_controls.lr = 0.0f;
|
||||
m_controls.accel = 0.0f;
|
||||
m_controls.brake = false;
|
||||
m_controls.wheelie = false;
|
||||
m_controls.jump = false;
|
||||
m_controls.fire = false;
|
||||
|
||||
// Set the brakes so that karts don't slide downhill
|
||||
for(int i=0; i<4; i++) m_vehicle->setBrake(5.0f, i);
|
||||
|
||||
world->m_track->findRoadSector(m_curr_pos.xyz, &m_track_sector);
|
||||
m_transform = m_reset_transform;
|
||||
|
||||
world->m_track->findRoadSector(getXYZ(), &m_track_sector);
|
||||
|
||||
//If m_track_sector == UNKNOWN_SECTOR, then the kart is not on top of
|
||||
//the road, so we have to use another function to find the sector.
|
||||
@@ -324,29 +328,20 @@ void Kart::reset()
|
||||
{
|
||||
m_on_road = false;
|
||||
m_track_sector = world->m_track->findOutOfRoadSector(
|
||||
m_curr_pos.xyz, Track::RS_DONT_KNOW, Track::UNKNOWN_SECTOR );
|
||||
getXYZ(), Track::RS_DONT_KNOW, Track::UNKNOWN_SECTOR );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_on_road = true;
|
||||
}
|
||||
|
||||
world->m_track->spatialToTrack( m_curr_track_coords, m_curr_pos.xyz,
|
||||
m_track_sector );
|
||||
world->m_track->spatialToTrack(m_curr_track_coords, getXYZ(),
|
||||
m_track_sector );
|
||||
|
||||
m_vehicle->applyEngineForce (0.0f, 2);
|
||||
m_vehicle->applyEngineForce (0.0f, 3);
|
||||
// Set heading:
|
||||
m_transform.setRotation(btQuaternion(btVector3(0.0f, 0.0f, 1.0f),
|
||||
DEGREE_TO_RAD(m_reset_pos.hpr[0])) );
|
||||
// Set position
|
||||
m_transform.setOrigin(btVector3(m_reset_pos.xyz[0],
|
||||
m_reset_pos.xyz[1],
|
||||
m_reset_pos.xyz[2]+0.5f*getKartHeight()));
|
||||
m_body->setCenterOfMassTransform(m_transform);
|
||||
m_body->setLinearVelocity (btVector3(0.0f,0.0f,0.0f));
|
||||
m_body->setAngularVelocity(btVector3(0.0f,0.0f,0.0f));
|
||||
m_motion_state->setWorldTransform(m_transform);
|
||||
|
||||
Moveable::reset();
|
||||
for(int j=0; j<m_vehicle->getNumWheels(); j++)
|
||||
{
|
||||
m_vehicle->updateWheelTransform(j, true);
|
||||
@@ -359,15 +354,13 @@ void Kart::reset()
|
||||
world->getPhysics()->addKart(this, m_vehicle);
|
||||
}
|
||||
m_rescue = false;
|
||||
|
||||
placeModel();
|
||||
TerrainInfo::update(getPos());
|
||||
TerrainInfo::update(getXYZ());
|
||||
} // reset
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void Kart::doLapCounting ()
|
||||
{
|
||||
bool newLap = m_last_track_coords[1] > 300.0f && m_curr_track_coords[1] < 20.0f;
|
||||
bool newLap = m_last_track_coords[1] > 300.0f && m_curr_track_coords.getY() < 20.0f;
|
||||
if ( newLap )
|
||||
{
|
||||
// Only increase the lap counter and set the new time if the
|
||||
@@ -423,7 +416,7 @@ void Kart::doLapCounting ()
|
||||
}
|
||||
m_lap_start_time = world->getTime();
|
||||
}
|
||||
else if ( m_curr_track_coords[1] > 300.0f && m_last_track_coords[1] < 20.0f)
|
||||
else if ( m_curr_track_coords.getY() > 300.0f && m_last_track_coords[1] < 20.0f)
|
||||
{
|
||||
m_race_lap-- ;
|
||||
// Prevent cheating by setting time to a negative number, indicating
|
||||
@@ -496,7 +489,7 @@ bool Kart::isOnGround() const
|
||||
m_vehicle->getWheelInfo(3).m_raycastInfo.m_isInContact;
|
||||
} // isOnGround
|
||||
//-----------------------------------------------------------------------------
|
||||
void Kart::handleExplosion(const btVector3& pos, bool direct_hit)
|
||||
void Kart::handleExplosion(const Vec3& pos, bool direct_hit)
|
||||
{
|
||||
if(direct_hit)
|
||||
{
|
||||
@@ -511,7 +504,7 @@ void Kart::handleExplosion(const btVector3& pos, bool direct_hit)
|
||||
}
|
||||
else // only affected by a distant explosion
|
||||
{
|
||||
btVector3 diff=getPos()-pos;
|
||||
btVector3 diff=getXYZ()-pos;
|
||||
//if the z component is negative, the resulting impulse could push the
|
||||
// kart through the floor. So in this case ignore z.
|
||||
if(diff.getZ()<0) diff.setZ(0.0f);
|
||||
@@ -548,20 +541,16 @@ void Kart::update(float dt)
|
||||
{
|
||||
if(isPlayerKart()) sound_manager -> playSfx ( SOUND_BZZT );
|
||||
m_attachment.set( ATTACH_TINYTUX, rescue_time ) ;
|
||||
m_rescue_pitch = m_curr_pos.hpr[1];
|
||||
m_rescue_roll = m_curr_pos.hpr[2];
|
||||
m_rescue_pitch = getHPR().getPitch();
|
||||
m_rescue_roll = getHPR().getRoll();
|
||||
world->getPhysics()->removeKart(this);
|
||||
}
|
||||
m_curr_pos.xyz[2] += rescue_height*dt/rescue_time;
|
||||
|
||||
m_transform.setOrigin(btVector3(m_curr_pos.xyz[0],m_curr_pos.xyz[1],
|
||||
m_curr_pos.xyz[2]));
|
||||
btQuaternion q_roll (btVector3(0.f, 1.f, 0.f),
|
||||
-m_rescue_roll*dt/rescue_time*M_PI/180.0f);
|
||||
btQuaternion q_pitch(btVector3(1.f, 0.f, 0.f),
|
||||
-m_rescue_pitch*dt/rescue_time*M_PI/180.0f);
|
||||
m_transform.setRotation(m_transform.getRotation()*q_roll*q_pitch);
|
||||
m_motion_state->setWorldTransform(m_transform);
|
||||
setXYZRotation(getXYZ()+Vec3(0, 0, rescue_height*dt/rescue_time),
|
||||
getRotation()*q_roll*q_pitch);
|
||||
} // if m_rescue
|
||||
m_attachment.update(dt);
|
||||
|
||||
@@ -573,12 +562,12 @@ void Kart::update(float dt)
|
||||
} // user_config->smoke
|
||||
updatePhysics(dt);
|
||||
|
||||
sgCopyVec2 ( m_last_track_coords, m_curr_track_coords );
|
||||
|
||||
m_last_track_coords = m_curr_track_coords;
|
||||
|
||||
Moveable::update(dt);
|
||||
|
||||
// Check if a kart is (nearly) upside down and not moving much --> automatic rescue
|
||||
if((fabs(m_curr_pos.hpr[2])>60 && fabs(getSpeed())<3.0f) )
|
||||
if((fabs(getHPR().getRoll())>60 && fabs(getSpeed())<3.0f) )
|
||||
{
|
||||
forceRescue();
|
||||
}
|
||||
@@ -634,7 +623,7 @@ void Kart::update(float dt)
|
||||
|
||||
int prev_sector = m_track_sector;
|
||||
if(!m_rescue)
|
||||
world->m_track->findRoadSector(m_curr_pos.xyz, &m_track_sector);
|
||||
world->m_track->findRoadSector(getXYZ(), &m_track_sector);
|
||||
|
||||
// Check if the kart is taking a shortcut (if it's not already doing one):
|
||||
if(!m_rescue && world->m_track->isShortcut(prev_sector, m_track_sector))
|
||||
@@ -655,10 +644,10 @@ void Kart::update(float dt)
|
||||
m_on_road = false;
|
||||
if( m_curr_track_coords[0] > 0.0 )
|
||||
m_track_sector = world->m_track->findOutOfRoadSector(
|
||||
m_curr_pos.xyz, Track::RS_RIGHT, prev_sector );
|
||||
getXYZ(), Track::RS_RIGHT, prev_sector );
|
||||
else
|
||||
m_track_sector = world->m_track->findOutOfRoadSector(
|
||||
m_curr_pos.xyz, Track::RS_LEFT, prev_sector );
|
||||
getXYZ(), Track::RS_LEFT, prev_sector );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -666,7 +655,7 @@ void Kart::update(float dt)
|
||||
}
|
||||
|
||||
world->m_track->spatialToTrack( m_curr_track_coords,
|
||||
m_curr_pos.xyz,
|
||||
getXYZ(),
|
||||
m_track_sector );
|
||||
|
||||
if(!m_finished_race) doLapCounting();
|
||||
@@ -881,8 +870,10 @@ void Kart::forceRescue(bool is_shortcut)
|
||||
void Kart::endRescue()
|
||||
{
|
||||
if ( m_track_sector > 0 ) m_track_sector-- ;
|
||||
world ->m_track -> trackToSpatial ( m_curr_pos.xyz, m_track_sector ) ;
|
||||
m_curr_pos.hpr[0] = world->m_track->m_angle[m_track_sector] ;
|
||||
setXYZ( world->m_track->trackToSpatial(m_track_sector) );
|
||||
btQuaternion heading(btVector3(0.0f, 0.0f, 1.0f),
|
||||
DEGREE_TO_RAD(world->m_track->m_angle[m_track_sector]) );
|
||||
setRotation(heading);
|
||||
m_rescue = false ;
|
||||
|
||||
m_body->setLinearVelocity (btVector3(0.0f,0.0f,0.0f));
|
||||
@@ -897,8 +888,7 @@ void Kart::endRescue()
|
||||
// that the drivelines are somewhat under the track. Otherwise, the
|
||||
// kart will be placed a little bit under the track, triggering
|
||||
// a rescue, ...
|
||||
pos.setOrigin(btVector3(m_curr_pos.xyz[0],m_curr_pos.xyz[1],
|
||||
m_curr_pos.xyz[2]+0.5f*getKartHeight()+0.1f));
|
||||
pos.setOrigin(getXYZ()+btVector3(0, 0, 0.5f*getKartHeight()+0.1f));
|
||||
pos.setRotation(btQuaternion(btVector3(0.0f, 0.0f, 1.0f),
|
||||
DEGREE_TO_RAD(world->m_track->m_angle[m_track_sector])));
|
||||
m_body->setCenterOfMassTransform(pos);
|
||||
@@ -925,22 +915,22 @@ void Kart::processSkidMarks()
|
||||
{
|
||||
if(isOnGround())
|
||||
{
|
||||
m_skidmark_left ->add(*getCoord(), ANGLE, LENGTH);
|
||||
m_skidmark_right->add(*getCoord(), ANGLE, LENGTH);
|
||||
//FIXME: no getCoord anymore m_skidmark_left ->add(*getCoord(), ANGLE, LENGTH);
|
||||
//FIXME m_skidmark_right->add(*getCoord(), ANGLE, LENGTH);
|
||||
}
|
||||
else
|
||||
{ // not on ground
|
||||
m_skidmark_left->addBreak(*getCoord(), ANGLE, LENGTH);
|
||||
m_skidmark_right->addBreak(*getCoord(), ANGLE, LENGTH);
|
||||
//FIXME m_skidmark_left->addBreak(*getCoord(), ANGLE, LENGTH);
|
||||
//FIRME m_skidmark_right->addBreak(*getCoord(), ANGLE, LENGTH);
|
||||
} // on ground
|
||||
}
|
||||
else
|
||||
{ // !skid_rear && !skid_front
|
||||
if(m_skidmark_left->wasSkidMarking())
|
||||
m_skidmark_left->addBreak(*getCoord(), ANGLE, LENGTH);
|
||||
//FIXME if(m_skidmark_left->wasSkidMarking())
|
||||
//FIXME m_skidmark_left->addBreak(*getCoord(), ANGLE, LENGTH);
|
||||
|
||||
if(m_skidmark_right->wasSkidMarking())
|
||||
m_skidmark_right->addBreak(*getCoord(), ANGLE, LENGTH);
|
||||
//FIXME if(m_skidmark_right->wasSkidMarking())
|
||||
//FIXME m_skidmark_right->addBreak(*getCoord(), ANGLE, LENGTH);
|
||||
}
|
||||
} // processSkidMarks
|
||||
|
||||
@@ -1039,7 +1029,7 @@ void Kart::loadData()
|
||||
} // loadData
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void Kart::placeModel ()
|
||||
void Kart::updateGraphics(const Vec3& off_xyz, const Vec3& off_hpr)
|
||||
{
|
||||
sgMat4 wheel_front;
|
||||
sgMat4 wheel_steer;
|
||||
@@ -1056,30 +1046,14 @@ void Kart::placeModel ()
|
||||
if (m_wheel_rear_l) m_wheel_rear_l->setTransform(wheel_rot);
|
||||
if (m_wheel_rear_r) m_wheel_rear_r->setTransform(wheel_rot);
|
||||
|
||||
// Only transfer the bullet data to the plib tree if no history is being
|
||||
// replayed.
|
||||
if(!user_config->m_replay_history)
|
||||
{
|
||||
//float m[4][4];
|
||||
//getTrans().getOpenGLMatrix((float*)&m);
|
||||
//sgSetCoord(&m_curr_pos, m);
|
||||
Coord coord(getTrans());
|
||||
// Transfer the new position and hpr to m_curr_pos
|
||||
sgCopyCoord(&m_curr_pos, &(coord.toSgCoord()));
|
||||
}
|
||||
sgCoord c ;
|
||||
sgCopyCoord ( &c, &m_curr_pos );
|
||||
const float CENTER_SHIFT = getGravityCenterShift();
|
||||
const float offset_pitch = m_wheelie_angle;
|
||||
const float offset_pitch = DEGREE_TO_RAD(m_wheelie_angle);
|
||||
const float offset_z = 0.3f*fabs(sin(m_wheelie_angle*SG_DEGREES_TO_RADIANS))
|
||||
- (0.5f-CENTER_SHIFT)*getKartHeight();
|
||||
|
||||
m_curr_pos.xyz[2] += offset_z;
|
||||
m_curr_pos.hpr[1] += offset_pitch;
|
||||
Moveable::placeModel();
|
||||
m_curr_pos.xyz[2] -= offset_z;
|
||||
m_curr_pos.hpr[1] -= offset_pitch;
|
||||
} // placeModel
|
||||
Moveable::updateGraphics(Vec3(0, 0, offset_z), Vec3(0, offset_pitch, 0));
|
||||
} // updateGraphics
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
float Kart::estimateFinishTime ()
|
||||
{
|
||||
|
||||
17
src/kart.hpp
17
src/kart.hpp
@@ -62,8 +62,9 @@ protected:
|
||||
KartControl m_controls; // The position of the karts controls
|
||||
int m_track_sector; // index in driveline, special values
|
||||
// e.g. UNKNOWN_SECTOR can be negative!
|
||||
sgVec2 m_last_track_coords;
|
||||
sgVec3 m_curr_track_coords;
|
||||
btTransform m_reset_transform; // reset position
|
||||
Vec3 m_curr_track_coords;
|
||||
Vec3 m_last_track_coords;
|
||||
float m_max_speed; // maximum speed of the kart, computed from
|
||||
float m_max_speed_reverse_ratio;
|
||||
float m_wheelie_angle;
|
||||
@@ -114,11 +115,11 @@ protected:
|
||||
void load_wheels (ssgBranch* obj);
|
||||
|
||||
public:
|
||||
Kart(const std::string& kart_name, int position_,
|
||||
sgCoord init_pos);
|
||||
Kart(const std::string& kart_name, int position,
|
||||
const btTransform& init_transform);
|
||||
virtual ~Kart();
|
||||
void loadData();
|
||||
void placeModel ();
|
||||
virtual void updateGraphics (const Vec3& off_xyz, const Vec3& off_hpr);
|
||||
const KartProperties*
|
||||
getKartProperties () const { return m_kart_properties; }
|
||||
void setKartProperties (const KartProperties *kp)
|
||||
@@ -130,8 +131,8 @@ public:
|
||||
virtual void setPosition (int p)
|
||||
{ m_race_position = p; }
|
||||
int getSector () const { return m_track_sector; }
|
||||
float getDistanceDownTrack() const { return m_curr_track_coords[1]; }
|
||||
float getDistanceToCenter () const { return m_curr_track_coords[0]; }
|
||||
float getDistanceDownTrack() const { return m_curr_track_coords.getY(); }
|
||||
float getDistanceToCenter () const { return m_curr_track_coords.getX(); }
|
||||
Attachment *getAttachment () { return &m_attachment; }
|
||||
void setAttachmentType (attachmentType t, float time_left=0.0f,
|
||||
Kart*k=NULL)
|
||||
@@ -204,7 +205,7 @@ public:
|
||||
void resetBrakes ();
|
||||
void adjustSpeedWeight(float f);
|
||||
void forceRescue (bool is_rescue=false);
|
||||
void handleExplosion (const btVector3& pos, bool direct_hit);
|
||||
void handleExplosion (const Vec3& pos, bool direct_hit);
|
||||
const std::string& getName () const {return m_kart_properties->getName();}
|
||||
const std::string& getIdent () const {return m_kart_properties->getIdent();}
|
||||
virtual int isPlayerKart () const {return 0; }
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// as published by the Free Software Foundation; either version 3
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
|
||||
@@ -35,9 +35,6 @@ Moveable::Moveable (bool bHasHistory)
|
||||
|
||||
m_model_transform->ref();
|
||||
|
||||
sgZeroVec3 ( m_reset_pos.xyz ) ; sgZeroVec3 ( m_reset_pos.hpr ) ;
|
||||
|
||||
reset ();
|
||||
if(bHasHistory)
|
||||
{
|
||||
m_history_velocity = new sgCoord[history->GetSize()];
|
||||
@@ -65,16 +62,21 @@ Moveable::~Moveable()
|
||||
} // ~Moveable
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// The reset position must be set before calling reset
|
||||
void Moveable::reset ()
|
||||
{
|
||||
m_collided = false;
|
||||
m_crashed = false;
|
||||
m_material_hot = NULL;
|
||||
m_normal_hot = NULL;
|
||||
if(m_body) m_body->setLinearVelocity(btVector3(0.0, 0.0, 0.0));
|
||||
sgCopyCoord( &m_curr_pos, &m_reset_pos );
|
||||
m_hpr = Vec3(m_curr_pos.hpr);
|
||||
m_hpr.degreeToRad();
|
||||
if(m_body)
|
||||
{
|
||||
m_body->setLinearVelocity(btVector3(0.0, 0.0, 0.0));
|
||||
m_body->setAngularVelocity(btVector3(0, 0, 0));
|
||||
m_body->setCenterOfMassTransform(m_transform);
|
||||
}
|
||||
Coord c(m_transform);
|
||||
m_hpr = c.getHPR();
|
||||
} // reset
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -103,18 +105,16 @@ void Moveable::createBody(float mass, btTransform& trans,
|
||||
//-----------------------------------------------------------------------------
|
||||
void Moveable::update (float dt)
|
||||
{
|
||||
m_motion_state->getWorldTransform(m_transform);
|
||||
m_velocityLC = getVelocity()*getTrans().getBasis();
|
||||
m_hpr.setHPR(m_transform.getBasis());
|
||||
|
||||
if(m_history_velocity)
|
||||
{
|
||||
if(user_config->m_replay_history)
|
||||
{
|
||||
sgCoord tmp;
|
||||
sgCopyCoord(&tmp, &(m_history_velocity[history->GetCurrentIndex()]));
|
||||
//printf("m_velocity=%f,%f,%f,%f,%f,%f\n",
|
||||
// m_velocity.xyz[0],m_velocity.xyz[1],m_velocity.xyz[2],
|
||||
// m_velocity.hpr[0],m_velocity.hpr[1],m_velocity.hpr[2]);
|
||||
//printf("tmp =%f,%f,%f,%f,%f,%f\n",
|
||||
// tmp.xyz[0],tmp.xyz[1],tmp.xyz[2],
|
||||
// tmp.hpr[0],tmp.hpr[1],tmp.hpr[2]);
|
||||
|
||||
#undef IGNORE_Z_IN_HISTORY
|
||||
#ifdef IGNORE_Z_IN_HISTORY
|
||||
@@ -139,42 +139,35 @@ void Moveable::update (float dt)
|
||||
{
|
||||
sgCoord tmp;
|
||||
sgCopyCoord(&tmp, &(m_history_position[history->GetCurrentIndex()]));
|
||||
//printf("m_curr_pos=%f,%f,%f,%f,%f,%f\n",
|
||||
// m_curr_pos.xyz[0],m_curr_pos.xyz[1],m_curr_pos.xyz[2],
|
||||
// m_curr_pos.hpr[0],m_curr_pos.hpr[1],m_curr_pos.hpr[2]);
|
||||
//printf("tmp =%f,%f,%f,%f,%f,%f --> %d\n",
|
||||
// tmp.xyz[0],tmp.xyz[1],tmp.xyz[2],
|
||||
// tmp.hpr[0],tmp.hpr[1],tmp.hpr[2],
|
||||
// history->GetCurrentIndex());
|
||||
|
||||
#ifdef IGNORE_Z_IN_HISTORY
|
||||
const float DUMMY=m_curr_pos.xyz[2];
|
||||
sgCopyCoord(&m_curr_pos, &tmp);
|
||||
m_curr_pos.xyz[2]=DUMMY;
|
||||
#else
|
||||
sgCopyCoord(&m_curr_pos, &tmp);
|
||||
#endif
|
||||
Vec3 hpr(tmp.hpr);
|
||||
hpr.degreeToRad();
|
||||
btMatrix3x3 rotation;
|
||||
rotation.setEulerZYX(hpr.getPitch(), hpr.getRoll(), hpr.getHeading());
|
||||
m_transform.setBasis(rotation);
|
||||
m_transform.setOrigin(Vec3(tmp.xyz));
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
sgCopyCoord(&(m_history_position[history->GetCurrentIndex()]), &m_curr_pos);
|
||||
Coord c(m_transform);
|
||||
sgCopyCoord(&(m_history_position[history->GetCurrentIndex()]), &c.toSgCoord());
|
||||
}
|
||||
} // if m_history_position
|
||||
|
||||
m_velocityLC = getVelocity()*getTrans().getBasis();
|
||||
m_motion_state->getWorldTransform(m_transform);
|
||||
m_hpr.setHPR(m_transform.getBasis());
|
||||
|
||||
placeModel();
|
||||
updateGraphics(Vec3(0,0,0), Vec3(0,0,0));
|
||||
m_first_time = false ;
|
||||
} // update
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void Moveable::placeModel()
|
||||
void Moveable::updateGraphics(const Vec3& off_xyz, const Vec3& off_hpr)
|
||||
{
|
||||
m_model_transform->setTransform(&m_curr_pos);
|
||||
} // placeModel
|
||||
Vec3 xyz=getXYZ()+off_xyz;
|
||||
Vec3 hpr=getHPR()+off_hpr;
|
||||
sgCoord c=Coord(xyz, hpr).toSgCoord();
|
||||
|
||||
m_model_transform->setTransform(&c);
|
||||
} // updateGraphics
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void Moveable::WriteHistory(char* s, int kartNumber, int indx)
|
||||
|
||||
@@ -39,8 +39,6 @@ private:
|
||||
btVector3 m_velocityLC; /* velocity in kart coordinates */
|
||||
protected:
|
||||
UserPointer m_user_pointer;
|
||||
sgCoord m_reset_pos; /* Where to start in case of a reset */
|
||||
sgCoord m_curr_pos; /* current position */
|
||||
sgVec4* m_normal_hot; /* plane on which HOT was computed */
|
||||
Material* m_material_hot; /* Material at HOT */
|
||||
ssgTransform* m_model_transform; // The transform where the model is under
|
||||
@@ -64,14 +62,19 @@ public:
|
||||
virtual const btVector3 &getVelocity() const {return m_body->getLinearVelocity();}
|
||||
const btVector3 &getVelocityLC() const {return m_velocityLC; }
|
||||
virtual void setVelocity(const btVector3& v) {m_body->setLinearVelocity(v); }
|
||||
sgCoord* getCoord () {return &m_curr_pos; }
|
||||
const Vec3& getPos () const {return (Vec3&)m_transform.getOrigin();}
|
||||
const Vec3& getRotation() const {return m_hpr; }
|
||||
const sgCoord* getCoord () const {return &m_curr_pos; }
|
||||
const sgVec4* getNormalHOT () const {return m_normal_hot; }
|
||||
const sgCoord* getResetPos () const {return &m_reset_pos; }
|
||||
void setCoord (sgCoord* pos) {sgCopyCoord ( &m_curr_pos,pos); }
|
||||
virtual void placeModel ();
|
||||
const Vec3& getXYZ () const {return (Vec3&)m_transform.getOrigin();}
|
||||
const Vec3& getHPR () const {return m_hpr; }
|
||||
const btQuaternion getRotation() const {return m_transform.getRotation(); }
|
||||
void setXYZ (const Vec3& a) {m_transform.setOrigin(a);
|
||||
m_motion_state->setWorldTransform(m_transform);}
|
||||
void setRotation (const btQuaternion&a){m_transform.setRotation(a);
|
||||
m_motion_state->setWorldTransform(m_transform);}
|
||||
void setXYZRotation(const Vec3& xyz, const btQuaternion& a)
|
||||
{m_transform.setRotation(a);
|
||||
m_transform.setOrigin(xyz);
|
||||
m_motion_state->setWorldTransform(m_transform);}
|
||||
const sgVec4* getNormalHOT () const {return m_normal_hot; }
|
||||
virtual void updateGraphics(const Vec3& off_xyz, const Vec3& off_hpr);
|
||||
virtual void handleZipper () {};
|
||||
virtual void reset ();
|
||||
virtual void update (float dt) ;
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
#include "camera.hpp"
|
||||
|
||||
PlayerKart::PlayerKart(const std::string& kart_name, int position, Player *player,
|
||||
sgCoord init_pos, int player_index) :
|
||||
const btTransform& init_pos, int player_index) :
|
||||
Kart(kart_name, position, init_pos)
|
||||
{
|
||||
m_player = player;
|
||||
@@ -166,7 +166,6 @@ void PlayerKart::update(float dt)
|
||||
// The call to update is necessary here (even though the kart
|
||||
// shouldn't actually change) to update m_transform. Otherwise
|
||||
// the camera gets the wrong position.
|
||||
// FIXME: that might not necessary anymore once m_curr_pos is removed!
|
||||
Kart::update(dt);
|
||||
}
|
||||
|
||||
@@ -273,7 +272,7 @@ void PlayerKart::addMessages()
|
||||
// ------------------------------------------------------
|
||||
if(race_manager->getDifficulty()==RaceManager::RD_EASY)
|
||||
{
|
||||
float angle_diff = getCoord()->hpr[0] - world->m_track->m_angle[getSector()];
|
||||
float angle_diff = RAD_TO_DEGREE(getHPR().getHeading()) - world->m_track->m_angle[getSector()];
|
||||
if(angle_diff > 180.0f) angle_diff -= 360.0f;
|
||||
else if (angle_diff < -180.0f) angle_diff += 360.0f;
|
||||
// Display a warning message if the kart is going back way (unless
|
||||
|
||||
@@ -44,7 +44,7 @@ private:
|
||||
public:
|
||||
PlayerKart(const std::string& kart_name,
|
||||
int position, Player *_player,
|
||||
sgCoord init_pos, int player_index);
|
||||
const btTransform& init_pos, int player_index);
|
||||
|
||||
int earlyStartPenalty () {return m_penalty_time>0; }
|
||||
Player* getPlayer () {return m_player; }
|
||||
|
||||
@@ -94,7 +94,7 @@ void ProjectileManager::update(float dt)
|
||||
while(p!=m_active_projectiles.end())
|
||||
{
|
||||
if(! (*p)->hasHit()) { p++; continue; }
|
||||
newExplosion((const Vec3&)(*p)->getPos());
|
||||
newExplosion((*p)->getXYZ());
|
||||
Flyable *f=*p;
|
||||
Projectiles::iterator pNext=m_active_projectiles.erase(p); // returns the next element
|
||||
delete f;
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
#include "default_robot.hpp"
|
||||
|
||||
DefaultRobot::DefaultRobot(const std::string& kart_name,
|
||||
int position, sgCoord init_pos ) :
|
||||
int position, const btTransform& init_pos ) :
|
||||
AutoKart( kart_name, position, init_pos )
|
||||
{
|
||||
reset();
|
||||
@@ -98,25 +98,25 @@ void DefaultRobot::update( float delta )
|
||||
|
||||
/*Get information that is needed by more than 1 of the handling funcs*/
|
||||
//Detect if we are going to crash with the track and/or kart
|
||||
int steps = 0;
|
||||
|
||||
// This should not happen (anymore :) ), but it keeps the game running
|
||||
// in case that m_future_sector becomes undefined.
|
||||
if(m_future_sector == Track::UNKNOWN_SECTOR )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr,"DefaultRobot: m_future_sector is undefined.\n");
|
||||
fprintf(stderr,"This shouldn't happen, but can be ignored.\n");
|
||||
#endif
|
||||
forceRescue();
|
||||
m_future_sector = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
steps = calc_steps();
|
||||
}
|
||||
|
||||
check_crashes( steps, m_curr_pos.xyz );
|
||||
int steps = 0;
|
||||
|
||||
// This should not happen (anymore :) ), but it keeps the game running
|
||||
// in case that m_future_sector becomes undefined.
|
||||
if(m_future_sector == Track::UNKNOWN_SECTOR )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr,"DefaultRobot: m_future_sector is undefined.\n");
|
||||
fprintf(stderr,"This shouldn't happen, but can be ignored.\n");
|
||||
#endif
|
||||
forceRescue();
|
||||
m_future_sector = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
steps = calc_steps();
|
||||
}
|
||||
|
||||
check_crashes( steps, getXYZ() );
|
||||
find_curve();
|
||||
|
||||
/*Response handling functions*/
|
||||
@@ -161,7 +161,7 @@ void DefaultRobot::handle_braking()
|
||||
if ( m_crashes.m_road && m_on_road && getVelocityLC().getY() > MIN_SPEED)
|
||||
{
|
||||
float kart_ang_diff = world->m_track->m_angle[m_track_sector] -
|
||||
m_curr_pos.hpr[0];
|
||||
RAD_TO_DEGREE(getHPR().getHeading());
|
||||
kart_ang_diff = normalize_angle(kart_ang_diff);
|
||||
kart_ang_diff = fabsf(kart_ang_diff);
|
||||
|
||||
@@ -341,7 +341,7 @@ void DefaultRobot::handle_items( const float DELTA, const int STEPS )
|
||||
{
|
||||
const float ANGLE_DIFF = fabsf( normalize_angle(
|
||||
world->m_track->m_angle[m_track_sector]-
|
||||
m_curr_pos.hpr[0] ) );
|
||||
RAD_TO_DEGREE(getHPR().getHeading()) ) );
|
||||
|
||||
if( m_time_since_last_shot > 10.0f && ANGLE_DIFF <
|
||||
15.0f && !m_crashes.m_road && STEPS > 8 )
|
||||
@@ -356,9 +356,8 @@ void DefaultRobot::handle_items( const float DELTA, const int STEPS )
|
||||
case COLLECT_HOMING:
|
||||
if( m_time_since_last_shot > 5.0f && m_crashes.m_kart != -1 )
|
||||
{
|
||||
if( sgDistanceVec2( m_curr_pos.xyz,
|
||||
world->getKart(m_crashes.m_kart)->getCoord()->xyz ) >
|
||||
m_kart_properties->getKartLength() * 2.5f )
|
||||
if( (getXYZ()-world->getKart(m_crashes.m_kart)->getXYZ() ).length_2d() >
|
||||
m_kart_properties->getKartLength() * 2.5f )
|
||||
{
|
||||
m_controls.fire = true;
|
||||
m_time_since_last_shot = 0.0f;
|
||||
@@ -435,15 +434,15 @@ bool DefaultRobot::do_wheelie ( const int STEPS )
|
||||
|
||||
//We have to be careful with normalizing, because if the source argument
|
||||
//has both the X and Y axis set to 0, it returns nan to the destiny.
|
||||
const btVector3 &VEL=getVelocity();
|
||||
btVector3 vel_normal(VEL.getX(), VEL.getY(), 0.0);
|
||||
float len=vel_normal.length();
|
||||
const Vec3 &VEL = getVelocity();
|
||||
Vec3 vel_normal(VEL.getX(), VEL.getY(), 0.0);
|
||||
float len = vel_normal.length();
|
||||
// Too slow for wheelies, and it avoids normalisation problems.
|
||||
if(len<getMaxSpeed()*getWheelieMaxSpeedRatio()) return false;
|
||||
vel_normal/=len;
|
||||
|
||||
sgVec2 step_coord;
|
||||
sgVec3 step_track_coord;
|
||||
Vec3 step_coord;
|
||||
Vec3 step_track_coord;
|
||||
float distance;
|
||||
|
||||
//FIXME: instead of using 1.5, it should find out how much time it
|
||||
@@ -458,11 +457,10 @@ bool DefaultRobot::do_wheelie ( const int STEPS )
|
||||
|
||||
for( int i = WHEELIE_STEPS; i > STEPS - 1; --i )
|
||||
{
|
||||
sgAddScaledVec2( step_coord, m_curr_pos.xyz, vel_normal,
|
||||
m_kart_properties->getKartLength() * i );
|
||||
step_coord = getXYZ()+vel_normal* m_kart_properties->getKartLength() * i ;
|
||||
|
||||
world->m_track->spatialToTrack( step_track_coord, step_coord,
|
||||
m_future_sector );
|
||||
world->m_track->spatialToTrack(step_track_coord, step_coord,
|
||||
m_future_sector );
|
||||
|
||||
distance = step_track_coord[0] > 0.0f ? step_track_coord[0]
|
||||
: -step_track_coord[0];
|
||||
@@ -533,7 +531,7 @@ float DefaultRobot::steer_to_angle (const size_t SECTOR, const float ANGLE)
|
||||
float angle = world->m_track->m_angle[SECTOR];
|
||||
|
||||
//Desired angle minus current angle equals how many angles to turn
|
||||
float steer_angle = angle - m_curr_pos.hpr[0];
|
||||
float steer_angle = angle - RAD_TO_DEGREE(getHPR().getHeading());
|
||||
|
||||
steer_angle += ANGLE;
|
||||
steer_angle = normalize_angle( steer_angle );
|
||||
@@ -545,8 +543,8 @@ float DefaultRobot::steer_to_angle (const size_t SECTOR, const float ANGLE)
|
||||
//-----------------------------------------------------------------------------
|
||||
float DefaultRobot::steer_to_point( const sgVec2 POINT )
|
||||
{
|
||||
const SGfloat ADJACENT_LINE = POINT[0] - m_curr_pos.xyz[0];
|
||||
const SGfloat OPPOSITE_LINE = POINT[1] - m_curr_pos.xyz[1];
|
||||
const SGfloat ADJACENT_LINE = POINT[0] - getXYZ().getX();
|
||||
const SGfloat OPPOSITE_LINE = POINT[1] - getXYZ().getY();
|
||||
SGfloat theta;
|
||||
|
||||
//Protection from division by zero
|
||||
@@ -559,14 +557,14 @@ float DefaultRobot::steer_to_point( const sgVec2 POINT )
|
||||
//The real value depends on the side of the track that the kart is
|
||||
theta += ADJACENT_LINE < 0.0f ? 90.0f : -90.0f;
|
||||
|
||||
float steer_angle = theta - getCoord()->hpr[0];
|
||||
float steer_angle = theta - RAD_TO_DEGREE(getHPR().getHeading());
|
||||
steer_angle = normalize_angle( steer_angle );
|
||||
|
||||
return steer_angle;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void DefaultRobot::check_crashes( const int STEPS, sgVec3 const pos )
|
||||
void DefaultRobot::check_crashes( const int STEPS, const Vec3& pos )
|
||||
{
|
||||
//Right now there are 2 kind of 'crashes': with other karts and another
|
||||
//with the track. The sight line is used to find if the karts crash with
|
||||
@@ -574,21 +572,21 @@ void DefaultRobot::check_crashes( const int STEPS, sgVec3 const pos )
|
||||
//having karts too close in any direction. The crash with the track can
|
||||
//tell when a kart is going to get out of the track so it steers.
|
||||
|
||||
btVector3 vel_normal;
|
||||
Vec3 vel_normal;
|
||||
//in this func we use it as a 2d-vector, but later on it is passed
|
||||
//to world->m_track->findRoadSector, there it is used as a 3d-vector
|
||||
//to find distance to plane, so z must be initialized to zero
|
||||
sgVec3 step_coord;
|
||||
Vec3 step_coord;
|
||||
SGfloat kart_distance;
|
||||
|
||||
step_coord[2] = 0.0;
|
||||
step_coord.setZ(0.0);
|
||||
|
||||
m_crashes.clear();
|
||||
|
||||
const size_t NUM_KARTS = race_manager->getNumKarts();
|
||||
|
||||
//Protection against having vel_normal with nan values
|
||||
const btVector3 &VEL = getVelocity();
|
||||
const Vec3 &VEL = getVelocity();
|
||||
vel_normal.setValue(VEL.getX(), VEL.getY(), 0.0);
|
||||
float len=vel_normal.length();
|
||||
if(len>0.0f)
|
||||
@@ -602,7 +600,7 @@ void DefaultRobot::check_crashes( const int STEPS, sgVec3 const pos )
|
||||
|
||||
for(int i = 1; STEPS > i; ++i)
|
||||
{
|
||||
sgAddScaledVec3( step_coord, pos, vel_normal, m_kart_properties->getKartLength() * i );
|
||||
step_coord = pos + vel_normal* m_kart_properties->getKartLength() * i;
|
||||
|
||||
/* Find if we crash with any kart, as long as we haven't found one
|
||||
* yet
|
||||
@@ -614,8 +612,7 @@ void DefaultRobot::check_crashes( const int STEPS, sgVec3 const pos )
|
||||
const Kart* kart=world->getKart(j);
|
||||
if(kart==this||kart->isEliminated()) continue; // ignore eliminated karts
|
||||
|
||||
kart_distance = sgDistanceVec2( step_coord,
|
||||
world->getKart(j)->getCoord()->xyz );
|
||||
kart_distance = (step_coord-world->getKart(j)->getXYZ()).length_2d();
|
||||
|
||||
if( kart_distance < m_kart_properties->getKartLength() + 0.125f * i )
|
||||
if( getVelocityLC().getY() > world->getKart(j)->
|
||||
@@ -694,8 +691,8 @@ void DefaultRobot::find_non_crashing_point( sgVec2 result )
|
||||
m_track_sector + 1 : 0;
|
||||
int target_sector;
|
||||
|
||||
sgVec2 direction;
|
||||
sgVec3 step_track_coord;
|
||||
Vec3 direction;
|
||||
Vec3 step_track_coord;
|
||||
SGfloat distance;
|
||||
int steps;
|
||||
|
||||
@@ -707,24 +704,22 @@ void DefaultRobot::find_non_crashing_point( sgVec2 result )
|
||||
target_sector = sector + 1 < DRIVELINE_SIZE ? sector + 1 : 0;
|
||||
|
||||
//direction is a vector from our kart to the sectors we are testing
|
||||
sgSubVec2( direction, world->m_track->m_driveline[target_sector],
|
||||
m_curr_pos.xyz );
|
||||
direction = world->m_track->m_driveline[target_sector] - getXYZ();
|
||||
|
||||
float len=sgLengthVec2(direction);
|
||||
float len=direction.length_2d();
|
||||
steps = int( len / m_kart_properties->getKartLength() );
|
||||
if( steps < 3 ) steps = 3;
|
||||
|
||||
//Protection against having vel_normal with nan values
|
||||
if(len>0.0f) {
|
||||
sgScaleVec2(direction, 1.0f/len);
|
||||
direction*= 1.0f/len;
|
||||
}
|
||||
|
||||
sgVec2 step_coord;
|
||||
Vec3 step_coord;
|
||||
//Test if we crash if we drive towards the target sector
|
||||
for( int i = 2; i < steps; ++i )
|
||||
{
|
||||
sgAddScaledVec2( step_coord, m_curr_pos.xyz, direction,
|
||||
m_kart_properties->getKartLength() * i );
|
||||
step_coord = getXYZ()+direction*m_kart_properties->getKartLength() * i ;
|
||||
|
||||
world->m_track->spatialToTrack( step_track_coord, step_coord,
|
||||
sector );
|
||||
|
||||
@@ -115,7 +115,7 @@ private:
|
||||
float steer_to_point(const sgVec2 POINT);
|
||||
|
||||
bool do_wheelie(const int STEPS);
|
||||
void check_crashes(const int STEPS, sgVec3 const pos);
|
||||
void check_crashes(const int STEPS, const Vec3& pos);
|
||||
void find_non_crashing_point(sgVec2 result);
|
||||
|
||||
float normalize_angle (float angle);
|
||||
@@ -128,11 +128,10 @@ private:
|
||||
|
||||
public:
|
||||
DefaultRobot(const std::string& kart_name, int position,
|
||||
sgCoord init_pos);
|
||||
const btTransform& init_pos);
|
||||
|
||||
void update (float delta) ;
|
||||
void reset ();
|
||||
int isPlayerKart() const {return 0;}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -177,10 +177,9 @@ void Scene::draw(float dt)
|
||||
float f=2.0f;
|
||||
glFrustum(-f, f, -f, f, 1.0, 1000.0);
|
||||
|
||||
btVector3 pos;
|
||||
sgCoord *c = world->getKart(race_manager->getNumKarts()-1)->getCoord();
|
||||
gluLookAt(c->xyz[0], c->xyz[1]-5.f, c->xyz[2]+4,
|
||||
c->xyz[0], c->xyz[1], c->xyz[2],
|
||||
Vec3 xyz = world->getKart(race_manager->getNumKarts()-1)->getXYZ();
|
||||
gluLookAt(xyz.getX(), xyz.getY()-5.f, xyz.getZ()+4,
|
||||
xyz.getX(), xyz.getY(), xyz.getZ(),
|
||||
0.0f, 0.0f, 1.0f);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
|
||||
|
||||
321
src/track.cpp
321
src/track.cpp
@@ -90,10 +90,10 @@ void Track::cleanup()
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Finds on which side of the line segment a given point is.
|
||||
*/
|
||||
inline float Track::pointSideToLine( const sgVec2 L1, const sgVec2 L2,
|
||||
const sgVec2 P ) const
|
||||
inline float Track::pointSideToLine( const Vec3& L1, const Vec3& L2,
|
||||
const Vec3& P ) const
|
||||
{
|
||||
return ( L2[0]-L1[0] )*( P[1]-L1[1] )-( L2[1]-L1[1] )*( P[0]-L1[0] );
|
||||
return ( L2.getX()-L1.getX() )*( P.getY()-L1.getY() )-( L2.getY()-L1.getY() )*( P.getX()-L1.getX() );
|
||||
} // pointSideToLine
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -107,11 +107,11 @@ inline float Track::pointSideToLine( const sgVec2 L1, const sgVec2 L2,
|
||||
*/
|
||||
int Track::pointInQuad
|
||||
(
|
||||
const sgVec2 A,
|
||||
const sgVec2 B,
|
||||
const sgVec2 C,
|
||||
const sgVec2 D,
|
||||
const sgVec2 POINT
|
||||
const Vec3& A,
|
||||
const Vec3& B,
|
||||
const Vec3& C,
|
||||
const Vec3& D,
|
||||
const Vec3& POINT
|
||||
) const
|
||||
{
|
||||
if(pointSideToLine( C, A, POINT ) >= 0.0 )
|
||||
@@ -139,7 +139,7 @@ int Track::pointInQuad
|
||||
* The 'sector' could be defined as the number of the closest track
|
||||
* segment to XYZ.
|
||||
*/
|
||||
void Track::findRoadSector( const sgVec3 XYZ, int *sector )const
|
||||
void Track::findRoadSector(const Vec3& XYZ, int *sector )const
|
||||
{
|
||||
if(*sector!=UNKNOWN_SECTOR)
|
||||
{
|
||||
@@ -166,7 +166,7 @@ void Track::findRoadSector( const sgVec3 XYZ, int *sector )const
|
||||
m_right_driveline[next], m_left_driveline[next],
|
||||
XYZ );
|
||||
|
||||
if (triangle != QUAD_TRI_NONE && ((XYZ[2]-m_left_driveline[i][2]) < 1.0f))
|
||||
if (triangle != QUAD_TRI_NONE && ((XYZ.getZ()-m_left_driveline[i].getZ()) < 1.0f))
|
||||
{
|
||||
possible_segment_tris.push_back(SegmentTriangle((int)i, triangle));
|
||||
}
|
||||
@@ -201,16 +201,18 @@ void Track::findRoadSector( const sgVec3 XYZ, int *sector )const
|
||||
|
||||
if( possible_segment_tris[i].triangle == QUAD_TRI_FIRST )
|
||||
{
|
||||
sgMakePlane( plane, m_left_driveline[segment],
|
||||
m_right_driveline[segment], m_right_driveline[next] );
|
||||
sgMakePlane( plane, m_left_driveline[segment].toFloat(),
|
||||
m_right_driveline[segment].toFloat(),
|
||||
m_right_driveline[next].toFloat() );
|
||||
}
|
||||
else //possible_segment_tris[i].triangle == QUAD_TRI_SECOND
|
||||
{
|
||||
sgMakePlane( plane, m_right_driveline[next],
|
||||
m_left_driveline[next], m_left_driveline[segment] );
|
||||
sgMakePlane( plane, m_right_driveline[next].toFloat(),
|
||||
m_left_driveline[next].toFloat(),
|
||||
m_left_driveline[segment].toFloat() );
|
||||
}
|
||||
|
||||
dist = sgHeightAbovePlaneVec3( plane, XYZ );
|
||||
dist = sgHeightAbovePlaneVec3( plane, XYZ.toFloat() );
|
||||
|
||||
/* sgHeightAbovePlaneVec3 gives a negative dist if the plane
|
||||
is on top, so we have to rule it out.
|
||||
@@ -264,7 +266,7 @@ void Track::findRoadSector( const sgVec3 XYZ, int *sector )const
|
||||
*/
|
||||
int Track::findOutOfRoadSector
|
||||
(
|
||||
const sgVec3 XYZ,
|
||||
const Vec3& XYZ,
|
||||
const RoadSide SIDE,
|
||||
const int CURR_SECTOR
|
||||
) const
|
||||
@@ -309,10 +311,10 @@ int Track::findOutOfRoadSector
|
||||
|
||||
if( SIDE != RS_RIGHT)
|
||||
{
|
||||
sgCopyVec3( line_seg.a, m_left_driveline[i] );
|
||||
sgCopyVec3( line_seg.b, m_left_driveline[next_sector] );
|
||||
sgCopyVec3( line_seg.a, m_left_driveline[i].toFloat() );
|
||||
sgCopyVec3( line_seg.b, m_left_driveline[next_sector].toFloat() );
|
||||
|
||||
dist = sgDistSquaredToLineSegmentVec3( line_seg, XYZ );
|
||||
dist = sgDistSquaredToLineSegmentVec3( line_seg, XYZ.toFloat() );
|
||||
|
||||
if ( dist < nearest_dist )
|
||||
{
|
||||
@@ -323,10 +325,10 @@ int Track::findOutOfRoadSector
|
||||
|
||||
if( SIDE != RS_LEFT )
|
||||
{
|
||||
sgCopyVec3( line_seg.a, m_right_driveline[i] );
|
||||
sgCopyVec3( line_seg.b, m_right_driveline[next_sector] );
|
||||
sgCopyVec3( line_seg.a, m_right_driveline[i].toFloat() );
|
||||
sgCopyVec3( line_seg.b, m_right_driveline[next_sector].toFloat() );
|
||||
|
||||
dist = sgDistSquaredToLineSegmentVec3( line_seg, XYZ );
|
||||
dist = sgDistSquaredToLineSegmentVec3( line_seg, XYZ.toFloat() );
|
||||
|
||||
if ( dist < nearest_dist )
|
||||
{
|
||||
@@ -355,8 +357,8 @@ int Track::findOutOfRoadSector
|
||||
*/
|
||||
int Track::spatialToTrack
|
||||
(
|
||||
sgVec3 dst,
|
||||
const sgVec2 POS,
|
||||
Vec3& dst,
|
||||
const Vec3& POS,
|
||||
const int SECTOR
|
||||
) const
|
||||
{
|
||||
@@ -370,8 +372,8 @@ int Track::spatialToTrack
|
||||
const size_t PREV = SECTOR == 0 ? DRIVELINE_SIZE - 1 : SECTOR - 1;
|
||||
const size_t NEXT = (size_t)SECTOR+1 >= DRIVELINE_SIZE ? 0 : SECTOR + 1;
|
||||
|
||||
const float DIST_PREV = sgDistanceVec2 ( m_driveline[PREV], POS );
|
||||
const float DIST_NEXT = sgDistanceVec2 ( m_driveline[NEXT], POS );
|
||||
const float DIST_PREV = (m_driveline[PREV]-POS).length2_2d();
|
||||
const float DIST_NEXT = (m_driveline[NEXT]-POS).length2_2d();
|
||||
|
||||
size_t p1, p2;
|
||||
if ( DIST_NEXT < DIST_PREV )
|
||||
@@ -386,14 +388,14 @@ int Track::spatialToTrack
|
||||
sgVec3 line_eqn;
|
||||
sgVec2 tmp;
|
||||
|
||||
sgMake2DLine ( line_eqn, m_driveline[p1], m_driveline[p2] );
|
||||
sgMake2DLine ( line_eqn, m_driveline[p1].toFloat(), m_driveline[p2].toFloat() );
|
||||
|
||||
dst[0] = sgDistToLineVec2 ( line_eqn, POS );
|
||||
dst.setX(sgDistToLineVec2 ( line_eqn, POS.toFloat() ) );
|
||||
|
||||
sgAddScaledVec2 ( tmp, POS, line_eqn, -dst [0] );
|
||||
sgAddScaledVec2 ( tmp, POS.toFloat(), line_eqn, -dst.getX() );
|
||||
|
||||
float dist_from_driveline_p1 = sgDistanceVec2 ( tmp, m_driveline[p1] );
|
||||
dst[1] = dist_from_driveline_p1 + m_distance_from_start[p1];
|
||||
float dist_from_driveline_p1 = sgDistanceVec2 ( tmp, m_driveline[p1].toFloat() );
|
||||
dst.setY(dist_from_driveline_p1 + m_distance_from_start[p1]);
|
||||
// Set z-axis to half the width (linear interpolation between the
|
||||
// width at p1 and p2) - m_path_width is actually already half the width
|
||||
// of the track. This is used to determine if a kart is too far
|
||||
@@ -401,43 +403,39 @@ int Track::spatialToTrack
|
||||
|
||||
float fraction = dist_from_driveline_p1
|
||||
/ (m_distance_from_start[p2]-m_distance_from_start[p1]);
|
||||
dst[2] = m_path_width[p1]*(1-fraction)+fraction*m_path_width[p2];
|
||||
dst.setZ(m_path_width[p1]*(1-fraction)+fraction*m_path_width[p2]);
|
||||
|
||||
return (int)p1;
|
||||
} // spatialToTrack
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void Track::trackToSpatial ( sgVec3 xyz, const int SECTOR ) const
|
||||
const Vec3& Track::trackToSpatial(const int SECTOR ) const
|
||||
{
|
||||
sgCopyVec3 ( xyz, m_driveline [ SECTOR ] ) ;
|
||||
return m_driveline[SECTOR];
|
||||
} // trackToSpatial
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Returns the start coordinates for a kart on a given position pos
|
||||
(with 0<=pos).
|
||||
*/
|
||||
void Track::getStartCoords(unsigned int pos, sgCoord* coords) const {
|
||||
btTransform Track::getStartTransform(unsigned int pos) const {
|
||||
// Bug fix/workaround: sometimes the first kart would be too close
|
||||
// to the first driveline point and not to the last one -->
|
||||
// This kart would not get any lap counting done in the first
|
||||
// lap! Therefor -1.5 is subtracted from the y position - which
|
||||
// is a somewhat arbitrary value.
|
||||
coords->xyz[0] = pos<m_start_x.size() ? m_start_x[pos] : ((pos%2==0)?1.5f:-1.5f);
|
||||
coords->xyz[1] = pos<m_start_y.size() ? m_start_y[pos] : -1.5f*pos-1.5f;
|
||||
// height must be larger than the actual hight for which hot is computed.
|
||||
coords->xyz[2] = pos<m_start_z.size() ? m_start_z[pos] : 1.0f;
|
||||
|
||||
coords->hpr[0] = pos<m_start_heading.size() ? m_start_heading[pos] : 0.0f;
|
||||
coords->hpr[1] = 0.0f;
|
||||
coords->hpr[2] = 0.0f;
|
||||
|
||||
Vec3 tmp_pos(coords->xyz);
|
||||
|
||||
Vec3 normal;
|
||||
const Material *material=NULL;
|
||||
getTerrainInfo(tmp_pos, &(coords->xyz[2]), &normal, &material);
|
||||
|
||||
} // getStartCoords
|
||||
Vec3 orig;
|
||||
pos--; // adjust from "1 to n" index to "0 to n-1"
|
||||
orig.setX( pos<m_start_x.size() ? m_start_x[pos] : ((pos%2==0)?1.5f:-1.5f) );
|
||||
orig.setY( pos<m_start_y.size() ? m_start_y[pos] : -1.5f*pos-1.5f );
|
||||
orig.setZ( pos<m_start_z.size() ? m_start_z[pos] : 1.0f );
|
||||
btTransform start;
|
||||
start.setOrigin(orig);
|
||||
start.setRotation(btQuaternion(btVector3(0, 0, 1),
|
||||
pos<m_start_heading.size()
|
||||
? DEGREE_TO_RAD(m_start_heading[pos]) : 0.0f ));
|
||||
return start;
|
||||
} // getStartTransform
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Determines if a kart moving from sector OLDSEC to sector NEWSEC
|
||||
@@ -450,7 +448,7 @@ bool Track::isShortcut(const int OLDSEC, const int NEWSEC) const
|
||||
if(OLDSEC==UNKNOWN_SECTOR || NEWSEC==UNKNOWN_SECTOR) return false;
|
||||
unsigned int distance_sectors = abs(OLDSEC-NEWSEC);
|
||||
// Handle 'wrap around': if the distance is more than half the
|
||||
// number of driveline poins, assume it's a 'wrap around'
|
||||
// number of driveline points, assume it's a 'wrap around'
|
||||
if(2*distance_sectors > (unsigned int)m_driveline.size())
|
||||
distance_sectors = (unsigned int)m_driveline.size() - distance_sectors;
|
||||
return (distance_sectors>stk_config->m_shortcut_segments);
|
||||
@@ -467,7 +465,7 @@ void Track::addDebugToScene(int type) const
|
||||
for(unsigned int i = 0; i < m_driveline.size(); ++i)
|
||||
{
|
||||
sphere = new ssgaSphere;
|
||||
sgCopyVec3(center, m_driveline[i]);
|
||||
sgCopyVec3(center, m_driveline[i].toFloat());
|
||||
sphere->setCenter(center);
|
||||
sphere->setSize(getWidth()[i] / 4.0f);
|
||||
|
||||
@@ -495,10 +493,10 @@ void Track::addDebugToScene(int type) const
|
||||
// The segment display must be slightly higher than the
|
||||
// track, otherwise it's not clearly visible.
|
||||
sgVec3 v;
|
||||
sgCopyVec3(v,m_left_driveline [i ]); v[2]+=0.1f; v_array->add(v);
|
||||
sgCopyVec3(v,m_right_driveline[i ]); v[2]+=0.1f; v_array->add(v);
|
||||
sgCopyVec3(v,m_right_driveline[ip1]); v[2]+=0.1f; v_array->add(v);
|
||||
sgCopyVec3(v,m_left_driveline [ip1]); v[2]+=0.1f; v_array->add(v);
|
||||
sgCopyVec3(v,m_left_driveline [i ].toFloat()); v[2]+=0.1f; v_array->add(v);
|
||||
sgCopyVec3(v,m_right_driveline[i ].toFloat()); v[2]+=0.1f; v_array->add(v);
|
||||
sgCopyVec3(v,m_right_driveline[ip1].toFloat()); v[2]+=0.1f; v_array->add(v);
|
||||
sgCopyVec3(v,m_left_driveline [ip1].toFloat()); v[2]+=0.1f; v_array->add(v);
|
||||
sgVec4 vc;
|
||||
vc[0] = i%2==0 ? 1.0f : 0.0f;
|
||||
vc[1] = 1.0f-v[0];
|
||||
@@ -528,16 +526,15 @@ void Track::addDebugToScene(int type) const
|
||||
|
||||
void Track::drawScaled2D(float x, float y, float w, float h) const
|
||||
{
|
||||
sgVec2 sc;
|
||||
sgSubVec2 ( sc, m_driveline_max, m_driveline_min );
|
||||
float width = m_driveline_max.getX() - m_driveline_min.getX();
|
||||
|
||||
float sx = w / sc[0];
|
||||
float sy = h / sc[1];
|
||||
float sx = w / width;
|
||||
float sy = h / ( m_driveline_max.getY()-m_driveline_min.getY() );
|
||||
|
||||
if( sx > sy )
|
||||
{
|
||||
sx = sy;
|
||||
x += w/2 - sc[0]*sx/2;
|
||||
x += w/2 - width*sx/2;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -558,16 +555,16 @@ void Track::drawScaled2D(float x, float y, float w, float h) const
|
||||
|
||||
for ( size_t i = 0 ; i < DRIVELINE_SIZE ; ++i )
|
||||
{
|
||||
glVertex2f ( x + ( m_left_driveline[i][0] - m_driveline_min[0] ) * sx,
|
||||
y + ( m_left_driveline[i][1] - m_driveline_min[1] ) * sy) ;
|
||||
glVertex2f ( x + ( m_left_driveline[i].getX() - m_driveline_min.getX() ) * sx,
|
||||
y + ( m_left_driveline[i].getY() - m_driveline_min.getY() ) * sy) ;
|
||||
|
||||
glVertex2f ( x + ( m_right_driveline[i][0] - m_driveline_min[0] ) * sx,
|
||||
y + ( m_right_driveline[i][1] - m_driveline_min[1] ) * sy ) ;
|
||||
glVertex2f ( x + ( m_right_driveline[i].getX() - m_driveline_min.getX() ) * sx,
|
||||
y + ( m_right_driveline[i].getY() - m_driveline_min.getY() ) * sy ) ;
|
||||
}
|
||||
glVertex2f ( x + ( m_left_driveline[0][0] - m_driveline_min[0] ) * sx,
|
||||
y + ( m_left_driveline[0][1] - m_driveline_min[1] ) * sy) ;
|
||||
glVertex2f ( x + ( m_right_driveline[0][0] - m_driveline_min[0] ) * sx,
|
||||
y + ( m_right_driveline[0][1] - m_driveline_min[1] ) * sy ) ;
|
||||
glVertex2f ( x + ( m_left_driveline[0].getX() - m_driveline_min.getX() ) * sx,
|
||||
y + ( m_left_driveline[0].getY() - m_driveline_min.getY() ) * sy) ;
|
||||
glVertex2f ( x + ( m_right_driveline[0].getX() - m_driveline_min.getX() ) * sx,
|
||||
y + ( m_right_driveline[0].getY() - m_driveline_min.getY() ) * sy ) ;
|
||||
|
||||
glEnd () ;
|
||||
|
||||
@@ -585,35 +582,35 @@ void Track::drawScaled2D(float x, float y, float w, float h) const
|
||||
for ( size_t i = 0 ; i < DRIVELINE_SIZE - 1 ; ++i )
|
||||
{
|
||||
/*Draw left driveline of the map*/
|
||||
glVertex2f ( x + ( m_left_driveline[i][0] - m_driveline_min[0] ) * sx,
|
||||
y + ( m_left_driveline[i][1] - m_driveline_min[1] ) * sy ) ;
|
||||
glVertex2f ( x + ( m_left_driveline[i].getX() - m_driveline_min.getX() ) * sx,
|
||||
y + ( m_left_driveline[i].getY() - m_driveline_min.getY() ) * sy ) ;
|
||||
|
||||
glVertex2f ( x + ( m_left_driveline[i+1][0] - m_driveline_min[0] ) * sx,
|
||||
y + ( m_left_driveline[i+1][1] - m_driveline_min[1] ) * sy ) ;
|
||||
glVertex2f ( x + ( m_left_driveline[i+1].getX() - m_driveline_min.getX() ) * sx,
|
||||
y + ( m_left_driveline[i+1].getY() - m_driveline_min.getY() ) * sy ) ;
|
||||
|
||||
|
||||
/*Draw left driveline of the map*/
|
||||
glVertex2f ( x + ( m_right_driveline[i][0] - m_driveline_min[0] ) * sx,
|
||||
y + ( m_right_driveline[i][1] - m_driveline_min[1] ) * sy ) ;
|
||||
glVertex2f ( x + ( m_right_driveline[i].getX() - m_driveline_min.getX() ) * sx,
|
||||
y + ( m_right_driveline[i].getY() - m_driveline_min.getY() ) * sy ) ;
|
||||
|
||||
glVertex2f ( x + ( m_right_driveline[i+1][0] - m_driveline_min[0] ) * sx,
|
||||
y + ( m_right_driveline[i+1][1] - m_driveline_min[1] ) * sy ) ;
|
||||
glVertex2f ( x + ( m_right_driveline[i+1].getX() - m_driveline_min.getX() ) * sx,
|
||||
y + ( m_right_driveline[i+1].getY() - m_driveline_min.getY() ) * sy ) ;
|
||||
}
|
||||
|
||||
//Close the left driveline
|
||||
glVertex2f ( x + ( m_left_driveline[DRIVELINE_SIZE - 1][0] - m_driveline_min[0] ) * sx,
|
||||
y + ( m_left_driveline[DRIVELINE_SIZE - 1][1] - m_driveline_min[1] ) * sy ) ;
|
||||
glVertex2f ( x + ( m_left_driveline[DRIVELINE_SIZE - 1].getX() - m_driveline_min.getX() ) * sx,
|
||||
y + ( m_left_driveline[DRIVELINE_SIZE - 1].getY() - m_driveline_min.getY() ) * sy ) ;
|
||||
|
||||
glVertex2f ( x + ( m_left_driveline[0][0] - m_driveline_min[0] ) * sx,
|
||||
y + ( m_left_driveline[0][1] - m_driveline_min[1] ) * sy ) ;
|
||||
glVertex2f ( x + ( m_left_driveline[0].getX() - m_driveline_min.getX() ) * sx,
|
||||
y + ( m_left_driveline[0].getY() - m_driveline_min.getY() ) * sy ) ;
|
||||
|
||||
|
||||
//Close the right driveline
|
||||
glVertex2f ( x + ( m_right_driveline[DRIVELINE_SIZE - 1][0] - m_driveline_min[0] ) * sx,
|
||||
y + ( m_right_driveline[DRIVELINE_SIZE - 1][1] - m_driveline_min[1] ) * sy ) ;
|
||||
glVertex2f ( x + ( m_right_driveline[DRIVELINE_SIZE - 1].getX() - m_driveline_min.getX() ) * sx,
|
||||
y + ( m_right_driveline[DRIVELINE_SIZE - 1].getY() - m_driveline_min.getY() ) * sy ) ;
|
||||
|
||||
glVertex2f ( x + ( m_right_driveline[0][0] - m_driveline_min[0] ) * sx,
|
||||
y + ( m_right_driveline[0][1] - m_driveline_min[1] ) * sy ) ;
|
||||
glVertex2f ( x + ( m_right_driveline[0].getX() - m_driveline_min.getX() ) * sx,
|
||||
y + ( m_right_driveline[0].getY() - m_driveline_min.getY() ) * sy ) ;
|
||||
glEnd () ;
|
||||
|
||||
#if 0
|
||||
@@ -624,16 +621,16 @@ void Track::drawScaled2D(float x, float y, float w, float h) const
|
||||
glBegin ( GL_LINE_LOOP ) ;
|
||||
for ( size_t i = 0 ; i < DRIVELINE_SIZE ; ++i )
|
||||
{
|
||||
glVertex2f ( x + ( m_left_driveline[i][0] - m_driveline_min[0] ) * sx,
|
||||
y + ( m_left_driveline[i][1] - m_driveline_min[1] ) * sy ) ;
|
||||
glVertex2f ( x + ( m_left_driveline[i].getX() - m_driveline_min.getX() ) * sx,
|
||||
y + ( m_left_driveline[i].getY() - m_driveline_min.getY() ) * sy ) ;
|
||||
}
|
||||
glEnd () ;
|
||||
|
||||
glBegin ( GL_LINE_LOOP ) ;
|
||||
for ( size_t i = 0 ; i < DRIVELINE_SIZE ; ++i )
|
||||
{
|
||||
glVertex2f ( x + ( m_right_driveline[i][0] - m_driveline_min[0] ) * sx,
|
||||
y + ( m_right_driveline[i][1] - m_driveline_min[1] ) * sy ) ;
|
||||
glVertex2f ( x + ( m_right_driveline[i].getX() - m_driveline_min.getX() ) * sx,
|
||||
y + ( m_right_driveline[i].getY() - m_driveline_min.getY() ) * sy ) ;
|
||||
}
|
||||
glEnd () ;
|
||||
#endif
|
||||
@@ -642,11 +639,11 @@ void Track::drawScaled2D(float x, float y, float w, float h) const
|
||||
glBegin ( GL_POINTS ) ;
|
||||
for ( size_t i = 0 ; i < DRIVELINE_SIZE ; ++i )
|
||||
{
|
||||
glVertex2f ( x + ( m_left_driveline[i][0] - m_driveline_min[0] ) * sx,
|
||||
y + ( m_left_driveline[i][1] - m_driveline_min[1] ) * sy ) ;
|
||||
glVertex2f ( x + ( m_left_driveline[i].getX() - m_driveline_min.getX() ) * sx,
|
||||
y + ( m_left_driveline[i].getY() - m_driveline_min.getY() ) * sy ) ;
|
||||
|
||||
glVertex2f ( x + ( m_right_driveline[i][0] - m_driveline_min[0] ) * sx,
|
||||
y + ( m_right_driveline[i][1] - m_driveline_min[1] ) * sy ) ;
|
||||
glVertex2f ( x + ( m_right_driveline[i].getX() - m_driveline_min.getX() ) * sx,
|
||||
y + ( m_right_driveline[i].getY() - m_driveline_min.getY() ) * sy ) ;
|
||||
}
|
||||
glEnd () ;
|
||||
|
||||
@@ -667,7 +664,7 @@ void Track::draw2Dview (float x_offset, float y_offset) const
|
||||
glDisable (GL_TEXTURE_2D);
|
||||
|
||||
//TODO: maybe colors should be configurable, or at least the alpha value
|
||||
glColor4f ( 1.0f,1.0f,1, 0.4f) ;
|
||||
glColor4f ( 1.0f, 1.0f, 1.0f, 0.4f) ;
|
||||
|
||||
|
||||
/*FIXME: Too much calculations here, we should be generating scaled driveline arrays
|
||||
@@ -678,15 +675,15 @@ void Track::draw2Dview (float x_offset, float y_offset) const
|
||||
glBegin ( GL_QUAD_STRIP ) ;
|
||||
|
||||
for ( size_t i = 0 ; i < DRIVELINE_SIZE ; ++i ) {
|
||||
glVertex2f ( x_offset + ( m_left_driveline[i][0] - m_driveline_min[0] ) * m_scale_x,
|
||||
y_offset + ( m_left_driveline[i][1] - m_driveline_min[1] ) * m_scale_y) ;
|
||||
glVertex2f ( x_offset + ( m_right_driveline[i][0] - m_driveline_min[0] ) * m_scale_x,
|
||||
y_offset + ( m_right_driveline[i][1] - m_driveline_min[1] ) * m_scale_y ) ;
|
||||
glVertex2f ( x_offset + ( m_left_driveline[i].getX() - m_driveline_min.getX() ) * m_scale_x,
|
||||
y_offset + ( m_left_driveline[i].getY() - m_driveline_min.getY() ) * m_scale_y) ;
|
||||
glVertex2f ( x_offset + ( m_right_driveline[i].getX() - m_driveline_min.getX() ) * m_scale_x,
|
||||
y_offset + ( m_right_driveline[i].getY() - m_driveline_min.getY() ) * m_scale_y ) ;
|
||||
}
|
||||
glVertex2f ( x_offset + ( m_left_driveline[0][0] - m_driveline_min[0] ) * m_scale_x,
|
||||
y_offset + ( m_left_driveline[0][1] - m_driveline_min[1] ) * m_scale_y ) ;
|
||||
glVertex2f ( x_offset + ( m_right_driveline[0][0] - m_driveline_min[0] ) * m_scale_x,
|
||||
y_offset + ( m_right_driveline[0][1] - m_driveline_min[1] ) * m_scale_y ) ;
|
||||
glVertex2f ( x_offset + ( m_left_driveline[0].getX() - m_driveline_min.getX() ) * m_scale_x,
|
||||
y_offset + ( m_left_driveline[0].getY() - m_driveline_min.getY() ) * m_scale_y ) ;
|
||||
glVertex2f ( x_offset + ( m_right_driveline[0].getX() - m_driveline_min.getX() ) * m_scale_x,
|
||||
y_offset + ( m_right_driveline[0].getY() - m_driveline_min.getY() ) * m_scale_y ) ;
|
||||
|
||||
glEnd () ;
|
||||
|
||||
@@ -706,35 +703,35 @@ void Track::draw2Dview (float x_offset, float y_offset) const
|
||||
for ( size_t i = 0 ; i < DRIVELINE_SIZE - 1 ; ++i )
|
||||
{
|
||||
/*Draw left driveline of the map*/
|
||||
glVertex2f ( x_offset + ( m_left_driveline[i][0] - m_driveline_min[0] ) * m_scale_x,
|
||||
y_offset + ( m_left_driveline[i][1] - m_driveline_min[1] ) * m_scale_y ) ;
|
||||
glVertex2f ( x_offset + ( m_left_driveline[i].getX() - m_driveline_min.getX() ) * m_scale_x,
|
||||
y_offset + ( m_left_driveline[i].getY() - m_driveline_min.getY() ) * m_scale_y ) ;
|
||||
|
||||
glVertex2f ( x_offset + ( m_left_driveline[i+1][0] - m_driveline_min[0] ) * m_scale_x,
|
||||
y_offset + ( m_left_driveline[i+1][1] - m_driveline_min[1] ) * m_scale_y ) ;
|
||||
glVertex2f ( x_offset + ( m_left_driveline[i+1].getX() - m_driveline_min.getX() ) * m_scale_x,
|
||||
y_offset + ( m_left_driveline[i+1].getY() - m_driveline_min.getY() ) * m_scale_y ) ;
|
||||
|
||||
|
||||
/*Draw left driveline of the map*/
|
||||
glVertex2f ( x_offset + ( m_right_driveline[i][0] - m_driveline_min[0] ) * m_scale_x,
|
||||
y_offset + ( m_right_driveline[i][1] - m_driveline_min[1] ) * m_scale_y ) ;
|
||||
glVertex2f ( x_offset + ( m_right_driveline[i].getX() - m_driveline_min.getX() ) * m_scale_x,
|
||||
y_offset + ( m_right_driveline[i].getY() - m_driveline_min.getY() ) * m_scale_y ) ;
|
||||
|
||||
glVertex2f ( x_offset + ( m_right_driveline[i+1][0] - m_driveline_min[0] ) * m_scale_x,
|
||||
y_offset + ( m_right_driveline[i+1][1] - m_driveline_min[1] ) * m_scale_y ) ;
|
||||
glVertex2f ( x_offset + ( m_right_driveline[i+1].getX() - m_driveline_min.getX() ) * m_scale_x,
|
||||
y_offset + ( m_right_driveline[i+1].getY() - m_driveline_min.getY() ) * m_scale_y ) ;
|
||||
}
|
||||
|
||||
//Close the left driveline
|
||||
glVertex2f ( x_offset + ( m_left_driveline[DRIVELINE_SIZE - 1][0] - m_driveline_min[0] ) * m_scale_x,
|
||||
y_offset + ( m_left_driveline[DRIVELINE_SIZE - 1][1] - m_driveline_min[1] ) * m_scale_y ) ;
|
||||
glVertex2f ( x_offset + ( m_left_driveline[DRIVELINE_SIZE - 1].getX() - m_driveline_min.getX() ) * m_scale_x,
|
||||
y_offset + ( m_left_driveline[DRIVELINE_SIZE - 1].getY() - m_driveline_min.getY() ) * m_scale_y ) ;
|
||||
|
||||
glVertex2f ( x_offset + ( m_left_driveline[0][0] - m_driveline_min[0] ) * m_scale_x,
|
||||
y_offset + ( m_left_driveline[0][1] - m_driveline_min[1] ) * m_scale_y ) ;
|
||||
glVertex2f ( x_offset + ( m_left_driveline[0].getX() - m_driveline_min.getX() ) * m_scale_x,
|
||||
y_offset + ( m_left_driveline[0].getY() - m_driveline_min.getY() ) * m_scale_y ) ;
|
||||
|
||||
|
||||
//Close the right driveline
|
||||
glVertex2f ( x_offset + ( m_right_driveline[DRIVELINE_SIZE - 1][0] - m_driveline_min[0] ) * m_scale_x,
|
||||
y_offset + ( m_right_driveline[DRIVELINE_SIZE - 1][1] - m_driveline_min[1] ) * m_scale_y ) ;
|
||||
glVertex2f ( x_offset + ( m_right_driveline[DRIVELINE_SIZE - 1].getX() - m_driveline_min.getX() ) * m_scale_x,
|
||||
y_offset + ( m_right_driveline[DRIVELINE_SIZE - 1].getY() - m_driveline_min.getY() ) * m_scale_y ) ;
|
||||
|
||||
glVertex2f ( x_offset + ( m_right_driveline[0][0] - m_driveline_min[0] ) * m_scale_x,
|
||||
y_offset + ( m_right_driveline[0][1] - m_driveline_min[1] ) * m_scale_y ) ;
|
||||
glVertex2f ( x_offset + ( m_right_driveline[0].getX() - m_driveline_min.getX() ) * m_scale_x,
|
||||
y_offset + ( m_right_driveline[0].getY() - m_driveline_min.getY() ) * m_scale_y ) ;
|
||||
glEnd () ;
|
||||
|
||||
#if 0
|
||||
@@ -745,16 +742,16 @@ void Track::draw2Dview (float x_offset, float y_offset) const
|
||||
glBegin ( GL_LINE_LOOP ) ;
|
||||
for ( size_t i = 0 ; i < DRIVELINE_SIZE ; ++i )
|
||||
{
|
||||
glVertex2f ( x_offset + ( m_left_driveline[i][0] - m_driveline_min[0] ) * m_scale_x,
|
||||
y_offset + ( m_left_driveline[i][1] - m_driveline_min[1] ) * m_scale_y ) ;
|
||||
glVertex2f ( x_offset + ( m_left_driveline[i].getX() - m_driveline_min.getX() ) * m_scale_x,
|
||||
y_offset + ( m_left_driveline[i].getY() - m_driveline_min.getY() ) * m_scale_y ) ;
|
||||
}
|
||||
glEnd () ;
|
||||
|
||||
glBegin ( GL_LINE_LOOP ) ;
|
||||
for ( size_t i = 0 ; i < DRIVELINE_SIZE ; ++i )
|
||||
{
|
||||
glVertex2f ( x_offset + ( m_right_driveline[i][0] - m_driveline_min[0] ) * m_scale_x,
|
||||
y_offset + ( m_right_driveline[i][1] - m_driveline_min[1] ) * m_scale_y ) ;
|
||||
glVertex2f ( x_offset + ( m_right_driveline[i].get() - m_driveline_min.getX() ) * m_scale_x,
|
||||
y_offset + ( m_right_driveline[i].getY() - m_driveline_min.getY() ) * m_scale_y ) ;
|
||||
}
|
||||
glEnd () ;
|
||||
#endif
|
||||
@@ -766,11 +763,11 @@ void Track::draw2Dview (float x_offset, float y_offset) const
|
||||
glBegin ( GL_POINTS) ;
|
||||
for ( size_t i = 0 ; i < DRIVELINE_SIZE ; ++i )
|
||||
{
|
||||
glVertex2f ( x_offset + ( m_left_driveline[i][0] - m_driveline_min[0] ) * m_scale_x,
|
||||
y_offset + ( m_left_driveline[i][1] - m_driveline_min[1] ) * m_scale_y ) ;
|
||||
glVertex2f ( x_offset + ( m_left_driveline[i].getX() - m_driveline_min.getX() ) * m_scale_x,
|
||||
y_offset + ( m_left_driveline[i].getY() - m_driveline_min.getY() ) * m_scale_y ) ;
|
||||
|
||||
glVertex2f ( x_offset + ( m_right_driveline[i][0] - m_driveline_min[0] ) * m_scale_x,
|
||||
y_offset + ( m_right_driveline[i][1] - m_driveline_min[1] ) * m_scale_y ) ;
|
||||
glVertex2f ( x_offset + ( m_right_driveline[i].getX() - m_driveline_min.getX() ) * m_scale_x,
|
||||
y_offset + ( m_right_driveline[i].getY() - m_driveline_min.getY() ) * m_scale_y ) ;
|
||||
}
|
||||
glEnd () ;
|
||||
|
||||
@@ -902,21 +899,16 @@ Track::loadDriveline()
|
||||
"and the left driveline is " << m_left_driveline.size()
|
||||
<< " vertex long. Track is " << m_name << " ." << std::endl;
|
||||
|
||||
SGfloat width;
|
||||
sgVec3 center_point, width_vector;
|
||||
m_driveline.reserve(DRIVELINE_SIZE);
|
||||
m_path_width.reserve(DRIVELINE_SIZE);
|
||||
m_angle.reserve(DRIVELINE_SIZE);
|
||||
for(unsigned int i = 0; i < DRIVELINE_SIZE; ++i)
|
||||
{
|
||||
sgAddVec3(center_point, m_left_driveline[i], m_right_driveline[i]);
|
||||
sgScaleVec3(center_point, 0.5f);
|
||||
Vec3 center_point = (m_left_driveline[i]+m_right_driveline[i])*0.5;
|
||||
m_driveline.push_back(center_point);
|
||||
|
||||
sgSubVec3(width_vector, m_right_driveline[i], center_point);
|
||||
width = sgLengthVec3(width_vector);
|
||||
if(width > 0.0f) m_path_width.push_back(width);
|
||||
else m_path_width.push_back(-width);
|
||||
float width = ( m_right_driveline[i] - center_point ).length();
|
||||
m_path_width.push_back(width);
|
||||
}
|
||||
|
||||
size_t next;
|
||||
@@ -926,8 +918,8 @@ Track::loadDriveline()
|
||||
for(unsigned int i = 0; i < DRIVELINE_SIZE; ++i)
|
||||
{
|
||||
next = i + 1 >= DRIVELINE_SIZE ? 0 : i + 1;
|
||||
adjacent_line = m_driveline[next][0] - m_driveline[i][0];
|
||||
opposite_line = m_driveline[next][1] - m_driveline[i][1];
|
||||
adjacent_line = m_driveline[next].getX() - m_driveline[i].getX();
|
||||
opposite_line = m_driveline[next].getY() - m_driveline[i].getY();
|
||||
|
||||
theta = sgATan(opposite_line/adjacent_line);
|
||||
theta += adjacent_line < 0.0f ? 90.0f : -90.0f;
|
||||
@@ -935,8 +927,8 @@ Track::loadDriveline()
|
||||
m_angle.push_back(theta);
|
||||
}
|
||||
|
||||
sgSetVec2 ( m_driveline_min, SG_MAX/2.0f, SG_MAX/2.0f ) ;
|
||||
sgSetVec2 ( m_driveline_max, -SG_MAX/2.0f, -SG_MAX/2.0f ) ;
|
||||
m_driveline_min = Vec3( SG_MAX/2.0f);
|
||||
m_driveline_max = Vec3(-SG_MAX/2.0f);
|
||||
|
||||
|
||||
m_distance_from_start.reserve(DRIVELINE_SIZE);
|
||||
@@ -946,40 +938,19 @@ Track::loadDriveline()
|
||||
//Both drivelines must be checked to get the true size of
|
||||
//the drivelines, and using the center driveline is not
|
||||
//good enough.
|
||||
if ( m_right_driveline[i][0] < m_driveline_min[0] )
|
||||
m_driveline_min[0] = m_right_driveline[i][0] ;
|
||||
if ( m_right_driveline[i][1] < m_driveline_min[1] )
|
||||
m_driveline_min[1] = m_right_driveline[i][1] ;
|
||||
if ( m_right_driveline[i][0] > m_driveline_max[0] )
|
||||
m_driveline_max[0] = m_right_driveline[i][0] ;
|
||||
if ( m_right_driveline[i][1] > m_driveline_max[1] )
|
||||
m_driveline_max[1] = m_right_driveline[i][1] ;
|
||||
|
||||
if ( m_left_driveline[i][0] < m_driveline_min[0] )
|
||||
m_driveline_min[0] = m_left_driveline[i][0] ;
|
||||
if ( m_left_driveline[i][1] < m_driveline_min[1] )
|
||||
m_driveline_min[1] = m_left_driveline[i][1] ;
|
||||
if ( m_left_driveline[i][0] > m_driveline_max[0] )
|
||||
m_driveline_max[0] = m_left_driveline[i][0] ;
|
||||
if ( m_left_driveline[i][1] > m_driveline_max[1] )
|
||||
m_driveline_max[1] = m_left_driveline[i][1] ;
|
||||
|
||||
m_driveline_min.min(m_right_driveline[i]);
|
||||
m_driveline_min.min(m_left_driveline[i] );
|
||||
m_driveline_max.max(m_right_driveline[i]);
|
||||
m_driveline_max.max(m_left_driveline[i] );
|
||||
|
||||
m_distance_from_start.push_back(d); // dfs[i] is not valid in windows here!
|
||||
|
||||
if ( i == DRIVELINE_SIZE - 1 )
|
||||
d += sgDistanceVec2 ( m_driveline[i], m_driveline[0] ) ;
|
||||
else
|
||||
d += sgDistanceVec2 ( m_driveline[i], m_driveline[i+1] ) ;
|
||||
d += (m_driveline[i]-m_driveline[ i==DRIVELINE_SIZE-1 ? 0 : i+1 ]).length();
|
||||
}
|
||||
|
||||
m_total_distance = d;
|
||||
Vec3 sc = m_driveline_max - m_driveline_min;
|
||||
|
||||
sgVec2 sc ;
|
||||
sgSubVec2 ( sc, m_driveline_max, m_driveline_min ) ;
|
||||
|
||||
m_scale_x = m_track_2d_width / sc[0] ;
|
||||
m_scale_y = m_track_2d_height / sc[1] ;
|
||||
m_scale_x = m_track_2d_width / sc.getX();
|
||||
m_scale_y = m_track_2d_height / sc.getY();
|
||||
|
||||
if(!m_do_stretch) m_scale_x = m_scale_y = std::min(m_scale_x, m_scale_y);
|
||||
|
||||
@@ -987,7 +958,7 @@ Track::loadDriveline()
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void
|
||||
Track::readDrivelineFromFile(std::vector<sgVec3Wrapper>& line, const std::string& file_ext)
|
||||
Track::readDrivelineFromFile(std::vector<Vec3>& line, const std::string& file_ext)
|
||||
{
|
||||
std::string path = file_manager->getTrackFile(m_ident+file_ext);
|
||||
FILE *fd = fopen ( path.c_str(), "r" ) ;
|
||||
@@ -1022,13 +993,10 @@ Track::readDrivelineFromFile(std::vector<sgVec3Wrapper>& line, const std::string
|
||||
throw std::runtime_error(msg);
|
||||
}
|
||||
|
||||
sgVec3 point;
|
||||
point[0] = x;
|
||||
point[1] = y;
|
||||
point[2] = z;
|
||||
Vec3 point(x,y,z);
|
||||
|
||||
if(prev_sector != UNKNOWN_SECTOR) prev_distance = sgDistanceVec2(
|
||||
point, line[prev_sector] );
|
||||
if(prev_sector != UNKNOWN_SECTOR)
|
||||
prev_distance = (point-line[prev_sector]).length2_2d();
|
||||
|
||||
//1.5f was choosen because it's more or less the length of the tuxkart
|
||||
if(prev_distance < 0.0000001)
|
||||
@@ -1354,7 +1322,8 @@ void Track::herring_command (sgVec3 *xyz, char htype, int bNeedHeight )
|
||||
// Time trial does not have any red herrings
|
||||
if(type==HE_RED && race_manager->getRaceMode()==RaceManager::RM_TIME_TRIAL)
|
||||
return;
|
||||
herring_manager->newHerring(type, xyz);
|
||||
Vec3 loc((*xyz));
|
||||
herring_manager->newHerring(type, loc);
|
||||
} // herring_command
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// $Id$
|
||||
//
|
||||
// SuperTuxKart - a fun racing game with go-kart
|
||||
// Copyright (C) 2004 Steve Baker <sjbaker1@airmail.net>
|
||||
//
|
||||
@@ -98,45 +96,21 @@ public:
|
||||
sgVec4 m_specular_col;
|
||||
sgVec4 m_diffuse_col;
|
||||
|
||||
/** sgVec3 is a float[3] array, so unfortunately we can't put it in a
|
||||
* std::vector because it lacks a copy-constructor, this hack should help...
|
||||
*/
|
||||
class sgVec3Wrapper
|
||||
{
|
||||
private:
|
||||
sgVec3 vec;
|
||||
|
||||
public:
|
||||
sgVec3Wrapper(const sgVec3& o)
|
||||
{
|
||||
sgCopyVec3(vec, o);
|
||||
}
|
||||
|
||||
operator const float* () const
|
||||
{
|
||||
return vec;
|
||||
}
|
||||
|
||||
operator float* ()
|
||||
{
|
||||
return vec;
|
||||
}
|
||||
};
|
||||
//FIXME: Maybe the next 4 vectors should be inside an struct and be used
|
||||
//from a vector of structs?
|
||||
//FIXME: should the driveline be set as a sgVec2?
|
||||
std::vector<sgVec3Wrapper> m_driveline;
|
||||
std::vector<Vec3> m_driveline;
|
||||
std::vector<SGfloat> m_distance_from_start;
|
||||
std::vector<SGfloat> m_path_width;
|
||||
std::vector<SGfloat> m_angle;
|
||||
|
||||
//Left and Right drivelines for overhead map rendering.
|
||||
//(Should probably be private as they are only use internally right now)
|
||||
std::vector<sgVec3Wrapper> m_left_driveline;
|
||||
std::vector<sgVec3Wrapper> m_right_driveline;
|
||||
std::vector<Vec3> m_left_driveline;
|
||||
std::vector<Vec3> m_right_driveline;
|
||||
|
||||
sgVec2 m_driveline_min;
|
||||
sgVec2 m_driveline_max;
|
||||
Vec3 m_driveline_min;
|
||||
Vec3 m_driveline_max;
|
||||
|
||||
|
||||
float m_total_distance;
|
||||
@@ -158,15 +132,15 @@ public:
|
||||
void drawScaled2D (float x, float y, float w,
|
||||
float h ) const;
|
||||
|
||||
void findRoadSector (const sgVec3 XYZ, int *sector) const;
|
||||
int findOutOfRoadSector(const sgVec3 XYZ,
|
||||
void findRoadSector (const Vec3& XYZ, int *sector) const;
|
||||
int findOutOfRoadSector(const Vec3& XYZ,
|
||||
const RoadSide SIDE,
|
||||
const int CURR_SECTOR
|
||||
) const;
|
||||
int spatialToTrack (sgVec3 dst,
|
||||
const sgVec2 POS,
|
||||
int spatialToTrack (Vec3& dst,
|
||||
const Vec3& POS,
|
||||
const int SECTOR ) const;
|
||||
void trackToSpatial (sgVec3 xyz, const int SECTOR) const;
|
||||
const Vec3& trackToSpatial (const int SECTOR) const;
|
||||
void loadTrackModel ();
|
||||
bool isShortcut (const int OLDSEC, const int NEWSEC) const;
|
||||
void addMusic (MusicInformation* mi)
|
||||
@@ -199,7 +173,7 @@ public:
|
||||
bool hasFinalCamera () const {return m_has_final_camera; }
|
||||
const Vec3& getCameraPosition () const {return m_camera_final_position;}
|
||||
const Vec3& getCameraHPR () const {return m_camera_final_hpr; }
|
||||
void getStartCoords (unsigned int pos, sgCoord* coords) const;
|
||||
btTransform getStartTransform (unsigned int pos) const;
|
||||
void getTerrainInfo(const Vec3 &pos, float *hot, Vec3* normal,
|
||||
const Material **material) const;
|
||||
void createPhysicsModel ();
|
||||
@@ -214,14 +188,14 @@ private:
|
||||
void loadTrack (std::string filename);
|
||||
void herring_command (sgVec3 *xyz, char htype, int bNeedHeight);
|
||||
void loadDriveline ();
|
||||
void readDrivelineFromFile (std::vector<sgVec3Wrapper>& line,
|
||||
void readDrivelineFromFile (std::vector<Vec3>& line,
|
||||
const std::string& file_ext );
|
||||
void convertTrackToBullet (ssgEntity *track, sgMat4 m);
|
||||
|
||||
float pointSideToLine(const sgVec2 L1, const sgVec2 L2,
|
||||
const sgVec2 P ) const;
|
||||
int pointInQuad(const sgVec2 A, const sgVec2 B,
|
||||
const sgVec2 C, const sgVec2 D, const sgVec2 POINT ) const;
|
||||
float pointSideToLine(const Vec3& L1, const Vec3& L2,
|
||||
const Vec3& P ) const;
|
||||
int pointInQuad(const Vec3& A, const Vec3& B,
|
||||
const Vec3& C, const Vec3& D, const Vec3& POINT ) const;
|
||||
void getMusicInformation(std::vector<std::string>& filenames,
|
||||
std::vector<MusicInformation*>& m_music );
|
||||
}
|
||||
|
||||
17
src/vec3.hpp
17
src/vec3.hpp
@@ -1,8 +1,4 @@
|
||||
// $Id: vec3.hpp 1954 2008-05-20 10:01:26Z scifly $
|
||||
//
|
||||
// SuperTuxKart - a fun racing game with go-kart
|
||||
// Copyright (C) 2008 Joerg Henrichs
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 3
|
||||
@@ -36,6 +32,7 @@ public:
|
||||
inline Vec3() : btVector3() {}
|
||||
inline Vec3(float x, float y, float z)
|
||||
: btVector3(x,y,z) {}
|
||||
inline Vec3(float x) : btVector3(x,x,x) {}
|
||||
|
||||
void setHPR(const btMatrix3x3& m);
|
||||
inline const float operator[](int n) const {return *(&m_x+n); }
|
||||
@@ -49,5 +46,17 @@ public:
|
||||
void degreeToRad();
|
||||
Vec3& operator=(const btVector3& a) {*(btVector3*)this=a; return *this;}
|
||||
Vec3& operator=(const btMatrix3x3& m) {setHPR(m); return *this;}
|
||||
Vec3 operator-(const Vec3& v1) const {return (Vec3)(*(btVector3*)this-(btVector3)v1);}
|
||||
// Helper functions to treat this vec3 as a 2d vector:
|
||||
float length2_2d() {return m_x*m_x + m_y*m_y;}
|
||||
float length_2d() {return sqrt(m_x*m_x + m_y*m_y);}
|
||||
void max(const Vec3& a) {if(a.getX()>m_x) m_x=a.getX();
|
||||
if(a.getY()>m_y) m_y=a.getY();
|
||||
if(a.getZ()>m_z) m_z=a.getZ();}
|
||||
void min(const Vec3& a) {if(a.getX()<m_x) m_x=a.getX();
|
||||
if(a.getY()<m_y) m_y=a.getY();
|
||||
if(a.getZ()<m_z) m_z=a.getZ();}
|
||||
}; // Vec3
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -99,8 +99,7 @@ World::World()
|
||||
for(unsigned int i=0; i<race_manager->getNumKarts(); i++)
|
||||
{
|
||||
int position = i+1; // position start with 1
|
||||
sgCoord init_pos;
|
||||
m_track->getStartCoords(i, &init_pos);
|
||||
btTransform init_pos=m_track->getStartTransform(position);
|
||||
Kart* newkart;
|
||||
const std::string& kart_name=race_manager->getKartName(i);
|
||||
if(user_config->m_profile)
|
||||
@@ -111,7 +110,6 @@ World::World()
|
||||
// karts can be seen.
|
||||
if(i==race_manager->getNumKarts()-1)
|
||||
{
|
||||
btVector3 startpos(init_pos.xyz[0], init_pos.xyz[1], init_pos.xyz[2]);
|
||||
scene->createCamera(playerIndex, newkart);
|
||||
}
|
||||
}
|
||||
@@ -623,7 +621,7 @@ void World::removeKart(int kart_number)
|
||||
camera->setMode(Camera::CM_LEADER_MODE);
|
||||
m_eliminated_players++;
|
||||
}
|
||||
projectile_manager->newExplosion(kart->getPos());
|
||||
projectile_manager->newExplosion(kart->getXYZ());
|
||||
// The kart can't be really removed from the m_kart array, since otherwise
|
||||
// a race can't be restarted. So it's only marked to be eliminated (and
|
||||
// ignored in all loops). Important:world->getCurrentNumKarts() returns
|
||||
@@ -751,7 +749,7 @@ void World::restartRace()
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
Kart* World::loadRobot(const std::string& kart_name, int position,
|
||||
sgCoord init_pos)
|
||||
const btTransform& init_pos)
|
||||
{
|
||||
Kart* currentRobot;
|
||||
|
||||
|
||||
@@ -132,7 +132,7 @@ private:
|
||||
void resetAllKarts ();
|
||||
void removeKart (int kart_number);
|
||||
Kart* loadRobot (const std::string& kart_name, int position,
|
||||
sgCoord init_pos);
|
||||
const btTransform& init_pos);
|
||||
void updateLeaderMode (float dt);
|
||||
void printProfileResultAndExit();
|
||||
void estimateFinishTimes();
|
||||
|
||||
Reference in New Issue
Block a user