40 #ifndef _rayquerytool_cpp
41 #define _rayquerytool_cpp
45 #include "rayquerytool.h"
47 #include "actormanager.h"
48 #include "areaeffect.h"
49 #include "areaeffectmanager.h"
52 #include "eventmanager.h"
53 #include "worldobject.h"
56 #include "MathTools/mathtools.h"
62 #include "Graphics/graphicsmanager.h"
63 #include "Graphics/scenemanager.h"
65 #include "Graphics/gamewindow.h"
66 #include "Graphics/viewport.h"
69 #include "Input/mouse.h"
70 #include "Input/inputmanager.h"
72 #include "Internal/meshtools.h.cpp"
93 typedef Ogre::RaySceneQuery* TargetPtrType;
95 typedef Ogre::RaySceneQuery TargetType;
97 Ogre::RaySceneQuery* RayQuery;
103 explicit RayQueryHandle(World* QueryWorld) :
104 ParentWorld(QueryWorld)
110 Graphics::SceneManager* SceneMan =
static_cast<Graphics::SceneManager*
>( this->ParentWorld->GetManager(ManagerBase::MT_SceneManager) );
111 this->RayQuery = SceneMan->_GetGraphicsWorldPointer()->createRayQuery(Ogre::Ray(), Ogre::SceneManager::WORLD_GEOMETRY_TYPE_MASK);
112 this->RayQuery->setSortByDistance(
true);
118 if( this->GetPointer() )
119 {
static_cast<Graphics::SceneManager*
>( this->ParentWorld->GetManager(ManagerBase::MT_SceneManager) )->_GetGraphicsWorldPointer()->destroyQuery(this->RayQuery); }
124 void SetPointer(TargetPtrType Value)
125 { this->RayQuery = Value; }
129 TargetPtrType GetPointer()
130 {
return this->RayQuery; }
133 typedef ManagedPtr<RayQueryHandle> ManagedRayQuery;
140 Boole ExecuteQuery(ManagedRayQuery& RayQuery, Ogre::Ray& Ooray)
143 RayQuery->setRay(Ooray);
144 RayQuery->setQueryMask(-1);
146 if( RayQuery->execute().size() <= 0 )
return false;
149 MEZZ_EXCEPTION(ExceptionBase::PARAMETERS_EXCEPTION,
"Attempting to run a query on Null RaySceneQuery");
158 RayQueryTool::RayQueryTool() :
159 IntersectedObject(NULL),
165 IntersectedObject(NULL),
166 ParentWorld(QueryWorld),
174 { this->ParentWorld = QueryWorld; }
181 this->ValidResult =
false;
183 this->IntersectedObject = NULL;
184 return this->ValidResult;
188 {
return this->ValidResult; }
191 {
return this->Offset; }
194 {
return this->IntersectedObject; }
201 RayQueryHandle ray( this->ParentWorld );
202 ManagedRayQuery RayQuery( ray );
205 if(!ExecuteQuery(RayQuery, Ooray))
215 IntersectedObject=NULL;
216 Ogre::RaySceneQueryResult &query_result = RayQuery->getLastResults();
217 for (
size_t qr_idx = 0; qr_idx < query_result.size(); qr_idx++)
220 if( (0.0f <= closest_distance) && (closest_distance < query_result[qr_idx].distance) )
225 if( (NULL != query_result[qr_idx].movable) && (0 == query_result[qr_idx].movable->getMovableType().compare(
"Entity")) ) {
227 Ogre::Entity *pentity =
static_cast<Ogre::Entity*
>(query_result[qr_idx].movable);
232 if( HitMetaInfo && ( HitMetaInfo->
GetType() & ObjectFlags ) ) {
234 Internal::MeshTools::Vector3Vec vertices;
235 Internal::MeshTools::IntVec indices;
238 Internal::MeshTools::GetTransformedMeshData( pentity, vertices, indices );
241 Boole new_closest_found =
false;
242 for(
size_t i = 0 ; i < indices.size() ; i += 3 )
245 std::pair<bool, Ogre::Real> hit = Ogre::Math::intersects(Ooray, vertices[indices[i]], vertices[indices[i+1]], vertices[indices[i+2]],
true,
false);
248 if( hit.first && ( (0.0f > closest_distance) || (hit.second < closest_distance) ) ) {
249 closest_distance = hit.second;
250 new_closest_found =
true;
255 if( new_closest_found ) {
256 closest_result = Ooray.getPoint(closest_distance);
257 IntersectedObject = Ogre::any_cast<Graphics::RenderableProxy*>(pentity->getUserAny())->GetParentObject();
269 if (IntersectedObject) {
280 RayQueryHandle ray( this->ParentWorld );
281 ManagedRayQuery RayQuery( ray );
283 if(!ExecuteQuery(RayQuery, Ooray))
286 Ogre::RaySceneQueryResult &query_result = RayQuery->getLastResults();
288 if (0 < query_result.size())
290 Ogre::Entity *pentity =
static_cast<Ogre::Entity*
>(query_result[0].movable);
305 MathTools::Point3DTestResult Result = MathTools::Intersects(QueryPlane,QueryRay);
306 this->Offset = Result.second;
307 this->IntersectedObject = NULL;
374 if(HoveredViewport) {
388 if( VersionAttr && VersionAttr.
SetValue(
"1"))
391 if( ResultAttr && ResultAttr.
SetValue(ValidResult))
403 if( WorldObjectAttr )
405 if( IntersectedObject )
434 if( WorldObjectName.size() ) {
436 IntersectedObject =
static_cast<DebrisManager*
>( this->ParentWorld->GetManager(ManagerBase::MT_DebrisManager) )->GetDebris(WorldObjectName);
437 if( IntersectedObject == NULL ) {
438 IntersectedObject =
static_cast<ActorManager*
>( this->ParentWorld->GetManager(ManagerBase::MT_ActorManager) )->GetActor(WorldObjectName);
440 if( IntersectedObject == NULL ) {
441 IntersectedObject =
static_cast<AreaEffectManager*
>( this->ParentWorld->GetManager(ManagerBase::MT_AreaEffectManager) )->GetAreaEffect(WorldObjectName);
444 IntersectedObject = NULL;
455 {
return "RayQueryTool"; }
Attribute AppendAttribute(const Char8 *Name)
Creates an Attribute and puts it at the end of this Nodes attributes.
A light-weight handle for manipulating attributes in DOM tree.
Thrown when an unknown internal error occurred.
bool Boole
Generally acts a single bit, true or false.
bool AsBool(bool def=false) const
Attempts to convert the value of the attribute to a float and returns the results.
virtual Ray GetCameraToViewportRay(const Real ScreenX, const Real ScreenY) const
Gets a Ray from the camera to the viewport.
A manager responsible for the storage and management of all areaeffects in use.
This file contains the declaration for the manager that manages debris objects in a world...
This file contains the declaration for the base class from which graphics proxies inherit...
#define MEZZ_EXCEPTION(num, desc)
An easy way to throw exceptions with rich information.
Thrown when a version is accessed/parsed/required and it cannot work correctly or is missing...
const Char8 * AsString(const Char8 *def="") const
Attempts to convert the value of the attribute to a String and returns the results.
This is the base proxy class for world proxies wrapping functionality of the graphics subsystem...
Whole GetActualWidth() const
Gets the width of the viewport in pixels.
virtual const String & GetName() const
Gets the name of this object.
This is used to represent a flat infinite slice of the game world.
virtual Mezzanine::WorldObjectType GetType() const =0
Gets the type of the object instance.
float Real
A Datatype used to represent a real floating point number.
The interface for serialization.
bool SetValue(const Char8 *rhs)
Set the value of this.
This is the base class from which classes that are insertable into the physical world.
bool SetName(const Char8 *rhs)
Set the name of .
static InputManager * GetSingletonPtr()
Fetches a pointer to the singleton.
This class is for creating and managing viewports within a game window.
Real Y
Coordinate on the Y vector.
This file contains the declaration for the World proxy wrapping camera functionality.
A manager responsible for the storage and management of all Debris that exist in a world...
A light-weight handle for manipulating nodes in DOM tree.
Real X
Coordinate on the X vector.
int AsInt(int def=0) const
Attempts to convert the value of the attribute to an int and returns the results. ...
This is used to represent a point on a 2 dimentional area, such as a screen.
This file contains the declaration for the debris class used to represent a small loose object in the...
Whole GetActualHeight() const
Gets the height of the viewport in pixels.
The interface for a class useful for applying RAII when it should have been used but wasn't...
The base class for all Actors is defined here.
void DeSerializeError(const String &FailedTo, const String &ClassName, Boole SOrD)
Simply does some string concatenation, then throws an Exception.
void ProtoDeSerialize(const XML::Node &OneNode)
Take the data stored in an XML and overwrite this instance of this object with it.
CameraProxy * GetCamera() const
Gets the CameraProxy associated with this viewport.
Thrown when the identity string wasn't valid at all.
This is used to represent a point in space, or a vector through space.
Ogre::Ray GetOgreRay() const
Gets an Ogre::Ray that contains this Rays information.
The bulk of the engine components go in this namspace.
unsigned long Whole
Whole is an unsigned integer, it will be at least 32bits in size.
This class represents a world for objects to interact within.
const Char8 * Name() const
ptrdiff_tGet the name of this Node.
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.
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.
This represents a line placed in 3D space and is used with spacial queries.
Node GetChild(const Char8 *Name) const
Attempt to get a child Node with a given name.
A manager responsible for the storage and management of all actors that exist in a world...