void AutoNavigator::rotate(const qv4& rotation) { const v3& currentRotationVel = getGoValue<v3>(ID::PV_RelativeRotationVelocity, pluginId()); // braking distance in radian v3 b = (currentRotationVel * currentRotationVel) / (2.0f * mMaxAngularAcceleration.value()); // reduce the vibration caused by the time delay of 2 frames by using the braking distance * 3 b *= 2.0f; quantity<si::plane_angle,f32> pitch = rotation.getPitch(false) * si::radian; quantity<si::plane_angle,f32> yaw = rotation.getYaw(false) * si::radian; // get the sign f32 factor = sign(pitch.value()); if ((factor * pitch) > (b.x * si::radian)) { if ((factor * pitch) > mOptimalAngle) mRotationFactorPitch = 1.0f * factor; else mRotationFactorPitch = 0.05f * factor; } else { mRotationFactorPitch = 0.0f; } // get the sign factor = sign(yaw.value()); if ((factor * yaw) > (b.y * si::radian)) { if ((factor * yaw) > mOptimalAngle) mRotationFactorYaw = 1.0f * factor; else mRotationFactorYaw = 0.05f * factor; } else mRotationFactorYaw = 0.0f; }
void AutoNavigator::rotate(const qv4& rotation) const { const v3& currentRotationVel = getGoValue<v3>(ID::PV_RelativeRotationVelocity, pluginId()); // braking distance in radian v3 b = (currentRotationVel * currentRotationVel) / (2.0f * mMaxAngularAcceleration.value()); // reduce the vibration caused by the time delay of 2 frames by using the braking distance * 3 b *= 2.0f; quantity<si::plane_angle,f32> pitch = rotation.getPitch(false) * si::radian; quantity<si::plane_angle,f32> yaw = rotation.getYaw(false) * si::radian; // get the sign f32 factor = sign(pitch.value()); if ((factor * pitch) > (b.x * si::radian)) { if ((factor * pitch) > mOptimalAngle) emit<GameObjectEvent>(ID::GOE_CONTROL_PITCH, 1.0f * factor, ownerHandle()); else emit<GameObjectEvent>(ID::GOE_CONTROL_PITCH, 0.05f * factor, ownerHandle()); } else { emit<GameObjectEvent>(ID::GOE_CONTROL_PITCH, 0.0f, ownerHandle()); } // get the sign factor = sign(yaw.value()); if ((factor * yaw) > (b.y * si::radian)) { if ((factor * yaw) > mOptimalAngle) emit<GameObjectEvent>(ID::GOE_CONTROL_YAW, 1.0f * factor, ownerHandle()); else emit<GameObjectEvent>(ID::GOE_CONTROL_YAW, 0.05f * factor, ownerHandle()); } else emit<GameObjectEvent>(ID::GOE_CONTROL_YAW, 0.0f, ownerHandle()); }