From 76979888017021f415eba94cd397040aa0468aec Mon Sep 17 00:00:00 2001 From: auria Date: Sun, 27 Nov 2011 23:41:38 +0000 Subject: [PATCH] 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 --- src/animations/billboard_animation.cpp | 37 ++++++++++++++++++++++++++ src/animations/billboard_animation.hpp | 6 +++++ 2 files changed, 43 insertions(+) diff --git a/src/animations/billboard_animation.cpp b/src/animations/billboard_animation.cpp index cc1910d50..f2f3ceb27 100644 --- a/src/animations/billboard_animation.cpp +++ b/src/animations/billboard_animation.cpp @@ -24,6 +24,11 @@ #include "graphics/material_manager.hpp" #include "io/file_manager.hpp" +#include +#include +#include +#include + 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 diff --git a/src/animations/billboard_animation.hpp b/src/animations/billboard_animation.hpp index aedd88bc8..4243ee1dc 100644 --- a/src/animations/billboard_animation.hpp +++ b/src/animations/billboard_animation.hpp @@ -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() {};