Added skid marks.

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@2538 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk 2008-12-01 22:05:25 +00:00
parent f43c8c397c
commit 5b33cdc3c0
4 changed files with 79 additions and 65 deletions

View File

@ -86,10 +86,25 @@ public:
const Vec3& getXYZ() const { return m_xyz; } const Vec3& getXYZ() const { return m_xyz; }
/** Returns heading, pitch, rolll. */ /** Returns heading, pitch, rolll. */
const Vec3& getHPR() const { return m_hpr; } const Vec3& getHPR() const { return m_hpr; }
/** Returns X. */
float getX() const { return m_xyz.getX(); }
/** Returns Y. */
float getY() const { return m_xyz.getY(); }
/** Returns Z. */
float getZ() const { return m_xyz.getZ(); }
/** Returns the heading. */
float getHeading() const { return m_hpr.getHeading(); }
/** Sets hpr. \param a Heading, pitch and roll. */ /** Sets hpr. \param a Heading, pitch and roll. */
void setHPR(const Vec3& a) { m_hpr = a; setSgCoord(); } void setHPR(const Vec3& a) { m_hpr = a; setSgCoord(); }
/** Sets xyz. \param a Coordinates. */ /** Sets xyz. \param a Coordinates. */
void setXYZ(const Vec3& a) { m_xyz = a; setSgCoord(); } void setXYZ(const Vec3& a) { m_xyz = a; setSgCoord(); }
/** Sets X. \param x New X value. */
void setX(float x) { m_xyz.setX(x); }
/** Sets Y. \param y New Y value. */
void setY(float y) { m_xyz.setY(y); }
/** Sets Z. \param z New Z value. */
void setZ(float z) { m_xyz.setZ(z); }
}; // Coord }; // Coord
#endif #endif

View File

