void Ship::Blastoff() { if (m_flightState != LANDED) return; vector3d up = GetPosition().Normalized(); assert(GetFrame()->GetBody()->IsType(Object::PLANET)); const double planetRadius = 2.0 + static_cast<Planet*>(GetFrame()->GetBody())->GetTerrainHeight(up); SetVelocity(vector3d(0, 0, 0)); SetAngVelocity(vector3d(0, 0, 0)); SetFlightState(FLYING); SetPosition(up*planetRadius - GetAabb().min.y*up); SetThrusterState(1, 1.0); // thrust upwards LuaEvent::Queue("onShipTakeOff", this, GetFrame()->GetBody()); }
void Ship::SetDockedWith(SpaceStation *s, int port) { if (s) { m_dockedWith = s; m_dockedWithPort = port; m_wheelState = 1.0f; m_flightState = DOCKED; SetVelocity(vector3d(0,0,0)); SetAngVelocity(vector3d(0,0,0)); Disable(); ClearThrusterState(); m_dockedWith->SetDocked(this, port); onDock.emit(); } else { Undock(); } }
void Ship::SetLandedOn(Planet *p, float latitude, float longitude) { m_wheelTransition = 0; m_wheelState = 1.0f; Frame* f = p->GetFrame()->GetRotFrame(); SetFrame(f); vector3d up = vector3d(cos(latitude)*sin(longitude), sin(latitude), cos(latitude)*cos(longitude)); const double planetRadius = p->GetTerrainHeight(up); SetPosition(up * (planetRadius - GetAabb().min.y)); vector3d right = up.Cross(vector3d(0,0,1)).Normalized(); SetOrient(matrix3x3d::FromVectors(right, up)); SetVelocity(vector3d(0, 0, 0)); SetAngVelocity(vector3d(0, 0, 0)); ClearThrusterState(); SetFlightState(LANDED); LuaEvent::Queue("onShipLanded", this, p); onLanded.emit(); }