Simplified shadow interface.

This commit is contained in:
hiker
2015-07-19 13:44:05 +10:00
parent 91c40e27c2
commit 8be383015c
4 changed files with 26 additions and 45 deletions

View File

@@ -28,6 +28,7 @@ Shadow::Shadow(const KartProperties *kart_properties,
scene::ISceneNode *node,
float y_offset = 0.0)
{
m_shadow_enabled = false;
video::SMaterial m;
m.setTexture(0, kart_properties->getShadowTexture());
m.BackfaceCulling = false;
@@ -74,24 +75,17 @@ Shadow::~Shadow()
} // ~Shadow
// ----------------------------------------------------------------------------
/** Removes the shadow, used for the simplified shadow when the kart is in
* the air.
/** Updates the simulated shadow. It takes the offset (distance from visual
* chassis to ground) to position the shadow quad exactly on the ground.
* It also disables the shadow if requested (e.g. if the kart is in the air).
* \param enabled If the shadow should be shown or not.
* \param offset Distance from visual chassis to ground = position of the
* shadow to make sure it is exactly on the ground.
*/
void Shadow::disableShadow()
{
m_node->setVisible(false);
}
// ----------------------------------------------------------------------------
/** Enables the shadow again, after it was disabled with disableShadow().
*/
void Shadow::enableShadow()
{
m_node->setVisible(true);
}
// ----------------------------------------------------------------------------
void Shadow::update(float hot)
void Shadow::update(bool enabled, float offset)
{
m_node->setVisible(enabled);
core::vector3df pos = m_node->getPosition();
pos.Y = hot;
pos.Y = offset;
m_node->setPosition(pos);
} // update

View File

@@ -41,20 +41,24 @@ class Shadow : public NoCopy
private:
/** The scene node for the shadow. */
scene::ISceneNode *m_node;
/** The mesh of the shadow. */
scene::IMesh *m_mesh;
/** The scene node of the kart to which this shadow belongs. */
scene::ISceneNode *m_parent_kart_node;
/** If a kart is flying, the shadow is disabled (since it is
* stuck to the kart, i.e. the shadow would be flying, too). */
bool m_shadow_enabled;
public:
Shadow(const KartProperties *kart_properties,
scene::ISceneNode *node, float y_offset);
~Shadow();
void enableShadow();
void disableShadow();
void update(float hot);
void update(bool enabled, float hot);
}; // Shadow
#endif
/* EOF */

View File

@@ -115,7 +115,6 @@ Kart::Kart (const std::string& ident, unsigned int world_kart_id,
m_bubblegum_torque = 0.0f;
m_invulnerable_time = 0.0f;
m_squash_time = 0.0f;
m_shadow_enabled = false;
m_shadow = NULL;
m_wheel_box = NULL;
@@ -1364,21 +1363,6 @@ void Kart::update(float dt)
}
}
//const bool dyn_shadows = World::getWorld()->getTrack()->hasShadows() &&
// UserConfigParams::m_shadows &&
// irr_driver->isGLSL();
// Disable the fake shadow if we're flying
if(m_shadow && (!isOnGround() || emergency) && m_shadow_enabled)
{
m_shadow_enabled = false;
m_shadow->disableShadow();
}
if(m_shadow && !m_shadow_enabled && isOnGround() && !emergency)
{
m_shadow->enableShadow();
m_shadow_enabled = true;
}
} // update
//-----------------------------------------------------------------------------
@@ -2687,11 +2671,14 @@ void Kart::updateGraphics(float dt, const Vec3& offset_xyz,
// leaves the shadow on the ground even if the kart is jumping because
// of skidding (shadows are disabled when wheel are not on the track).
if (m_shadow)
m_shadow->update( m_terrain_info->getHoT() - getXYZ().getY()
- m_skidding->getGraphicalJumpOffset()
- m_graphical_y_offset
- m_kart_model->getLowestPoint());
{
const bool emergency = getKartAnimation() != NULL;
m_shadow->update(isOnGround() && !emergency,
m_terrain_info->getHoT() - getXYZ().getY()
- m_skidding->getGraphicalJumpOffset()
- m_graphical_y_offset
- m_kart_model->getLowestPoint());
}
#ifdef XX
// cheap wheelie effect
if (m_controls.m_nitro)

View File

@@ -173,10 +173,6 @@ private:
/** The shadow of a kart. */
Shadow *m_shadow;
/** If a kart is flying, the shadow is disabled (since it is
* stuck to the kart, i.e. the shadow would be flying, too). */
bool m_shadow_enabled;
ParticleEmitter *m_sky_particles_emitter;
/** All particle effects. */