Commit c2e1206e authored by hybrid's avatar hybrid

Small part of the billboard patch from rogerborg

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@3983 dfc29bdd-3216-0410-991c-e03cc46cb475
parent e18cd079
...@@ -26,25 +26,43 @@ public: ...@@ -26,25 +26,43 @@ public:
const core::vector3df& position = core::vector3df(0,0,0)) const core::vector3df& position = core::vector3df(0,0,0))
: ISceneNode(parent, mgr, id, position) {} : ISceneNode(parent, mgr, id, position) {}
//! Sets the size of the billboard. //! Sets the size of the billboard, making it rectangular.
virtual void setSize(const core::dimension2d<f32>& size) = 0; virtual void setSize(const core::dimension2d<f32>& size) = 0;
//! Sets the widths of the bottom and top edges of the billboard independently.
/** \param[in] startEdgeWidth The width of the start (bottom) edge of the billboard.
\param[in] endEdgeWidth The width of the end (top) edge of the billboard.
*/
virtual void setWidths(f32 startEdgeWidth, f32 endEdgeWidth) = 0;
//! Returns the size of the billboard. //! Returns the size of the billboard.
/** This will return the width of the bottom edge of the billboard.
Use getWidths() to retrieve the bottom and top edges independently.
\return Size of the billboard.
*/
virtual const core::dimension2d<f32>& getSize() const = 0; virtual const core::dimension2d<f32>& getSize() const = 0;
//! Gets the widths of the top and bottom edges of the billboard.
/** \param[out] startEdgeWidth The width of the start (bottom) edge of the billboard.
\param[out] endEdgeWidth The width of the end (top) edge of the billboard.
*/
virtual void getWidths(f32& startEdgeWidth, f32& endEdgeWidth) const =0;
//! Set the color of all vertices of the billboard //! Set the color of all vertices of the billboard
/** \param overallColor: the color to set */ /** \param[in] overallColor Color to set */
virtual void setColor(const video::SColor & overallColor) = 0; virtual void setColor(const video::SColor& overallColor) = 0;
//! Set the color of the top and bottom vertices of the billboard //! Set the color of the top and bottom vertices of the billboard
/** \param topColor: the color to set the top vertices /** \param[in] topColor Color to set the top vertices
\param bottomColor: the color to set the bottom vertices */ \param[in] bottomColor Color to set the bottom vertices */
virtual void setColor(const video::SColor & topColor, const video::SColor & bottomColor) = 0; virtual void setColor(const video::SColor& topColor,
const video::SColor& bottomColor) = 0;
//! Gets the color of the top and bottom vertices of the billboard //! Gets the color of the top and bottom vertices of the billboard
/** \param topColor: stores the color of the top vertices /** \param[out] topColor Stores the color of the top vertices
\param bottomColor: stores the color of the bottom vertices */ \param[out] bottomColor Stores the color of the bottom vertices */
virtual void getColor(video::SColor & topColor, video::SColor & bottomColor) const = 0; virtual void getColor(video::SColor& topColor,
video::SColor& bottomColor) const = 0;
}; };
} // end namespace scene } // end namespace scene
......
...@@ -81,6 +81,7 @@ void CBillboardSceneNode::render() ...@@ -81,6 +81,7 @@ void CBillboardSceneNode::render()
horizontal.set(up.Y,up.X,up.Z); horizontal.set(up.Y,up.X,up.Z);
} }
horizontal.normalize(); horizontal.normalize();
core::vector3df topHorizontal = horizontal * 0.5f * TopEdgeWidth;
horizontal *= 0.5f * Size.Width; horizontal *= 0.5f * Size.Width;
core::vector3df vertical = horizontal.crossProduct(view); core::vector3df vertical = horizontal.crossProduct(view);
...@@ -92,14 +93,24 @@ void CBillboardSceneNode::render() ...@@ -92,14 +93,24 @@ void CBillboardSceneNode::render()
for (s32 i=0; i<4; ++i) for (s32 i=0; i<4; ++i)
vertices[i].Normal = view; vertices[i].Normal = view;
vertices[0].Pos = pos + horizontal + vertical; /* Vertices are:
3--0
| /|
|/ |
2--1
*/
vertices[0].Pos = pos + topHorizontal + vertical;
vertices[0].Normal = up;
vertices[1].Pos = pos + horizontal - vertical; vertices[1].Pos = pos + horizontal - vertical;
vertices[1].Normal = up;
vertices[2].Pos = pos - horizontal - vertical; vertices[2].Pos = pos - horizontal - vertical;
vertices[3].Pos = pos - horizontal + vertical; vertices[2].Normal = up;
vertices[3].Pos = pos - topHorizontal + vertical;
vertices[3].Normal = up;
// draw // draw
if ( DebugDataVisible & scene::EDS_BBOX ) if (DebugDataVisible & scene::EDS_BBOX)
{ {
driver->setTransform(video::ETS_WORLD, AbsoluteTransformation); driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
video::SMaterial m; video::SMaterial m;
...@@ -128,13 +139,31 @@ void CBillboardSceneNode::setSize(const core::dimension2d<f32>& size) ...@@ -128,13 +139,31 @@ void CBillboardSceneNode::setSize(const core::dimension2d<f32>& size)
{ {
Size = size; Size = size;
if (Size.Width == 0.0f) if (core::equals(Size.Width, 0.0f))
Size.Width = 1.0f; Size.Width = 1.0f;
TopEdgeWidth = Size.Width;
if (Size.Height == 0.0f ) if (core::equals(Size.Height, 0.0f))
Size.Height = 1.0f; Size.Height = 1.0f;
f32 avg = (size.Width + size.Height)/6; const f32 avg = (Size.Width + Size.Height)/6;
BBox.MinEdge.set(-avg,-avg,-avg);
BBox.MaxEdge.set(avg,avg,avg);
}
void CBillboardSceneNode::setWidths(f32 bottomEdgeWidth, f32 topEdgeWidth)
{
Size.Width = bottomEdgeWidth;
TopEdgeWidth = topEdgeWidth;
if (core::equals(Size.Width, 0.f))
Size.Width = 1.0f;
if (core::equals(TopEdgeWidth, 0.f))
TopEdgeWidth = 1.0f;
const f32 avg = (core::max_(Size.Width,TopEdgeWidth) + Size.Height)/6;
BBox.MinEdge.set(-avg,-avg,-avg); BBox.MinEdge.set(-avg,-avg,-avg);
BBox.MaxEdge.set(avg,avg,avg); BBox.MaxEdge.set(avg,avg,avg);
} }
...@@ -160,12 +189,22 @@ const core::dimension2d<f32>& CBillboardSceneNode::getSize() const ...@@ -160,12 +189,22 @@ const core::dimension2d<f32>& CBillboardSceneNode::getSize() const
} }
//! Gets the widths of the top and bottom edges of the billboard.
void CBillboardSceneNode::getWidths(f32& bottomEdgeWidth,
f32& topEdgeWidth) const
{
bottomEdgeWidth = Size.Width;
topEdgeWidth = TopEdgeWidth;
}
//! Writes attributes of the scene node. //! Writes attributes of the scene node.
void CBillboardSceneNode::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const void CBillboardSceneNode::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const
{ {
IBillboardSceneNode::serializeAttributes(out, options); IBillboardSceneNode::serializeAttributes(out, options);
out->addFloat("Width", Size.Width); out->addFloat("Width", Size.Width);
out->addFloat("TopEdgeWidth", TopEdgeWidth);
out->addFloat("Height", Size.Height); out->addFloat("Height", Size.Height);
out->addColor ("Shade_Top", vertices[1].Color ); out->addColor ("Shade_Top", vertices[1].Color );
out->addColor ("Shade_Down", vertices[0].Color ); out->addColor ("Shade_Down", vertices[0].Color );
...@@ -179,18 +218,24 @@ void CBillboardSceneNode::deserializeAttributes(io::IAttributes* in, io::SAttrib ...@@ -179,18 +218,24 @@ void CBillboardSceneNode::deserializeAttributes(io::IAttributes* in, io::SAttrib
Size.Width = in->getAttributeAsFloat("Width"); Size.Width = in->getAttributeAsFloat("Width");
Size.Height = in->getAttributeAsFloat("Height"); Size.Height = in->getAttributeAsFloat("Height");
vertices[1].Color = in->getAttributeAsColor ( "Shade_Top" );
vertices[0].Color = in->getAttributeAsColor ( "Shade_Down" );
vertices[2].Color = vertices[1].Color;
vertices[3].Color = vertices[0].Color;
setSize(Size); setSize(Size);
if (in->existsAttribute("TopEdgeWidth"))
{
TopEdgeWidth = in->getAttributeAsFloat("TopEdgeWidth");
if (Size.Width != TopEdgeWidth)
setWidths(Size.Width, TopEdgeWidth);
}
vertices[1].Color = in->getAttributeAsColor("Shade_Top");
vertices[0].Color = in->getAttributeAsColor("Shade_Down");
vertices[2].Color = vertices[1].Color;
vertices[3].Color = vertices[0].Color;
} }
//! Set the color of all vertices of the billboard //! Set the color of all vertices of the billboard
//! \param overallColor: the color to set //! \param overallColor: the color to set
void CBillboardSceneNode::setColor(const video::SColor & overallColor) void CBillboardSceneNode::setColor(const video::SColor& overallColor)
{ {
for(u32 vertex = 0; vertex < 4; ++vertex) for(u32 vertex = 0; vertex < 4; ++vertex)
vertices[vertex].Color = overallColor; vertices[vertex].Color = overallColor;
...@@ -200,7 +245,8 @@ void CBillboardSceneNode::setColor(const video::SColor & overallColor) ...@@ -200,7 +245,8 @@ void CBillboardSceneNode::setColor(const video::SColor & overallColor)
//! Set the color of the top and bottom vertices of the billboard //! Set the color of the top and bottom vertices of the billboard
//! \param topColor: the color to set the top vertices //! \param topColor: the color to set the top vertices
//! \param bottomColor: the color to set the bottom vertices //! \param bottomColor: the color to set the bottom vertices
void CBillboardSceneNode::setColor(const video::SColor & topColor, const video::SColor & bottomColor) void CBillboardSceneNode::setColor(const video::SColor& topColor,
const video::SColor& bottomColor)
{ {
vertices[0].Color = bottomColor; vertices[0].Color = bottomColor;
vertices[1].Color = topColor; vertices[1].Color = topColor;
...@@ -212,7 +258,8 @@ void CBillboardSceneNode::setColor(const video::SColor & topColor, const video:: ...@@ -212,7 +258,8 @@ void CBillboardSceneNode::setColor(const video::SColor & topColor, const video::
//! Gets the color of the top and bottom vertices of the billboard //! Gets the color of the top and bottom vertices of the billboard
//! \param[out] topColor: stores the color of the top vertices //! \param[out] topColor: stores the color of the top vertices
//! \param[out] bottomColor: stores the color of the bottom vertices //! \param[out] bottomColor: stores the color of the bottom vertices
void CBillboardSceneNode::getColor(video::SColor & topColor, video::SColor & bottomColor) const void CBillboardSceneNode::getColor(video::SColor& topColor,
video::SColor& bottomColor) const
{ {
bottomColor = vertices[0].Color; bottomColor = vertices[0].Color;
topColor = vertices[1].Color; topColor = vertices[1].Color;
...@@ -232,6 +279,7 @@ ISceneNode* CBillboardSceneNode::clone(ISceneNode* newParent, ISceneManager* new ...@@ -232,6 +279,7 @@ ISceneNode* CBillboardSceneNode::clone(ISceneNode* newParent, ISceneManager* new
nb->cloneMembers(this, newManager); nb->cloneMembers(this, newManager);
nb->Material = Material; nb->Material = Material;
nb->TopEdgeWidth = this->TopEdgeWidth;
if ( newParent ) if ( newParent )
nb->drop(); nb->drop();
......
...@@ -22,7 +22,8 @@ public: ...@@ -22,7 +22,8 @@ public:
//! constructor //! constructor
CBillboardSceneNode(ISceneNode* parent, ISceneManager* mgr, s32 id, 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 colorTop=video::SColor(0xFFFFFFFF),video::SColor colorBottom=video::SColor(0xFFFFFFFF)); video::SColor colorTop=video::SColor(0xFFFFFFFF),
video::SColor colorBottom=video::SColor(0xFFFFFFFF));
//! pre render event //! pre render event
virtual void OnRegisterSceneNode(); virtual void OnRegisterSceneNode();
...@@ -36,9 +37,15 @@ public: ...@@ -36,9 +37,15 @@ public:
//! sets the size of the billboard //! sets the size of the billboard
virtual void setSize(const core::dimension2d<f32>& size); virtual void setSize(const core::dimension2d<f32>& size);
//! Sets the widths of the top and bottom edges of the billboard independently.
virtual void setWidths(f32 bottomEdgeWidth, f32 topEdgeWidth);
//! gets the size of the billboard //! gets the size of the billboard
virtual const core::dimension2d<f32>& getSize() const; virtual const core::dimension2d<f32>& getSize() const;
//! Gets the widths of the top and bottom edges of the billboard.
virtual void getWidths(f32& bottomEdgeWidth, f32& topEdgeWidth) const;
virtual video::SMaterial& getMaterial(u32 i); virtual video::SMaterial& getMaterial(u32 i);
//! returns amount of materials used by this scene node. //! returns amount of materials used by this scene node.
...@@ -46,17 +53,19 @@ public: ...@@ -46,17 +53,19 @@ public:
//! Set the color of all vertices of the billboard //! Set the color of all vertices of the billboard
//! \param overallColor: the color to set //! \param overallColor: the color to set
virtual void setColor(const video::SColor & overallColor); virtual void setColor(const video::SColor& overallColor);
//! Set the color of the top and bottom vertices of the billboard //! Set the color of the top and bottom vertices of the billboard
//! \param topColor: the color to set the top vertices //! \param topColor: the color to set the top vertices
//! \param bottomColor: the color to set the bottom vertices //! \param bottomColor: the color to set the bottom vertices
virtual void setColor(const video::SColor & topColor, const video::SColor & bottomColor); virtual void setColor(const video::SColor& topColor,
const video::SColor& bottomColor);
//! Gets the color of the top and bottom vertices of the billboard //! Gets the color of the top and bottom vertices of the billboard
//! \param[out] topColor: stores the color of the top vertices //! \param[out] topColor: stores the color of the top vertices
//! \param[out] bottomColor: stores the color of the bottom vertices //! \param[out] bottomColor: stores the color of the bottom vertices
virtual void getColor(video::SColor& topColor, video::SColor& bottomColor) const; virtual void getColor(video::SColor& topColor,
video::SColor& bottomColor) const;
//! Writes attributes of the scene node. //! Writes attributes of the scene node.
virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) const; virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) const;
...@@ -72,7 +81,9 @@ public: ...@@ -72,7 +81,9 @@ public:
private: private:
//! Size.Width is the bottom edge width
core::dimension2d<f32> Size; core::dimension2d<f32> Size;
f32 TopEdgeWidth;
core::aabbox3d<f32> BBox; core::aabbox3d<f32> BBox;
video::SMaterial Material; video::SMaterial Material;
......
...@@ -115,6 +115,17 @@ namespace scene ...@@ -115,6 +115,17 @@ namespace scene
//! \param bottomColor: stores the color of the bottom vertices //! \param bottomColor: stores the color of the bottom vertices
virtual void getColor(video::SColor & topColor, video::SColor & bottomColor) const; virtual void getColor(video::SColor & topColor, video::SColor & bottomColor) const;
virtual void setWidths(f32 bottomEdgeWidth, f32 topEdgeWidth)
{
setSize(core::dimension2df(bottomEdgeWidth, Size.Height));
}
virtual void getWidths(f32& bottomEdgeWidth, f32& topEdgeWidth) const
{
bottomEdgeWidth = Size.Width;
topEdgeWidth = Size.Width;
}
private: private:
core::stringw Text; core::stringw Text;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment