Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 5870f840473d
Choose a base ref
...
head repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 1c2dc8c42b88
Choose a head ref
  • 6 commits
  • 5 files changed
  • 1 contributor

Commits on Mar 11, 2017

  1. now I understand this bug

    eggrobin committed Mar 11, 2017
    Copy the full SHA
    44bd958 View commit details
  2. do it in C++

    eggrobin committed Mar 11, 2017
    Copy the full SHA
    382ad17 View commit details
  3. oops forgot to clear that

    eggrobin committed Mar 11, 2017
    Copy the full SHA
    b989359 View commit details
  4. nothing to capture

    eggrobin committed Mar 11, 2017
    Copy the full SHA
    5dffa83 View commit details
  5. after pleroy's review

    eggrobin committed Mar 11, 2017
    Copy the full SHA
    6e654c4 View commit details
  6. Merge pull request #1243 from eggrobin/starting-thrust

    Fix the camera and selection bugs
    eggrobin authored Mar 11, 2017
    Copy the full SHA
    1c2dc8c View commit details
Showing with 70 additions and 71 deletions.
  1. +12 −6 ksp_plugin/interface.cpp
  2. +23 −32 ksp_plugin/plugin.cpp
  3. +6 −7 ksp_plugin/plugin.hpp
  4. +27 −26 ksp_plugin_adapter/ksp_plugin_adapter.cs
  5. +2 −0 serialization/journal.proto
18 changes: 12 additions & 6 deletions ksp_plugin/interface.cpp
Original file line number Diff line number Diff line change
@@ -217,10 +217,13 @@ WXYZ principia__CelestialSphereRotation(Plugin const* const plugin) {
}

