1) Skid marks fade out (fade out time set in stk_config: skid-fadeout-time,
currently one minute. 2) Skid marks now support proper culling, which should help with slowdown some people have seen. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@2840 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
1419948f02
commit
0d593da26e
@ -14,6 +14,7 @@
|
||||
(game-style "nitro") ;; "wheelie" or "nitro"
|
||||
(max-history 10000) ;; maximum number of history frames.
|
||||
(max-skidmarks 100) ;; max. number of skidmarks per kart.
|
||||
(skid-fadeout-time 60) ;; Time till skidm marks fade out
|
||||
(delay-finish-time 10) ;; delay till race results are displayed.
|
||||
(music-credit-time 10) ;; time for which the music credits are displayed.
|
||||
|
||||
|
@ -23,6 +23,8 @@
|
||||
#include "karts/kart.hpp"
|
||||
#include "utils/coord.hpp"
|
||||
|
||||
float SkidMarks::m_avoid_z_fighting = 0.0f;
|
||||
const float SkidMarks::m_start_alpha = 0.5f;
|
||||
|
||||
/** Initialises empty skid marks. */
|
||||
SkidMarks::SkidMarks(const Kart& kart, float width) : m_kart(kart)
|
||||
@ -68,6 +70,13 @@ void SkidMarks::reset()
|
||||
*/
|
||||
void SkidMarks::update(float dt)
|
||||
{
|
||||
float f = dt/stk_config->m_skid_fadeout_time;
|
||||
for(int i=0; i<m_current; i++)
|
||||
{
|
||||
m_left[i]->fade(f);
|
||||
m_right[i]->fade(f);
|
||||
}
|
||||
|
||||
if(m_skid_marking)
|
||||
{
|
||||
// Get raycast information
|
||||
@ -135,14 +144,21 @@ void SkidMarks::update(float dt)
|
||||
delta.normalize();
|
||||
delta *= m_width;
|
||||
|
||||
m_avoid_z_fighting += 0.001f;
|
||||
if(m_avoid_z_fighting>0.01f) m_avoid_z_fighting = 0.0f;
|
||||
|
||||
SkidMarkQuads *smq_left = new SkidMarkQuads(raycast_left.m_contactPointWS,
|
||||
raycast_left.m_contactPointWS + delta,
|
||||
m_skid_state);
|
||||
m_skid_state, m_avoid_z_fighting);
|
||||
scene->add(smq_left);
|
||||
|
||||
m_avoid_z_fighting += 0.001f;
|
||||
if(m_avoid_z_fighting>0.01f) m_avoid_z_fighting = 0.0f;
|
||||
SkidMarkQuads *smq_right = new SkidMarkQuads(raycast_right.m_contactPointWS
|
||||
- delta,
|
||||
raycast_right.m_contactPointWS,
|
||||
m_skid_state);
|
||||
m_skid_state,
|
||||
m_avoid_z_fighting);
|
||||
scene->add(smq_right);
|
||||
m_current++;
|
||||
if(m_current>=stk_config->m_max_skidmarks)
|
||||
@ -167,23 +183,57 @@ void SkidMarks::update(float dt)
|
||||
|
||||
//=============================================================================
|
||||
SkidMarks::SkidMarkQuads::SkidMarkQuads(const Vec3 &left, const Vec3 &right,
|
||||
ssgSimpleState *state)
|
||||
ssgSimpleState *state, float z_offset)
|
||||
: ssgVtxTable(GL_QUAD_STRIP,
|
||||
new ssgVertexArray,
|
||||
new ssgNormalArray,
|
||||
new ssgTexCoordArray,
|
||||
new ssgColourArray )
|
||||
{
|
||||
m_z_offset = z_offset;
|
||||
m_fade_out = 0.0f;
|
||||
// If only one colours and/or normal is specified, it is used for
|
||||
// all fertices in the table.
|
||||
sgVec4 colour;
|
||||
sgSetVec4(colour, 0.00f, 0.00f, 0.00f, SkidMarks::m_start_alpha);
|
||||
colours->add(colour);
|
||||
sgVec3 normal;
|
||||
sgSetVec3(normal, 0, 0, 1);
|
||||
normals->add(normal);
|
||||
|
||||
setState(state);
|
||||
m_aabb_min = Vec3(10000);
|
||||
m_aabb_max = Vec3(-10000);
|
||||
add(left, right);
|
||||
} // SkidMarkQuads
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Fades the current skid marks.
|
||||
* \param f fade factor.
|
||||
*/
|
||||
void SkidMarks::SkidMarkQuads::fade(float f)
|
||||
{
|
||||
m_fade_out += f;
|
||||
// Only actually change the alpha value every 0.1. Otherwise we can't use
|
||||
// display lists, which makes skid marks too slow
|
||||
if(m_fade_out>0.1f)
|
||||
{
|
||||
float *c=colours->get(0);
|
||||
c[3] -= m_fade_out;
|
||||
if(c[3]<0.0f) c[3]=0.0f;
|
||||
makeDList();
|
||||
m_fade_out = 0.0f;
|
||||
}
|
||||
} // fade
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void SkidMarks::SkidMarkQuads::recalcBSphere()
|
||||
{
|
||||
bsphere.setRadius(1000.0f);
|
||||
bsphere.setCenter(0, 0, 0);
|
||||
Vec3 diff = m_aabb_max - m_aabb_min;
|
||||
bsphere.setRadius(diff.length()*0.5f);
|
||||
Vec3 center = (m_aabb_min + m_aabb_max)*0.5f;
|
||||
bsphere.setCenter(center.toFloat());
|
||||
} // recalcBSphere
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -193,19 +243,15 @@ void SkidMarks::SkidMarkQuads::add(const Vec3 &left, const Vec3 &right)
|
||||
// too much with the track.
|
||||
sgVec3 l;
|
||||
sgCopyVec3(l, left.toFloat());
|
||||
l[2]+=0.01f;
|
||||
l[2]+=0.01f+m_z_offset;
|
||||
sgVec3 r;
|
||||
sgCopyVec3(r, right.toFloat());
|
||||
r[2]+=0.01f;
|
||||
vertices->add(l);
|
||||
vertices->add(r);
|
||||
sgVec3 normal;
|
||||
sgSetVec3(normal, 0, 0, 1);
|
||||
normals->add(normal);normals->add(normal);
|
||||
|
||||
sgVec4 colour;
|
||||
sgSetVec4(colour, 0.00f, 0.00f, 0.00f, 0.5f);
|
||||
colours->add(colour); colours->add(colour);
|
||||
// Adjust the axis-aligned boundary boxes.
|
||||
m_aabb_min.min(left);m_aabb_min.min(right);
|
||||
m_aabb_max.max(left);m_aabb_max.max(right);
|
||||
|
||||
dirtyBSphere();
|
||||
} // add
|
||||
|
@ -42,21 +42,35 @@ private:
|
||||
/** Index of current (last added) skid mark quad. */
|
||||
int m_current;
|
||||
|
||||
/** Initial alpha value. */
|
||||
static const float m_start_alpha;
|
||||
|
||||
class SkidMarkQuads : public ssgVtxTable
|
||||
{
|
||||
/** Used to move skid marks at the same location slightly on
|
||||
* top of each other to avoid a 'wobbling' effect when sometines
|
||||
* the first and sometimes the 2nd one is drawn on top
|
||||
*/
|
||||
float m_z_offset;
|
||||
/** Fade out = alpha value. */
|
||||
float m_fade_out;
|
||||
/** For culling, we need the overall radius of the skid marks. We
|
||||
* approximate this by maintaining an axis-aligned boundary box. */
|
||||
Vec3 m_aabb_min, m_aabb_max;
|
||||
public:
|
||||
SkidMarkQuads (const Vec3 &left, const Vec3 &right,
|
||||
ssgSimpleState *state);
|
||||
ssgSimpleState *state, float z_offset);
|
||||
void recalcBSphere();
|
||||
void add (const Vec3 &left,
|
||||
const Vec3 &right);
|
||||
void fade (float f);
|
||||
}; // SkidMarkQuads
|
||||
|
||||
/** Two skidmark objects for the left and right wheel. */
|
||||
std::vector <SkidMarkQuads *> m_left, m_right;
|
||||
/** The state for colour etc. */
|
||||
ssgSimpleState *m_skid_state;
|
||||
|
||||
static float m_avoid_z_fighting;
|
||||
public:
|
||||
SkidMarks(const Kart& kart, float width=0.2f);
|
||||
~SkidMarks();
|
||||
|
@ -107,6 +107,7 @@ void STKConfig::load(const std::string &filename)
|
||||
CHECK_NEG(m_explosion_impulse_objects, "explosion-impulse-objects" );
|
||||
CHECK_NEG(m_max_history, "max-history" );
|
||||
CHECK_NEG(m_max_skidmarks, "max-skidmarks" );
|
||||
CHECK_NEG(m_skid_fadeout_time, "skid-fadeout-time" );
|
||||
CHECK_NEG(m_delay_finish_time, "delay-finish-time" );
|
||||
CHECK_NEG(m_music_credit_time, "music-credit-time" );
|
||||
m_kart_properties.checkAllSet(filename);
|
||||
@ -127,7 +128,7 @@ void STKConfig::init_defaults()
|
||||
m_zipper_force = m_zipper_speed_gain =
|
||||
m_explosion_impulse = m_explosion_impulse_objects =
|
||||
m_shortcut_length = m_music_credit_time =
|
||||
m_delay_finish_time =
|
||||
m_delay_finish_time = m_skid_fadeout_time =
|
||||
UNDEFINED;
|
||||
m_max_karts = -100;
|
||||
m_grid_order = -100;
|
||||
@ -169,6 +170,7 @@ void STKConfig::getAllData(const lisp::Lisp* lisp)
|
||||
lisp->getVector("scores", m_scores );
|
||||
lisp->get("max-history", m_max_history );
|
||||
lisp->get("max-skidmarks", m_max_skidmarks );
|
||||
lisp->get("skid-fadeout-time", m_skid_fadeout_time );
|
||||
lisp->get("delay-finish-time", m_delay_finish_time );
|
||||
lisp->get("music-credit-time", m_music_credit_time );
|
||||
lisp->get("menu-background", m_menu_background );
|
||||
|
@ -68,7 +68,7 @@ public:
|
||||
int m_max_history; /**<Maximum number of frames to save in
|
||||
a history files. */
|
||||
int m_max_skidmarks; /**<Maximum number of skid marks/kart. */
|
||||
|
||||
float m_skid_fadeout_time; /**<Time till skidmarks fade away. */
|
||||
bool m_enable_networking;
|
||||
|
||||
std::vector<float>
|
||||
|
Loading…
Reference in New Issue
Block a user