Fixed nitro being emitted by small blobs

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@8501 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria 2011-05-02 00:21:53 +00:00
parent 6b9f04c858
commit 0cf4133d8a
6 changed files with 82 additions and 12 deletions

View File

@ -343,9 +343,9 @@ void ParticleEmitter::setParticleType(const ParticleKind* type)
{
const float box_size_x = type->getBoxSizeX()/2.0f;
const float box_size_y = type->getBoxSizeY()/2.0f;
const float box_size_z = type->getBoxSizeZ()/2.0f;
m_emitter = m_node->createBoxEmitter(core::aabbox3df(-box_size_x, -box_size_y, -box_size_z,
box_size_x, box_size_y, box_size_z),
m_emitter = m_node->createBoxEmitter(core::aabbox3df(-box_size_x, -box_size_y, -0.6f,
box_size_x, box_size_y, -0.6f - type->getBoxSizeZ()),
core::vector3df(m_particle_type->getVelocityX(),
m_particle_type->getVelocityY(),
m_particle_type->getVelocityZ()), // velocity in m/ms
@ -353,10 +353,30 @@ void ParticleEmitter::setParticleType(const ParticleKind* type)
type->getMinColor(), type->getMaxColor(),
lifeTimeMin, lifeTimeMax,
m_particle_type->getAngleSpread() /* angle */
);
);
#if VISUALIZE_BOX_EMITTER
if (m_parent != NULL)
{
for (int x=0; x<2; x++)
{
for (int y=0; y<2; y++)
{
for (int z=0; z<2; z++)
{
m_visualisation.push_back(
irr_driver->getSceneManager()->addSphereSceneNode(0.05f, 16, m_parent, -1,
core::vector3df((x ? box_size_x : -box_size_x),
(y ? box_size_y : -box_size_y),
-0.6 - (z ? 0 : type->getBoxSizeZ())))
);
}
}
}
}
#endif
break;
}
default:
{
fprintf(stderr, "[ParticleEmitter] Unknown shape\n");
@ -400,3 +420,37 @@ void ParticleEmitter::addHeightMapAffector(Track* t)
m_node->addAffector(hmca);
hmca->drop();
}
void ParticleEmitter::resizeBox(float size)
{
scene::IParticleBoxEmitter* emitter = (scene::IParticleBoxEmitter*)m_emitter;
const float box_size_x = m_particle_type->getBoxSizeX()/2.0f;
const float box_size_y = m_particle_type->getBoxSizeY()/2.0f;
emitter->setBox( core::aabbox3df(-box_size_x, -box_size_y, -0.6f,
box_size_x, box_size_y, -0.6f - size) );
#if VISUALIZE_BOX_EMITTER
if (m_parent != NULL)
{
int n = 0;
for (int x=0; x<2; x++)
{
for (int y=0; y<2; y++)
{
for (int z=0; z<2; z++)
{
m_visualisation[n]->setPosition(
core::vector3df((x ? box_size_x : -box_size_x),
(y ? box_size_y : -box_size_y),
-0.6 - (z ? 0 : size))
);
n++;
}
}
}
}
#endif
}

View File

@ -26,6 +26,12 @@ using namespace irr;
#include "utils/no_copy.hpp"
#include "utils/vec3.hpp"
#define VISUALIZE_BOX_EMITTER 0
#if VISUALIZE_BOX_EMITTER
#include <vector>
#endif
class Material;
class ParticleKind;
class Track;
@ -49,6 +55,10 @@ private:
* particles per second. */
scene::IParticleEmitter *m_emitter;
#if VISUALIZE_BOX_EMITTER
std::vector<scene::ISceneNode*> m_visualisation;
#endif
const ParticleKind *m_particle_type;
unsigned int m_magic_number;
@ -68,6 +78,8 @@ public:
void setParticleType(const ParticleKind* p);
void resizeBox(float size);
scene::IParticleSystemSceneNode* getNode() { return m_node; }
void addHeightMapAffector(Track* t);

View File

@ -1805,7 +1805,7 @@ void Kart::applyEngineForce(float force)
* \param offset_xyz Offset to be added to the position.
* \param rotation Additional rotation.
*/
void Kart::updateGraphics(const Vec3& offset_xyz,
void Kart::updateGraphics(float dt, const Vec3& offset_xyz,
const btQuaternion& rotation)
{
float wheel_up_axis[4];
@ -1845,6 +1845,10 @@ void Kart::updateGraphics(const Vec3& offset_xyz,
m_nitro->setCreationRate(m_controls.m_nitro && isOnGround() &&
m_collected_energy>0
? (min_rate + rate*(max_rate - min_rate)) : 0);
// the emitter box should spread from last frame's position to the current position
// if we want nitro to be emitted in a smooth, continuous flame and not in blobs
m_nitro->resizeBox(std::max(0.25f, getSpeed()*dt));
}
}
@ -1852,7 +1856,7 @@ void Kart::updateGraphics(const Vec3& offset_xyz,
float speed_ratio = getSpeed()/MaxSpeed::getCurrentMaxSpeed();
float offset_heading = getSteerPercent()*m_kart_properties->getSkidVisual()
* speed_ratio * m_skidding*m_skidding;
Moveable::updateGraphics(center_shift,
Moveable::updateGraphics(dt, center_shift,
btQuaternion(offset_heading, 0, 0));
} // updateGraphics

View File

@ -201,7 +201,7 @@ public:
void setWorldKartId(unsigned int n) { m_world_kart_id=n; }
void loadData(RaceManager::KartType type, bool is_first_kart, Track* track,
bool animatedModel);
virtual void updateGraphics(const Vec3& off_xyz,
virtual void updateGraphics(float dt, const Vec3& off_xyz,
const btQuaternion& off_rotation);
void createPhysics ();
bool isInRest () const;
@ -365,7 +365,7 @@ public:
btUprightConstraint *getUprightConstraint() const
{return m_uprightConstraint;}
// ------------------------------------------------------------------------
/** Returns the speed of the kart. */
/** Returns the speed of the kart in meters/second. */
float getSpeed () const {return m_speed; }
// ------------------------------------------------------------------------
/** This is used on the client side only to set the speed of the kart

View File

@ -62,7 +62,7 @@ void Moveable::setNode(scene::ISceneNode *n)
* \param offset_xyz Offset to be added to the position.
* \param rotation Additional rotation.
*/
void Moveable::updateGraphics(const Vec3& offset_xyz,
void Moveable::updateGraphics(float dt, const Vec3& offset_xyz,
const btQuaternion& rotation)
{
Vec3 xyz=getXYZ()+offset_xyz;
@ -129,7 +129,7 @@ void Moveable::update(float dt)
m_pitch = atan2(up.getZ(), fabsf(up.getY()));
m_roll = atan2(up.getX(), up.getY());
updateGraphics(Vec3(0,0,0), btQuaternion(0, 0, 0, 1));
updateGraphics(dt, Vec3(0,0,0), btQuaternion(0, 0, 0, 1));
} // update
//-----------------------------------------------------------------------------

View File

@ -97,7 +97,7 @@ public:
m_motion_state->setWorldTransform(m_transform);
}
// ------------------------------------------------------------------------
virtual void updateGraphics(const Vec3& off_xyz,
virtual void updateGraphics(float dt, const Vec3& off_xyz,
const btQuaternion& off_rotation);
virtual void reset();
virtual void update(float dt) ;