m_position = readV3F1000(is);
// yaw
m_yaw = readF1000(is);
+ // is_end_position (for interpolation)
+ bool is_end_position = readU8(is);
if(do_interpolate)
- pos_translator.update(m_position);
+ pos_translator.update(m_position, is_end_position);
else
pos_translator.init(m_position);
updateNodePos();
v3f vect_old;
v3f vect_show;
v3f vect_aim;
+ bool aim_is_end;
f32 anim_counter;
f32 anim_time;
f32 anim_time_counter;
vect_old = vect;
vect_show = vect;
vect_aim = vect;
+ aim_is_end = true;
anim_counter = 0;
anim_time = 0;
anim_time_counter = 0;
init(vect_show);
}
- void update(v3f vect_new)
+ void update(v3f vect_new, bool is_end_position=false)
{
+ aim_is_end = is_end_position;
vect_old = vect_show;
vect_aim = vect_new;
if(anim_time < 0.001 || anim_time > 1.0)
moveratio = anim_time_counter / anim_time;
// Move a bit less than should, to avoid oscillation
moveratio = moveratio * 0.5;
- if(moveratio > 1.5)
- moveratio = 1.5;
+ float move_end = 1.5;
+ if(aim_is_end)
+ move_end = 1.0;
+ if(moveratio > move_end)
+ moveratio = move_end;
vect_show = vect_old + vect_move * moveratio;
}
if(send_recommended == false)
return;
+ bool move_end = false;
float minchange = 0.2*BS;
- if(m_last_sent_position_timer > 1.0)
+ if(m_last_sent_position_timer > 1.0){
minchange = 0.01*BS;
- else if(m_last_sent_position_timer > 0.2)
+ move_end = true;
+ } else if(m_last_sent_position_timer > 0.2){
minchange = 0.05*BS;
+ }
if(m_base_position.getDistanceFrom(m_last_sent_position) > minchange
|| fabs(m_yaw - m_last_sent_yaw) > 1.0){
- sendPosition(true);
+ sendPosition(true, move_end);
}
}
void LuaEntitySAO::setPos(v3f pos)
{
m_base_position = pos;
- sendPosition(false);
+ sendPosition(false, true);
}
void LuaEntitySAO::moveTo(v3f pos)
{
m_base_position = pos;
+ sendPosition(true, true);
}
-void LuaEntitySAO::sendPosition(bool do_interpolate)
+void LuaEntitySAO::sendPosition(bool do_interpolate, bool is_movement_end)
{
m_last_sent_yaw = m_yaw;
m_last_sent_position = m_base_position;
std::ostringstream os(std::ios::binary);
// command (0 = update position)
writeU8(os, 0);
+
// do_interpolate
writeU8(os, do_interpolate);
// pos
writeV3F1000(os, m_base_position);
// yaw
writeF1000(os, m_yaw);
+ // is_end_position (for interpolation)
+ writeU8(os, is_movement_end);
+
// create message and add to list
ActiveObjectMessage aom(getId(), false, os.str());
m_messages_out.push_back(aom);