1) Removed unused (and nearly empty) traffic driver

2) Added new vec3 object, which is used to convert all
   sg* data structures to btVector3. Replaced more sg*
   data structures using vec3.
3) Replaced all individual red,reen,blue values in .kart
   files with a single 'rgb' vector entry.


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@2047 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk 2008-05-25 16:02:26 +00:00
parent a6439e35a5
commit ecde6ed51e
23 changed files with 194 additions and 79 deletions

View File

@ -26,6 +26,7 @@ libstatic_ssg_a_CXXFLAGS = @NOREGMOVE@
AM_CPPFLAGS=-DSUPERTUXKART_DATADIR="\"$(datadir)/games/@PACKAGE@/\""
supertuxkart_SOURCES = main.cpp \
vec3.cpp vec3.hpp \
actionmap.cpp actionmap.hpp \
material.cpp material.hpp \
material_manager.cpp material_manager.hpp \
@ -39,7 +40,7 @@ supertuxkart_SOURCES = main.cpp \
music_information.cpp music_information.hpp \
sfx_openal.cpp sfx_openal.hpp \
smoke.cpp smoke.hpp \
input.hpp \
input.hpp \
isect.cpp isect.hpp \
track.cpp track.hpp \
herring.cpp herring.hpp \
@ -90,7 +91,6 @@ supertuxkart_SOURCES = main.cpp \
scene.hpp scene.cpp \
no_copy.hpp constants.hpp \
translation.cpp translation.hpp \
traffic.cpp \
player.hpp \
challenges/challenge.hpp challenges/challenge.cpp \
challenges/energy_math_class.cpp challenges/energy_math_class.hpp\

View File

@ -69,13 +69,7 @@ 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->getCoord());
// Best solution would probably be to trigger the
// explosion, and then to attach a new, random
// attachment. Unfortunately, handleExplosion() is not
// really severe enough, and forceRescue() attaches
// tinytux, so that the new attachment is immediately lost.
// m_kart->handleExplosion(m_kart->getCoord()->xyz, true);
case ATTACH_BOMB: projectile_manager->newExplosion(m_kart->getPos());
m_kart->handleExplosion(m_kart->getPos(), /*direct_hit*/ true);
clear();
random_attachment = rand()%3;
@ -145,7 +139,7 @@ void Attachment::update(float dt)
case ATTACH_MAX: break;
case ATTACH_BOMB: if(m_time_left<=0.0)
{
projectile_manager->newExplosion(m_kart->getCoord());
projectile_manager->newExplosion(m_kart->getPos());
m_kart->handleExplosion(m_kart->getPos(),
/*direct_hit*/ true);
}

View File

@ -24,7 +24,7 @@
#include "scene.hpp"
Explosion::Explosion(sgCoord* coord) : ssgTransform()
Explosion::Explosion(const Vec3& coord) : ssgTransform()
{
this->ref();
ssgCutout *cut = new ssgCutout();
@ -35,11 +35,14 @@ Explosion::Explosion(sgCoord* coord) : ssgTransform()
} // Explosion
//-----------------------------------------------------------------------------
void Explosion::init(sgCoord* coord)
void Explosion::init(const Vec3& coord)
{
sound_manager->playSfx( SOUND_EXPLOSION );
setTransform(coord);
sgCoord c;
c.xyz[0]=coord[0];c.xyz[1]=coord[1];c.xyz[2]=coord[2];
c.hpr[0]=0; c.hpr[1]=0; c.hpr[2]=0;
setTransform(&c);
m_step = -1;
scene->add(this);
}
@ -58,5 +61,3 @@ void Explosion::update (float dt)
m_seq -> selectStep ( m_step ) ;
}

View File

