Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix catastrofic rotation after undocking from space station. #5422

Merged
merged 1 commit into from
Nov 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/DynamicBody.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ DynamicBody::DynamicBody(const Json &jsonObj, Space *space) :
m_mass = dynamicBodyObj["mass"];
m_massRadius = dynamicBodyObj["mass_radius"];
m_angInertia = dynamicBodyObj["ang_inertia"];
m_isMoving = dynamicBodyObj["is_moving"];
SetMoving(dynamicBodyObj["is_moving"]);
} catch (Json::type_error &) {
throw SavedGameCorruptException();
}
Expand All @@ -71,6 +71,18 @@ DynamicBody::DynamicBody(const Json &jsonObj, Space *space) :
m_decelerating = false;
}

void DynamicBody::SetMoving(bool isMoving)
{
m_isMoving = isMoving;

if (!m_isMoving) {
m_vel = vector3d(0.0);
m_angVel = vector3d(0.0);
m_force = vector3d(0.0);
m_torque = vector3d(0.0);
}
}

void DynamicBody::SaveToJson(Json &jsonObj, Space *space)
{
ModelBody::SaveToJson(jsonObj, space);
Expand Down
2 changes: 1 addition & 1 deletion src/DynamicBody.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class DynamicBody : public ModelBody {
vector3d GetAngularMomentum() const;
double GetAngularInertia() const { return m_angInertia; }
void SetMassDistributionFromModel();
void SetMoving(bool isMoving) { m_isMoving = isMoving; }
void SetMoving(bool isMoving);
bool IsMoving() const { return m_isMoving; }
virtual double GetMass() const override { return m_mass; } // XXX don't override this
virtual void TimeStepUpdate(const float timeStep) override;
Expand Down