Luanti 5.15.0-dev
 
Loading...
Searching...
No Matches
activeobject.h
Go to the documentation of this file.
1// Luanti
2// SPDX-License-Identifier: LGPL-2.1-or-later
3// Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5#pragma once
6
7#include "irr_aabb3d.h"
8#include "irr_v3d.h"
9#include <quaternion.h>
10#include <string>
11#include <unordered_map>
12
13
17// Obsolete stuff
18// ACTIVEOBJECT_TYPE_ITEM = 2,
19// ACTIVEOBJECT_TYPE_RAT = 3,
20// ACTIVEOBJECT_TYPE_OERKKI1 = 4,
21// ACTIVEOBJECT_TYPE_FIREFLY = 5,
22// ACTIVEOBJECT_TYPE_MOBV2 = 6,
23// End obsolete stuff
25// Special type, not stored as a static object
27// Special type, only exists as CAO
29};
30// Other types are defined in content_object.h
31
33{
34 ActiveObjectMessage(u16 id_, bool reliable_=true, std::string_view data_ = "") :
35 id(id_),
36 reliable(reliable_),
37 datastring(data_)
38 {}
39
40 u16 id;
42 std::string datastring;
43};
44
61
63{
71
72 v3f getPosition(v3f anim_pos) const {
73 f32 progress = dtime_passed / position.interp_duration;
74 if (progress > 1.0f || position.interp_duration == 0.0f)
75 progress = 1.0f;
76 return position.vector.getInterpolated(position.previous, progress)
77 + (position.absolute ? v3f() : anim_pos);
78 }
79
81 {
82 core::quaternion previous;
83 core::quaternion next;
84 // Redundantly store the euler angles serverside
85 // so that we can return them in the appropriate getters
87 bool absolute = false;
88 f32 interp_duration = 0.0f;
90
91 v3f getRotationEulerDeg(v3f anim_rot_euler) const {
92 core::quaternion rot;
93
94 f32 progress = dtime_passed / rotation.interp_duration;
95 if (progress > 1.0f || rotation.interp_duration == 0.0f)
96 progress = 1.0f;
97 rot.slerp(rotation.previous, rotation.next, progress);
98 if (!rotation.absolute) {
99 core::quaternion anim_rot(anim_rot_euler * core::DEGTORAD);
100 rot = rot * anim_rot; // first rotate by anim. bone rot., then rot.
101 }
102
103 v3f rot_euler;
104 rot.toEuler(rot_euler);
105 return rot_euler * core::RADTODEG;
106 }
107
109 {
110 v3f previous = v3f(1.0f);
111 v3f vector = v3f(1.0f);
112 bool absolute = false;
113 f32 interp_duration = 0.0f;
115
116 v3f getScale(v3f anim_scale) const {
117 f32 progress = dtime_passed / scale.interp_duration;
118 if (progress > 1.0f || scale.interp_duration == 0.0f)
119 progress = 1.0f;
120 return scale.vector.getInterpolated(scale.previous, progress)
121 * (scale.absolute ? v3f(1.0f) : anim_scale);
122 }
123
124 f32 dtime_passed = 0.0f;
125
127 {
128 return dtime_passed >= std::max(std::max(
131 }
132
133 bool isIdentity() const
134 {
135 return finishedInterpolation()
137 && !rotation.absolute && rotation.next == core::quaternion()
138 && !scale.absolute && scale.vector == v3f(1.0f);
139 }
140};
141
142typedef std::unordered_map<std::string, BoneOverride> BoneOverrideMap;
143
144
145/*
146 Parent class for ServerActiveObject and ClientActiveObject
147*/
149{
150public:
151 typedef u16 object_t;
152
154 m_id(id)
155 {
156 }
157
159 {
160 return m_id;
161 }
162
164 {
165 m_id = id;
166 }
167
168 virtual ActiveObjectType getType() const = 0;
169
170
178 virtual bool getCollisionBox(aabb3f *toset) const = 0;
179
180
188 virtual bool getSelectionBox(aabb3f *toset) const = 0;
189
190
191 virtual bool collideWithObjects() const = 0;
192
193
194 virtual void setAttachment(object_t parent_id, const std::string &bone, v3f position,
195 v3f rotation, bool force_visible) {}
196 virtual void getAttachment(object_t *parent_id, std::string *bone, v3f *position,
197 v3f *rotation, bool *force_visible) const {}
198 // Detach all children
199 virtual void clearChildAttachments() {}
200 // Detach from parent
202 {
203 setAttachment(0, "", v3f(), v3f(), false);
204 }
205
206 // To be be called from setAttachment() and descendants, but not manually!
207 virtual void addAttachmentChild(object_t child_id) {}
208 virtual void removeAttachmentChild(object_t child_id) {}
209
210protected:
211 object_t m_id; // 0 is invalid, "no id"
212};
std::unordered_map< std::string, BoneOverride > BoneOverrideMap
Definition activeobject.h:142
ActiveObjectCommand
Definition activeobject.h:45
@ AO_CMD_SET_TEXTURE_MOD
Definition activeobject.h:48
@ AO_CMD_OBSOLETE1
Definition activeobject.h:56
@ AO_CMD_SPAWN_INFANT
Definition activeobject.h:58
@ AO_CMD_SET_PROPERTIES
Definition activeobject.h:46
@ AO_CMD_PUNCHED
Definition activeobject.h:50
@ AO_CMD_UPDATE_POSITION
Definition activeobject.h:47
@ AO_CMD_SET_PHYSICS_OVERRIDE
Definition activeobject.h:55
@ AO_CMD_SET_ANIMATION
Definition activeobject.h:52
@ AO_CMD_SET_ANIMATION_SPEED
Definition activeobject.h:59
@ AO_CMD_ATTACH_TO
Definition activeobject.h:54
@ AO_CMD_UPDATE_ARMOR_GROUPS
Definition activeobject.h:51
@ AO_CMD_SET_BONE_POSITION
Definition activeobject.h:53
@ AO_CMD_SET_SPRITE
Definition activeobject.h:49
ActiveObjectType
Definition activeobject.h:14
@ ACTIVEOBJECT_TYPE_TEST
Definition activeobject.h:16
@ ACTIVEOBJECT_TYPE_PLAYER
Definition activeobject.h:26
@ ACTIVEOBJECT_TYPE_INVALID
Definition activeobject.h:15
@ ACTIVEOBJECT_TYPE_GENERIC
Definition activeobject.h:28
@ ACTIVEOBJECT_TYPE_LUAENTITY
Definition activeobject.h:24
Definition activeobject.h:149
virtual void clearParentAttachment()
Definition activeobject.h:201
object_t getId() const
Definition activeobject.h:158
virtual void setAttachment(object_t parent_id, const std::string &bone, v3f position, v3f rotation, bool force_visible)
Definition activeobject.h:194
virtual bool getCollisionBox(aabb3f *toset) const =0
ActiveObject(object_t id)
Definition activeobject.h:153
virtual void clearChildAttachments()
Definition activeobject.h:199
virtual void removeAttachmentChild(object_t child_id)
Definition activeobject.h:208
virtual void addAttachmentChild(object_t child_id)
Definition activeobject.h:207
virtual bool collideWithObjects() const =0
object_t m_id
Definition activeobject.h:211
void setId(object_t id)
Definition activeobject.h:163
virtual ActiveObjectType getType() const =0
virtual bool getSelectionBox(aabb3f *toset) const =0
u16 object_t
Definition activeobject.h:151
virtual void getAttachment(object_t *parent_id, std::string *bone, v3f *position, v3f *rotation, bool *force_visible) const
Definition activeobject.h:196
core::aabbox3d< f32 > aabb3f
Definition irr_aabb3d.h:11
core::vector3df v3f
Definition irr_v3d.h:11
Definition activeobject.h:33
ActiveObjectMessage(u16 id_, bool reliable_=true, std::string_view data_="")
Definition activeobject.h:34
std::string datastring
Definition activeobject.h:42
u16 id
Definition activeobject.h:40
bool reliable
Definition activeobject.h:41
Definition activeobject.h:65
f32 interp_duration
Definition activeobject.h:69
bool absolute
Definition activeobject.h:68
v3f vector
Definition activeobject.h:67
v3f previous
Definition activeobject.h:66
Definition activeobject.h:81
f32 interp_duration
Definition activeobject.h:88
core::quaternion next
Definition activeobject.h:83
core::quaternion previous
Definition activeobject.h:82
bool absolute
Definition activeobject.h:87
v3f next_radians
Definition activeobject.h:86
Definition activeobject.h:109
v3f previous
Definition activeobject.h:110
v3f vector
Definition activeobject.h:111
bool absolute
Definition activeobject.h:112
f32 interp_duration
Definition activeobject.h:113
Definition activeobject.h:63
v3f getRotationEulerDeg(v3f anim_rot_euler) const
Definition activeobject.h:91
v3f getPosition(v3f anim_pos) const
Definition activeobject.h:72
bool isIdentity() const
Definition activeobject.h:133
v3f getScale(v3f anim_scale) const
Definition activeobject.h:116
bool finishedInterpolation() const
Definition activeobject.h:126
struct BoneOverride::ScaleProperty scale
f32 dtime_passed
Definition activeobject.h:124
struct BoneOverride::PositionProperty position
struct BoneOverride::RotationProperty rotation