@ -21,6 +21,7 @@
#define HEADER_EXPLOSION_H
#include <plib/sg.h>
#include "vec3.hpp"
class Explosion : public ssgTransform
{
@ -29,8 +30,8 @@ public:
ssgSelector *m_seq ;
public:
Explosion(sgCoord* coord);
void init (sgCoord *coord);
Explosion(const Vec3& coord);
void init (const Vec3& coord);
void update (float delta_t);
int inUse () {return (m_step >= 0); }
bool hasEnded () {return m_step >= m_seq->getNumKids(); }

View File

@ -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(trans.getOrigin());
TerrainInfo::update(m_owner->getPos());
float pitch = getTerrainPitch(heading);
btMatrix3x3 m;
@ -166,15 +166,15 @@ void Flyable::update (float dt)
{
if(m_exploded) return;
btTransform trans=getBody()->getWorldTransform();
TerrainInfo::update(trans.getOrigin());
Vec3 pos=getBody()->getWorldTransform().getOrigin();
TerrainInfo::update(pos);
if(getHoT()==Track::NOHIT)
{
explode(NULL); // flyable out of track boundary
return;
}
float hat = trans.getOrigin().getZ()-getHoT();
float hat = pos.getZ()-getHoT();
// Use the Height Above Terrain to set the Z velocity.
// HAT is clamped by min/max height. This might be somewhat

View File

@ -296,7 +296,7 @@ void RaceGUI::drawMap ()
Kart* kart = world->getKart(i);
if(kart->isEliminated()) continue; // don't draw eliminated kart
glColor3fv ( *kart->getColor());
glColor3fv ( kart->getColor().toFloat());
c = kart->getCoord () ;
/* If it's a player, draw a bigger sign */

View File

@ -682,6 +682,10 @@
RelativePath="../../../src\attachment.cpp"
>
</File>
<File
RelativePath="../../../src\attachment_manager.cpp"
>
</File>
<File
RelativePath="../../../src\callback_manager.cpp"
>
@ -898,10 +902,6 @@
RelativePath="../../../src\track_manager.cpp"
>
</File>
<File
RelativePath="../../../src\traffic.cpp"
>
</File>
<File
RelativePath="..\..\translation.cpp"
>
@ -918,6 +918,10 @@
RelativePath="../../../src\user_config.cpp"
>
</File>
<File
RelativePath="..\..\vec3.cpp"
>
</File>
<File
RelativePath="..\..\widget.cpp"
>
@ -1304,6 +1308,10 @@
RelativePath="../../../src\player_kart.hpp"
>
</File>
<File
RelativePath="..\..\position.hpp"
>
</File>
<File
RelativePath="../../../src\projectile_manager.hpp"
>
@ -1420,6 +1428,10 @@
RelativePath="..\..\user_pointer.hpp"
>
</File>
<File
RelativePath="..\..\vec3.hpp"
>
</File>
<File
RelativePath="..\..\widget.hpp"
>
@ -1635,10 +1647,6 @@
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
</Filter>
<File
RelativePath="../../../src\attachment_manager.cpp"
>
</File>
</Files>
<Globals>
</Globals>

View File

@ -360,7 +360,7 @@ void Kart::reset()
m_rescue = false;
placeModel();
TerrainInfo::update(m_transform.getOrigin());
TerrainInfo::update(getPos());
} // reset
//-----------------------------------------------------------------------------
@ -592,7 +592,7 @@ void Kart::update(float dt)
// dependent on the wheel size, suspension data etc.: when jumping,
// the wheel suspension will be fully compressed, resulting in the
// ray to start too low (under the track).
btVector3 pos_plus_epsilon = trans.getOrigin()+btVector3(0,0,0.2f);
Vec3 pos_plus_epsilon = trans.getOrigin()+btVector3(0,0,0.2f);
//btVector3 pos_plus_epsilon (-56.6874237, -137.48851, -3.06826854);
TerrainInfo::update(pos_plus_epsilon);

View File

@ -153,7 +153,7 @@ public:
// Functions to access the current kart properties (which might get changed,
// e.g. mass increase or air_friction increase depending on attachment etc.)
// -------------------------------------------------------------------------
const sgVec3* getColor () const {return m_kart_properties->getColor();}
const Vec3 &getColor () const {return m_kart_properties->getColor();}
float getMass () const
{
return m_kart_properties->getMass()
@ -219,21 +219,6 @@ public:
virtual void raceFinished (float time);
};
class TrafficDriver : public Kart
{
public:
TrafficDriver (const std::string& kart_name, sgVec3 _pos,
sgCoord init_pos)
: Kart (kart_name, 0, init_pos )
{
sgCopyVec3 ( m_reset_pos.xyz, _pos ) ;
reset () ;
}
virtual void doLapCounting () ;
virtual void doZipperProcessing () ;
virtual void update (float delta) ;
} ;
#endif

View File

@ -143,9 +143,7 @@ void KartProperties::getAllData(const lisp::Lisp* lisp)
lisp->get("model-file", m_model_file);
lisp->get("icon-file", m_icon_file);
lisp->get("shadow-file", m_shadow_file);
lisp->get("red", m_color[0]);
lisp->get("green", m_color[1]);
lisp->get("blue", m_color[2]);
lisp->get("rgb", m_color);
lisp->get("wheel-base", m_wheel_base);
lisp->get("heightCOG", m_height_cog);
@ -206,7 +204,7 @@ void KartProperties::init_defaults()
m_icon_file = "tuxicon.png";
m_shadow_file = "tuxkartshadow.png";
m_color[0] = 1.0f; m_color[1] = 0.0f; m_color[2] = 0.0f;
m_color.setValue(1.0f, 0.0f, 0.0f);
m_kart_width = 1.0f;
m_kart_length = 1.5f;

View File

@ -22,6 +22,7 @@
#include <string>
#include <vector>
#include "vec3.hpp"
#include "lisp/lisp.hpp"
#include "no_copy.hpp"
@ -45,7 +46,7 @@ protected:
// the statusbar and the character select screen
std::string m_shadow_file; // Filename of the image file that contains the
// shadow for this kart
float m_color[3]; // Color the represents the kart in the status
Vec3 m_color; // Color the represents the kart in the status
// bar and on the track-view
// Physic properties
@ -121,7 +122,7 @@ public:
const std::string& getIdent () const {return m_ident; }
const std::string& getShadowFile () const {return m_shadow_file; }
const std::string& getIconFile () const {return m_icon_file; }
const sgVec3* getColor () const {return &m_color; }
const Vec3 &getColor () const {return m_color; }
float getMass () const {return m_mass; }
float getKartLength () const {return m_kart_length; }
float getKartWidth () const {return m_kart_width; }

View File

@ -23,7 +23,7 @@
#include <string>
#include <vector>
#include <plib/sg.h>
#include "btBulletDynamicsCommon.h"
#include "vec3.hpp"
namespace lisp
{
@ -140,7 +140,7 @@ namespace lisp
}
return true;
}
bool get(const char* name, btVector3& val) const
bool get(const char* name, Vec3& val) const
{
const Lisp* lisp = getLisp(name);
if(!lisp)

View File

@ -160,6 +160,9 @@ void Moveable::update (float dt)
} // if m_history_position
m_velocityLC = getVelocity()*getTrans().getBasis();
const btMatrix3x3& basis=m_body->getWorldTransform().getBasis();
m_hpr.setHPR(basis);
placeModel();
m_first_time = false ;
} // update

