void Body::SwitchToFrame(Frame *newFrame) { vector3d vel = GetVelocityRelTo(newFrame); // do this first because it uses position vector3d fpos = m_frame->GetPositionRelTo(newFrame); matrix3x3d forient = m_frame->GetOrientRelTo(newFrame); SetPosition(forient * GetPosition() + fpos); SetOrient(forient * GetOrient()); SetVelocity(vel + newFrame->GetStasisVelocity(GetPosition())); SetFrame(newFrame); LuaEvent::Queue("onFrameChanged", this); }
void Player::SetFlightControlState(enum FlightControlState s) { m_flightControlState = s; if (m_flightControlState == CONTROL_AUTOPILOT) { AIClearInstructions(); } else if (m_flightControlState == CONTROL_FIXSPEED) { AIClearInstructions(); m_setSpeed = m_setSpeedTarget ? GetVelocityRelTo(m_setSpeedTarget).Length() : GetVelocity().Length(); } else { AIClearInstructions(); } Pi::onPlayerChangeFlightControlState.emit(); }
vector3d Body::GetVelocityRelTo(const Body *other) const { return GetVelocityRelTo(GetFrame()) - other->GetVelocityRelTo(GetFrame()); }
vector3d Body::GetVelocityRelTo(const Body *relTo) const { return GetVelocityRelTo(relTo->m_frame) - relTo->GetVelocityRelTo(relTo->m_frame); }
// vel is desired velocity in ship's frame // returns true if this can be attained in a single timestep // todo: check space station rotating frame case bool Ship::AIMatchVel(const vector3d &vel) { matrix4x4d rot; GetRotMatrix(rot); vector3d diffvel = (vel - GetVelocityRelTo(GetFrame())) * rot; // convert to object space return AIChangeVelBy(diffvel); }