Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ICmpPosition.h
Go to the documentation of this file.
1 /* Copyright (C) 2013 Wildfire Games.
2  * This file is part of 0 A.D.
3  *
4  * 0 A.D. 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 2 of the License, or
7  * (at your option) any later version.
8  *
9  * 0 A.D. 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 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef INCLUDED_ICMPPOSITION
19 #define INCLUDED_ICMPPOSITION
20 
22 
24 #include "maths/FixedVector3D.h"
25 #include "maths/FixedVector2D.h"
26 
27 class CMatrix3D;
28 
29 /**
30  * Represents an entity's position in the world (plus its orientation).
31  *
32  * Entity positions are determined by the following:
33  * - X, Z coordinates (giving left/right and front/back coordinates on the map)
34  * - Y offset (height; entities always snap to the ground, then are offset by this amount)
35  * - 'Floating' flag (snap to surface of water instead of going underneath)
36  * As far as the simulation code is concerned, movements are instantaneous.
37  * The only exception is GetInterpolatedTransform, used for rendering, which may
38  * interpolate between the previous and current positions.
39  * (The "Jump" methods circumvent the interpolation, and should be used whenever immediate
40  * movement is needed.)
41  *
42  * Orientations consist of the following:
43  * - Rotation around upwards 'Y' axis (the common form of rotation)
44  * - Terrain conformance mode, one of:
45  * - Upright (upwards axis is always the world Y axis, e.g. for humans)
46  * - Pitch (rotates backwards and forwards to match the terrain, e.g. for horses)
47  * - Pitch-Roll (rotates in all directions to match the terrain, e.g. for carts)
48  * - Roll (rotates sideways to match the terrain)
49  * NOTE: terrain conformance is currently only a local, visual effect; it doesn't change
50  * the network synchronized rotation or the data returned by GetRotation
51  * - Rotation around relative X (pitch), Z (roll) axes (rare; used for special effects)
52  * NOTE: if XZ rotation is non-zero, it will override the terrain conformance mode
53  *
54  * Entities can also be 'outside the world' (e.g. hidden inside a building), in which
55  * case they have no position. Callers <b>must</b> check the entity is in the world, before
56  * querying its position.
57  */
58 class ICmpPosition : public IComponent
59 {
60 public:
61  /**
62  * Returns true if the entity currently exists at a defined position in the world.
63  */
64  virtual bool IsInWorld() = 0;
65 
66  /**
67  * Causes IsInWorld to return false. (Use MoveTo() or JumpTo() to move back into the world.)
68  */
69  virtual void MoveOutOfWorld() = 0;
70 
71  /**
72  * Move smoothly to the given location.
73  */
74  virtual void MoveTo(entity_pos_t x, entity_pos_t z) = 0;
75 
76  /**
77  * Move immediately to the given location, with no interpolation.
78  */
79  virtual void JumpTo(entity_pos_t x, entity_pos_t z) = 0;
80 
81  /**
82  * Set the vertical offset above the terrain/water surface.
83  */
84  virtual void SetHeightOffset(entity_pos_t dy) = 0;
85 
86  /**
87  * Returns the current vertical offset above the terrain/water surface.
88  */
89  virtual entity_pos_t GetHeightOffset() = 0;
90 
91  /**
92  * Set the vertical position as a fixed, absolute value.
93  * Will stay at this height until the next call to SetHeightFixed or SetHeightOffset.
94  */
95  virtual void SetHeightFixed(entity_pos_t y) = 0;
96 
97  /**
98  * Returns whether the entity floats on water.
99  */
100  virtual bool IsFloating() = 0;
101 
102  /**
103  * Returns the current x,y,z position (no interpolation).
104  * Depends on the current terrain heightmap.
105  * Must not be called unless IsInWorld is true.
106  */
107  virtual CFixedVector3D GetPosition() = 0;
108 
109  /**
110  * Returns the current x,z position (no interpolation).
111  * Must not be called unless IsInWorld is true.
112  */
113  virtual CFixedVector2D GetPosition2D() = 0;
114 
115  /**
116  * Returns the previous turn's x,y,z position (no interpolation).
117  * Depends on the current terrain heightmap.
118  * Must not be called unless IsInWorld is true.
119  */
120  virtual CFixedVector3D GetPreviousPosition() = 0;
121 
122  /**
123  * Returns the previous turn's x,z position (no interpolation).
124  * Must not be called unless IsInWorld is true.
125  */
126  virtual CFixedVector2D GetPreviousPosition2D() = 0;
127 
128  /**
129  * Rotate smoothly to the given angle around the upwards axis.
130  * @param y clockwise radians from the +Z axis.
131  */
132  virtual void TurnTo(entity_angle_t y) = 0;
133 
134  /**
135  * Rotate immediately to the given angle around the upwards axis.
136  * @param y clockwise radians from the +Z axis.
137  */
138  virtual void SetYRotation(entity_angle_t y) = 0;
139 
140  /**
141  * Rotate immediately to the given angles around the X (pitch) and Z (roll) axes.
142  * @param x radians around the X axis. (TODO: in which direction?)
143  * @param z radians around the Z axis.
144  * @note if either x or z is non-zero, it will override terrain conformance mode
145  */
146  virtual void SetXZRotation(entity_angle_t x, entity_angle_t z) = 0;
147 
148  // NOTE: we separate Y from XZ because most code will only ever change Y;
149  // XZ are typically just used in the editor, and other code should never
150  // worry about them
151 
152  /**
153  * Returns the current rotation (relative to the upwards axis), as Euler
154  * angles with X=pitch, Y=yaw, Z=roll. (TODO: is that the right way round?)
155  */
156  virtual CFixedVector3D GetRotation() = 0;
157 
158  /**
159  * Returns the distance that the unit will be interpolated over,
160  * i.e. the distance travelled since the start of the turn.
161  */
162  virtual fixed GetDistanceTravelled() = 0;
163 
164  /**
165  * Get the current interpolated 2D position and orientation, for rendering.
166  * Must not be called unless IsInWorld is true.
167  */
168  virtual void GetInterpolatedPosition2D(float frameOffset, float& x, float& z, float& rotY) = 0;
169 
170  /**
171  * Get the current interpolated transform matrix, for rendering.
172  * Must not be called unless IsInWorld is true.
173  */
174  virtual CMatrix3D GetInterpolatedTransform(float frameOffset, bool forceFloating) = 0;
175 
176  DECLARE_INTERFACE_TYPE(Position)
177 };
178 
179 #endif // INCLUDED_ICMPPOSITION
A simple fixed-point number class.
Definition: Fixed.h:115
virtual CFixedVector3D GetPreviousPosition()=0
Returns the previous turn&#39;s x,y,z position (no interpolation).
virtual CFixedVector3D GetRotation()=0
Returns the current rotation (relative to the upwards axis), as Euler angles with X=pitch...
Represents an entity&#39;s position in the world (plus its orientation).
Definition: ICmpPosition.h:58
virtual CMatrix3D GetInterpolatedTransform(float frameOffset, bool forceFloating)=0
Get the current interpolated transform matrix, for rendering.
virtual bool IsInWorld()=0
Returns true if the entity currently exists at a defined position in the world.
virtual CFixedVector2D GetPreviousPosition2D()=0
Returns the previous turn&#39;s x,z position (no interpolation).
virtual void MoveOutOfWorld()=0
Causes IsInWorld to return false.
virtual fixed GetDistanceTravelled()=0
Returns the distance that the unit will be interpolated over, i.e.
virtual void SetYRotation(entity_angle_t y)=0
Rotate immediately to the given angle around the upwards axis.
virtual void TurnTo(entity_angle_t y)=0
Rotate smoothly to the given angle around the upwards axis.
virtual CFixedVector2D GetPosition2D()=0
Returns the current x,z position (no interpolation).
#define DECLARE_INTERFACE_TYPE(iname)
Definition: Interface.h:23
virtual void MoveTo(entity_pos_t x, entity_pos_t z)=0
Move smoothly to the given location.
virtual void GetInterpolatedPosition2D(float frameOffset, float &x, float &z, float &rotY)=0
Get the current interpolated 2D position and orientation, for rendering.
virtual CFixedVector3D GetPosition()=0
Returns the current x,y,z position (no interpolation).
virtual void JumpTo(entity_pos_t x, entity_pos_t z)=0
Move immediately to the given location, with no interpolation.
virtual entity_pos_t GetHeightOffset()=0
Returns the current vertical offset above the terrain/water surface.
Entity coordinate types.
virtual void SetHeightOffset(entity_pos_t dy)=0
Set the vertical offset above the terrain/water surface.
virtual void SetHeightFixed(entity_pos_t y)=0
Set the vertical position as a fixed, absolute value.
virtual void SetXZRotation(entity_angle_t x, entity_angle_t z)=0
Rotate immediately to the given angles around the X (pitch) and Z (roll) axes.
virtual bool IsFloating()=0
Returns whether the entity floats on water.