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
class IAttributeExchangingObject : public virtual IReferenceCounted
class IAttributeExchangingObject : virtual public IReferenceCounted
{
public:

View File

@ -17,7 +17,7 @@ namespace scene
which always looks to the camera. It is usually used for explosions, fire,
lensflares, particles and things like that.
*/
class IBillboardSceneNode : public ISceneNode
class IBillboardSceneNode : virtual public ISceneNode
{
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
to attach a light to a moving car, or to place a walking character on a moving platform
on a moving ship. */
class ISceneNode : public io::IAttributeExchangingObject
class ISceneNode : virtual public io::IAttributeExchangingObject
{
public:
@ -375,7 +375,7 @@ namespace scene
//! Gets 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;
}
@ -410,7 +410,7 @@ namespace scene
//! Gets the position of the node.
/** Note that the position is 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;
}

View File

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

View File

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

View File

@ -15,9 +15,9 @@ namespace scene
//! constructor
CBillboardSceneNode::CBillboardSceneNode(ISceneNode* parent, ISceneManager* mgr, s32 id,
const core::vector3df& position, const core::dimension2d<f32>& size,
video::SColor shade_top, video::SColor shade_down)
: IBillboardSceneNode(parent, mgr, id, position)
const core::vector3df& position, const core::dimension2d<f32>& size,
video::SColor shade_top, video::SColor shade_down)
: ISceneNode(parent, mgr, id, position), IBillboardSceneNode(parent, mgr, id, position)
{
#ifdef _DEBUG
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,
//! which always looks to the camera.
class CBillboardSceneNode : public IBillboardSceneNode
class CBillboardSceneNode : virtual public IBillboardSceneNode
{
public:

View File

@ -22,7 +22,7 @@ CTextSceneNode::CTextSceneNode(ISceneNode* parent, ISceneManager* mgr, s32 id,
gui::IGUIFont* font, scene::ISceneCollisionManager* coll,
const core::vector3df& position, const wchar_t* text,
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)
{
@ -93,7 +93,7 @@ CBillboardTextSceneNode::CBillboardTextSceneNode(ISceneNode* parent, ISceneManag
gui::IGUIFont* font,const wchar_t* text,
const core::vector3df& position, const core::dimension2d<f32>& size,
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)
{
#ifdef _DEBUG
@ -228,7 +228,6 @@ void CBillboardTextSceneNode::setText(const wchar_t* text)
info.firstVert = firstVert;
Symbol.push_back(info);
}
}
@ -333,10 +332,7 @@ void CBillboardTextSceneNode::render()
core::matrix4 mat;
driver->setTransform(video::ETS_WORLD, mat);
u32 i;
for ( i = 0; i < Mesh->getMeshBufferCount(); ++i )
for (u32 i = 0; i < Mesh->getMeshBufferCount(); ++i)
{
driver->setMaterial(Mesh->getMeshBuffer(i)->getMaterial());
driver->drawMeshBuffer(Mesh->getMeshBuffer(i));
@ -350,9 +346,9 @@ void CBillboardTextSceneNode::render()
driver->setMaterial(m);
driver->draw3DBox(BBox, video::SColor(0,208,195,152));
}
}
//! returns the axis aligned bounding box of this node
const core::aabbox3d<f32>& CBillboardTextSceneNode::getBoundingBox() const
{
@ -397,20 +393,62 @@ u32 CBillboardTextSceneNode::getMaterialCount() const
//! gets the size of the billboard
const core::dimension2d<f32>& CBillboardTextSceneNode::getSize()
const core::dimension2d<f32>& CBillboardTextSceneNode::getSize() const
{
return Size;
}
//! sets the color of the text
void CBillboardTextSceneNode::setTextColor(video::SColor 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 irr

View File

@ -6,6 +6,7 @@
#define __C_TEXT_SCENE_NODE_H_INCLUDED__
#include "ITextSceneNode.h"
#include "IBillboardSceneNode.h"
#include "IGUIFont.h"
#include "IGUIFontBitmap.h"
#include "ISceneCollisionManager.h"
@ -56,7 +57,7 @@ namespace scene
core::aabbox3d<f32> Box;
};
class CBillboardTextSceneNode : public ITextSceneNode
class CBillboardTextSceneNode : virtual public ITextSceneNode, virtual public IBillboardSceneNode
{
public:
@ -86,7 +87,7 @@ namespace scene
virtual void setSize(const core::dimension2d<f32>& size);
//! 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);
@ -96,6 +97,20 @@ namespace scene
//! Returns type of the scene node
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:
core::stringw Text;