mirror of
https://github.com/luanti-org/luanti.git
synced 2025-07-12 16:58:39 +00:00
Add Lua methods 'set_rotation()' and 'get_rotation()' (#7395)
* Adds Lua methods 'set_rotation()' and 'get_rotation'. Also changed some method names to be more clear. Instead of an f32 being sent over network for yaw, now a v3f is sent for rotation on xyz axes. Perserved Lua method set_yaw/setyaw so that old mods still work, other wise to set yaw they would need to switch to set_rotation(0, yaw, 0).
This commit is contained in:
parent
9519d57017
commit
faa358e797
18 changed files with 211 additions and 99 deletions
|
@ -349,7 +349,7 @@ ServerActiveObject* LuaEntitySAO::create(ServerEnvironment *env, v3f pos,
|
|||
std::string state;
|
||||
s16 hp = 1;
|
||||
v3f velocity;
|
||||
float yaw = 0;
|
||||
v3f rotation;
|
||||
if (!data.empty()) {
|
||||
std::istringstream is(data, std::ios::binary);
|
||||
// read version
|
||||
|
@ -364,7 +364,7 @@ ServerActiveObject* LuaEntitySAO::create(ServerEnvironment *env, v3f pos,
|
|||
state = deSerializeLongString(is);
|
||||
hp = readS16(is);
|
||||
velocity = readV3F1000(is);
|
||||
yaw = readF1000(is);
|
||||
rotation = readV3F1000(is);
|
||||
}
|
||||
}
|
||||
// create object
|
||||
|
@ -373,7 +373,7 @@ ServerActiveObject* LuaEntitySAO::create(ServerEnvironment *env, v3f pos,
|
|||
LuaEntitySAO *sao = new LuaEntitySAO(env, pos, name, state);
|
||||
sao->m_hp = hp;
|
||||
sao->m_velocity = velocity;
|
||||
sao->m_yaw = yaw;
|
||||
sao->m_rotation = rotation;
|
||||
return sao;
|
||||
}
|
||||
|
||||
|
@ -443,8 +443,8 @@ void LuaEntitySAO::step(float dtime, bool send_recommended)
|
|||
float max_rotation_delta =
|
||||
dtime * m_prop.automatic_face_movement_max_rotation_per_sec;
|
||||
|
||||
m_yaw = wrapDegrees_0_360(m_yaw);
|
||||
wrappedApproachShortest(m_yaw, target_yaw, max_rotation_delta, 360.f);
|
||||
m_rotation.Y = wrapDegrees_0_360(m_rotation.Y);
|
||||
wrappedApproachShortest(m_rotation.Y, target_yaw, max_rotation_delta, 360.f);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -468,7 +468,10 @@ void LuaEntitySAO::step(float dtime, bool send_recommended)
|
|||
move_d += m_last_sent_move_precision;
|
||||
float vel_d = m_velocity.getDistanceFrom(m_last_sent_velocity);
|
||||
if (move_d > minchange || vel_d > minchange ||
|
||||
std::fabs(m_yaw - m_last_sent_yaw) > 1.0) {
|
||||
std::fabs(m_rotation.X - m_last_sent_rotation.X) > 1.0f ||
|
||||
std::fabs(m_rotation.Y - m_last_sent_rotation.Y) > 1.0f ||
|
||||
std::fabs(m_rotation.Z - m_last_sent_rotation.Z) > 1.0f) {
|
||||
|
||||
sendPosition(true, false);
|
||||
}
|
||||
}
|
||||
|
@ -530,7 +533,7 @@ std::string LuaEntitySAO::getClientInitializationData(u16 protocol_version)
|
|||
writeU8(os, 0); // is_player
|
||||
writeS16(os, getId()); //id
|
||||
writeV3F1000(os, m_base_position);
|
||||
writeF1000(os, m_yaw);
|
||||
writeV3F1000(os, m_rotation);
|
||||
writeS16(os, m_hp);
|
||||
|
||||
std::ostringstream msg_os(std::ios::binary);
|
||||
|
@ -585,8 +588,9 @@ void LuaEntitySAO::getStaticData(std::string *result) const
|
|||
writeS16(os, m_hp);
|
||||
// velocity
|
||||
writeV3F1000(os, m_velocity);
|
||||
// yaw
|
||||
writeF1000(os, m_yaw);
|
||||
// rotation
|
||||
writeV3F1000(os, m_rotation);
|
||||
|
||||
*result = os.str();
|
||||
}
|
||||
|
||||
|
@ -767,10 +771,10 @@ void LuaEntitySAO::sendPosition(bool do_interpolate, bool is_movement_end)
|
|||
m_last_sent_move_precision = m_base_position.getDistanceFrom(
|
||||
m_last_sent_position);
|
||||
m_last_sent_position_timer = 0;
|
||||
m_last_sent_yaw = m_yaw;
|
||||
m_last_sent_position = m_base_position;
|
||||
m_last_sent_velocity = m_velocity;
|
||||
//m_last_sent_acceleration = m_acceleration;
|
||||
m_last_sent_rotation = m_rotation;
|
||||
|
||||
float update_interval = m_env->getSendRecommendedInterval();
|
||||
|
||||
|
@ -778,7 +782,7 @@ void LuaEntitySAO::sendPosition(bool do_interpolate, bool is_movement_end)
|
|||
m_base_position,
|
||||
m_velocity,
|
||||
m_acceleration,
|
||||
m_yaw,
|
||||
m_rotation,
|
||||
do_interpolate,
|
||||
is_movement_end,
|
||||
update_interval
|
||||
|
@ -919,9 +923,9 @@ std::string PlayerSAO::getClientInitializationData(u16 protocol_version)
|
|||
writeU8(os, 1); // version
|
||||
os << serializeString(m_player->getName()); // name
|
||||
writeU8(os, 1); // is_player
|
||||
writeS16(os, getId()); //id
|
||||
writeS16(os, getId()); // id
|
||||
writeV3F1000(os, m_base_position);
|
||||
writeF1000(os, m_yaw);
|
||||
writeV3F1000(os, m_rotation);
|
||||
writeS16(os, getHP());
|
||||
|
||||
std::ostringstream msg_os(std::ios::binary);
|
||||
|
@ -1073,7 +1077,7 @@ void PlayerSAO::step(float dtime, bool send_recommended)
|
|||
return;
|
||||
|
||||
// If the object is attached client-side, don't waste bandwidth sending its
|
||||
// position to clients.
|
||||
// position or rotation to clients.
|
||||
if (m_position_not_sent && !isAttached()) {
|
||||
m_position_not_sent = false;
|
||||
float update_interval = m_env->getSendRecommendedInterval();
|
||||
|
@ -1087,7 +1091,7 @@ void PlayerSAO::step(float dtime, bool send_recommended)
|
|||
pos,
|
||||
v3f(0.0f, 0.0f, 0.0f),
|
||||
v3f(0.0f, 0.0f, 0.0f),
|
||||
m_yaw,
|
||||
v3f(0.0f, 0.0f, 0.0f),
|
||||
true,
|
||||
false,
|
||||
update_interval
|
||||
|
@ -1188,12 +1192,14 @@ void PlayerSAO::moveTo(v3f pos, bool continuous)
|
|||
m_env->getGameDef()->SendMovePlayer(m_peer_id);
|
||||
}
|
||||
|
||||
void PlayerSAO::setYaw(const float yaw)
|
||||
void PlayerSAO::setPlayerYaw(const float yaw)
|
||||
{
|
||||
if (m_player && yaw != m_yaw)
|
||||
v3f rotation(0, yaw, 0);
|
||||
if (m_player && yaw != m_rotation.Y)
|
||||
m_player->setDirty(true);
|
||||
|
||||
UnitSAO::setYaw(yaw);
|
||||
// Set player model yaw, not look view
|
||||
UnitSAO::setRotation(rotation);
|
||||
}
|
||||
|
||||
void PlayerSAO::setFov(const float fov)
|
||||
|
@ -1212,13 +1218,13 @@ void PlayerSAO::setWantedRange(const s16 range)
|
|||
m_wanted_range = range;
|
||||
}
|
||||
|
||||
void PlayerSAO::setYawAndSend(const float yaw)
|
||||
void PlayerSAO::setPlayerYawAndSend(const float yaw)
|
||||
{
|
||||
setYaw(yaw);
|
||||
setPlayerYaw(yaw);
|
||||
m_env->getGameDef()->SendMovePlayer(m_peer_id);
|
||||
}
|
||||
|
||||
void PlayerSAO::setPitch(const float pitch)
|
||||
void PlayerSAO::setLookPitch(const float pitch)
|
||||
{
|
||||
if (m_player && pitch != m_pitch)
|
||||
m_player->setDirty(true);
|
||||
|
@ -1226,9 +1232,9 @@ void PlayerSAO::setPitch(const float pitch)
|
|||
m_pitch = pitch;
|
||||
}
|
||||
|
||||
void PlayerSAO::setPitchAndSend(const float pitch)
|
||||
void PlayerSAO::setLookPitchAndSend(const float pitch)
|
||||
{
|
||||
setPitch(pitch);
|
||||
setLookPitch(pitch);
|
||||
m_env->getGameDef()->SendMovePlayer(m_peer_id);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue