Example #1
0
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);
}
Example #2
0
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();
}
Example #3
0
vector3d Body::GetVelocityRelTo(const Body *other) const
{
	return GetVelocityRelTo(GetFrame()) - other->GetVelocityRelTo(GetFrame());
}
Example #4
0
vector3d Body::GetVelocityRelTo(const Body *relTo) const
{
	return GetVelocityRelTo(relTo->m_frame) - relTo->GetVelocityRelTo(relTo->m_frame);
}
Example #5
0
// 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);
}