Added 'starts rotating around head' effect for hit karts
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@4358 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
@@ -70,6 +70,8 @@ supertuxkart_SOURCES = \
|
||||
graphics/skid_marks.hpp \
|
||||
graphics/smoke.cpp \
|
||||
graphics/smoke.hpp \
|
||||
graphics/stars.cpp \
|
||||
graphics/stars.hpp \
|
||||
graphics/water_splash.hpp \
|
||||
graphics/water_splash.cpp \
|
||||
guiengine/CGUIFont.cpp \
|
||||
|
||||
@@ -364,6 +364,17 @@ scene::ISceneNode *IrrDriver::addMesh(scene::IMesh *mesh)
|
||||
return m_scene_manager->addMeshSceneNode(mesh);
|
||||
} // addMesh
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Adds a billboard node to scene.
|
||||
*/
|
||||
scene::ISceneNode *IrrDriver::addBillboard(const core::dimension2d< f32 > size, video::ITexture *texture, scene::ISceneNode* parent)
|
||||
{
|
||||
scene::IBillboardSceneNode* node = m_scene_manager->addBillboardSceneNode(parent, size);
|
||||
assert(node->getMaterialCount() > 0);
|
||||
node->setMaterialTexture(0, texture);
|
||||
return node;
|
||||
} // addMesh
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Creates a quad mesh buffer and adds it to the scene graph. (FIXME: wrong docs? I don't think it does)
|
||||
*/
|
||||
|
||||
@@ -89,6 +89,8 @@ public:
|
||||
float wave_speed, float wave_length);
|
||||
scene::ISceneNode *addOctTree(scene::IMesh *mesh);
|
||||
scene::ISceneNode *addMesh(scene::IMesh *mesh);
|
||||
scene::ISceneNode *addBillboard(const core::dimension2d< f32 > size, video::ITexture *texture, scene::ISceneNode* parent=NULL);
|
||||
|
||||
scene::IParticleSystemSceneNode
|
||||
*addParticleNode(bool default_emitter=true);
|
||||
scene::ISceneNode *addSkyDome(const std::string &texture, int hori_res,
|
||||
|
||||
124
src/graphics/stars.cpp
Normal file
124
src/graphics/stars.cpp
Normal file
@@ -0,0 +1,124 @@
|
||||
// SuperTuxKart - a fun racing game with go-kart
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 3
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#include "graphics/stars.hpp"
|
||||
|
||||
#include "graphics/irr_driver.hpp"
|
||||
#include "graphics/material.hpp"
|
||||
#include "graphics/material_manager.hpp"
|
||||
|
||||
#include "irrlicht.h"
|
||||
#include <cmath>
|
||||
|
||||
const int STAR_AMOUNT = 8;
|
||||
const float RADIUS = 0.7f;
|
||||
const float STAR_SIZE = 0.4f;
|
||||
|
||||
Stars::Stars(scene::IAnimatedMeshSceneNode* parentKart)
|
||||
{
|
||||
m_parent_kart_node = parentKart;
|
||||
m_enabled = false;
|
||||
|
||||
video::ITexture* texture = irr_driver->getTexture("starparticle.png");
|
||||
Material* star_material = material_manager->getMaterial("starparticle.png");
|
||||
|
||||
m_center = core::vector3df(0.0f, 0.6f, 0.0f);
|
||||
|
||||
for (int n=0; n<STAR_AMOUNT; n++)
|
||||
{
|
||||
scene::ISceneNode* billboard = irr_driver->addBillboard(core::dimension2d< f32 >(STAR_SIZE, STAR_SIZE),
|
||||
texture,
|
||||
parentKart);
|
||||
star_material->setMaterialProperties(&(billboard->getMaterial(0)));
|
||||
billboard->setMaterialTexture(0, star_material->getTexture());
|
||||
|
||||
billboard->setVisible(false);
|
||||
|
||||
m_nodes.push_back(billboard);
|
||||
}
|
||||
|
||||
// for debugging
|
||||
//m_enabled = true;
|
||||
//m_remaining_time = 99999.0f;
|
||||
//update(0);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
Stars::~Stars()
|
||||
{
|
||||
const int nodeAmount = m_nodes.size();
|
||||
for (int n=0; n<nodeAmount; n++)
|
||||
{
|
||||
m_parent_kart_node->removeChild(m_nodes[n]);
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void Stars::showFor(float time)
|
||||
{
|
||||
m_enabled = true;
|
||||
m_remaining_time = time;
|
||||
|
||||
const int nodeAmount = m_nodes.size();
|
||||
for (int n=0; n<nodeAmount; n++)
|
||||
{
|
||||
m_nodes[n]->setVisible(true);
|
||||
}
|
||||
|
||||
// set stars initial position
|
||||
update(0);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void Stars::update(float delta_t)
|
||||
{
|
||||
if (!m_enabled) return;
|
||||
|
||||
m_remaining_time -= delta_t;
|
||||
if (m_remaining_time < 0)
|
||||
{
|
||||
m_enabled = false;
|
||||
|
||||
const int nodeAmount = m_nodes.size();
|
||||
for (int n=0; n<nodeAmount; n++)
|
||||
{
|
||||
m_nodes[n]->setVisible(false);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
const int nodeAmount = m_nodes.size();
|
||||
for (int n=0; n<nodeAmount; n++)
|
||||
{
|
||||
// do one full rotation every 4 seconds (this "ranges" ranges from 0 to 1)
|
||||
float angle = (m_remaining_time / 4.0f) - (int)(m_remaining_time / 4);
|
||||
|
||||
// each star must be at a different angle
|
||||
angle += n * (1.0f / STAR_AMOUNT);
|
||||
|
||||
// keep angle in range [0, 1[
|
||||
angle -= (int)angle;
|
||||
|
||||
// set position
|
||||
m_nodes[n]->setPosition(m_center + core::vector3df( std::cos(angle*M_PI*2.0f)*RADIUS,
|
||||
0.0f,
|
||||
std::sin(angle*M_PI*2.0f)*RADIUS));
|
||||
}
|
||||
}
|
||||
|
||||
59
src/graphics/stars.hpp
Normal file
59
src/graphics/stars.hpp
Normal file
@@ -0,0 +1,59 @@
|
||||
// SuperTuxKart - a fun racing game with go-kart
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 3
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#ifndef HEADER_STARS_HPP
|
||||
#define HEADER_STARS_HPP
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "irrlicht.h"
|
||||
using namespace irr;
|
||||
|
||||
/**
|
||||
* This class is used to display rotating stars around a kart's head.
|
||||
*/
|
||||
class Stars
|
||||
{
|
||||
private:
|
||||
|
||||
/** Vector containing the stars */
|
||||
std::vector<scene::ISceneNode*> m_nodes;
|
||||
|
||||
/** The scene node of the kart to which this shadow belongs. */
|
||||
scene::ISceneNode *m_parent_kart_node;
|
||||
|
||||
/** Center around which stars rotate */
|
||||
core::vector3df m_center;
|
||||
|
||||
/** Whether stars are currently enabled */
|
||||
bool m_enabled;
|
||||
|
||||
float m_remaining_time;
|
||||
|
||||
public:
|
||||
Stars (scene::IAnimatedMeshSceneNode* parentKart);
|
||||
~Stars ();
|
||||
//void show ();
|
||||
void showFor (float time);
|
||||
//void hide ();
|
||||
void update (float delta_t);
|
||||
|
||||
};
|
||||
#endif
|
||||
|
||||
/* EOF */
|
||||
|
||||
|
||||
@@ -269,6 +269,7 @@
|
||||
95C77D631069589B0080838E /* ambient_light_sphere.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 95C77D621069589B0080838E /* ambient_light_sphere.cpp */; };
|
||||
95C77D66106958A50080838E /* check_line.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 95C77D65106958A50080838E /* check_line.cpp */; };
|
||||
95C77D6F106958E10080838E /* check_sphere.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 95C77D6D106958E10080838E /* check_sphere.cpp */; };
|
||||
95C9C97210E93456005A418D /* stars.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 95C9C97010E93456005A418D /* stars.cpp */; };
|
||||
95CB476C0FF30EF400413BAE /* bezier_curve.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 95CB476B0FF30EF400413BAE /* bezier_curve.cpp */; };
|
||||
95D1F5F70FC8C3E300FF6968 /* input.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 95D1F5F60FC8C3E300FF6968 /* input.cpp */; };
|
||||
95D2343F1078227A00625256 /* feature_unlocked.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 95D2343E1078227A00625256 /* feature_unlocked.cpp */; };
|
||||
@@ -868,6 +869,8 @@
|
||||
95C77D65106958A50080838E /* check_line.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = check_line.cpp; path = ../../tracks/check_line.cpp; sourceTree = SOURCE_ROOT; };
|
||||
95C77D6D106958E10080838E /* check_sphere.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = check_sphere.cpp; path = ../../tracks/check_sphere.cpp; sourceTree = SOURCE_ROOT; };
|
||||
95C77D6E106958E10080838E /* check_sphere.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = check_sphere.hpp; path = ../../tracks/check_sphere.hpp; sourceTree = SOURCE_ROOT; };
|
||||
95C9C97010E93456005A418D /* stars.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = stars.cpp; path = ../../graphics/stars.cpp; sourceTree = SOURCE_ROOT; };
|
||||
95C9C97110E93456005A418D /* stars.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = stars.hpp; path = ../../graphics/stars.hpp; sourceTree = SOURCE_ROOT; };
|
||||
95CA59F60F82FCB7003323DB /* physical_object.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = physical_object.hpp; path = ../../physics/physical_object.hpp; sourceTree = SOURCE_ROOT; };
|
||||
95CA59F70F82FCB7003323DB /* physical_object.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = physical_object.cpp; path = ../../physics/physical_object.cpp; sourceTree = SOURCE_ROOT; };
|
||||
95CB476A0FF30EF400413BAE /* bezier_curve.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = bezier_curve.hpp; path = ../../tracks/bezier_curve.hpp; sourceTree = SOURCE_ROOT; };
|
||||
@@ -1211,6 +1214,8 @@
|
||||
952A1540103F66D600B1895D /* skid_marks.hpp */,
|
||||
952A1541103F66D600B1895D /* smoke.cpp */,
|
||||
952A1542103F66D600B1895D /* smoke.hpp */,
|
||||
95C9C97010E93456005A418D /* stars.cpp */,
|
||||
95C9C97110E93456005A418D /* stars.hpp */,
|
||||
952A1543103F66D600B1895D /* water_splash.cpp */,
|
||||
952A1544103F66D600B1895D /* water_splash.hpp */,
|
||||
);
|
||||
@@ -2576,6 +2581,7 @@
|
||||
953C3CCA10CAF3EE0025F78A /* CGUIFont.cpp in Sources */,
|
||||
956541BB10DD5F0A00C83E99 /* arenas_screen.cpp in Sources */,
|
||||
956541E110DD628C00C83E99 /* add_device_dialog.cpp in Sources */,
|
||||
95C9C97210E93456005A418D /* stars.cpp in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include "graphics/shadow.hpp"
|
||||
#include "graphics/skid_marks.hpp"
|
||||
#include "graphics/smoke.hpp"
|
||||
#include "graphics/stars.hpp"
|
||||
#include "graphics/water_splash.hpp"
|
||||
#include "modes/world.hpp"
|
||||
#include "io/file_manager.hpp"
|
||||
@@ -75,6 +76,7 @@ Kart::Kart (const std::string& kart_name, int position,
|
||||
m_shadow_enabled = false;
|
||||
m_shadow = NULL;
|
||||
m_smoke_system = NULL;
|
||||
m_stars_effect = NULL;
|
||||
m_water_splash_system = NULL;
|
||||
m_nitro = NULL;
|
||||
m_skidmarks = NULL;
|
||||
@@ -278,6 +280,7 @@ Kart::~Kart()
|
||||
if(m_nitro) delete m_nitro;
|
||||
|
||||
delete m_shadow;
|
||||
delete m_stars_effect;
|
||||
|
||||
if(m_skidmarks) delete m_skidmarks ;
|
||||
|
||||
@@ -511,6 +514,8 @@ void Kart::handleExplosion(const Vec3& pos, bool direct_hit)
|
||||
getVehicle()->getRigidBody()->applyTorqueImpulse(btVector3(sign_c * float(rand()%32*5),
|
||||
sign_d * float(rand()%32*5),
|
||||
sign_e * float(rand()%32*5)));
|
||||
|
||||
m_stars_effect->showFor(6.0f);
|
||||
}
|
||||
else // only affected by a distant explosion
|
||||
{
|
||||
@@ -533,6 +538,7 @@ void Kart::handleExplosion(const Vec3& pos, bool direct_hit)
|
||||
float sign_a = (sign_bits & (0x1 << 8)) ? 1.0f : -1.0f;
|
||||
getVehicle()->getRigidBody()->applyTorqueImpulse(btVector3(0, 0, sign_a * float(rand()%32*5)));
|
||||
}
|
||||
|
||||
} // handleExplosion
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -1152,6 +1158,9 @@ void Kart::updatePhysics (float dt)
|
||||
,getHPR().getHeading()
|
||||
);
|
||||
#endif
|
||||
|
||||
// update star effect (call will do nothing if stars are not activated)
|
||||
m_stars_effect->update(dt);
|
||||
} // updatePhysics
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -1195,7 +1204,8 @@ void Kart::loadData()
|
||||
|
||||
m_shadow = new Shadow(file_manager->getKartFile(m_kart_properties->getShadowFile(),
|
||||
getIdent() ),
|
||||
m_animated_node);
|
||||
m_animated_node);
|
||||
m_stars_effect = new Stars(m_animated_node);
|
||||
} // loadData
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
@@ -42,6 +42,7 @@ class btUprightConstraint;
|
||||
class btKart;
|
||||
class btVehicleTuning;
|
||||
class Quad;
|
||||
class Stars;
|
||||
|
||||
class Kart : public TerrainInfo, public Moveable
|
||||
{
|
||||
@@ -84,14 +85,20 @@ 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;
|
||||
|
||||
/** Smoke from skidding. */
|
||||
Smoke *m_smoke_system;
|
||||
|
||||
/** Water splash when driving in water. */
|
||||
WaterSplash *m_water_splash_system;
|
||||
|
||||
/** For stars rotating around head effect */
|
||||
Stars *m_stars_effect;
|
||||
|
||||
/** Graphical effect when using a nitro. */
|
||||
Nitro *m_nitro;
|
||||
float m_wheel_rotation;
|
||||
|
||||
Reference in New Issue
Block a user