Cleanup of skidmark code (no visual change yet).
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@1697 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
4ba210c28b
commit
83382cb5e5
108
src/kart.cpp
108
src/kart.cpp
@ -898,7 +898,9 @@ void Kart::processSkidMarks()
|
||||
{
|
||||
assert(m_skidmark_left);
|
||||
assert(m_skidmark_right);
|
||||
const float threshold=0.3f;
|
||||
const float threshold = 0.3f;
|
||||
const float ANGLE = 43.0f;
|
||||
const float LENGTH = 0.57f;
|
||||
bool skid_front = m_vehicle->getWheelInfo(0).m_skidInfo < threshold ||
|
||||
m_vehicle->getWheelInfo(1).m_skidInfo < threshold;
|
||||
bool skid_rear = m_vehicle->getWheelInfo(2).m_skidInfo < threshold ||
|
||||
@ -907,102 +909,23 @@ void Kart::processSkidMarks()
|
||||
{
|
||||
if(isOnGround())
|
||||
{
|
||||
const float LENGTH = 0.57f;
|
||||
if(m_skidmark_left)
|
||||
{
|
||||
const float ANGLE = -43.0f;
|
||||
|
||||
sgCoord wheelpos;
|
||||
sgCopyCoord(&wheelpos, getCoord());
|
||||
|
||||
wheelpos.xyz[0] += LENGTH * sgSin(wheelpos.hpr[0] + ANGLE);
|
||||
wheelpos.xyz[1] += LENGTH * -sgCos(wheelpos.hpr[0] + ANGLE);
|
||||
|
||||
if(m_skidmark_left->wasSkidMarking())
|
||||
m_skidmark_left->add(&wheelpos);
|
||||
else
|
||||
m_skidmark_left->addBreak(&wheelpos);
|
||||
} // if m_skidmark_left
|
||||
|
||||
if(m_skidmark_right)
|
||||
{
|
||||
const float ANGLE = 43.0f;
|
||||
|
||||
sgCoord wheelpos;
|
||||
sgCopyCoord(&wheelpos, getCoord());
|
||||
|
||||
wheelpos.xyz[0] += LENGTH * sgSin(wheelpos.hpr[0] + ANGLE);
|
||||
wheelpos.xyz[1] += LENGTH * -sgCos(wheelpos.hpr[0] + ANGLE);
|
||||
|
||||
if(m_skidmark_right->wasSkidMarking())
|
||||
m_skidmark_right->add(&wheelpos);
|
||||
else
|
||||
m_skidmark_right->addBreak(&wheelpos);
|
||||
} // if m_skidmark_right
|
||||
m_skidmark_left ->add(*getCoord(), ANGLE, LENGTH);
|
||||
m_skidmark_right->add(*getCoord(), ANGLE, LENGTH);
|
||||
}
|
||||
else
|
||||
{ // not on ground
|
||||
if(m_skidmark_left)
|
||||
{
|
||||
const float LENGTH = 0.57f;
|
||||
const float ANGLE = -43.0f;
|
||||
|
||||
sgCoord wheelpos;
|
||||
sgCopyCoord(&wheelpos, getCoord());
|
||||
|
||||
wheelpos.xyz[0] += LENGTH * sgSin(wheelpos.hpr[0] + ANGLE);
|
||||
wheelpos.xyz[1] += LENGTH * -sgCos(wheelpos.hpr[0] + ANGLE);
|
||||
|
||||
m_skidmark_left->addBreak(&wheelpos);
|
||||
} // if m_skidmark_left
|
||||
|
||||
if(m_skidmark_right)
|
||||
{
|
||||
const float LENGTH = 0.57f;
|
||||
const float ANGLE = 43.0f;
|
||||
|
||||
sgCoord wheelpos;
|
||||
sgCopyCoord(&wheelpos, getCoord());
|
||||
|
||||
wheelpos.xyz[0] += LENGTH * sgSin(wheelpos.hpr[0] + ANGLE);
|
||||
wheelpos.xyz[1] += LENGTH * -sgCos(wheelpos.hpr[0] + ANGLE);
|
||||
|
||||
m_skidmark_right->addBreak(&wheelpos);
|
||||
} // if m_skidmark_right
|
||||
m_skidmark_left->addBreak(*getCoord(), ANGLE, LENGTH);
|
||||
m_skidmark_right->addBreak(*getCoord(), ANGLE, LENGTH);
|
||||
} // on ground
|
||||
}
|
||||
else
|
||||
{ // !skid_rear && _skid_front
|
||||
if(m_skidmark_left)
|
||||
if(m_skidmark_left->wasSkidMarking())
|
||||
{
|
||||
const float ANGLE = -43.0f;
|
||||
const float LENGTH = 0.57f;
|
||||
{ // !skid_rear && !skid_front
|
||||
if(m_skidmark_left->wasSkidMarking())
|
||||
m_skidmark_left->addBreak(*getCoord(), ANGLE, LENGTH);
|
||||
|
||||
sgCoord wheelpos;
|
||||
sgCopyCoord(&wheelpos, getCoord());
|
||||
|
||||
wheelpos.xyz[0] += LENGTH * sgSin(wheelpos.hpr[0] + ANGLE);
|
||||
wheelpos.xyz[1] += LENGTH * -sgCos(wheelpos.hpr[0] + ANGLE);
|
||||
|
||||
m_skidmark_left->addBreak(&wheelpos);
|
||||
} // m_skidmark_left->wasSkidMarking
|
||||
|
||||
if(m_skidmark_right)
|
||||
if(m_skidmark_right->wasSkidMarking())
|
||||
{
|
||||
const float ANGLE = 43.0f;
|
||||
const float LENGTH = 0.57f;
|
||||
|
||||
sgCoord wheelpos;
|
||||
sgCopyCoord(&wheelpos, getCoord());
|
||||
|
||||
wheelpos.xyz[0] += LENGTH * sgSin(wheelpos.hpr[0] + ANGLE);
|
||||
wheelpos.xyz[1] += LENGTH * -sgCos(wheelpos.hpr[0] + ANGLE);
|
||||
|
||||
m_skidmark_right->addBreak(&wheelpos);
|
||||
} // m_skidmark_right->wasSkidMarking
|
||||
} // m_velocity < 20
|
||||
if(m_skidmark_right->wasSkidMarking())
|
||||
m_skidmark_right->addBreak(*getCoord(), ANGLE, LENGTH);
|
||||
}
|
||||
} // processSkidMarks
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -1090,8 +1013,9 @@ void Kart::loadData()
|
||||
// m_exhaust_pipe -> addKid (m_smoke_system) ;
|
||||
// comp_model-> addKid (m_exhaust_pipe) ;
|
||||
|
||||
m_skidmark_left = new SkidMark();
|
||||
m_skidmark_right = new SkidMark();
|
||||
//
|
||||
m_skidmark_left = new SkidMark(/* angle sign */ -1);
|
||||
m_skidmark_right = new SkidMark(/* angle sign */ 1);
|
||||
|
||||
m_shadow = createShadow(m_kart_properties->getShadowFile(), -1, 1, -1, 1);
|
||||
m_shadow->ref();
|
||||
|
@ -22,9 +22,10 @@
|
||||
|
||||
float SkidMark::m_global_track_offset = 0.005f;
|
||||
|
||||
SkidMark::SkidMark()
|
||||
SkidMark::SkidMark(float angle_sign)
|
||||
{
|
||||
m_skid_state = new ssgSimpleState ();
|
||||
m_skid_state = new ssgSimpleState();
|
||||
m_angle_sign = angle_sign;
|
||||
m_skid_state->ref();
|
||||
m_skid_state -> enable (GL_BLEND);
|
||||
//This is just for the skidmarks, so the ones drawn when the kart is in
|
||||
@ -48,17 +49,27 @@ SkidMark::~SkidMark()
|
||||
} // ~SkidMark
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void SkidMark::add(sgCoord* coord)
|
||||
void SkidMark::add(const sgCoord& coord, float angle, float length)
|
||||
{
|
||||
assert(m_skid_marking);
|
||||
|
||||
const int CURRENT = (int)m_skid_marks.size() - 1;
|
||||
m_skid_marks[CURRENT]->add(coord);
|
||||
if(m_skid_marking)
|
||||
{
|
||||
const int CURRENT = (int)m_skid_marks.size() - 1;
|
||||
m_skid_marks[CURRENT]->add(coord, m_angle_sign*angle, length);
|
||||
}
|
||||
else
|
||||
{
|
||||
addBreak(coord, angle, length);
|
||||
}
|
||||
} // add
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void SkidMark::addBreak(sgCoord* coord)
|
||||
void SkidMark::addBreak(const sgCoord& 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);
|
||||
|
||||
|
||||
const unsigned int CURRENT = (unsigned int)m_skid_marks.size() - 1;
|
||||
if(m_skid_marking)
|
||||
m_skid_marks[CURRENT]->addEnd(coord);
|
||||
@ -72,16 +83,16 @@ void SkidMark::addBreak(sgCoord* coord)
|
||||
|
||||
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.xyz[0] + sgSin(coord.hpr[0]-90) * WIDTH,
|
||||
coord.xyz[1] - sgCos(coord.hpr[0]-90) * WIDTH,
|
||||
coord.xyz[2] + 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.xyz[0] + sgSin(coord.hpr[0]+90) * WIDTH,
|
||||
coord.xyz[1] - sgCos(coord.hpr[0]+90) * WIDTH,
|
||||
coord.xyz[2] + m_global_track_offset);
|
||||
SkidMarkVertices->add(pos);
|
||||
|
||||
sgVec3 norm;
|
||||
@ -153,23 +164,29 @@ void SkidMark::SkidMarkPos::recalcBSphere()
|
||||
} // recalcBSphere
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void SkidMark::SkidMarkPos::add(sgCoord* coord)
|
||||
void SkidMark::SkidMarkPos::add(const sgCoord& 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);
|
||||
|
||||
|
||||
// Width of the skidmark
|
||||
const float WIDTH = 0.1f;
|
||||
|
||||
static float a = 1.0f;
|
||||
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.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);
|
||||
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.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);
|
||||
vertices->add(pos);
|
||||
a = (a > 0.0f ? -1.0f : 1.0f);
|
||||
|
||||
@ -184,22 +201,22 @@ void SkidMark::SkidMarkPos::add(sgCoord* coord)
|
||||
} // add
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void SkidMark::SkidMarkPos::addEnd(sgCoord* coord)
|
||||
void SkidMark::SkidMarkPos::addEnd(const sgCoord& 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.xyz[0] + sgSin(coord.hpr[0]-90) * width,
|
||||
coord.xyz[1] - sgCos(coord.hpr[0]-90) * width,
|
||||
coord.xyz[2] + 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.xyz[0] + sgSin(coord.hpr[0]+90) * width,
|
||||
coord.xyz[1] - sgCos(coord.hpr[0]+90) * width,
|
||||
coord.xyz[2] + m_track_offset);
|
||||
vertices->add(pos);
|
||||
|
||||
sgVec3 norm;
|
||||
|
@ -26,12 +26,17 @@
|
||||
|
||||
class SkidMark
|
||||
{
|
||||
|
||||
private:
|
||||
float m_angle_sign;
|
||||
public:
|
||||
SkidMark();
|
||||
SkidMark(float angle_sign);
|
||||
~SkidMark();
|
||||
void add (sgCoord* coord); // Add a position where the skidmark is
|
||||
void addBreak (sgCoord *coord); //Begin or finish an skidmark
|
||||
void add (const sgCoord& coord, // Add a position where the skidmark is
|
||||
float angle,
|
||||
float length);
|
||||
void addBreak (const sgCoord& coord, //Begin or finish an skidmark
|
||||
float angle,
|
||||
float length);
|
||||
bool wasSkidMarking() const;
|
||||
|
||||
private:
|
||||
@ -46,8 +51,10 @@ class SkidMarkPos : public ssgVtxTable
|
||||
float global_track_offset);
|
||||
~SkidMarkPos ();
|
||||
void recalcBSphere();
|
||||
void add (sgCoord* coord); // Add a position where the skidmark is
|
||||
void addEnd (sgCoord *coord);
|
||||
void add (const sgCoord& coord, // Add a position where the skidmark is
|
||||
float angle,
|
||||
float length);
|
||||
void addEnd (const sgCoord& coord);
|
||||
private:
|
||||
float m_track_offset; // Amount of which the skidmark is lifted
|
||||
// above the track to avoid z-buffer errors
|
||||
|
Loading…
x
Reference in New Issue
Block a user