View File

@ -22,6 +22,7 @@
#define HEADER_MOVEABLE_H
#include <plib/ssg.h>
#include "vec3.hpp"
#include "material.hpp"
#include "btBulletDynamicsCommon.h"
#include "user_pointer.hpp"
@ -53,7 +54,7 @@ protected:
btRigidBody* m_body;
btDefaultMotionState* m_motion_state;
btTransform m_transform;
btVector3 m_hpr;
Vec3 m_hpr;
public:
Moveable (bool bHasHistory=false);
@ -64,8 +65,8 @@ public:
const btVector3 &getVelocityLC() const {return m_velocityLC; }
virtual void setVelocity(const btVector3& v) {m_body->setLinearVelocity(v); }
sgCoord* getCoord () {return &m_curr_pos; }
const btVector3& getPos () const {return m_transform.getOrigin(); }
const btVector3& getRotation() const {return m_hpr; }
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; }

View File

@ -94,7 +94,7 @@ void ProjectileManager::update(float dt)
while(p!=m_active_projectiles.end())
{
if(! (*p)->hasHit()) { p++; continue; }
newExplosion((*p)->getCoord());
newExplosion((const Vec3&)(*p)->getPos());
Flyable *f=*p;
Projectiles::iterator pNext=m_active_projectiles.erase(p); // returns the next element
delete f;
@ -141,7 +141,7 @@ Flyable *ProjectileManager::newProjectile(Kart *kart, CollectableType type)
// -----------------------------------------------------------------------------
/** See if there is an old, unused explosion object available. If so,
* reuse this object, otherwise create a new one. */
Explosion* ProjectileManager::newExplosion(sgCoord* coord)
Explosion* ProjectileManager::newExplosion(const Vec3& coord)
{
Explosion *e = new Explosion(coord);
m_active_explosions.push_back(e);

View File

@ -22,6 +22,7 @@
#include <vector>
#include <plib/ssg.h>
#include "vec3.hpp"
#include "flyable.hpp"
#include "collectable_manager.hpp"
@ -60,7 +61,7 @@ public:
void cleanup ();
void update (float dt);
Flyable* newProjectile (Kart *kart, CollectableType type);
Explosion* newExplosion (sgCoord *coord);
Explosion* newExplosion (const Vec3& coord);
void Deactivate (Flyable *p) {}
void removeTextures ();
};

View File

@ -23,7 +23,7 @@
#include "world.hpp"
#include "constants.hpp"
TerrainInfo::TerrainInfo(const btVector3 &pos, int frequency)
TerrainInfo::TerrainInfo(const Vec3 &pos, int frequency)
{
m_HoT_frequency = frequency;
m_HoT_counter = frequency;
@ -31,7 +31,7 @@ TerrainInfo::TerrainInfo(const btVector3 &pos, int frequency)
update(pos);
}
//-----------------------------------------------------------------------------
void TerrainInfo::update(const btVector3& pos)
void TerrainInfo::update(const Vec3& pos)
{
m_HoT_counter++;
if(m_HoT_counter>=m_HoT_frequency)

View File

@ -20,7 +20,7 @@
#ifndef HEADER_TERRAIN_INFO_H
#define HEADER_TERRAIN_INFO_H
#include "btBulletDynamicsCommon.h"
#include "vec3.hpp"
#include "material.hpp"
/** This class stores information about the triangle that's under an object, i.e.:
@ -31,19 +31,19 @@ class TerrainInfo
private:
int m_HoT_frequency; // how often hight of terrain is computed
int m_HoT_counter; // compute HAT only every N timesteps
btVector3 m_normal; // normal of the triangle under the object
Vec3 m_normal; // normal of the triangle under the object
const Material *m_material; // material of the triangle under the object
float m_HoT; // height of terrain
public:
TerrainInfo(int frequency=1) {m_HoT_frequency=frequency;
m_HoT_counter=frequency; }
TerrainInfo(const btVector3 &pos, int frequency=1);
TerrainInfo(const Vec3 &pos, int frequency=1);
virtual ~TerrainInfo() {};
virtual void update(const btVector3 &pos);
virtual void update(const Vec3 &pos);
float getHoT() const { return m_HoT; }
const Material* getMaterial() const { return m_material; }
const btVector3& getNormal() const { return m_normal; }
const Material *getMaterial() const { return m_material; }
const Vec3 &getNormal() const { return m_normal; }
float getTerrainPitch(float heading) const;
}; // TerrainInfo

View File

@ -431,9 +431,9 @@ void Track::getStartCoords(unsigned int pos, sgCoord* coords) const {
coords->hpr[1] = 0.0f;
coords->hpr[2] = 0.0f;
btVector3 tmp_pos(coords->xyz[0],coords->xyz[1],coords->xyz[2]);
Vec3 tmp_pos(coords->xyz);
btVector3 normal;
Vec3 normal;
const Material *material=NULL;
getTerrainInfo(tmp_pos, &(coords->xyz[2]), &normal, &material);
@ -1358,7 +1358,7 @@ void Track::herring_command (sgVec3 *xyz, char htype, int bNeedHeight )
} // herring_command
// ----------------------------------------------------------------------------
void Track::getTerrainInfo(const btVector3 &pos, float *hot, btVector3* normal,
void Track::getTerrainInfo(const Vec3 &pos, float *hot, Vec3 *normal,
const Material **material) const
{
btVector3 to_pos(pos);

View File

@ -34,6 +34,7 @@
#include <string>
#include <vector>
#include "btBulletDynamicsCommon.h"
#include "vec3.hpp"
#include "material.hpp"
#include "triangle_mesh.hpp"
#include "music_information.hpp"
@ -60,8 +61,8 @@ private:
float m_AI_angle_adjustment;
float m_AI_curve_speed_adjustment;
bool m_has_final_camera;
btVector3 m_camera_final_position;
btVector3 m_camera_final_hpr;
Vec3 m_camera_final_position;
Vec3 m_camera_final_hpr;
public:
enum RoadSide{ RS_DONT_KNOW = -1, RS_LEFT = 0, RS_RIGHT = 1 };
@ -196,10 +197,10 @@ public:
const std::vector<SGfloat>& getWidth () const {return m_path_width; }
const std::string& getHerringStyle () const {return m_herring_style; }
bool hasFinalCamera () const {return m_has_final_camera; }
const btVector3& getCameraPosition () const {return m_camera_final_position;}
const btVector3& getCameraHPR () const {return m_camera_final_hpr; }
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;
void getTerrainInfo(const btVector3 &pos, float *hot, btVector3* normal,
void getTerrainInfo(const Vec3 &pos, float *hot, Vec3* normal,
const Material **material) const;
void createPhysicsModel ();
void glVtx (sgVec2 v, float x_offset, float y_offset) const

79
src/vec3.cpp Executable file
View File

@ -0,0 +1,79 @@
// $Id: vec3.cpp 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 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// 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"
void Vec3::setHPR(const btMatrix3x3& m)
{
float f[4][4];
m.getOpenGLSubMatrix((float*)f);
// sgSetCoord(m_curr_pos, f);
//void sgSetCoord ( sgCoord *dst, const sgMat4 src )
float s = m.getColumn(0).length();
if ( s <= 0.00001 )
{
fprintf(stderr,"setHPR: bad matrix\n");
setValue(0,0,0);
return ;
}
s=1/s;
#define CLAMPTO1(x) x<-1 ? -1 : (x>1 ? 1 : x)
setY(asin(CLAMPTO1(m.getRow(2).getY())));
SGfloat cp = cos(getY());
/* If pointing nearly vertically up - then heading is ill-defined */
if ( cp > -0.00001 && cp < 0.00001 )
{
float cr = CLAMPTO1( m.getRow(1).getX()*s);
float sr = CLAMPTO1(-m.getRow(1).getZ()*s);
setX(0.0f);
setZ(atan2(sr, cr ));
}
else
{
cp = s / cp ; // includes the scaling factor
float sr = CLAMPTO1( -m.getRow(2).getX() * cp );
float cr = CLAMPTO1( m.getRow(2).getZ() * cp );
float sh = CLAMPTO1( -m.getRow(0).getY() * cp );
float ch = CLAMPTO1( m.getRow(1).getY() * cp );
if ( (sh == 0.0f && ch == 0.0f) || (sr == 0.0f && cr == 0.0f) )
{
cr = CLAMPTO1( m.getRow(1).getX()*s);
sr = CLAMPTO1(-m.getRow(1).getZ()*s) ;
setX(0.0f);
}
else
setX(atan2(sh, ch ));
setZ(atan2(sr, cr ));
}
} // setHPR
// ----------------------------------------------------------------------------

42
src/vec3.hpp Executable file
View File

@ -0,0 +1,42 @@
// $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 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef HEADER_VEC3_H
#define HEADER_VEC3_H
#include <plib/sg.h>
#include "LinearMath/btVector3.h"
#include "LinearMath/btMatrix3x3.h"
class Vec3 : public btVector3
{
private:
inline float clampToUnity(float f) {return f<-1?f:(f>1?1:f);}
public:
inline Vec3(sgVec3 a) : btVector3(a[0], a[1], a[2]) {}
inline Vec3(const btVector3& a) : btVector3(a) {}
inline Vec3() : btVector3() {}
void setHPR(const btMatrix3x3& m);
inline const float operator[](int n) const {return *(&m_x+n); }
float* toFloat() const {return (float*)this; }
Vec3& operator=(const btVector3& a) {*(btVector3*)this=a; return *this;}
Vec3& operator=(const btMatrix3x3& m) {setHPR(m); return *this;}
}; // Vec3
#endif

View File

@ -623,7 +623,7 @@ void World::removeKart(int kart_number)
camera->setMode(Camera::CM_LEADER_MODE);
m_eliminated_players++;
}
projectile_manager->newExplosion(kart->getCoord());
projectile_manager->newExplosion(kart->getPos());
// 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