QP principia__CelestialWorldDegreesOfFreedom(Plugin const* const plugin,
int const index) {
journal::Method<journal::CelestialWorldDegreesOfFreedom> m({plugin, index});
int const index,
PartId const part_at_origin) {
journal::Method<journal::CelestialWorldDegreesOfFreedom> m(
{plugin, index, part_at_origin});
CHECK_NOTNULL(plugin);
auto const result = plugin->CelestialWorldDegreesOfFreedom(index);
auto const result =
plugin->CelestialWorldDegreesOfFreedom(index, part_at_origin);
return m.Return(
{ToXYZ((result.position() - World::origin).coordinates() / Metre),
ToXYZ(result.velocity().coordinates() / (Metre / Second))});
@@ -351,10 +354,13 @@ int principia__GetBufferedLogging() {
}

QP principia__GetPartActualDegreesOfFreedom(Plugin const* const plugin,
PartId const part_id) {
journal::Method<journal::GetPartActualDegreesOfFreedom> m({plugin, part_id});
PartId const part_id,
PartId const part_at_origin) {
journal::Method<journal::GetPartActualDegreesOfFreedom> m(
{plugin, part_id, part_at_origin});
DegreesOfFreedom<World> const degrees_of_freedom =
CHECK_NOTNULL(plugin)->GetPartActualDegreesOfFreedom(part_id);
CHECK_NOTNULL(plugin)->GetPartActualDegreesOfFreedom(part_id,
part_at_origin);
return m.Return(QP{
ToXYZ((degrees_of_freedom.position() - World::origin).coordinates() /
Metre),
55 changes: 23 additions & 32 deletions ksp_plugin/plugin.cpp
Original file line number Diff line number Diff line change
@@ -604,19 +604,8 @@ void Plugin::AdvanceTime(Instant const& t, Angle const& planetarium_rotation) {
Vessel& vessel = *pair.second;
vessel.AdvanceTime();
}
if (loaded_vessels_.empty()) {
bubble_barycentre_ = std::experimental::nullopt;
} else {
BarycentreCalculator<DegreesOfFreedom<Barycentric>, Mass>
bubble_barycentre_calculator;
for (not_null<Vessel*> const vessel : loaded_vessels_) {
vessel->ForAllParts([&bubble_barycentre_calculator](Part& part) {
part.clear_intrinsic_force();
bubble_barycentre_calculator.Add(part.degrees_of_freedom(),
part.mass());
});
}
bubble_barycentre_ = bubble_barycentre_calculator.Get();
for (not_null<Vessel*> const vessel : loaded_vessels_) {
vessel->ForAllParts([](Part& part) { part.clear_intrinsic_force(); });
}

VLOG(1) << "Time has been advanced" << '\n'
@@ -628,34 +617,36 @@ void Plugin::AdvanceTime(Instant const& t, Angle const& planetarium_rotation) {
}

DegreesOfFreedom<World> Plugin::GetPartActualDegreesOfFreedom(
PartId const part_id) const {
CHECK(bubble_barycentre_);
PartId const part_id,
PartId const part_at_origin) const {
auto const world_origin = FindOrDie(part_id_to_vessel_, part_at_origin)->
part(part_at_origin)->
degrees_of_freedom();
RigidMotion<Barycentric, World> barycentric_to_world{
RigidTransformation<Barycentric, World>{
bubble_barycentre_->position(), World::origin, BarycentricToWorld()},
world_origin.position(), World::origin, BarycentricToWorld()},
AngularVelocity<Barycentric>{},
bubble_barycentre_->velocity()};
return barycentric_to_world(FindOrDie(part_id_to_vessel_, part_id)
->part(part_id)
->degrees_of_freedom());
}

DegreesOfFreedom<Barycentric> Plugin::GetBubbleBarycentre() const {
CHECK(bubble_barycentre_);
return *bubble_barycentre_;
world_origin.velocity()};
return barycentric_to_world(FindOrDie(part_id_to_vessel_, part_id)->
part(part_id)->
degrees_of_freedom());
}

DegreesOfFreedom<World> Plugin::CelestialWorldDegreesOfFreedom(
Index const index) const {
Index const index,
PartId const part_at_origin) const {
auto const world_origin = FindOrDie(part_id_to_vessel_, part_at_origin)->
part(part_at_origin)->
degrees_of_freedom();
RigidMotion<Barycentric, World> barycentric_to_world{
RigidTransformation<Barycentric, World>{GetBubbleBarycentre().position(),
World::origin,
BarycentricToWorld()},
RigidTransformation<Barycentric, World>{
world_origin.position(), World::origin, BarycentricToWorld()},
AngularVelocity<Barycentric>{},
GetBubbleBarycentre().velocity()};
world_origin.velocity()};
return barycentric_to_world(
FindOrDie(celestials_, index)->trajectory().EvaluateDegreesOfFreedom(
current_time_, /*hint=*/nullptr));
FindOrDie(celestials_, index)->
trajectory().EvaluateDegreesOfFreedom(current_time_,
/*hint=*/nullptr));
}

void Plugin::ForgetAllHistoriesBefore(Instant const& t) const {
13 changes: 6 additions & 7 deletions ksp_plugin/plugin.hpp
Original file line number Diff line number Diff line change
@@ -221,17 +221,17 @@ class Plugin {
virtual void AdvanceTime(Instant const& t, Angle const& planetarium_rotation);

// Returns the degrees of freedom of the given part in |World|, assuming that
// the origin of |World| is fixed at |bubble_barycentre_|. The part must be
// in a loaded vessel.
// the origin of |World| is fixed at the centre of mass of the
// |part_at_origin|.
virtual DegreesOfFreedom<World> GetPartActualDegreesOfFreedom(
PartId part_id) const;

virtual DegreesOfFreedom<Barycentric> GetBubbleBarycentre() const;
PartId part_id,
PartId part_at_origin) const;

// Returns the |World| degrees of freedom of the |Celestial| with the given
// |Index|, identifying the origin of |World| with that of |Bubble|.
virtual DegreesOfFreedom<World> CelestialWorldDegreesOfFreedom(
Index const index) const;
Index const index,
PartId part_at_origin) const;

// Forgets the histories of the |celestials_| and of the vessels before |t|.
virtual void ForgetAllHistoriesBefore(Instant const& t) const;
@@ -511,7 +511,6 @@ class Plugin {
// The vessels that were inserted unloaded and have yet to be collected into a
// pile-up.
std::set<not_null<Vessel*>> new_unloaded_vessels_;
std::experimental::optional<DegreesOfFreedom<Barycentric>> bubble_barycentre_;

friend class NavballFrameField;
friend class TestablePlugin;
53 changes: 27 additions & 26 deletions ksp_plugin_adapter/ksp_plugin_adapter.cs
Original file line number Diff line number Diff line change
@@ -796,36 +796,37 @@ private System.Collections.IEnumerator
// We don't want to do too many things here, since all the KSP classes
// still think they're in the preceding step. We only nudge the Unity
// transforms of loaded vessels & their parts.
// TODO(egg): get vessel nudged positions and call Vessel.SetPosition.
// Hopefully that will be enough.
foreach (Vessel vessel in FlightGlobals.VesselsLoaded) {
// TODO(egg): if I understand anything, there should probably be a
// special treatment for loaded packed vessels. I don't understand
// anything though.
if (vessel.packed || !plugin_.HasVessel(vessel.id.ToString())) {
continue;
}
foreach (Part part in vessel.parts) {
if (part.rb == null) {
if (has_active_vessel_in_space() && !FlightGlobals.ActiveVessel.packed) {
// TODO(egg): move this to the C++, this is just to check that I
// understand the issue.
foreach (Vessel vessel in FlightGlobals.VesselsLoaded) {
// TODO(egg): if I understand anything, there should probably be a
// special treatment for loaded packed vessels. I don't understand
// anything though.
if (vessel.packed || !plugin_.HasVessel(vessel.id.ToString())) {
continue;
}
QP part_actual_degrees_of_freedom =
plugin_.GetPartActualDegreesOfFreedom(part.flightID);
// TODO(egg): use the centre of mass. Here it's a bit tedious, some
// transform nonsense must probably be done.
Log.Error(
"q correction " +
((Vector3d)part_actual_degrees_of_freedom.q - part.rb.position));
Log.Error(
"v correction " +
((Vector3d)part_actual_degrees_of_freedom.p - part.rb.velocity));
part.rb.position = (Vector3d)part_actual_degrees_of_freedom.q;
part.rb.velocity = (Vector3d)part_actual_degrees_of_freedom.p;
foreach (Part part in vessel.parts) {
if (part.rb == null) {
continue;
}
QP part_actual_degrees_of_freedom =
plugin_.GetPartActualDegreesOfFreedom(part.flightID, FlightGlobals.ActiveVessel.rootPart.flightID);
// TODO(egg): use the centre of mass. Here it's a bit tedious, some
// transform nonsense must probably be done.
Log.Error(
"q correction " +
((Vector3d)part_actual_degrees_of_freedom.q - part.rb.position));
Log.Error(
"v correction " +
((Vector3d)part_actual_degrees_of_freedom.p - part.rb.velocity));
part.rb.position = (Vector3d)part_actual_degrees_of_freedom.q;
part.rb.velocity = (Vector3d)part_actual_degrees_of_freedom.p;
}
}
}
if (has_active_vessel_in_space() && !FlightGlobals.ActiveVessel.packed) {
QP main_body_dof = plugin_.CelestialWorldDegreesOfFreedom(
FlightGlobals.ActiveVessel.mainBody.flightGlobalsIndex);
FlightGlobals.ActiveVessel.mainBody.flightGlobalsIndex,
FlightGlobals.ActiveVessel.rootPart.flightID);
Log.Error("change in framevel: " +
(-(Vector3d)main_body_dof.p - krakensbane.FrameVel));
krakensbane.FrameVel = -(Vector3d)main_body_dof.p;
2 changes: 2 additions & 0 deletions serialization/journal.proto
Original file line number Diff line number Diff line change
@@ -197,6 +197,7 @@ message CelestialWorldDegreesOfFreedom {
required fixed64 plugin = 1 [(pointer_to) = "Plugin const",
(is_subject) = true];
required int32 index = 2;
required fixed32 part_at_origin = 3;
}
message Return {
required QP result = 1;
@@ -606,6 +607,7 @@ message GetPartActualDegreesOfFreedom {
required fixed64 plugin = 1 [(pointer_to) = "Plugin const",
(is_subject) = true];
required fixed32 part_id = 2;
required fixed32 part_at_origin = 3;
}
message Return {
required QP result = 1;