Luanti 5.11.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_timer;
74 if (progress > 1.0f || position.interp_timer == 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_timer = 0;
90
91 v3f getRotationEulerDeg(v3f anim_rot_euler) const {
92 core::quaternion rot;
93
94 f32 progress = dtime_passed / rotation.interp_timer;
95 if (progress > 1.0f || rotation.interp_timer == 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 {
111 v3f vector{1, 1, 1};
112 bool absolute = false;
115
116 v3f getScale(v3f anim_scale) const {
117 f32 progress = dtime_passed / scale.interp_timer;
118 if (progress > 1.0f || scale.interp_timer == 0.0f)
119 progress = 1.0f;
120 return scale.vector.getInterpolated(scale.previous, progress)
121 * (scale.absolute ? v3f(1) : anim_scale);
122 }
123
125
126 bool isIdentity() const
127 {
128 return !position.absolute && position.vector == v3f()
129 && !rotation.absolute && rotation.next == core::quaternion()
130 && !scale.absolute && scale.vector == v3f(1);
131 }
132};
133
134typedef std::unordered_map<std::string, BoneOverride> BoneOverrideMap;
135
136
137/*
138 Parent class for ServerActiveObject and ClientActiveObject
139*/
141{
142public:
143 typedef u16 object_t;
144
146 m_id(id)
147 {
148 }
149
151 {
152 return m_id;
153 }
154
156 {
157 m_id = id;
158 }
159
160 virtual ActiveObjectType getType() const = 0;
161
162
170 virtual bool getCollisionBox(aabb3f *toset) const = 0;
171
172
180 virtual bool getSelectionBox(aabb3f *toset) const = 0;
181
182
183 virtual bool collideWithObjects() const = 0;
184
185
186 virtual void setAttachment(object_t parent_id, const std::string &bone, v3f position,
187 v3f rotation, bool force_visible) {}
188 virtual void getAttachment(object_t *parent_id, std::string *bone, v3f *position,
189 v3f *rotation, bool *force_visible) const {}
190 // Detach all children
191 virtual void clearChildAttachments() {}
192 // Detach from parent
194 {
195 setAttachment(0, "", v3f(), v3f(), false);
196 }
197
198 // To be be called from setAttachment() and descendants, but not manually!
199 virtual void addAttachmentChild(object_t child_id) {}
200 virtual void removeAttachmentChild(object_t child_id) {}
201
202protected:
203 object_t m_id; // 0 is invalid, "no id"
204};
std::unordered_map< std::string, BoneOverride > BoneOverrideMap
Definition activeobject.h:134
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:141
virtual void clearParentAttachment()
Definition activeobject.h:193
object_t getId() const
Definition activeobject.h:150
virtual void setAttachment(object_t parent_id, const std::string &bone, v3f position, v3f rotation, bool force_visible)
Definition activeobject.h:186
virtual bool getCollisionBox(aabb3f *toset) const =0
ActiveObject(object_t id)
Definition activeobject.h:145
virtual void clearChildAttachments()
Definition activeobject.h:191
virtual void removeAttachmentChild(object_t child_id)
Definition activeobject.h:200
virtual void addAttachmentChild(object_t child_id)
Definition activeobject.h:199
virtual bool collideWithObjects() const =0
object_t m_id
Definition activeobject.h:203
void setId(object_t id)
Definition activeobject.h:155
virtual ActiveObjectType getType() const =0
virtual bool getSelectionBox(aabb3f *toset) const =0
u16 object_t
Definition activeobject.h:143
virtual void getAttachment(object_t *parent_id, std::string *bone, v3f *position, v3f *rotation, bool *force_visible) const
Definition activeobject.h:188
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
bool absolute
Definition activeobject.h:68
v3f vector
Definition activeobject.h:67
v3f previous
Definition activeobject.h:66
f32 interp_timer
Definition activeobject.h:69
Definition activeobject.h:81
f32 interp_timer
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
f32 interp_timer
Definition activeobject.h:113
v3f vector
Definition activeobject.h:111
bool absolute
Definition activeobject.h:112
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:126
v3f getScale(v3f anim_scale) const
Definition activeobject.h:116
struct BoneOverride::ScaleProperty scale
f32 dtime_passed
Definition activeobject.h:124
struct BoneOverride::PositionProperty position
struct BoneOverride::RotationProperty rotation