Spinning Topp Logo BlackTopp Studios
inc
rayquerytool.h
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 _rayquerytool_h
41 #define _rayquerytool_h
42 
43 #include "datatypes.h"
44 #include "crossplatformexport.h"
45 #include "vector3.h"
46 
47 namespace Ogre
48 {
49  class RaySceneQuery;
50  class Vector3;
51  class Quaternion;
52  class Entity;
53 }
54 
55 namespace Mezzanine
56 {
57  class Plane;
58  class Ray;
59  class WorldObject;
60  class World;
61  ///////////////////////////////////////////////////////////////////////////////
62  /// @class RayQueryTool
63  /// @brief This provides a number of optional tools for working with a Mezzanine::World
64  /// @details Currently this allows for more seamless mouse use, including 'picking'
65  /// of objects with the mouse, and associated functionality.
66  ///////////////////////////////////////
68  {
69  private:
70  /// @brief An Offset or location from something meaningful to the last query.
71  Vector3 Offset;
72  /// @brief If there is an WorldObject result to a query the result will be stored in this.
73  /// @warning This is weak reference, Some other system could delete out from under us and we cannot delete this.
74  WorldObject* IntersectedObject;
75  /// @brief The world to perform queries in.
76  World* ParentWorld;
77  /// @brief True if the last Query yielded a meaningful Result.
78  Boole ValidResult;
79  public:
80  /// @brief Blank constructor.
81  /// @warning A world must be set before using this class.
82  RayQueryTool();
83  /// @brief Create a RayQueryTool ready for querying.
84  /// @param QueryWorld The world in which to perform the ray queries.
85  RayQueryTool(World* QueryWorld);
86 
87  ///////////////////////////////////////////////////////////////////////////////
88  // Utility
89 
90  /// @brief Sets the World in which the ray query is to be performed.
91  /// @param QueryWorld The world in which to perform the ray queries.
92  void SetWorld(World* QueryWorld);
93 
94  ///////////////////////////////////////////////////////////////////////////////
95  // Query Results
96 
97  /// @brief Clears an previously stored return values.
98  /// @brief returns false.
99  Boole ClearReturns();
100  /// @brief Check to see if the last query found anything.
101  /// @return True if something was found, false otherwise.
102  Boole LastQueryResultsValid() const;
103  /// @brief Get an offset from the last query. Depending on the last query, this could be an Offset from a variety of things.
104  /// @return A Vector3 if the last query worked and returns an Offset, A empty vector otherwise. Use LastQueryResultsValid() Prior to this.
105  Vector3 LastQueryResultsOffset() const;
106  /// @brief It is common to ray query for WorldObjects, if so the results can be retrieved with this.
107  /// @return A pointer to an WorldObject if the last query returns a WorldObject and worked, a Null pointer otherwise. Use LastQueryResultsValid() Prior to this.
108  /// @warning Does not confer ownership of WorldObject, do not delete pointers returned by this unless you have taken special steps.
109  WorldObject* LastQueryResultsObjectPtr() const;
110 
111  ///////////////////////////////////////////////////////////////////////////////
112  // Ray Queries
113 
114  /// @brief This will find the first Object to intesect the Given ray.
115  /// @details This use the graphics subsystem to cast a ray in the world. If the ray passes through any the triangles in an actor
116  /// This will return that actor. This function runs in linear time relative to the amount of triangles in 3d meshes near the the
117  /// ray being cast. This will start at ray.from and go to ray.to .
118  /// @param ActorRay The Ray to search along.
119  /// @param ObjectFlags A whole comprising all the valid objects to be checked in the scene.
120  /// See WorldAndSceneObjectType in enumerations.h for a listing of objects to use as flags.
121  /// @return True if something is found, false otherwise. Use LastQueryResultsOffset() and LastQueryResultsActorPtr() for more details.
122  Boole GetFirstObjectOnRayByPolygon(Ray ObjectRay, Whole ObjectFlags);
123  /// @brief Partially implemented. This should find the first Object that is on or almost on the a given Ray.
124  /// @details This casts a ray through the gameworld. The first actor with an Axis Aligned Bounding Box that intersects that ray is returned.
125  /// Presently this is untested and does not return the Offset of the intersection. This should perform faster than WorldQueryTool::GetFirstActorOnRayByPolygon
126  /// but not by a known amount.
127  /// @param ActorRay The Ray to search along.
128  /// @param ObjectFlags A whole comprising all the valid objects to be checked in the scene.
129  /// See WorldAndSceneObjectType in enumerations.h for a listing of objects to use as flags.
130  /// @return True if something is found, false otherwise. Use LastQueryResultsActorPtr() for more details. Any return Offset is empty
131  Boole GetFirstObjectOnRayByAABB(Ray ObjectRay, Whole ObjectFlags);
132  /// @brief Where does this Ray Meet this Plane?
133  /// @details This does some fancy math to return the point where the ray and the plane intersent.
134  /// @param QueryRay This is the Ray that could intersent the plane
135  /// @param QueryPlane This is the plane to be interesected.
136  /// @return True if something is found, false otherwise. Use LastQueryResultsOffset() for more details. Any return Actor Pointer is NULL;
137  Boole RayPlaneIntersection(const Ray& QueryRay, const Plane& QueryPlane);
138 
139  /// @brief Get a Ray from the current viewport, following the mouse
140  /// @details This calls on the graphics subsystem to get a ray from the location of the current camera
141  /// @return This returns a ray that matches originates at the camera and goes out in 3d space behind the mouse pointer.
142  static Ray GetMouseRay();
143 
144  ///////////////////////////////////////////////////////////////////////////////
145  // Serialization
146 
147  /// @brief Convert this class to an XML::Node ready for serialization
148  /// @param CurrentRoot The point in the XML hierarchy that all this vector3 should be appended to.
149  void ProtoSerialize(XML::Node& CurrentRoot) const;
150  /// @brief Take the data stored in an XML and overwrite this instance of this object with it
151  /// @param OneNode and XML::Node containing the data.
152  void ProtoDeSerialize(const XML::Node& OneNode);
153  /// @brief Get the name of the the XML tag this class will leave behind as its instances are serialized.
154  /// @return A string containing "Vector3"
155  static String GetSerializableName();
156  };//RayQueryTool
157 }//Mezzanine
158 
159 #endif
bool Boole
Generally acts a single bit, true or false.
Definition: datatypes.h:173
This file is used on some platforms to determine what data should be read and written to and from a s...
All the definitions for datatypes as well as some basic conversion functions are defined here...
This is used to represent a flat infinite slice of the game world.
Definition: plane.h:65
This is the base class from which classes that are insertable into the physical world.
Definition: worldobject.h:60
A light-weight handle for manipulating nodes in DOM tree.
Definition: node.h:89
This is used to represent a point in space, or a vector through space.
Definition: vector3.h:77
#define MEZZ_LIB
Some platforms require special decorations to denote what is exported/imported in a share library...
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56
unsigned long Whole
Whole is an unsigned integer, it will be at least 32bits in size.
Definition: datatypes.h:151
This provides a number of optional tools for working with a Mezzanine::World.
Definition: rayquerytool.h:67
This class represents a world for objects to interact within.
Definition: world.h:74
std::string String
A datatype used to a series of characters.
Definition: datatypes.h:159
This represents a line placed in 3D space and is used with spacial queries.
Definition: ray.h:67