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:
parent
f43c8c397c
commit
5b33cdc3c0
@ -81,15 +81,30 @@ public:
|
||||
}
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the corresponding plib data structure. */
|
||||
const sgCoord& toSgCoord() const { return m_coord; }
|
||||
const sgCoord& toSgCoord() const { return m_coord; }
|
||||
/** Returns the translation. */
|
||||
const Vec3& getXYZ() const { return m_xyz; }
|
||||
const Vec3& getXYZ() const { return m_xyz; }
|
||||
/** 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. */
|
||||
void setHPR(const Vec3& a) { m_hpr = a; setSgCoord(); }
|
||||
void setHPR(const Vec3& a) { m_hpr = a; setSgCoord(); }
|
||||
/** 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
|
||||
|
||||
#endif
|
||||
|
@ -49,7 +49,7 @@ 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)
|
||||
{
|
||||
@ -63,12 +63,14 @@ void SkidMark::add(const sgCoord& coord, float angle, float length)
|
||||
} // 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.xyz[0] += length * sgSin(coord.hpr[0] + m_angle_sign*angle);
|
||||
coord.xyz[1] += length* -sgCos(coord.hpr[0] + m_angle_sign*angle);
|
||||
|
||||
Coord coord(kart_coord);
|
||||
float rad_angle = DEGREE_TO_RAD(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;
|
||||
if(m_skid_marking)
|
||||
@ -83,16 +85,16 @@ void SkidMark::addBreak(const sgCoord& kart_coord, float angle, float length)
|
||||
|
||||
sgVec3 pos;
|
||||
sgSetVec3(pos,
|
||||
coord.xyz[0] + sgSin(coord.hpr[0]-90) * WIDTH,
|
||||
coord.xyz[1] - sgCos(coord.hpr[0]-90) * WIDTH,
|
||||
coord.xyz[2] + m_global_track_offset);
|
||||
coord.getX() + sin(coord.getHeading()-M_PI*0.5f) * WIDTH,
|
||||
coord.getY() - cos(coord.getHeading()-M_PI*0.5f) * WIDTH,
|
||||
coord.getZ() + m_global_track_offset);
|
||||
ssgVertexArray* SkidMarkVertices = new ssgVertexArray;
|
||||
SkidMarkVertices->add(pos);
|
||||
|
||||
sgSetVec3(pos,
|
||||
coord.xyz[0] + sgSin(coord.hpr[0]+90) * WIDTH,
|
||||
coord.xyz[1] - sgCos(coord.hpr[0]+90) * WIDTH,
|
||||
coord.xyz[2] + m_global_track_offset);
|
||||
coord.getX() + sin(coord.getHeading()+M_PI*0.5f) * WIDTH,
|
||||
coord.getY() - cos(coord.getHeading()+M_PI*0.5f) * WIDTH,
|
||||
coord.getZ() + m_global_track_offset);
|
||||
SkidMarkVertices->add(pos);
|
||||
|
||||
sgVec3 norm;
|
||||
@ -164,31 +166,32 @@ void SkidMark::SkidMarkPos::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.xyz[0] += length * sgSin(kart_coord.hpr[0] + angle);
|
||||
coord.xyz[1] += length * -sgCos(kart_coord.hpr[0] + angle);
|
||||
Coord coord(kart_coord);
|
||||
|
||||
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
|
||||
const float WIDTH = 0.1f;
|
||||
|
||||
static float a = 1.0f;
|
||||
static float a = 0.5f;
|
||||
sgVec3 pos;
|
||||
sgSetVec3(pos,
|
||||
coord.xyz[0] + sgSin(coord.hpr[0]+a*90) * WIDTH,
|
||||
coord.xyz[1] - sgCos(coord.hpr[0]+a*90) * WIDTH,
|
||||
coord.xyz[2] + m_track_offset);
|
||||
coord.getX() + sgSin(coord.getHeading()+a*M_PI) * WIDTH,
|
||||
coord.getY() - sgCos(coord.getHeading()+a*M_PI) * WIDTH,
|
||||
coord.getZ() + m_track_offset);
|
||||
vertices->add(pos);
|
||||
|
||||
sgSetVec3(pos,
|
||||
coord.xyz[0] + sgSin(coord.hpr[0]-a*90) * WIDTH,
|
||||
coord.xyz[1] - sgCos(coord.hpr[0]-a*90) * WIDTH,
|
||||
coord.xyz[2] + m_track_offset);
|
||||
coord.getX() + sin(coord.getHeading()-a*M_PI) * WIDTH,
|
||||
coord.getY() - cos(coord.getHeading()-a*M_PI) * WIDTH,
|
||||
coord.getZ() + m_track_offset);
|
||||
vertices->add(pos);
|
||||
a = (a > 0.0f ? -1.0f : 1.0f);
|
||||
a = (a > 0.0f ? -0.5f : 0.5f);
|
||||
|
||||
sgVec3 norm;
|
||||
sgSetVec3(norm, 0, 0, 1);
|
||||
@ -201,22 +204,22 @@ void SkidMark::SkidMarkPos::add(const sgCoord& kart_coord, float angle, float le
|
||||
} // add
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void SkidMark::SkidMarkPos::addEnd(const sgCoord& coord)
|
||||
void SkidMark::SkidMarkPos::addEnd(const Coord& coord)
|
||||
{
|
||||
// Width of the skidmark
|
||||
const float width = 0.1f;
|
||||
|
||||
sgVec3 pos;
|
||||
sgSetVec3(pos,
|
||||
coord.xyz[0] + sgSin(coord.hpr[0]-90) * width,
|
||||
coord.xyz[1] - sgCos(coord.hpr[0]-90) * width,
|
||||
coord.xyz[2] + m_track_offset);
|
||||
coord.getX() + sin(coord.getHeading()-M_PI*0.5f) * width,
|
||||
coord.getY() - cos(coord.getHeading()-M_PI*0.5f) * width,
|
||||
coord.getZ() + m_track_offset);
|
||||
vertices->add(pos);
|
||||
|
||||
sgSetVec3(pos,
|
||||
coord.xyz[0] + sgSin(coord.hpr[0]+90) * width,
|
||||
coord.xyz[1] - sgCos(coord.hpr[0]+90) * width,
|
||||
coord.xyz[2] + m_track_offset);
|
||||
coord.getX() + sin(coord.getHeading()+M_PI*0.5f) * width,
|
||||
coord.getY() - cos(coord.getHeading()+M_PI*0.5f) * width,
|
||||
coord.getZ() + m_track_offset);
|
||||
vertices->add(pos);
|
||||
|
||||
sgVec3 norm;
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include <plib/ssg.h>
|
||||
#include "coord.hpp"
|
||||
|
||||
class SkidMark
|
||||
{
|
||||
@ -31,10 +32,10 @@ private:
|
||||
public:
|
||||
SkidMark(float angle_sign);
|
||||
~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 length);
|
||||
void addBreak (const sgCoord& coord, //Begin or finish an skidmark
|
||||
void addBreak (const Coord& coord, //Begin or finish an skidmark
|
||||
float angle,
|
||||
float length);
|
||||
bool wasSkidMarking() const;
|
||||
@ -51,10 +52,10 @@ class SkidMarkPos : public ssgVtxTable
|
||||
float global_track_offset);
|
||||
~SkidMarkPos ();
|
||||
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 length);
|
||||
void addEnd (const sgCoord& coord);
|
||||
void addEnd (const Coord& coord);
|
||||
private:
|
||||
float m_track_offset; // Amount of which the skidmark is lifted
|
||||
// above the track to avoid z-buffer errors
|
||||
|
@ -893,34 +893,28 @@ void Kart::endRescue()
|
||||
//-----------------------------------------------------------------------------
|
||||
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;
|
||||
//FIXME const float ANGLE = 43.0f;
|
||||
//FIXME const float LENGTH = 0.57f;
|
||||
if(m_controls.jump)
|
||||
const float ANGLE = 43.0f;
|
||||
const float LENGTH = 0.57f;
|
||||
if(m_skidding>1 && isOnGround())
|
||||
{
|
||||
if(isOnGround())
|
||||
{
|
||||
//FIXME: no getCoord anymore m_skidmark_left ->add(*getCoord(), ANGLE, LENGTH);
|
||||
//FIXME m_skidmark_right->add(*getCoord(), ANGLE, LENGTH);
|
||||
}
|
||||
else
|
||||
{ // not on ground
|
||||
//FIXME m_skidmark_left->addBreak(*getCoord(), ANGLE, LENGTH);
|
||||
//FIRME m_skidmark_right->addBreak(*getCoord(), ANGLE, LENGTH);
|
||||
} // on ground
|
||||
Coord coord(getXYZ(), getHPR());
|
||||
coord.setZ(getVehicle()->getWheelInfo(2).m_raycastInfo.m_contactPointWS.getZ());
|
||||
m_skidmark_right->add(coord, ANGLE, LENGTH);
|
||||
coord.setZ(getVehicle()->getWheelInfo(2).m_raycastInfo.m_contactPointWS.getZ());
|
||||
m_skidmark_left ->add(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);
|
||||
{
|
||||
// Either both sides are skidding, or none at all
|
||||
if(m_skidmark_left->wasSkidMarking())
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
} // processSkidMarks
|
||||
|
||||
@ -974,6 +968,7 @@ void Kart::setSuspensionLength()
|
||||
m_vehicle->getWheelInfo(i).m_raycastInfo.m_suspensionLength;
|
||||
} // for i
|
||||
} // setSuspensionLength
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void Kart::updateGraphics(const Vec3& off_xyz, const Vec3& off_hpr)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user