1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Allow rotating entity selectionboxes (#12379)

This commit is contained in:
Lars Müller 2022-10-30 16:53:14 +01:00 committed by GitHub
parent b829231992
commit 077627181e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 271 additions and 58 deletions

View file

@ -197,6 +197,11 @@ void LuaEntitySAO::step(float dtime, bool send_recommended)
}
}
if (fabs(m_prop.automatic_rotate) > 0.001f) {
m_rotation_add_yaw = modulo360f(m_rotation_add_yaw + dtime * core::RADTODEG *
m_prop.automatic_rotate);
}
if(m_registered) {
m_env->getScriptIface()->luaentity_Step(m_id, dtime, moveresult_p);
}

View file

@ -22,6 +22,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "object_properties.h"
#include "serveractiveobject.h"
#include <quaternion.h>
#include "util/numeric.h"
class UnitSAO : public ServerActiveObject
{
@ -36,6 +38,17 @@ public:
// Rotation
void setRotation(v3f rotation) { m_rotation = rotation; }
const v3f &getRotation() const { return m_rotation; }
const v3f getTotalRotation() const {
// This replicates what happens clientside serverside
core::matrix4 rot;
setPitchYawRoll(rot, -m_rotation);
v3f res;
// First rotate by m_rotation, then rotate by the automatic rotate yaw
(core::quaternion(v3f(0, -m_rotation_add_yaw * core::DEGTORAD, 0))
* core::quaternion(rot.getRotationDegrees() * core::DEGTORAD))
.toEuler(res);
return res * core::RADTODEG;
}
v3f getRadRotation() { return m_rotation * core::DEGTORAD; }
// Deprecated
@ -95,6 +108,7 @@ protected:
u16 m_hp = 1;
v3f m_rotation;
f32 m_rotation_add_yaw = 0;
ItemGroupList m_armor_groups;