File: ICmpPosition.h

package info (click to toggle)
0ad 0~r11863-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 30,560 kB
  • sloc: cpp: 201,230; ansic: 28,387; sh: 10,593; perl: 4,847; python: 2,240; makefile: 658; java: 412; xml: 243; sql: 40
file content (161 lines) | stat: -rw-r--r-- 5,527 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/* Copyright (C) 2011 Wildfire Games.
 * This file is part of 0 A.D.
 *
 * 0 A.D. is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * 0 A.D. is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef INCLUDED_ICMPPOSITION
#define INCLUDED_ICMPPOSITION

#include "simulation2/system/Interface.h"

#include "simulation2/helpers/Position.h"
#include "maths/FixedVector3D.h"
#include "maths/FixedVector2D.h"

class CMatrix3D;

/**
 * Represents an entity's position in the world (plus its orientation).
 *
 * Entity positions are determined by the following:
 *   - X, Z coordinates (giving left/right and front/back coordinates on the map)
 *   - Y offset (height; entities always snap to the ground, then are offset by this amount)
 *   - 'Floating' flag (snap to surface of water instead of going underneath)
 * As far as the simulation code is concerned, movements are instantaneous.
 * The only exception is GetInterpolatedTransform, used for rendering, which may
 * interpolate between the previous and current positions.
 * (The "Jump" methods circumvent the interpolation, and should be used whenever immediate
 * movement is needed.)
 *
 * Orientations consist of the following:
 *   - Rotation around upwards 'Y' axis (the common form of rotation)
 *   - Terrain conformance mode, one of:
 *     - Upright (upwards axis is always the world Y axis, e.g. for humans)
 *     - Pitch (rotates backwards and forwards to match the terrain, e.g. for horses)
 *     - PitchRoll (rotates in all directions to match the terrain, e.g. for carts)
 *   - Rotation around relative X (pitch), Z (roll) axes (rare; used for special effects)
 *
 * Entities can also be 'outside the world' (e.g. hidden inside a building), in which
 * case they have no position. Callers <b>must</b> check the entity is in the world, before
 * querying its position.
 */
class ICmpPosition : public IComponent
{
public:
	/**
	 * Returns true if the entity currently exists at a defined position in the world.
	 */
	virtual bool IsInWorld() = 0;

	/**
	 * Causes IsInWorld to return false. (Use MoveTo() or JumpTo() to move back into the world.)
	 */
	virtual void MoveOutOfWorld() = 0;

	/**
	 * Move smoothly to the given location.
	 */
	virtual void MoveTo(entity_pos_t x, entity_pos_t z) = 0;

	/**
	 * Move immediately to the given location, with no interpolation.
	 */
	virtual void JumpTo(entity_pos_t x, entity_pos_t z) = 0;

	/**
	 * Set the vertical offset above the terrain/water surface.
	 */
	virtual void SetHeightOffset(entity_pos_t dy) = 0;

	/**
	 * Returns the current vertical offset above the terrain/water surface.
	 */
	virtual entity_pos_t GetHeightOffset() = 0;

	/**
	 * Set the vertical position as a fixed, absolute value.
	 * Will stay at this height until the next call to SetHeightFixed or SetHeightOffset.
	 */
	virtual void SetHeightFixed(entity_pos_t y) = 0;

	/**
	 * Returns whether the entity floats on water.
	 */
	virtual bool IsFloating() = 0;

	/**
	 * Returns the current x,y,z position (no interpolation).
	 * Depends on the current terrain heightmap.
	 * Must not be called unless IsInWorld is true.
	 */
	virtual CFixedVector3D GetPosition() = 0;

	/**
	 * Returns the current x,z position (no interpolation).
	 * Must not be called unless IsInWorld is true.
	 */
	virtual CFixedVector2D GetPosition2D() = 0;

	/**
	 * Rotate smoothly to the given angle around the upwards axis.
	 * @param y clockwise radians from the +Z axis.
	 */
	virtual void TurnTo(entity_angle_t y) = 0;

	/**
	 * Rotate immediately to the given angle around the upwards axis.
	 * @param y clockwise radians from the +Z axis.
	 */
	virtual void SetYRotation(entity_angle_t y) = 0;

	/**
	 * Rotate immediately to the given angles around the X (pitch) and Z (roll) axes.
	 * @param x radians around the X axis. (TODO: in which direction?)
	 * @param z radians around the Z axis.
	 */
	virtual void SetXZRotation(entity_angle_t x, entity_angle_t z) = 0;

	// NOTE: we separate Y from XZ because most code will only ever change Y;
	// XZ are typically just used in the editor, and other code should never
	// worry about them

	/**
	 * Returns the current rotation (relative to the upwards axis), as Euler
	 * angles with X=pitch, Y=yaw, Z=roll. (TODO: is that the right way round?)
	 */
	virtual CFixedVector3D GetRotation() = 0;

	/**
	 * Returns the distance that the unit will be interpolated over,
	 * i.e. the distance travelled since the start of the turn.
	 */
	virtual fixed GetDistanceTravelled() = 0;

	/**
	 * Get the current interpolated 2D position and orientation, for rendering.
	 * Must not be called unless IsInWorld is true.
	 */
	virtual void GetInterpolatedPosition2D(float frameOffset, float& x, float& z, float& rotY) = 0;

	/**
	 * Get the current interpolated transform matrix, for rendering.
	 * Must not be called unless IsInWorld is true.
	 */
	virtual CMatrix3D GetInterpolatedTransform(float frameOffset, bool forceFloating) = 0;

	DECLARE_INTERFACE_TYPE(Position)
};

#endif // INCLUDED_ICMPPOSITION