18 #include "precompiled.h"
88 "<a:help>Allows this entity to exist at a location (and orientation) in the world, and defines some details of the positioning.</a:help>"
90 "<Anchor>upright</Anchor>"
91 "<Altitude>0.0</Altitude>"
92 "<Floating>false</Floating>"
93 "<TurnRate>6.0</TurnRate>"
95 "<element name='Anchor' a:help='Automatic rotation to follow the slope of terrain'>"
97 "<value a:help='Always stand straight up (e.g. humans)'>upright</value>"
98 "<value a:help='Rotate backwards and forwards to follow the terrain (e.g. animals)'>pitch</value>"
99 "<value a:help='Rotate sideways to follow the terrain'>roll</value>"
100 "<value a:help='Rotate in all directions to follow the terrain (e.g. carts)'>pitch-roll</value>"
103 "<element name='Altitude' a:help='Height above terrain in metres'>"
104 "<data type='decimal'/>"
106 "<element name='Floating' a:help='Whether the entity floats on water'>"
107 "<data type='boolean'/>"
109 "<element name='TurnRate' a:help='Maximum graphical rotation speed around Y axis, in radians per second'>"
110 "<ref name='positiveDecimal'/>"
117 if (anchor == L
"pitch")
119 else if (anchor == L
"pitch-roll")
121 else if (anchor == L
"roll")
163 const char* anchor =
"???";
171 anchor =
"pitch-roll";
300 LOGERROR(L
"CCmpPosition::GetPosition called on entity when IsInWorld is false");
326 LOGERROR(L
"CCmpPosition::GetPosition2D called on entity when IsInWorld is false");
337 LOGERROR(L
"CCmpPosition::GetPreviousPosition called on entity when IsInWorld is false");
363 LOGERROR(L
"CCmpPosition::GetPreviousPosition2D called on entity when IsInWorld is false");
418 LOGERROR(L
"CCmpPosition::GetDistanceTravelled called on entity when IsInWorld is false");
429 LOGERROR(L
"CCmpPosition::GetInterpolatedPosition2D called on entity when IsInWorld is false");
443 LOGERROR(L
"CCmpPosition::GetInterpolatedTransform called on entity when IsInWorld is false");
476 m.RotateY(rotY + (
float)
M_PI);
496 delta = fmodf(delta + (
float)
M_PI, 2*(
float)M_PI);
497 if (delta < 0) delta += 2*(float)M_PI;
498 delta -= (float)M_PI;
503 m_InterpolatedRotY = rotY + deltaClamped - delta;
566 LOGERROR(L
"CCmpPosition::UpdateXZRotation called on entity when IsInWorld is false");
579 if (!cmpTerrain || !cmpTerrain->
IsLoaded())
593 normal.
X = projected.
X;
594 normal.
Z = projected.
Y;
An entity initialisation parameter node.
virtual CFixedVector3D GetPreviousPosition()
Returns the previous turn's x,y,z position (no interpolation).
void SubscribeToMessageType(MessageTypeId mtid)
Subscribe the current component type to the given message type.
A simple fixed-point number class.
virtual entity_pos_t GetGroundLevel(entity_pos_t x, entity_pos_t z)=0
bool m_NeedInitialXZRotation
entity_pos_t m_LastYOffset
virtual entity_pos_t GetWaterLevel(entity_pos_t x, entity_pos_t z)=0
Get the current water level at the given point.
#define REGISTER_COMPONENT_TYPE(cname)
virtual CFixedVector3D GetPosition()
Returns the current x,y,z position (no interpolation).
void NumberFixed_Unbounded(const char *name, fixed value)
Serialize a number.
virtual void Bool(const char *name, bool &out)
#define UNUSED(param)
mark a function parameter as unused and avoid the corresponding compiler warning. ...
bool ToBool() const
Parses the content of this node as a boolean ("true" == true, anything else == false) ...
T Interpolate(const T &a, const T &b, float l)
const std::wstring & ToString() const
Returns the content of this node as a string.
static std::string GetSchema()
virtual bool IsDebug() const
Returns true if the serializer is being used in debug mode.
void Rotate(float angle)
Rotates this vector counterclockwise by angle radians.
Serialization interface; see serialization overview.
virtual float GetExactGroundLevel(float x, float z)=0
virtual CMatrix3D GetInterpolatedTransform(float frameOffset, bool forceFloating)
Get the current interpolated transform matrix, for rendering.
virtual void SetHeightFixed(entity_pos_t y)
Set the vertical position as a fixed, absolute value.
Represents an entity's position in the world (plus its orientation).
virtual bool IsInWorld()
Returns true if the entity currently exists at a defined position in the world.
virtual void NumberFixed_Unbounded(const char *name, fixed &out)
float deltaSimTime
Elapsed simulation time since previous interpolate, in seconds.
virtual void Deserialize(const CParamNode ¶mNode, IDeserializer &deserialize)
fixed ToFixed() const
Parses the content of this node as a fixed-point number.
virtual CFixedVector3D GetRotation()
Returns the current rotation (relative to the upwards axis), as Euler angles with X=pitch...
entity_id_t GetEntityId() const
virtual int GetType() const =0
const CParamNode & GetChild(const char *name) const
Returns the (unique) child node with the given name, or a node with IsOk() == false if there is none...
virtual CVector3D CalcExactNormal(float x, float z)=0
virtual void Init(const CParamNode ¶mNode)
void StringASCII(const char *name, const std::string &value, uint32_t minlength, uint32_t maxlength)
Serialize an ASCII string.
virtual void JumpTo(entity_pos_t x, entity_pos_t z)
Move immediately to the given location, with no interpolation.
virtual void SetXZRotation(entity_angle_t x, entity_angle_t z)
Rotate immediately to the given angles around the X (pitch) and Z (roll) axes.
float ToFloat() const
Convert to float. May be lossy - float can't represent all values.
virtual void TurnTo(entity_angle_t y)
Rotate smoothly to the given angle around the upwards axis.
static void ClassInit(CComponentManager &componentManager)
virtual float GetExactWaterLevel(float x, float z)=0
Get the current water level at the given point.
Basic ICmpPosition implementation.
void Bool(const char *name, bool value)
Serialize a boolean.
#define DEFAULT_COMPONENT_ALLOCATOR(cname)
virtual void SetHeightOffset(entity_pos_t dy)
Set the vertical offset above the terrain/water surface.
const CSimContext & GetSimContext() const
A simplified syntax for accessing entity components.
CEntityHandle GetSystemEntity() const
static CFixed FromInt(int n)
virtual void Serialize(ISerializer &serialize)
void PostMessage(entity_id_t ent, const CMessage &msg) const
Send a message, targeted at a particular entity.
fixed Length() const
Returns the length of the vector.
virtual void SetYRotation(entity_angle_t y)
Rotate immediately to the given angle around the upwards axis.
virtual CFixedVector2D GetPreviousPosition2D()
Returns the previous turn's x,z position (no interpolation).
virtual void MoveOutOfWorld()
Causes IsInWorld to return false.
virtual void MoveTo(entity_pos_t x, entity_pos_t z)
Move smoothly to the given location.
virtual void HandleMessage(const CMessage &msg, bool global)
bool IsZero() const
Returns true if the number is precisely 0.
virtual bool IsFloating()
Returns whether the entity floats on water.
virtual CFixedVector2D GetPosition2D()
Returns the current x,z position (no interpolation).
float m_LastInterpolatedRotZ
void SetXRotation(float angle)
virtual void GetInterpolatedPosition2D(float frameOffset, float &x, float &z, float &rotY)
Get the current interpolated 2D position and orientation, for rendering.
virtual bool IsLoaded()=0
virtual fixed GetDistanceTravelled()
Returns the distance that the unit will be interpolated over, i.e.
Prepare for rendering a new frame (set up model positions etc).
T clamp(T value, T min, T max)
float m_LastInterpolatedRotX
CComponentManager & GetComponentManager() const
void AdvertisePositionChanges()
Deserialization interface; see serialization overview.
virtual entity_pos_t GetHeightOffset()
Returns the current vertical offset above the terrain/water surface.
enum CCmpPosition::@56 m_AnchorType