Spinning Topp Logo BlackTopp Studios
inc
billboard.cpp
Go to the documentation of this file.
1 // © Copyright 2010 - 2016 BlackTopp Studios Inc.
2 /* This file is part of The Mezzanine Engine.
3 
4  The Mezzanine Engine is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  The Mezzanine Engine is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with The Mezzanine Engine. If not, see <http://www.gnu.org/licenses/>.
16 */
17 /* The original authors have included a copy of the license specified above in the
18  'Docs' folder. See 'gpl.txt'
19 */
20 /* We welcome the use of the Mezzanine engine to anyone, including companies who wish to
21  Build professional software and charge for their product.
22 
23  However there are some practical restrictions, so if your project involves
24  any of the following you should contact us and we will try to work something
25  out:
26  - DRM or Copy Protection of any kind(except Copyrights)
27  - Software Patents You Do Not Wish to Freely License
28  - Any Kind of Linking to Non-GPL licensed Works
29  - Are Currently In Violation of Another Copyright Holder's GPL License
30  - If You want to change our code and not add a few hundred MB of stuff to
31  your distribution
32 
33  These and other limitations could cause serious legal problems if you ignore
34  them, so it is best to simply contact us or the Free Software Foundation, if
35  you have any questions.
36 
37  Joseph Toppi - toppij@gmail.com
38  John Blackwood - makoenergy02@gmail.com
39 */
40 #ifndef _graphicsbillboard_cpp
41 #define _graphicsbillboard_cpp
42 
43 /// @file
44 /// @brief This file contains the implementation for the Billboard class used by BillboardSetProxy.
45 
46 #include "Graphics/billboard.h"
47 
48 #include "exception.h"
49 #include "serialization.h"
50 #include "stringtool.h"
51 
52 #include <Ogre.h>
53 
54 namespace Mezzanine
55 {
56  namespace Graphics
57  {
58  Billboard::Billboard(Ogre::Billboard* InternalBillboard) :
59  GraphicsBillboard(InternalBillboard)
60  { }
61 
63  { }
64 
65  ///////////////////////////////////////////////////////////////////////////////
66  // Utility
67 
69  { return this->GraphicsBillboard->hasOwnDimensions(); }
70 
72  { this->GraphicsBillboard->resetDimensions(); }
73 
75  { return this->GraphicsBillboard->isUseTexcoordRect(); }
76 
77  ///////////////////////////////////////////////////////////////////////////////
78  // Billboard Properties
79 
81  { this->GraphicsBillboard->setPosition( Loc.GetOgreVector3() ); }
82 
84  { return Vector3( this->GraphicsBillboard->getPosition() ); }
85 
87  { this->GraphicsBillboard->mDirection = Dir.GetOgreVector3(); }
88 
90  { return Vector3( this->GraphicsBillboard->mDirection ); }
91 
92  void Billboard::SetRotation(const Real Rot)
93  { this->GraphicsBillboard->setRotation( Ogre::Radian(Rot) ); }
94 
96  { return this->GraphicsBillboard->getRotation().valueRadians(); }
97 
98  void Billboard::SetColour(const ColourValue& Colour)
99  { this->GraphicsBillboard->setColour( Colour.GetOgreColourValue() ); }
100 
102  { return ColourValue( this->GraphicsBillboard->getColour() ); }
103 
104  void Billboard::SetDimensions(const Real Width, const Real Height)
105  { this->GraphicsBillboard->setDimensions(Width,Height); }
106 
108  { return this->GraphicsBillboard->getOwnWidth(); }
109 
111  { return this->GraphicsBillboard->getOwnHeight(); }
112 
113  void Billboard::SetTextureCoordRect(const Real Left, const Real Top, const Real Right, const Real Bottom)
114  { this->GraphicsBillboard->setTexcoordRect(Left,Top,Right,Bottom); }
115 
117  { return this->GraphicsBillboard->getTexcoordRect().left; }
118 
120  { return this->GraphicsBillboard->getTexcoordRect().top; }
121 
123  { return this->GraphicsBillboard->getTexcoordRect().right; }
124 
126  { return this->GraphicsBillboard->getTexcoordRect().bottom; }
127 
128  ///////////////////////////////////////////////////////////////////////////////
129  // Serialization
130 
131  void Billboard::ProtoSerialize(XML::Node& ParentNode) const
132  {
133  XML::Node SelfRoot = SelfRoot.AppendChild( Billboard::GetSerializableName() );
134 
135  if( SelfRoot.AppendAttribute("Version").SetValue("1") &&
136  SelfRoot.AppendAttribute("Rotation").SetValue( this->GetRotation() ) )
137  {
138  if( this->HasOwnDimensions() ) {
139  if( !( SelfRoot.AppendAttribute("OwnWidth").SetValue( this->GetOwnWidth() ) &&
140  SelfRoot.AppendAttribute("OwnHeight").SetValue( this->GetOwnHeight() ) ) )
141  {
142  SerializeError("Create XML Attribute Values",Billboard::GetSerializableName(),true);
143  }
144  }
145 
146  if( this->IsUsingTextureCoordRect() ) {
147  if( !( SelfRoot.AppendAttribute("LeftTexCoord").SetValue( this->GetLeftTextureCoord() ) &&
148  SelfRoot.AppendAttribute("TopTexCoord").SetValue( this->GetTopTextureCoord() ) &&
149  SelfRoot.AppendAttribute("RightTexCoord").SetValue( this->GetRightTextureCoord() ) &&
150  SelfRoot.AppendAttribute("BottomTexCoord").SetValue( this->GetBottomTextureCoord() ) ) )
151  {
152  SerializeError("Create XML Attribute Values",Billboard::GetSerializableName(),true);
153  }
154  }
155 
156  XML::Node LocationNode = SelfRoot.AppendChild("Location");
157  this->GetLocation().ProtoSerialize( LocationNode );
158  XML::Node DirectionNode = SelfRoot.AppendChild("Direction");
159  this->GetDirection().ProtoSerialize( DirectionNode );
160  XML::Node ColourNode = SelfRoot.AppendChild("Colour");
161  this->GetColour().ProtoSerialize( ColourNode );
162 
163  return;
164  }else{
165  SerializeError("Create XML Attribute Values",Billboard::GetSerializableName(),true);
166  }
167  }
168 
170  {
171  XML::Attribute CurrAttrib;
172 
173  if( String( SelfRoot.Name() ) == Billboard::GetSerializableName() ) {
174  if(SelfRoot.GetAttribute("Version").AsInt() == 1) {
175  Real OwnWidth = -1.0, OwnHeight = -1.0;
176  Real LeftTexCoord = -1.0, TopTexCoord = -1.0, RightTexCoord = -1.0, BottomTexCoord = -1.0;
177 
178  CurrAttrib = SelfRoot.GetAttribute("Rotation");
179  if( !CurrAttrib.Empty() )
180  this->SetRotation( CurrAttrib.AsReal() );
181 
182  CurrAttrib = SelfRoot.GetAttribute("OwnWidth");
183  if( !CurrAttrib.Empty() )
184  OwnWidth = CurrAttrib.AsReal();
185 
186  CurrAttrib = SelfRoot.GetAttribute("OwnHeight");
187  if( !CurrAttrib.Empty() )
188  OwnHeight = CurrAttrib.AsReal();
189 
190  if( OwnWidth >= 0 && OwnHeight >= 0 ) {
191  this->SetDimensions(OwnWidth,OwnHeight);
192  }
193 
194  CurrAttrib = SelfRoot.GetAttribute("LeftTexCoord");
195  if( !CurrAttrib.Empty() )
196  LeftTexCoord = CurrAttrib.AsReal();
197 
198  CurrAttrib = SelfRoot.GetAttribute("TopTexCoord");
199  if( !CurrAttrib.Empty() )
200  TopTexCoord = CurrAttrib.AsReal();
201 
202  CurrAttrib = SelfRoot.GetAttribute("RightTexCoord");
203  if( !CurrAttrib.Empty() )
204  RightTexCoord = CurrAttrib.AsReal();
205 
206  CurrAttrib = SelfRoot.GetAttribute("BottomTexCoord");
207  if( !CurrAttrib.Empty() )
208  BottomTexCoord = CurrAttrib.AsReal();
209 
210  if( LeftTexCoord >= 0 && TopTexCoord >= 0 && RightTexCoord >= 0 && BottomTexCoord >= 0 ) {
211  this->SetTextureCoordRect(LeftTexCoord,TopTexCoord,RightTexCoord,BottomTexCoord);
212  }
213 
214  XML::Node LocationNode = SelfRoot.GetChild("Location").GetFirstChild();
215  if( !LocationNode.Empty() ) {
216  Vector3 Loc(LocationNode);
217  this->SetLocation(Loc);
218  }
219 
220  XML::Node DirectionNode = SelfRoot.GetChild("Direction").GetFirstChild();
221  if( !DirectionNode.Empty() ) {
222  Vector3 Dir(DirectionNode);
223  this->SetDirection(Dir);
224  }
225 
226  XML::Node ColourNode = SelfRoot.GetChild("Colour").GetFirstChild();
227  if( !ColourNode.Empty() ) {
228  ColourValue Colour(ColourNode);
229  this->SetColour(Colour);
230  }
231  }else{
232  MEZZ_EXCEPTION(ExceptionBase::INVALID_VERSION_EXCEPTION,"Incompatible XML Version for " + Billboard::GetSerializableName() + ": Not Version 1.");
233  }
234  }else{
235  MEZZ_EXCEPTION(ExceptionBase::II_IDENTITY_NOT_FOUND_EXCEPTION,Billboard::GetSerializableName() + " was not found in the provided XML node, which was expected.");
236  }
237  }
238 
240  { return "Billboard"; }
241 
242  ///////////////////////////////////////////////////////////////////////////////
243  // Internal Methods
244 
245  Ogre::Billboard* Billboard::_GetGraphicsObject() const
246  { return this->GraphicsBillboard; }
247  }//Graphics
248 }//Mezzanine
249 
250 #endif
Attribute AppendAttribute(const Char8 *Name)
Creates an Attribute and puts it at the end of this Nodes attributes.
void SetColour(const ColourValue &Colour)
Sets the base colour of this billboard.
Definition: billboard.cpp:98
A light-weight handle for manipulating attributes in DOM tree.
Definition: attribute.h:74
void ResetDimensions()
Resets whatever dimensions are on this billboard to the default provided to the parent BillboardSetPr...
Definition: billboard.cpp:71
void SetLocation(const Vector3 &Loc)
Sets the location of this billboard relative to it's parent set.
Definition: billboard.cpp:80
bool Boole
Generally acts a single bit, true or false.
Definition: datatypes.h:173
Real GetRightTextureCoord() const
Gets the Right side texture coordinate being used to render this billboard.
Definition: billboard.cpp:122
void ProtoDeSerialize(const XML::Node &SelfRoot)
Take the data stored in an XML Node and overwrite this object with it.
Definition: billboard.cpp:169
Vector3 GetDirection() const
Gets the facing direction of this billboard. Only useful with specific types of BillboardSetProxies.
Definition: billboard.cpp:89
Thrown when the requested identity could not be found.
Definition: exception.h:94
Node GetFirstChild() const
Get the first child Node of this Node.
#define MEZZ_EXCEPTION(num, desc)
An easy way to throw exceptions with rich information.
Definition: exception.h:3048
Real GetBottomTextureCoord() const
Gets the Bottom side texture coordinate being used to render this billboard.
Definition: billboard.cpp:125
Real GetOwnHeight() const
Gets the individually configured world unit Height of this billboard.
Definition: billboard.cpp:110
Thrown when a version is accessed/parsed/required and it cannot work correctly or is missing...
Definition: exception.h:112
~Billboard()
Class destructor.
Definition: billboard.cpp:62
ColourValue GetColour() const
Gets the base colour of this billboard.
Definition: billboard.cpp:101
Vector3 GetLocation() const
Gets the location of this billboard relative to it's parent set.
Definition: billboard.cpp:83
This is a simple class for holding 4 reals representing the colour any give object or lightsource can...
Definition: colourvalue.h:64
bool Empty() const
Is this storing anything at all?
This implements the exception hiearchy for Mezzanine.
void SetTextureCoordRect(const Real Left, const Real Top, const Real Right, const Real Bottom)
Sets the rect in texture coordinates to use for rendering this billboard.
Definition: billboard.cpp:113
float Real
A Datatype used to represent a real floating point number.
Definition: datatypes.h:141
The interface for serialization.
bool SetValue(const Char8 *rhs)
Set the value of this.
static String GetSerializableName()
Get the name of the the XML tag the proxy class will leave behind as its instances are serialized...
Definition: billboard.cpp:239
A light-weight handle for manipulating nodes in DOM tree.
Definition: node.h:89
Real GetLeftTextureCoord() const
Gets the Left side texture coordinate being used to render this billboard.
Definition: billboard.cpp:116
int AsInt(int def=0) const
Attempts to convert the value of the attribute to an int and returns the results. ...
Real GetOwnWidth() const
Gets the individually configured world unit Width of this billboard.
Definition: billboard.cpp:107
bool Empty() const
Is this storing anything at all?
Real GetTopTextureCoord() const
Gets the Top side texture coordinate being used to render this billboard.
Definition: billboard.cpp:119
Ogre::Vector3 GetOgreVector3() const
Gets a Ogre vector3.
Definition: vector3.cpp:572
Real AsReal(Real def=0) const
Attempts to convert the value of the attribute to a Real and returns the results. ...
void ProtoSerialize(XML::Node &ParentNode) const
Convert this class to an XML::Node ready for serialization.
Definition: billboard.cpp:131
This file contains the declaration for the Billboard class used by BillboardSetProxy.
This is used to represent a point in space, or a vector through space.
Definition: vector3.h:77
Boole IsUsingTextureCoordRect() const
Gets whether or not this billboard is using custom texture coordinates.
Definition: billboard.cpp:74
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56
Ogre::Billboard * _GetGraphicsObject() const
Accessor for the internal billboard.
Definition: billboard.cpp:245
void ProtoSerialize(XML::Node &CurrentRoot) const
Convert this class to an XML::Node ready for serialization.
Boole HasOwnDimensions() const
Gets whether or not this billboard has had it's dimensions individually configured.
Definition: billboard.cpp:68
const Char8 * Name() const
ptrdiff_tGet the name of this Node.
Ogre::ColourValue GetOgreColourValue() const
Creates and returns an Ogre ColourValue class with values equal to this one.
Definition: colourvalue.cpp:86
void SerializeError(const String &FailedTo, const String &ClassName, Boole SOrD)
Simply does some string concatenation, then throws an Exception.
Billboard(Ogre::Billboard *InternalBillboard)
Internal constructor.
Definition: billboard.cpp:58
Node AppendChild(NodeType Type=NodeElement)
Creates a Node and makes it a child of this one.
std::string String
A datatype used to a series of characters.
Definition: datatypes.h:159
void SetDirection(const Vector3 &Dir)
Sets the facing direction of this billboard. Only useful with specific types of BillboardSetProxies.
Definition: billboard.cpp:86
Attribute GetAttribute(const Char8 *Name) const
Attempt to get an Attribute on this Node with a given name.
void ProtoSerialize(XML::Node &CurrentRoot) const
Convert this class to an XML::Node ready for serialization.
Definition: vector3.cpp:588
Real GetRotation() const
Gets the rotation of this billboard.
Definition: billboard.cpp:95
Node GetChild(const Char8 *Name) const
Attempt to get a child Node with a given name.
Ogre::Billboard * GraphicsBillboard
A pointer to the internal Billboard.
Definition: billboard.h:67
void SetRotation(const Real Rot)
Sets the rotation of this billboard.
Definition: billboard.cpp:92
void SetDimensions(const Real Width, const Real Height)
Sets the world unit dimensions of this billboard.
Definition: billboard.cpp:104