Spinning Topp Logo BlackTopp Studios
inc
renderableproxy.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 _graphicsrenderableproxy_cpp
41 #define _graphicsrenderableproxy_cpp
42 
43 /// @file
44 /// @brief This file contains the implementation for the base class from which graphics proxies inherit.
45 
47 #include "Graphics/scenemanager.h"
48 
49 #include "enumerations.h"
50 #include "exception.h"
51 #include "serialization.h"
52 #include "stringtool.h"
53 
54 #include <Ogre.h>
55 
56 namespace Mezzanine
57 {
58  namespace Graphics
59  {
61  GraphicsNode(NULL),
62  Manager(Creator),
63  VisibilityMask(Ogre::MovableObject::getDefaultVisibilityFlags()),
64  QueryMask(Ogre::MovableObject::getDefaultQueryFlags()),
65  InWorld(false)
66  {
67  this->GraphicsNode = this->Manager->_GetGraphicsWorldPointer()->getRootSceneNode()->createChildSceneNode();
68  }
69 
71  WorldProxy(ID),
72  GraphicsNode(NULL),
73  Manager(Creator),
74  VisibilityMask(Ogre::MovableObject::getDefaultVisibilityFlags()),
75  QueryMask(Ogre::MovableObject::getDefaultQueryFlags()),
76  InWorld(false)
77  {
78  this->GraphicsNode = this->Manager->_GetGraphicsWorldPointer()->getRootSceneNode()->createChildSceneNode();
79  }
80 
82  {
83  this->GraphicsNode->getParentSceneNode()->removeChild(this->GraphicsNode);
84  this->Manager->_GetGraphicsWorldPointer()->destroySceneNode(this->GraphicsNode);
85  }
86 
87  ///////////////////////////////////////////////////////////////////////////////
88  // Utility
89 
91  { return AxisAlignedBox( this->_GetBaseGraphicsObject()->getBoundingBox() ); }
92 
94  {
95  if( !this->InWorld ) {
96  this->_GetBaseGraphicsObject()->setVisibilityFlags( this->VisibilityMask );
97  this->_GetBaseGraphicsObject()->setQueryFlags( this->QueryMask );
98  this->InWorld = true;
99  }
100  }
101 
103  {
104  if( this->InWorld ) {
105  this->_GetBaseGraphicsObject()->setVisibilityFlags(0);
106  this->_GetBaseGraphicsObject()->setQueryFlags(0);
107  this->InWorld = false;
108  }
109  }
110 
112  { return this->InWorld; }
113 
115  { return this->Manager; }
116 
117  ///////////////////////////////////////////////////////////////////////////////
118  // RenderableProxy Properties
119 
120  void RenderableProxy::SetVisible(const Boole Visible)
121  { this->_GetBaseGraphicsObject()->setVisible(Visible); }
122 
124  { return this->_GetBaseGraphicsObject()->getVisible(); }
125 
126  void RenderableProxy::SetCastShadows(const Boole CastShadows)
127  { this->_GetBaseGraphicsObject()->setCastShadows(CastShadows); }
128 
130  { return this->_GetBaseGraphicsObject()->getCastShadows(); }
131 
133  { return this->_GetBaseGraphicsObject()->getReceivesShadows(); }
134 
136  { this->_GetBaseGraphicsObject()->setLightMask(Mask); }
137 
139  { return this->_GetBaseGraphicsObject()->getLightMask(); }
140 
142  {
143  this->VisibilityMask = Mask;
144  if( this->InWorld ) {
145  this->_GetBaseGraphicsObject()->setVisibilityFlags( this->VisibilityMask );
146  }
147  }
148 
150  { return this->VisibilityMask; }
151 
153  {
154  this->QueryMask = Mask;
155  if( this->InWorld ) {
156  this->_GetBaseGraphicsObject()->setQueryFlags( this->QueryMask );
157  }
158  }
159 
161  { return this->QueryMask; }
162 
164  { this->_GetBaseGraphicsObject()->setRenderingDistance(Distance); }
165 
167  { return this->_GetBaseGraphicsObject()->getRenderingDistance(); }
168 
169  ///////////////////////////////////////////////////////////////////////////////
170  // Transform Methods
171 
173  { this->GraphicsNode->setPosition( Loc.GetOgreVector3() ); }
174 
175  void RenderableProxy::SetLocation(const Real X, const Real Y, const Real Z)
176  { this->GraphicsNode->setPosition(X,Y,Z); }
177 
179  { return Vector3( this->GraphicsNode->getPosition() ); }
180 
182  { this->GraphicsNode->setOrientation( Ori.GetOgreQuaternion() ); }
183 
184  void RenderableProxy::SetOrientation(const Real X, const Real Y, const Real Z, const Real W)
185  { this->GraphicsNode->setOrientation(W,X,Y,Z); }
186 
188  { return Quaternion( this->GraphicsNode->getOrientation() ); }
189 
191  { this->GraphicsNode->setScale( Sc.GetOgreVector3() ); }
192 
193  void RenderableProxy::SetScale(const Real X, const Real Y, const Real Z)
194  { this->GraphicsNode->setScale(X,Y,Z); }
195 
197  { return Vector3( this->GraphicsNode->getScale() ); }
198 
200  { this->SetLocation( this->GetLocation() + Trans ); }
201 
202  void RenderableProxy::Translate(const Real X, const Real Y, const Real Z)
203  { this->SetLocation( this->GetLocation() + Vector3(X,Y,Z) ); }
204 
205  void RenderableProxy::Yaw(const Real Angle)
206  { this->SetOrientation( this->GetOrientation() * Quaternion(Angle,Vector3::Unit_Y()) ); }
207 
208  void RenderableProxy::Pitch(const Real Angle)
209  { this->SetOrientation( this->GetOrientation() * Quaternion(Angle,Vector3::Unit_X()) ); }
210 
211  void RenderableProxy::Roll(const Real Angle)
212  { this->SetOrientation( this->GetOrientation() * Quaternion(Angle,Vector3::Unit_Z()) ); }
213 
214  void RenderableProxy::Rotate(const Vector3& Axis, const Real Angle)
215  { this->SetOrientation( this->GetOrientation() * Quaternion(Angle,Axis) ); }
216 
217  void RenderableProxy::Rotate(const Quaternion& Rotation)
218  { this->SetOrientation( this->GetOrientation() * Rotation ); }
219 
220  void RenderableProxy::Scale(const Vector3& Scale)
221  { this->SetScale( this->GetScale() * Scale ); }
222 
223  void RenderableProxy::Scale(const Real X, const Real Y, const Real Z)
224  { this->SetScale( this->GetScale() * Vector3(X,Y,Z) ); }
225 
226  ///////////////////////////////////////////////////////////////////////////////
227  // Serialization
228 
230  {
231  this->WorldProxy::ProtoSerializeProperties(SelfRoot);
232 
233  XML::Node PropertiesNode = SelfRoot.AppendChild( RenderableProxy::GetSerializableName() + "Properties" );
234 
235  if( PropertiesNode.AppendAttribute("Version").SetValue("1") &&
236  PropertiesNode.AppendAttribute("Visible").SetValue( this->GetVisible() ? "true" : "false" ) &&
237  PropertiesNode.AppendAttribute("CastShadows").SetValue( this->GetCastShadows() ? "true" : "false" ) &&
238  PropertiesNode.AppendAttribute("LightMask").SetValue( this->GetLightMask() ) &&
239  PropertiesNode.AppendAttribute("VisibilityMask").SetValue( this->GetVisibilityMask() ) &&
240  PropertiesNode.AppendAttribute("QueryMask").SetValue( this->GetQueryMask() ) &&
241  PropertiesNode.AppendAttribute("RenderDistance").SetValue( this->GetRenderDistance() ) )
242  {
243  return;
244  }else{
245  SerializeError("Create XML Attribute Values",RenderableProxy::GetSerializableName() + "Properties",true);
246  }
247  }
248 
250  {
252 
253  XML::Attribute CurrAttrib;
254  XML::Node PropertiesNode = SelfRoot.GetChild( RenderableProxy::GetSerializableName() + "Properties" );
255 
256  if( !PropertiesNode.Empty() ) {
257  if(PropertiesNode.GetAttribute("Version").AsInt() == 1) {
258  CurrAttrib = PropertiesNode.GetAttribute("Visible");
259  if( !CurrAttrib.Empty() )
260  this->SetVisible( StringTools::ConvertToBool( CurrAttrib.AsString() ) );
261 
262  CurrAttrib = PropertiesNode.GetAttribute("CastShadows");
263  if( !CurrAttrib.Empty() )
264  this->SetCastShadows( StringTools::ConvertToBool( CurrAttrib.AsString() ) );
265 
266  CurrAttrib = PropertiesNode.GetAttribute("LightMask");
267  if( !CurrAttrib.Empty() )
268  this->SetLightMask( CurrAttrib.AsWhole() );
269 
270  CurrAttrib = PropertiesNode.GetAttribute("VisibilityMask");
271  if( !CurrAttrib.Empty() )
272  this->SetVisibilityMask( CurrAttrib.AsWhole() );
273 
274  CurrAttrib = PropertiesNode.GetAttribute("QueryMask");
275  if( !CurrAttrib.Empty() )
276  this->SetQueryMask( CurrAttrib.AsWhole() );
277 
278  CurrAttrib = PropertiesNode.GetAttribute("RenderDistance");
279  if( !CurrAttrib.Empty() )
280  this->SetRenderDistance( CurrAttrib.AsReal() );
281  }else{
282  MEZZ_EXCEPTION(ExceptionBase::INVALID_VERSION_EXCEPTION,"Incompatible XML Version for " + (RenderableProxy::GetSerializableName() + "Properties" ) + ": Not Version 1.");
283  }
284  }else{
285  MEZZ_EXCEPTION(ExceptionBase::II_IDENTITY_NOT_FOUND_EXCEPTION,RenderableProxy::GetSerializableName() + "Properties" + " was not found in the provided XML node, which was expected.");
286  }
287  }
288 
291 
293  { return "RenderableProxy"; }
294 
295  ///////////////////////////////////////////////////////////////////////////////
296  // Internal Methods
297 
298  Ogre::SceneNode* RenderableProxy::_GetGraphicsNode() const
299  { return this->GraphicsNode; }
300  }//Graphics
301 }//Mezzanine
302 
303 #endif
virtual void SetQueryMask(const UInt32 Mask)
Sets the bitmesk that will be used to determine if this object should be counted in scene queries...
virtual ~RenderableProxy()
Class destructor.
virtual Boole GetReceiveShadows() const
Gets whether or not this proxy can be rendered with a shadow casted on it.
Attribute AppendAttribute(const Char8 *Name)
Creates an Attribute and puts it at the end of this Nodes attributes.
virtual UInt32 GetLightMask() const
Gets which types of lights will affect this proxy.
virtual void SetLightMask(const UInt32 Mask)
Sets which types of lights will affect this proxy.
virtual UInt32 GetVisibilityMask() const
Gets the bitmask that will be used to determine if this object should be visible when rendering...
virtual void Scale(const Vector3 &Scale)
Scales the object from it's current size.
A light-weight handle for manipulating attributes in DOM tree.
Definition: attribute.h:74
virtual Boole GetVisible() const
Gets whether or not this proxy is visible.
virtual String GetDerivedSerializableName() const
Gets the most derived serializable name of this WorldProxy.
virtual AxisAlignedBox GetAABB() const
Gets this proxies AABB.
bool Boole
Generally acts a single bit, true or false.
Definition: datatypes.h:173
virtual void SetVisible(const Boole Visible)
Sets whether or not this proxy is visible.
This class contains utilities and functions to allow the manipulation of the Graphical scene...
Definition: scenemanager.h:85
virtual void SetOrientation(const Quaternion &Ori)
Sets the orientation of this object in parent space.
virtual Ogre::MovableObject * _GetBaseGraphicsObject() const =0
Accessor for the internal graphics object.
virtual void Roll(const Real Angle)
Rotate the object around the Z axis.
virtual Vector3 GetLocation() const
Gets this objects current location.
virtual Boole GetCastShadows() const
Gets whether or not this proxy can cast a shadow.
This file contains the declaration for the base class from which graphics proxies inherit...
virtual void Translate(const Vector3 &Trans)
Moves this object from it's current location.
Thrown when the requested identity could not be found.
Definition: exception.h:94
#define MEZZ_EXCEPTION(num, desc)
An easy way to throw exceptions with rich information.
Definition: exception.h:3048
SceneManager * Manager
This is a pointer to the scene manager that created and owns this proxy.
Thrown when a version is accessed/parsed/required and it cannot work correctly or is missing...
Definition: exception.h:112
static String GetSerializableName()
Get the name of the the XML tag the proxy class will leave behind as its instances are serialized...
const Char8 * AsString(const Char8 *def="") const
Attempts to convert the value of the attribute to a String and returns the results.
virtual WorldManager * GetCreator() const
Gets a pointer to this proxies creator.
virtual void ProtoDeSerializeProperties(const XML::Node &SelfRoot)
Take the data stored in an XML Node and overwrite the properties of this object with it...
Definition: worldproxy.cpp:129
Any global enumerations shared between multiple classes is to be declared here.
virtual void Rotate(const Vector3 &Axis, const Real Angle)
Rotates the object from it's existing rotation.
virtual void SetVisibilityMask(const UInt32 Mask)
Sets the bitmask that will be used to determine if this object should be visible when rendering...
virtual void SetRenderDistance(const Real Distance)
Sets the distance at which the proxy will stop rendering.
bool Empty() const
Is this storing anything at all?
This implements the exception hiearchy for Mezzanine.
UInt32 QueryMask
This is a bitmask identifying this objects type when being queried. Used for advanced query configura...
Ogre::SceneNode * GraphicsNode
A pointer to the internal object storing the proxy transform.
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.
virtual void ProtoDeSerializeProperties(const XML::Node &SelfRoot)
Take the data stored in an XML Node and overwrite the properties of this object with it...
Whole AsWhole(Whole def=0) const
Attempts to convert the value of the attribute to a Whole and returns the results.
Ogre::Quaternion GetOgreQuaternion(Boole normalize=false) const
Gets a Ogre quaternion.
Definition: quaternion.cpp:263
Boole ConvertToBool(const String &ToConvert, const Boole Default)
Converts a string into a Boole.
Definition: stringtool.cpp:379
virtual Quaternion GetOrientation() const
Gets this objects current orientation.
virtual void SetScale(const Vector3 &Sc)
Sets the scaling to be applied to this object.
A light-weight handle for manipulating nodes in DOM tree.
Definition: node.h:89
int AsInt(int def=0) const
Attempts to convert the value of the attribute to an int and returns the results. ...
This is the base class for proxy objects belonging to the various 3D subsystems.
Definition: worldproxy.h:53
uint32_t UInt32
An 32-bit unsigned integer.
Definition: datatypes.h:126
virtual void ProtoSerializeProperties(XML::Node &SelfRoot) const
Convert the properties of this class to an XML::Node ready for serialization.
Definition: worldproxy.cpp:94
static Vector3 Unit_Y()
Gets a vector representing the Y unit of a Vector3.
Definition: vector3.cpp:134
bool Empty() const
Is this storing anything at all?
virtual void RemoveFromWorld()
Unhooks this proxy from it's respective world.
Ogre::Vector3 GetOgreVector3() const
Gets a Ogre vector3.
Definition: vector3.cpp:572
virtual UInt32 GetQueryMask() const
Gets the bitmask that will be used to determine if this object should be counted in scene queries...
Real AsReal(Real def=0) const
Attempts to convert the value of the attribute to a Real and returns the results. ...
virtual void Pitch(const Real Angle)
Rotate the object around the X axis.
This is the base class for all managers that belong to a single world instance.
Definition: worldmanager.h:55
static Vector3 Unit_X()
Gets a vector representing the X unit of a Vector3.
Definition: vector3.cpp:131
static Vector3 Unit_Z()
Gets a vector representing the Z unit of a Vector3.
Definition: vector3.cpp:137
UInt32 VisibilityMask
This is a bitmask identifying this objects type when being rendered. Used for advanced visibility con...
Ogre::SceneManager * _GetGraphicsWorldPointer() const
Gets the internal Ogre Scene Manager pointer.
This is used to represent a point in space, or a vector through space.
Definition: vector3.h:77
virtual Real GetRenderDistance() const
Gets the distance at which the proxy will stop rendering.
virtual void SetCastShadows(const Boole CastShadows)
Sets whether or not this proxy can cast a shadow.
Boole InWorld
This stores whether the proxy is currently in the graphics world or not.
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56
virtual Boole IsInWorld() const
Gets whether or not this object is inside of it's world.
virtual void SetLocation(const Vector3 &Loc)
Sets the location of this object in parent space.
virtual void AddToWorld()
Performs all the necessary task to ensure this object is connected to it's respective world and ready...
virtual Ogre::SceneNode * _GetGraphicsNode() const
Accessor for the internal node in the scenegraph for this proxy.
This is used to store information about rotation in 3d space.
Definition: quaternion.h:68
RenderableProxy(SceneManager *Creator)
XML-assist Constructor.
virtual void Yaw(const Real Angle)
Rotate the object around the Y axis.
void SerializeError(const String &FailedTo, const String &ClassName, Boole SOrD)
Simply does some string concatenation, then throws an Exception.
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
Attribute GetAttribute(const Char8 *Name) const
Attempt to get an Attribute on this Node with a given name.
virtual Vector3 GetScale() const
Gets the scaling currently being applied to this object.
Node GetChild(const Char8 *Name) const
Attempt to get a child Node with a given name.
virtual void ProtoSerializeProperties(XML::Node &SelfRoot) const
Convert the properties of this class to an XML::Node ready for serialization.
This is a utility class used to represent the Axis-Aligned Bounding Boxes of objects in various subsy...