@ -49,7 +49,7 @@ SkidMark::~SkidMark()
} // ~SkidMark } // ~SkidMark
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void SkidMark::add(const sgCoord& coord, float angle, float length) void SkidMark::add(const Coord& coord, float angle, float length)
{ {
if(m_skid_marking) if(m_skid_marking)
{ {
@ -63,12 +63,14 @@ void SkidMark::add(const sgCoord& coord, float angle, float length)
} // add } // add
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void SkidMark::addBreak(const sgCoord& kart_coord, float angle, float length) void SkidMark::addBreak(const Coord& kart_coord, float angle, float length)
{ {
sgCoord coord(kart_coord); Coord coord(kart_coord);
coord.xyz[0] += length * sgSin(coord.hpr[0] + m_angle_sign*angle); float rad_angle = DEGREE_TO_RAD(m_angle_sign*angle);
coord.xyz[1] += length* -sgCos(coord.hpr[0] + m_angle_sign*angle); Vec3 add( length * sin(coord.getHeading() + rad_angle),
-length * cos(coord.getHeading() + rad_angle),
0);
coord.setXYZ(coord.getXYZ()+add);
const unsigned int CURRENT = (unsigned int)m_skid_marks.size() - 1; const unsigned int CURRENT = (unsigned int)m_skid_marks.size() - 1;
if(m_skid_marking) if(m_skid_marking)
@ -83,16 +85,16 @@ void SkidMark::addBreak(const sgCoord& kart_coord, float angle, float length)
sgVec3 pos; sgVec3 pos;
sgSetVec3(pos, sgSetVec3(pos,
coord.xyz[0] + sgSin(coord.hpr[0]-90) * WIDTH, coord.getX() + sin(coord.getHeading()-M_PI*0.5f) * WIDTH,
coord.xyz[1] - sgCos(coord.hpr[0]-90) * WIDTH, coord.getY() - cos(coord.getHeading()-M_PI*0.5f) * WIDTH,
coord.xyz[2] + m_global_track_offset); coord.getZ() + m_global_track_offset);
ssgVertexArray* SkidMarkVertices = new ssgVertexArray; ssgVertexArray* SkidMarkVertices = new ssgVertexArray;
SkidMarkVertices->add(pos); SkidMarkVertices->add(pos);
sgSetVec3(pos, sgSetVec3(pos,
coord.xyz[0] + sgSin(coord.hpr[0]+90) * WIDTH, coord.getX() + sin(coord.getHeading()+M_PI*0.5f) * WIDTH,
coord.xyz[1] - sgCos(coord.hpr[0]+90) * WIDTH, coord.getY() - cos(coord.getHeading()+M_PI*0.5f) * WIDTH,
coord.xyz[2] + m_global_track_offset); coord.getZ() + m_global_track_offset);
SkidMarkVertices->add(pos); SkidMarkVertices->add(pos);
sgVec3 norm; sgVec3 norm;
@ -164,31 +166,32 @@ void SkidMark::SkidMarkPos::recalcBSphere()
} // recalcBSphere } // recalcBSphere
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void SkidMark::SkidMarkPos::add(const sgCoord& kart_coord, float angle, float length) void SkidMark::SkidMarkPos::add(const Coord& kart_coord, float angle, float length)
{ {
sgCoord coord(kart_coord); Coord coord(kart_coord);
coord.xyz[0] += length * sgSin(kart_coord.hpr[0] + angle);
coord.xyz[1] += length * -sgCos(kart_coord.hpr[0] + angle);
Vec3 add( length * sin(kart_coord.getHPR().getHeading() + angle),
-length * cos(kart_coord.getHPR().getHeading() + angle),
0);
coord.setXYZ(coord.getXYZ()+add);
// Width of the skidmark // Width of the skidmark
const float WIDTH = 0.1f; const float WIDTH = 0.1f;
static float a = 1.0f; static float a = 0.5f;
sgVec3 pos; sgVec3 pos;
sgSetVec3(pos, sgSetVec3(pos,
coord.xyz[0] + sgSin(coord.hpr[0]+a*90) * WIDTH, coord.getX() + sgSin(coord.getHeading()+a*M_PI) * WIDTH,
coord.xyz[1] - sgCos(coord.hpr[0]+a*90) * WIDTH, coord.getY() - sgCos(coord.getHeading()+a*M_PI) * WIDTH,
coord.xyz[2] + m_track_offset); coord.getZ() + m_track_offset);
vertices->add(pos); vertices->add(pos);
sgSetVec3(pos, sgSetVec3(pos,
coord.xyz[0] + sgSin(coord.hpr[0]-a*90) * WIDTH, coord.getX() + sin(coord.getHeading()-a*M_PI) * WIDTH,
coord.xyz[1] - sgCos(coord.hpr[0]-a*90) * WIDTH, coord.getY() - cos(coord.getHeading()-a*M_PI) * WIDTH,
coord.xyz[2] + m_track_offset); coord.getZ() + m_track_offset);
vertices->add(pos); vertices->add(pos);
a = (a > 0.0f ? -1.0f : 1.0f); a = (a > 0.0f ? -0.5f : 0.5f);
sgVec3 norm; sgVec3 norm;
sgSetVec3(norm, 0, 0, 1); sgSetVec3(norm, 0, 0, 1);
@ -201,22 +204,22 @@ void SkidMark::SkidMarkPos::add(const sgCoord& kart_coord, float angle, float le
} // add } // add
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void SkidMark::SkidMarkPos::addEnd(const sgCoord& coord) void SkidMark::SkidMarkPos::addEnd(const Coord& coord)
{ {
// Width of the skidmark // Width of the skidmark
const float width = 0.1f; const float width = 0.1f;
sgVec3 pos; sgVec3 pos;
sgSetVec3(pos, sgSetVec3(pos,
coord.xyz[0] + sgSin(coord.hpr[0]-90) * width, coord.getX() + sin(coord.getHeading()-M_PI*0.5f) * width,
coord.xyz[1] - sgCos(coord.hpr[0]-90) * width, coord.getY() - cos(coord.getHeading()-M_PI*0.5f) * width,
coord.xyz[2] + m_track_offset); coord.getZ() + m_track_offset);
vertices->add(pos); vertices->add(pos);
sgSetVec3(pos, sgSetVec3(pos,
coord.xyz[0] + sgSin(coord.hpr[0]+90) * width, coord.getX() + sin(coord.getHeading()+M_PI*0.5f) * width,
coord.xyz[1] - sgCos(coord.hpr[0]+90) * width, coord.getY() - cos(coord.getHeading()+M_PI*0.5f) * width,
coord.xyz[2] + m_track_offset); coord.getZ() + m_track_offset);
vertices->add(pos); vertices->add(pos);
sgVec3 norm; sgVec3 norm;

View File

@ -23,6 +23,7 @@
#include <vector> #include <vector>
#include <plib/ssg.h> #include <plib/ssg.h>
#include "coord.hpp"
class SkidMark class SkidMark
{ {
@ -31,10 +32,10 @@ private:
public: public:
SkidMark(float angle_sign); SkidMark(float angle_sign);
~SkidMark(); ~SkidMark();
void add (const sgCoord& coord, // Add a position where the skidmark is void add (const Coord& coord, // Add a position where the skidmark is
float angle, float angle,
float length); float length);
void addBreak (const sgCoord& coord, //Begin or finish an skidmark void addBreak (const Coord& coord, //Begin or finish an skidmark
float angle, float angle,
float length); float length);
bool wasSkidMarking() const; bool wasSkidMarking() const;
@ -51,10 +52,10 @@ class SkidMarkPos : public ssgVtxTable
float global_track_offset); float global_track_offset);
~SkidMarkPos (); ~SkidMarkPos ();
void recalcBSphere(); void recalcBSphere();
void add (const sgCoord& coord, // Add a position where the skidmark is void add (const Coord& coord, // Add a position where the skidmark is
float angle, float angle,
float length); float length);
void addEnd (const sgCoord& coord); void addEnd (const Coord& coord);
private: private:
float m_track_offset; // Amount of which the skidmark is lifted float m_track_offset; // Amount of which the skidmark is lifted
// above the track to avoid z-buffer errors // above the track to avoid z-buffer errors

View File

@ -893,34 +893,28 @@ void Kart::endRescue()
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void Kart::processSkidMarks() void Kart::processSkidMarks()
{ {
// FIXME: disable skidmarks for now, they currently look ugly, and are
// sometimes hovering in the air
return;
assert(m_skidmark_left);
assert(m_skidmark_right);
const float threshold = 0.3f; const float threshold = 0.3f;
//FIXME const float ANGLE = 43.0f; const float ANGLE = 43.0f;
//FIXME const float LENGTH = 0.57f; const float LENGTH = 0.57f;
if(m_controls.jump) if(m_skidding>1 && isOnGround())
{ {
if(isOnGround()) Coord coord(getXYZ(), getHPR());
{ coord.setZ(getVehicle()->getWheelInfo(2).m_raycastInfo.m_contactPointWS.getZ());
//FIXME: no getCoord anymore m_skidmark_left ->add(*getCoord(), ANGLE, LENGTH); m_skidmark_right->add(coord, ANGLE, LENGTH);
//FIXME m_skidmark_right->add(*getCoord(), ANGLE, LENGTH); coord.setZ(getVehicle()->getWheelInfo(2).m_raycastInfo.m_contactPointWS.getZ());
m_skidmark_left ->add(coord, ANGLE, LENGTH);
} }
else else
{ // not on ground {
//FIXME m_skidmark_left->addBreak(*getCoord(), ANGLE, LENGTH); // Either both sides are skidding, or none at all
//FIRME m_skidmark_right->addBreak(*getCoord(), ANGLE, LENGTH); if(m_skidmark_left->wasSkidMarking())
} // on ground {
Coord coord(getXYZ(), getHPR());
coord.setZ(getVehicle()->getWheelInfo(2).m_raycastInfo.m_contactPointWS.getZ());
m_skidmark_right->addBreak(coord, ANGLE, LENGTH);
coord.setZ(getVehicle()->getWheelInfo(3).m_raycastInfo.m_contactPointWS.getZ());
m_skidmark_left ->addBreak(coord, ANGLE, LENGTH);
} }
else
{ // !skid_rear && !skid_front
//FIXME if(m_skidmark_left->wasSkidMarking())
//FIXME m_skidmark_left->addBreak(*getCoord(), ANGLE, LENGTH);
//FIXME if(m_skidmark_right->wasSkidMarking())
//FIXME m_skidmark_right->addBreak(*getCoord(), ANGLE, LENGTH);
} }
} // processSkidMarks } // processSkidMarks
@ -974,6 +968,7 @@ void Kart::setSuspensionLength()
m_vehicle->getWheelInfo(i).m_raycastInfo.m_suspensionLength; m_vehicle->getWheelInfo(i).m_raycastInfo.m_suspensionLength;
} // for i } // for i
} // setSuspensionLength } // setSuspensionLength
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void Kart::updateGraphics(const Vec3& off_xyz, const Vec3& off_hpr) void Kart::updateGraphics(const Vec3& off_xyz, const Vec3& off_hpr)
{ {