Emergency 20 Dokumentation  4.2.0
RayMapQuery.h
Go to the documentation of this file.
1 // Copyright (C) 2012-2018 Promotion Software GmbH
2 
3 
4 //[-------------------------------------------------------]
5 //[ Header guard ]
6 //[-------------------------------------------------------]
7 #pragma once
8 
9 
10 //[-------------------------------------------------------]
11 //[ Includes ]
12 //[-------------------------------------------------------]
13 #include "em5/Export.h"
14 
15 #include <qsf/base/WeakPtr.h>
17 
18 
19 //[-------------------------------------------------------]
20 //[ Forward declarations ]
21 //[-------------------------------------------------------]
22 namespace Ogre
23 {
24  struct RaySceneQueryResultEntry;
25 }
26 namespace qsf
27 {
28  class Entity;
29  class Prototype;
30  class Transform;
31 }
32 
33 
34 //[-------------------------------------------------------]
35 //[ Namespace ]
36 //[-------------------------------------------------------]
37 namespace em5
38 {
39 
40 
41  //[-------------------------------------------------------]
42  //[ Classes ]
43  //[-------------------------------------------------------]
45  {
46  // Definitions
47  enum Flag
48  {
51  FOR_SELECTION = 1<<3,
52  EXCLUDE_TERRAIN = 1<<4,
54  };
56  typedef boost::function<void(const RayMapQueryResponse&)> Callback;
57 
58  // Data
59  Flags flags;
60  bool success;
62  glm::vec3 position;
63  Callback callback;
64 
66  success(false)
67  { }
68 
69  explicit RayMapQueryResponse(uint8 _flags) :
70  flags(_flags),
71  success(false)
72  { }
73 
74  };
75 
81  {
82 
83 
84  //[-------------------------------------------------------]
85  //[ Public methods ]
86  //[-------------------------------------------------------]
87  public:
95  explicit RayMapQuery(const qsf::Map& map);
96 
104  virtual ~RayMapQuery();
105 
117  void getEntityUnderNormalizedMousePosition(const glm::vec2& normalizedMousePosition, RayMapQueryResponse& rayMapQueryResponse, const IgnoreEntityIds* ignoreEntityIds = nullptr);
118 
130  void getEntityOnMapPosition(const glm::vec3& mapPosition, RayMapQueryResponse& rayMapQueryResponse, const IgnoreEntityIds* ignoreEntityIds = nullptr);
131 
132  void getEntityUnderMousePosition(qsf::Ray& ray, RayMapQueryResponse& rayMapQueryResponse, const IgnoreEntityIds* ignoreEntityIds = nullptr);
133 
134 
135  //[-------------------------------------------------------]
136  //[ Private methods ]
137  //[-------------------------------------------------------]
138  private:
139  void getFirstHitEntityAlongRay(const qsf::Ray& ray, RayMapQueryResponse& rayMapQueryResponse, bool forSelection, const qsf::RayMapQuery::QueryParameters& parameters = qsf::RayMapQuery::QueryParameters());
140  bool isOgreEntityHitByRay(const qsf::Ray& ray, Ogre::Ray& ogreRay, qsf::Prototype& prototype, const qsf::Transform& transform, Ogre::MovableObject& ogreMovableObject, const Ogre::RaySceneQueryResultEntry& iterator, QueryAccuracy queryAccuracy, float& closestDistance, glm::vec3* outPosition = nullptr);
141 
142 
143  };
144 
145 
146 //[-------------------------------------------------------]
147 //[ Namespace ]
148 //[-------------------------------------------------------]
149 } // em5
Definition: ActionPriority.h:13
Exclude the terrain for the check.
Definition: RayMapQuery.h:52
qsf::BitFlagSet< uint8, Flag > Flags
Definition: RayMapQuery.h:55
Asynchronous response; flag will only be used if there's a response callback provided - TODO(co) Rese...
Definition: RayMapQuery.h:49
Definition: RayMapQuery.h:128
Map class.
Definition: Map.h:93
boost::container::flat_set< uint64 > IgnoreEntityIds
Definition: RayMapQuery.h:126
#define EM5_API_EXPORT
Definition: Export.h:28
Class representing a 3D ray, defined by an origin point and a (usually normalized) direction...
Definition: Ray.h:32
Flag
Definition: RayMapQuery.h:47
glm::vec3 position
Receives on success the found world space position, on failure the content is not touched...
Definition: RayMapQuery.h:62
Flags flags
Hint which query response data is required (used for skipping expensive work, inexpensive not require...
Definition: RayMapQuery.h:59
Definition: RayMapQuery.h:44
Callback callback
Query response callback; called in case of asynchronous processing from the main thread.
Definition: RayMapQuery.h:63
QueryAccuracy
Definition: RayMapQuery.h:110
3D transform class
Definition: Transform.h:45
Definition: PickupPersonByParamedicAction.h:21
Exclude the OGRE entities for the check.
Definition: RayMapQuery.h:53
World space position query response data required.
Definition: RayMapQuery.h:50
Ray map query interface.
Definition: RayMapQuery.h:80
qsf::WeakPtr< qsf::Entity > entity
Receives on success the entity the rest of the response data comes from, on failure the content is no...
Definition: RayMapQuery.h:61
RayMapQueryResponse()
Definition: RayMapQuery.h:65
Prototype class.
Definition: Prototype.h:100
Ray map query interface.
Definition: RayMapQuery.h:102
Definition: BuildingClippingManager.h:23
bool success
Set if query was successful, i.e. the ray hit anything at all.
Definition: RayMapQuery.h:60
Indicates if only selectable entities should be returned.
Definition: RayMapQuery.h:51
boost::function< void(const RayMapQueryResponse &)> Callback
Query response callback; called in case of asynchronous processing from the main thread.
Definition: RayMapQuery.h:56
RayMapQueryResponse(uint8 _flags)
Definition: RayMapQuery.h:69
unsigned char uint8
Definition: PlatformTypes.h:175