2007-05-27 12:01:53 -04:00
|
|
|
// $Id$
|
|
|
|
//
|
|
|
|
// SuperTuxKart - a fun racing game with go-kart
|
|
|
|
// Copyright (C) 2004 Steve Baker <sjbaker1@airmail.net>
|
|
|
|
//
|
|
|
|
// 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_TRACK_H
|
|
|
|
#define HEADER_TRACK_H
|
|
|
|
|
|
|
|
#ifdef __APPLE__
|
|
|
|
# include <OpenGL/gl.h>
|
|
|
|
#else
|
2007-08-23 23:42:59 -04:00
|
|
|
# ifdef WIN32
|
|
|
|
# define WIN32_LEAN_AND_MEAN
|
|
|
|
# include <windows.h>
|
|
|
|
# endif
|
2007-05-27 12:01:53 -04:00
|
|
|
# include <GL/gl.h>
|
|
|
|
#endif
|
|
|
|
#include <plib/sg.h>
|
|
|
|
#include <plib/ssg.h>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2007-12-12 09:07:26 -05:00
|
|
|
#include "btBulletDynamicsCommon.h"
|
|
|
|
#include "material.hpp"
|
2008-01-01 09:30:39 -05:00
|
|
|
#include "triangle_mesh.hpp"
|
2008-03-14 05:49:17 -04:00
|
|
|
#include "music_information.hpp"
|
2007-05-27 12:01:53 -04:00
|
|
|
|
|
|
|
class Track
|
|
|
|
{
|
|
|
|
private:
|
2007-12-12 09:07:26 -05:00
|
|
|
float m_gravity;
|
|
|
|
std::string m_ident;
|
|
|
|
std::string m_screenshot;
|
|
|
|
std::string m_top_view;
|
2008-03-14 05:49:17 -04:00
|
|
|
std::vector<MusicInformation const *> m_music;
|
|
|
|
std::vector<MusicInformation const *> m_music_last_lap;
|
2007-09-25 23:43:02 -04:00
|
|
|
std::vector<float> m_start_x, m_start_y, m_start_z, m_start_heading;
|
2007-12-12 09:07:26 -05:00
|
|
|
std::string m_herring_style;
|
|
|
|
std::string m_description;
|
|
|
|
std::string m_filename;
|
|
|
|
ssgBranch* m_model;
|
2008-01-01 09:30:39 -05:00
|
|
|
TriangleMesh* m_track_mesh;
|
|
|
|
TriangleMesh* m_non_collision_mesh;
|
2008-02-17 23:16:57 -05:00
|
|
|
// The next two variables are for AI improvements: the AI sometimes does
|
|
|
|
// not estimate curve speed and/or angle correctly, resulting in too much
|
|
|
|
// braking. These factors are used to adjust this.
|
|
|
|
float m_AI_angle_adjustment;
|
|
|
|
float m_AI_curve_speed_adjustment;
|
2007-05-27 12:01:53 -04:00
|
|
|
public:
|
|
|
|
enum RoadSide{ RS_DONT_KNOW = -1, RS_LEFT = 0, RS_RIGHT = 1 };
|
|
|
|
|
|
|
|
//An enum is not used for the QUAD_TRI_* constants because of limitations
|
|
|
|
//of the conversion between enums and ints.
|
2008-01-13 18:51:09 -05:00
|
|
|
static const int QUAD_TRI_NONE;
|
|
|
|
static const int QUAD_TRI_FIRST;
|
|
|
|
static const int QUAD_TRI_SECOND;
|
2007-05-27 12:01:53 -04:00
|
|
|
|
2008-01-13 18:51:09 -05:00
|
|
|
static const int UNKNOWN_SECTOR;
|
2007-05-27 12:01:53 -04:00
|
|
|
|
|
|
|
struct SegmentTriangle
|
|
|
|
{
|
|
|
|
int segment;
|
|
|
|
int triangle;
|
|
|
|
|
|
|
|
SegmentTriangle
|
|
|
|
(
|
|
|
|
int _segment,
|
|
|
|
int _triangle
|
|
|
|
) : segment(_segment), triangle(_triangle) {};
|
|
|
|
};
|
|
|
|
|
|
|
|
std::string m_name;
|
|
|
|
sgVec4 m_sky_color;
|
|
|
|
bool m_use_fog;
|
|
|
|
sgVec4 m_fog_color;
|
|
|
|
float m_fog_density;
|
|
|
|
float m_fog_start;
|
|
|
|
float m_fog_end;
|
|
|
|
sgVec3 m_sun_position; /** Position of the sun */
|
|
|
|
sgVec4 m_ambient_col;
|
|
|
|
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<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;
|
|
|
|
|
|
|
|
sgVec2 m_driveline_min;
|
|
|
|
sgVec2 m_driveline_max;
|
|
|
|
|
|
|
|
|
|
|
|
float m_total_distance;
|
2007-12-17 08:16:09 -05:00
|
|
|
static const float NOHIT;
|
2007-05-27 12:01:53 -04:00
|
|
|
|
|
|
|
float m_track_2d_width, // Width and heigth of the 2d display of the track
|
|
|
|
m_track_2d_height;
|
|
|
|
float m_scale_x, // Scaling to fit track into the size determined by
|
|
|
|
m_scale_y; // track2dWidth/Heightheigth
|
|
|
|
bool m_do_stretch; // 2d track display might be stretched to fit better
|
|
|
|
|
2008-02-28 22:26:07 -05:00
|
|
|
Track (std::string filename,float w=100,
|
|
|
|
float h=100, bool stretch=1);
|
|
|
|
~Track ();
|
|
|
|
void cleanup ();
|
|
|
|
void addDebugToScene (int type ) const;
|
|
|
|
void draw2Dview (float x_offset,
|
|
|
|
float y_offset ) const;
|
|
|
|
void drawScaled2D (float x, float y, float w,
|
|
|
|
float h ) const;
|
|
|
|
|
|
|
|
void findRoadSector (const sgVec3 XYZ, int *sector) const;
|
2007-05-27 12:01:53 -04:00
|
|
|
int findOutOfRoadSector(const sgVec3 XYZ,
|
|
|
|
const RoadSide SIDE,
|
|
|
|
const int CURR_SECTOR
|
|
|
|
) const;
|
2008-02-28 22:26:07 -05:00
|
|
|
int spatialToTrack (sgVec3 dst,
|
|
|
|
const sgVec2 POS,
|
|
|
|
const int SECTOR ) const;
|
|
|
|
void trackToSpatial (sgVec3 xyz, const int SECTOR) const;
|
|
|
|
void loadTrackModel ();
|
|
|
|
bool isShortcut (const int OLDSEC, const int NEWSEC) const;
|
2008-03-14 05:49:17 -04:00
|
|
|
void addMusic (const MusicInformation* mi)
|
|
|
|
{m_music.push_back(mi); }
|
|
|
|
void addMusicLastLap (const MusicInformation* mi)
|
|
|
|
{m_music_last_lap.push_back(mi);}
|
2008-02-28 22:26:07 -05:00
|
|
|
ssgBranch* getModel () const {return m_model; }
|
|
|
|
float getGravity () const {return m_gravity; }
|
|
|
|
float getTrackLength () const {return m_total_distance; }
|
|
|
|
const std::string& getIdent () const {return m_ident; }
|
|
|
|
const char* getName () const {return m_name.c_str(); }
|
2008-03-14 05:49:17 -04:00
|
|
|
void playMusic () const;
|
2008-02-28 22:26:07 -05:00
|
|
|
const std::string& getFilename () const {return m_filename; }
|
|
|
|
const sgVec3& getSunPos () const {return m_sun_position; }
|
|
|
|
const sgVec4& getAmbientCol () const {return m_ambient_col; }
|
|
|
|
const sgVec4& getDiffuseCol () const {return m_diffuse_col; }
|
|
|
|
const sgVec4& getSpecularCol () const {return m_specular_col; }
|
|
|
|
const bool& useFog () const {return m_use_fog; }
|
|
|
|
const sgVec4& getFogColor () const {return m_fog_color; }
|
|
|
|
const float& getFogDensity () const {return m_fog_density; }
|
|
|
|
const float& getFogStart () const {return m_fog_start; }
|
|
|
|
const float& getFogEnd () const {return m_fog_end; }
|
|
|
|
const float& getAIAngleAdjustment () const {return m_AI_angle_adjustment;}
|
2008-02-17 23:16:57 -05:00
|
|
|
const float& getAICurveSpeedAdjustment() const {return m_AI_curve_speed_adjustment;}
|
2008-02-28 22:26:07 -05:00
|
|
|
const sgVec4& getSkyColor () const {return m_sky_color; }
|
|
|
|
const std::string& getDescription () const {return m_description; }
|
|
|
|
const std::string& getTopviewFile () const {return m_top_view; }
|
|
|
|
const std::string& getScreenshotFile () const {return m_screenshot; }
|
|
|
|
const std::vector<SGfloat>& getWidth () const {return m_path_width; }
|
|
|
|
const std::string& getHerringStyle () const {return m_herring_style; }
|
|
|
|
void getStartCoords (unsigned int pos, sgCoord* coords) const;
|
2008-04-17 00:37:49 -04:00
|
|
|
void getTerrainInfo(const btVector3 &pos, float *hot, btVector3* normal,
|
2007-12-17 08:16:09 -05:00
|
|
|
const Material **material) const;
|
2008-02-28 22:26:07 -05:00
|
|
|
void createPhysicsModel ();
|
|
|
|
void glVtx (sgVec2 v, float x_offset, float y_offset) const
|
2007-05-27 12:01:53 -04:00
|
|
|
{
|
|
|
|
glVertex2f(
|
|
|
|
x_offset+(v[0]-m_driveline_min[0])*m_scale_x,
|
|
|
|
y_offset+(v[1]-m_driveline_min[1])*m_scale_y);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2008-01-01 09:30:39 -05:00
|
|
|
void loadTrack (std::string filename);
|
|
|
|
void herring_command (sgVec3 *xyz, char htype, int bNeedHeight);
|
|
|
|
void loadDriveline ();
|
|
|
|
void readDrivelineFromFile (std::vector<sgVec3Wrapper>& line,
|
2007-05-27 12:01:53 -04:00
|
|
|
const std::string& file_ext );
|
2008-01-01 09:30:39 -05:00
|
|
|
void convertTrackToBullet (ssgEntity *track, sgMat4 m);
|
2007-05-27 12:01:53 -04:00
|
|
|
|
2008-01-01 09:30:39 -05:00
|
|
|
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;
|
2008-03-14 05:49:17 -04:00
|
|
|
void getMusicInformation(std::vector<std::string>& filenames,
|
|
|
|
std::vector<MusicInformation const*>& m_music );
|
2007-05-27 12:01:53 -04:00
|
|
|
}
|
|
|
|
; // class Track
|
|
|
|
|
|
|
|
#endif
|