Minetest 5.9.0-dev
 
Loading...
Searching...
No Matches
activeobject.h
Go to the documentation of this file.
1/*
2Minetest
3Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5This program is free software; you can redistribute it and/or modify
6it under the terms of the GNU Lesser General Public License as published by
7the Free Software Foundation; either version 2.1 of the License, or
8(at your option) any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU Lesser General Public License for more details.
14
15You should have received a copy of the GNU Lesser General Public License along
16with this program; if not, write to the Free Software Foundation, Inc.,
1751 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18*/
19
20#pragma once
21
22#include "irr_aabb3d.h"
23#include "irr_v3d.h"
24#include <quaternion.h>
25#include <string>
26#include <unordered_map>
27
28
32// Obsolete stuff
33// ACTIVEOBJECT_TYPE_ITEM = 2,
34// ACTIVEOBJECT_TYPE_RAT = 3,
35// ACTIVEOBJECT_TYPE_OERKKI1 = 4,
36// ACTIVEOBJECT_TYPE_FIREFLY = 5,
37// ACTIVEOBJECT_TYPE_MOBV2 = 6,
38// End obsolete stuff
40// Special type, not stored as a static object
42// Special type, only exists as CAO
44};
45// Other types are defined in content_object.h
46
48{
49 ActiveObjectMessage(u16 id_, bool reliable_=true, std::string_view data_ = "") :
50 id(id_),
51 reliable(reliable_),
52 datastring(data_)
53 {}
54
55 u16 id;
57 std::string datastring;
58};
59
72 // ^ UPDATE_NAMETAG_ATTRIBUTES deprecated since 0.4.14, removed in 5.3.0
75};
76
78{
80 {
83 bool absolute = false;
84 f32 interp_timer = 0;
86
87 v3f getPosition(v3f anim_pos) const {
88 f32 progress = dtime_passed / position.interp_timer;
89 if (progress > 1.0f || position.interp_timer == 0.0f)
90 progress = 1.0f;
91 return position.vector.getInterpolated(position.previous, progress)
92 + (position.absolute ? v3f() : anim_pos);
93 }
94
96 {
97 core::quaternion previous;
98 core::quaternion next;
99 bool absolute = false;
102
103 v3f getRotationEulerDeg(v3f anim_rot_euler) const {
104 core::quaternion rot;
105
106 f32 progress = dtime_passed / rotation.interp_timer;
107 if (progress > 1.0f || rotation.interp_timer == 0.0f)
108 progress = 1.0f;
109 rot.slerp(rotation.previous, rotation.next, progress);
110 if (!rotation.absolute) {
111 core::quaternion anim_rot(anim_rot_euler * core::DEGTORAD);
112 rot = rot * anim_rot; // first rotate by anim. bone rot., then rot.
113 }
114
115 v3f rot_euler;
116 rot.toEuler(rot_euler);
117 return rot_euler * core::RADTODEG;
118 }
119
121 {
123 v3f vector{1, 1, 1};
124 bool absolute = false;
127
128 v3f getScale(v3f anim_scale) const {
129 f32 progress = dtime_passed / scale.interp_timer;
130 if (progress > 1.0f || scale.interp_timer == 0.0f)
131 progress = 1.0f;
132 return scale.vector.getInterpolated(scale.previous, progress)
133 * (scale.absolute ? v3f(1) : anim_scale);
134 }
135
137
138 bool isIdentity() const
139 {
140 return !position.absolute && position.vector == v3f()
141 && !rotation.absolute && rotation.next == core::quaternion()
142 && !scale.absolute && scale.vector == v3f(1);
143 }
144};
145
146typedef std::unordered_map<std::string, BoneOverride> BoneOverrideMap;
147
148
149/*
150 Parent class for ServerActiveObject and ClientActiveObject
151*/
153{
154public:
156 m_id(id)
157 {
158 }
159
160 u16 getId() const
161 {
162 return m_id;
163 }
164
165 void setId(u16 id)
166 {
167 m_id = id;
168 }
169
170 virtual ActiveObjectType getType() const = 0;
171
172
180 virtual bool getCollisionBox(aabb3f *toset) const = 0;
181
182
190 virtual bool getSelectionBox(aabb3f *toset) const = 0;
191
192
193 virtual bool collideWithObjects() const = 0;
194
195
196 virtual void setAttachment(int parent_id, const std::string &bone, v3f position,
197 v3f rotation, bool force_visible) {}
198 virtual void getAttachment(int *parent_id, std::string *bone, v3f *position,
199 v3f *rotation, bool *force_visible) const {}
200 virtual void clearChildAttachments() {}
201 virtual void clearParentAttachment() {}
202 virtual void addAttachmentChild(int child_id) {}
203 virtual void removeAttachmentChild(int child_id) {}
204protected:
205 u16 m_id; // 0 is invalid, "no id"
206};
std::unordered_map< std::string, BoneOverride > BoneOverrideMap
Definition: activeobject.h:146
ActiveObjectCommand
Definition: activeobject.h:60
@ AO_CMD_SET_TEXTURE_MOD
Definition: activeobject.h:63
@ AO_CMD_OBSOLETE1
Definition: activeobject.h:71
@ AO_CMD_SPAWN_INFANT
Definition: activeobject.h:73
@ AO_CMD_SET_PROPERTIES
Definition: activeobject.h:61
@ AO_CMD_PUNCHED
Definition: activeobject.h:65
@ AO_CMD_UPDATE_POSITION
Definition: activeobject.h:62
@ AO_CMD_SET_PHYSICS_OVERRIDE
Definition: activeobject.h:70
@ AO_CMD_SET_ANIMATION
Definition: activeobject.h:67
@ AO_CMD_SET_ANIMATION_SPEED
Definition: activeobject.h:74
@ AO_CMD_ATTACH_TO
Definition: activeobject.h:69
@ AO_CMD_UPDATE_ARMOR_GROUPS
Definition: activeobject.h:66
@ AO_CMD_SET_BONE_POSITION
Definition: activeobject.h:68
@ AO_CMD_SET_SPRITE
Definition: activeobject.h:64
ActiveObjectType
Definition: activeobject.h:29
@ ACTIVEOBJECT_TYPE_TEST
Definition: activeobject.h:31
@ ACTIVEOBJECT_TYPE_PLAYER
Definition: activeobject.h:41
@ ACTIVEOBJECT_TYPE_INVALID
Definition: activeobject.h:30
@ ACTIVEOBJECT_TYPE_GENERIC
Definition: activeobject.h:43
@ ACTIVEOBJECT_TYPE_LUAENTITY
Definition: activeobject.h:39
Definition: activeobject.h:153
virtual void clearParentAttachment()
Definition: activeobject.h:201
u16 m_id
Definition: activeobject.h:205
void setId(u16 id)
Definition: activeobject.h:165
virtual void getAttachment(int *parent_id, std::string *bone, v3f *position, v3f *rotation, bool *force_visible) const
Definition: activeobject.h:198
virtual bool getCollisionBox(aabb3f *toset) const =0
virtual void clearChildAttachments()
Definition: activeobject.h:200
virtual void removeAttachmentChild(int child_id)
Definition: activeobject.h:203
virtual bool collideWithObjects() const =0
virtual void addAttachmentChild(int child_id)
Definition: activeobject.h:202
virtual ActiveObjectType getType() const =0
virtual void setAttachment(int parent_id, const std::string &bone, v3f position, v3f rotation, bool force_visible)
Definition: activeobject.h:196
virtual bool getSelectionBox(aabb3f *toset) const =0
ActiveObject(u16 id)
Definition: activeobject.h:155
u16 getId() const
Definition: activeobject.h:160
core::aabbox3d< f32 > aabb3f
Definition: irr_aabb3d.h:26
core::vector3df v3f
Definition: irr_v3d.h:26
Definition: activeobject.h:48
ActiveObjectMessage(u16 id_, bool reliable_=true, std::string_view data_="")
Definition: activeobject.h:49
std::string datastring
Definition: activeobject.h:57
u16 id
Definition: activeobject.h:55
bool reliable
Definition: activeobject.h:56
Definition: activeobject.h:80
bool absolute
Definition: activeobject.h:83
v3f vector
Definition: activeobject.h:82
v3f previous
Definition: activeobject.h:81
f32 interp_timer
Definition: activeobject.h:84
Definition: activeobject.h:96
f32 interp_timer
Definition: activeobject.h:100
core::quaternion next
Definition: activeobject.h:98
core::quaternion previous
Definition: activeobject.h:97
bool absolute
Definition: activeobject.h:99
Definition: activeobject.h:121
v3f previous
Definition: activeobject.h:122
f32 interp_timer
Definition: activeobject.h:125
v3f vector
Definition: activeobject.h:123
bool absolute
Definition: activeobject.h:124
Definition: activeobject.h:78
v3f getRotationEulerDeg(v3f anim_rot_euler) const
Definition: activeobject.h:103
v3f getPosition(v3f anim_pos) const
Definition: activeobject.h:87
bool isIdentity() const
Definition: activeobject.h:138
v3f getScale(v3f anim_scale) const
Definition: activeobject.h:128
struct BoneOverride::ScaleProperty scale
f32 dtime_passed
Definition: activeobject.h:136
struct BoneOverride::PositionProperty position
struct BoneOverride::RotationProperty rotation