Add feature requested by samuncle

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@10268 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria 2011-11-27 23:41:38 +00:00
parent 407c5319b5
commit 7697988801
2 changed files with 43 additions and 0 deletions

View File

@ -24,6 +24,11 @@
#include "graphics/material_manager.hpp"
#include "io/file_manager.hpp"
#include <ISceneManager.h>
#include <ICameraSceneNode.h>
#include <SColor.h>
#include <IBillboardSceneNode.h>
class XMLNode;
/** A 2d billboard animation. */
@ -36,6 +41,16 @@ BillboardAnimation::BillboardAnimation(const XMLNode &xml_node)
xml_node.get("texture", &texture_name);
xml_node.get("width", &width );
xml_node.get("height", &height );
m_fade_out_when_close = false;
xml_node.get("fadeout", &m_fade_out_when_close);
if (m_fade_out_when_close)
{
xml_node.get("start", &m_fade_out_start);
xml_node.get("end", &m_fade_out_end );
}
video::ITexture *texture =
irr_driver->getTexture(file_manager->getTextureFile(texture_name));
m_node = irr_driver->addBillboard(core::dimension2df(width, height),
@ -63,4 +78,26 @@ void BillboardAnimation::update(float dt)
m_node->setScale(scale);
// Setting rotation doesn't make sense
}
if (m_fade_out_when_close)
{
scene::ICameraSceneNode* curr_cam = irr_driver->getSceneManager()->getActiveCamera();
const float dist = m_node->getPosition().getDistanceFrom( curr_cam->getPosition() );
scene::IBillboardSceneNode* node = (scene::IBillboardSceneNode*)m_node;
if (dist < m_fade_out_start)
{
node->setColor(video::SColor(0, 255, 255, 255));
}
else if (dist > m_fade_out_end)
{
node->setColor(video::SColor(255, 255, 255, 255));
}
else
{
int a = (int)(255*(dist - m_fade_out_start) / (m_fade_out_end - m_fade_out_start));
node->setColor(video::SColor(a, 255, 255, 255));
}
}
} // update

View File

@ -32,6 +32,12 @@ class XMLNode;
*/
class BillboardAnimation : public AnimationBase
{
/** To create halo-like effects where the halo disapears when you get
close to it. Requested by samuncle */
bool m_fade_out_when_close;
float m_fade_out_start;
float m_fade_out_end;
public:
BillboardAnimation(const XMLNode &node);
virtual ~BillboardAnimation() {};