Added multiple inheritance to the billboard texte scene node in order to expose both billboard and textnode interface.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@1244 dfc29bdd-3216-0410-991c-e03cc46cb475
master
hybrid 2008-02-12 16:01:26 +00:00
parent 6ae3b9e478
commit 25235a32fe
9 changed files with 79 additions and 26 deletions

View File

@ -48,7 +48,7 @@ struct SAttributeReadWriteOptions
//! An object which is able to serialize and deserialize its attributes into an attributes object //! An object which is able to serialize and deserialize its attributes into an attributes object
class IAttributeExchangingObject : public virtual IReferenceCounted class IAttributeExchangingObject : virtual public IReferenceCounted
{ {
public: public:

View File

@ -17,7 +17,7 @@ namespace scene
which always looks to the camera. It is usually used for explosions, fire, which always looks to the camera. It is usually used for explosions, fire,
lensflares, particles and things like that. lensflares, particles and things like that.
*/ */
class IBillboardSceneNode : public ISceneNode class IBillboardSceneNode : virtual public ISceneNode
{ {
public: public:

View File

@ -30,7 +30,7 @@ namespace scene
visible, its children won't be visible too. In this way, it is for example easily possible visible, its children won't be visible too. In this way, it is for example easily possible
to attach a light to a moving car, or to place a walking character on a moving platform to attach a light to a moving car, or to place a walking character on a moving platform
on a moving ship. */ on a moving ship. */
class ISceneNode : public io::IAttributeExchangingObject class ISceneNode : virtual public io::IAttributeExchangingObject
{ {
public: public:
@ -375,7 +375,7 @@ namespace scene
//! Gets the scale of the scene node. //! Gets the scale of the scene node.
/** \return Returns the scale of the scene node. */ /** \return Returns the scale of the scene node. */
virtual core::vector3df getScale() const virtual const core::vector3df& getScale() const
{ {
return RelativeScale; return RelativeScale;
} }
@ -410,7 +410,7 @@ namespace scene
//! Gets the position of the node. //! Gets the position of the node.
/** Note that the position is relative to the parent. /** Note that the position is relative to the parent.
\return Returns the current position of the node relative to the parent. */ \return Returns the current position of the node relative to the parent. */
virtual const core::vector3df getPosition() const virtual const core::vector3df& getPosition() const
{ {
return RelativeTranslation; return RelativeTranslation;
} }

View File

@ -13,7 +13,7 @@ namespace scene
{ {
//! A scene node for displaying 2d text at a position in three dimensional space //! A scene node for displaying 2d text at a position in three dimensional space
class ITextSceneNode : public ISceneNode class ITextSceneNode : virtual public ISceneNode
{ {
public: public:

View File

@ -359,9 +359,9 @@ namespace video
{ {
public: public:
//! Constructs a color. All values are initialised with 0.0f, resulting //! Constructs a color. All colors are initialised with 0.0f, resulting
//! in a black color. //! in a black color. alpha is 1.0f for no transparency.
SColorf() : r(0.0f), g(0.0f), b(0.0f), a(0.0f) {}; SColorf() : r(0.0f), g(0.0f), b(0.0f), a(1.0f) {};
//! Constructs a color from three color values: red, green and blue. //! Constructs a color from three color values: red, green and blue.
//! \param r: Red color component. Should be a value between 0.0f meaning //! \param r: Red color component. Should be a value between 0.0f meaning

View File

@ -15,9 +15,9 @@ namespace scene
//! constructor //! constructor
CBillboardSceneNode::CBillboardSceneNode(ISceneNode* parent, ISceneManager* mgr, s32 id, CBillboardSceneNode::CBillboardSceneNode(ISceneNode* parent, ISceneManager* mgr, s32 id,
const core::vector3df& position, const core::dimension2d<f32>& size, const core::vector3df& position, const core::dimension2d<f32>& size,
video::SColor shade_top, video::SColor shade_down) video::SColor shade_top, video::SColor shade_down)
: IBillboardSceneNode(parent, mgr, id, position) : ISceneNode(parent, mgr, id, position), IBillboardSceneNode(parent, mgr, id, position)
{ {
#ifdef _DEBUG #ifdef _DEBUG
setDebugName("CBillboardSceneNode"); setDebugName("CBillboardSceneNode");

View File

@ -15,7 +15,7 @@ namespace scene
//! Scene node which is a billboard. A billboard is like a 3d sprite: A 2d element, //! Scene node which is a billboard. A billboard is like a 3d sprite: A 2d element,
//! which always looks to the camera. //! which always looks to the camera.
class CBillboardSceneNode : public IBillboardSceneNode class CBillboardSceneNode : virtual public IBillboardSceneNode
{ {
public: public:

View File

@ -22,7 +22,7 @@ CTextSceneNode::CTextSceneNode(ISceneNode* parent, ISceneManager* mgr, s32 id,
gui::IGUIFont* font, scene::ISceneCollisionManager* coll, gui::IGUIFont* font, scene::ISceneCollisionManager* coll,
const core::vector3df& position, const wchar_t* text, const core::vector3df& position, const wchar_t* text,
video::SColor color) video::SColor color)
: ITextSceneNode(parent, mgr, id, position), Text(text), Color(color), : ISceneNode(parent, mgr, id, position), ITextSceneNode(parent, mgr, id, position), Text(text), Color(color),
Font(font), Coll(coll) Font(font), Coll(coll)
{ {
@ -93,7 +93,7 @@ CBillboardTextSceneNode::CBillboardTextSceneNode(ISceneNode* parent, ISceneManag
gui::IGUIFont* font,const wchar_t* text, gui::IGUIFont* font,const wchar_t* text,
const core::vector3df& position, const core::dimension2d<f32>& size, const core::vector3df& position, const core::dimension2d<f32>& size,
video::SColor shade_top,video::SColor shade_bottom ) video::SColor shade_top,video::SColor shade_bottom )
: ITextSceneNode(parent, mgr, id, position), : ISceneNode(parent, mgr, id, position), ITextSceneNode(parent, mgr, id, position), IBillboardSceneNode(parent, mgr, id, position),
Font(0), Shade_top(shade_top), Shade_bottom(shade_bottom), Mesh(0) Font(0), Shade_top(shade_top), Shade_bottom(shade_bottom), Mesh(0)
{ {
#ifdef _DEBUG #ifdef _DEBUG
@ -228,7 +228,6 @@ void CBillboardTextSceneNode::setText(const wchar_t* text)
info.firstVert = firstVert; info.firstVert = firstVert;
Symbol.push_back(info); Symbol.push_back(info);
} }
} }
@ -333,10 +332,7 @@ void CBillboardTextSceneNode::render()
core::matrix4 mat; core::matrix4 mat;
driver->setTransform(video::ETS_WORLD, mat); driver->setTransform(video::ETS_WORLD, mat);
for (u32 i = 0; i < Mesh->getMeshBufferCount(); ++i)
u32 i;
for ( i = 0; i < Mesh->getMeshBufferCount(); ++i )
{ {
driver->setMaterial(Mesh->getMeshBuffer(i)->getMaterial()); driver->setMaterial(Mesh->getMeshBuffer(i)->getMaterial());
driver->drawMeshBuffer(Mesh->getMeshBuffer(i)); driver->drawMeshBuffer(Mesh->getMeshBuffer(i));
@ -350,9 +346,9 @@ void CBillboardTextSceneNode::render()
driver->setMaterial(m); driver->setMaterial(m);
driver->draw3DBox(BBox, video::SColor(0,208,195,152)); driver->draw3DBox(BBox, video::SColor(0,208,195,152));
} }
} }
//! returns the axis aligned bounding box of this node //! returns the axis aligned bounding box of this node
const core::aabbox3d<f32>& CBillboardTextSceneNode::getBoundingBox() const const core::aabbox3d<f32>& CBillboardTextSceneNode::getBoundingBox() const
{ {
@ -397,20 +393,62 @@ u32 CBillboardTextSceneNode::getMaterialCount() const
//! gets the size of the billboard //! gets the size of the billboard
const core::dimension2d<f32>& CBillboardTextSceneNode::getSize() const core::dimension2d<f32>& CBillboardTextSceneNode::getSize() const
{ {
return Size; return Size;
} }
//! sets the color of the text //! sets the color of the text
void CBillboardTextSceneNode::setTextColor(video::SColor color) void CBillboardTextSceneNode::setTextColor(video::SColor color)
{ {
Color = color; Color = color;
} }
//! Set the color of all vertices of the billboard
//! \param overallColor: the color to set
void CBillboardTextSceneNode::setColor(const video::SColor & overallColor)
{
for ( u32 i = 0; i != Text.size (); ++i )
{
const SSymbolInfo &info = Symbol[i];
SMeshBuffer* buf = (SMeshBuffer*)Mesh->getMeshBuffer(info.bufNo);
buf->Vertices[info.firstVert+0].Color = overallColor;
buf->Vertices[info.firstVert+1].Color = overallColor;
buf->Vertices[info.firstVert+2].Color = overallColor;
buf->Vertices[info.firstVert+3].Color = overallColor;
}
}
//! Set the color of the top and bottom vertices of the billboard
//! \param topColor: the color to set the top vertices
//! \param bottomColor: the color to set the bottom vertices
void CBillboardTextSceneNode::setColor(const video::SColor & topColor, const video::SColor & bottomColor)
{
Shade_bottom = bottomColor;
Shade_top = topColor;
for ( u32 i = 0; i != Text.size (); ++i )
{
const SSymbolInfo &info = Symbol[i];
SMeshBuffer* buf = (SMeshBuffer*)Mesh->getMeshBuffer(info.bufNo);
buf->Vertices[info.firstVert+0].Color = Shade_bottom;
buf->Vertices[info.firstVert+3].Color = Shade_bottom;
buf->Vertices[info.firstVert+1].Color = Shade_top;
buf->Vertices[info.firstVert+2].Color = Shade_top;
}
}
//! Gets the color of the top and bottom vertices of the billboard
//! \param topColor: stores the color of the top vertices
//! \param bottomColor: stores the color of the bottom vertices
void CBillboardTextSceneNode::getColor(video::SColor & topColor, video::SColor & bottomColor) const
{
topColor = Shade_top;
bottomColor = Shade_bottom;
}
} // end namespace scene } // end namespace scene
} // end namespace irr } // end namespace irr

View File

@ -6,6 +6,7 @@
#define __C_TEXT_SCENE_NODE_H_INCLUDED__ #define __C_TEXT_SCENE_NODE_H_INCLUDED__
#include "ITextSceneNode.h" #include "ITextSceneNode.h"
#include "IBillboardSceneNode.h"
#include "IGUIFont.h" #include "IGUIFont.h"
#include "IGUIFontBitmap.h" #include "IGUIFontBitmap.h"
#include "ISceneCollisionManager.h" #include "ISceneCollisionManager.h"
@ -56,7 +57,7 @@ namespace scene
core::aabbox3d<f32> Box; core::aabbox3d<f32> Box;
}; };
class CBillboardTextSceneNode : public ITextSceneNode class CBillboardTextSceneNode : virtual public ITextSceneNode, virtual public IBillboardSceneNode
{ {
public: public:
@ -86,7 +87,7 @@ namespace scene
virtual void setSize(const core::dimension2d<f32>& size); virtual void setSize(const core::dimension2d<f32>& size);
//! gets the size of the billboard //! gets the size of the billboard
virtual const core::dimension2d<f32>& getSize(); virtual const core::dimension2d<f32>& getSize() const;
virtual video::SMaterial& getMaterial(u32 i); virtual video::SMaterial& getMaterial(u32 i);
@ -96,6 +97,20 @@ namespace scene
//! Returns type of the scene node //! Returns type of the scene node
virtual ESCENE_NODE_TYPE getType() const { return ESNT_TEXT; } virtual ESCENE_NODE_TYPE getType() const { return ESNT_TEXT; }
//! Set the color of all vertices of the billboard
//! \param overallColor: the color to set
virtual void setColor(const video::SColor & overallColor);
//! Set the color of the top and bottom vertices of the billboard
//! \param topColor: the color to set the top vertices
//! \param bottomColor: the color to set the bottom vertices
virtual void setColor(const video::SColor & topColor, const video::SColor & bottomColor);
//! Gets the color of the top and bottom vertices of the billboard
//! \param topColor: stores the color of the top vertices
//! \param bottomColor: stores the color of the bottom vertices
virtual void getColor(video::SColor & topColor, video::SColor & bottomColor) const;
private: private:
core::stringw Text; core::stringw Text;