void SmoothTranslatorWrappedv3f::translate(f32 dtime) { anim_time_counter = anim_time_counter + dtime; v3f val_diff_v3f; val_diff_v3f.X = std::abs(val_target.X - val_old.X); val_diff_v3f.Y = std::abs(val_target.Y - val_old.Y); val_diff_v3f.Z = std::abs(val_target.Z - val_old.Z); if (val_diff_v3f.X > 180.f) val_diff_v3f.X = 360.f - val_diff_v3f.X; if (val_diff_v3f.Y > 180.f) val_diff_v3f.Y = 360.f - val_diff_v3f.Y; if (val_diff_v3f.Z > 180.f) val_diff_v3f.Z = 360.f - val_diff_v3f.Z; f32 moveratio = 1.0; if (anim_time > 0.001) moveratio = anim_time_counter / anim_time; f32 move_end = aim_is_end ? 1.0 : 1.5; // Move a bit less than should, to avoid oscillation moveratio = std::min(moveratio * 0.8f, move_end); wrappedApproachShortest(val_current.X, val_target.X, val_diff_v3f.X * moveratio, 360.f); wrappedApproachShortest(val_current.Y, val_target.Y, val_diff_v3f.Y * moveratio, 360.f); wrappedApproachShortest(val_current.Z, val_target.Z, val_diff_v3f.Z * moveratio, 360.f); }
void SmoothTranslatorWrapped::translate(f32 dtime) { anim_time_counter = anim_time_counter + dtime; f32 val_diff = std::abs(val_target - val_old); if (val_diff > 180.f) val_diff = 360.f - val_diff; f32 moveratio = 1.0; if (anim_time > 0.001) moveratio = anim_time_counter / anim_time; f32 move_end = aim_is_end ? 1.0 : 1.5; // Move a bit less than should, to avoid oscillation moveratio = std::min(moveratio * 0.8f, move_end); wrappedApproachShortest(val_current, val_target, val_diff * moveratio, 360.f); }
void LuaEntitySAO::step(float dtime, bool send_recommended) { if(!m_properties_sent) { m_properties_sent = true; std::string str = getPropertyPacket(); // create message and add to list ActiveObjectMessage aom(getId(), true, str); m_messages_out.push(aom); } // If attached, check that our parent is still there. If it isn't, detach. if(m_attachment_parent_id && !isAttached()) { m_attachment_parent_id = 0; m_attachment_bone = ""; m_attachment_position = v3f(0,0,0); m_attachment_rotation = v3f(0,0,0); sendPosition(false, true); } m_last_sent_position_timer += dtime; // Each frame, parent position is copied if the object is attached, otherwise it's calculated normally // If the object gets detached this comes into effect automatically from the last known origin if(isAttached()) { v3f pos = m_env->getActiveObject(m_attachment_parent_id)->getBasePosition(); m_base_position = pos; m_velocity = v3f(0,0,0); m_acceleration = v3f(0,0,0); } else { if(m_prop.physical){ aabb3f box = m_prop.collisionbox; box.MinEdge *= BS; box.MaxEdge *= BS; collisionMoveResult moveresult; f32 pos_max_d = BS*0.25; // Distance per iteration v3f p_pos = m_base_position; v3f p_velocity = m_velocity; v3f p_acceleration = m_acceleration; moveresult = collisionMoveSimple(m_env, m_env->getGameDef(), pos_max_d, box, m_prop.stepheight, dtime, &p_pos, &p_velocity, p_acceleration, this, m_prop.collideWithObjects); // Apply results m_base_position = p_pos; m_velocity = p_velocity; m_acceleration = p_acceleration; } else { m_base_position += dtime * m_velocity + 0.5 * dtime * dtime * m_acceleration; m_velocity += dtime * m_acceleration; } if (m_prop.automatic_face_movement_dir && (fabs(m_velocity.Z) > 0.001 || fabs(m_velocity.X) > 0.001)) { float target_yaw = atan2(m_velocity.Z, m_velocity.X) * 180 / M_PI + m_prop.automatic_face_movement_dir_offset; 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); } } if(m_registered){ m_env->getScriptIface()->luaentity_Step(m_id, dtime); } if (!send_recommended) return; if(!isAttached()) { // TODO: force send when acceleration changes enough? float minchange = 0.2*BS; if(m_last_sent_position_timer > 1.0){ minchange = 0.01*BS; } else if(m_last_sent_position_timer > 0.2){ minchange = 0.05*BS; } float move_d = m_base_position.getDistanceFrom(m_last_sent_position); 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) { sendPosition(true, false); } } if (!m_armor_groups_sent) { m_armor_groups_sent = true; std::string str = gob_cmd_update_armor_groups( m_armor_groups); // create message and add to list ActiveObjectMessage aom(getId(), true, str); m_messages_out.push(aom); } if (!m_animation_sent) { m_animation_sent = true; std::string str = gob_cmd_update_animation( m_animation_range, m_animation_speed, m_animation_blend, m_animation_loop); // create message and add to list ActiveObjectMessage aom(getId(), true, str); m_messages_out.push(aom); } if (!m_animation_speed_sent) { m_animation_speed_sent = true; std::string str = gob_cmd_update_animation_speed(m_animation_speed); // create message and add to list ActiveObjectMessage aom(getId(), true, str); m_messages_out.push(aom); } if (!m_bone_position_sent) { m_bone_position_sent = true; for (std::unordered_map<std::string, core::vector2d<v3f>>::const_iterator ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii){ std::string str = gob_cmd_update_bone_position((*ii).first, (*ii).second.X, (*ii).second.Y); // create message and add to list ActiveObjectMessage aom(getId(), true, str); m_messages_out.push(aom); } } if (!m_attachment_sent) { m_attachment_sent = true; std::string str = gob_cmd_update_attachment(m_attachment_parent_id, m_attachment_bone, m_attachment_position, m_attachment_rotation); // create message and add to list ActiveObjectMessage aom(getId(), true, str); m_messages_out.push(aom); } }