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: 4f2991673ac5
Choose a base ref
...
head repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 89f583886ee8
Choose a head ref
  • 9 commits
  • 5 files changed
  • 2 contributors

Commits on Sep 24, 2017

  1. a failing test.

    eggrobin committed Sep 24, 2017
    Copy the full SHA
    5356080 View commit details
  2. Copy the full SHA
    e7bc686 View commit details

Commits on Sep 25, 2017

  1. callbacks

    eggrobin committed Sep 25, 2017
    Copy the full SHA
    e8cafdf View commit details

Commits on Sep 26, 2017

  1. Copy the full SHA
    36403bb View commit details
  2. why doesn't that work

    eggrobin committed Sep 26, 2017
    Copy the full SHA
    1a5f09f View commit details
  3. .... add not remove

    eggrobin committed Sep 26, 2017
    Copy the full SHA
    681b105 View commit details
  4. sign

    eggrobin committed Sep 26, 2017
    Copy the full SHA
    6fc1f58 View commit details

Commits on Sep 30, 2017

  1. blank

    eggrobin committed Sep 30, 2017
    Copy the full SHA
    1b8aca0 View commit details
  2. Merge pull request #1583 from eggrobin/reunification-point-2

    Reunification points 1 & 2
    pleroy authored Sep 30, 2017
    Copy the full SHA
    89f5838 View commit details
Showing with 223 additions and 55 deletions.
  1. +23 −5 ksp_plugin/interface.cpp
  2. +70 −25 ksp_plugin/plugin.cpp
  3. +9 −2 ksp_plugin/plugin.hpp
  4. +88 −12 ksp_plugin_adapter/ksp_plugin_adapter.cs
  5. +33 −11 serialization/journal.proto
28 changes: 23 additions & 5 deletions ksp_plugin/interface.cpp
Original file line number Diff line number Diff line change
@@ -232,6 +232,13 @@ QP principia__CelestialWorldDegreesOfFreedom(Plugin const* const plugin,
FromGameTime(*plugin, time))));
}

void principia__ClearWorldRotationalReferenceFrame(Plugin* const plugin) {
journal::Method<journal::ClearWorldRotationalReferenceFrame> m({plugin});
CHECK_NOTNULL(plugin);
plugin->ClearWorldRotationalReferenceFrame();
return m.Return();
}

double principia__CurrentTime(Plugin const* const plugin) {
journal::Method<journal::CurrentTime> m({plugin});
CHECK_NOTNULL(plugin);
@@ -780,15 +787,18 @@ void principia__SetMainBody(Plugin* const plugin, int const index) {
return m.Return();
}

void principia__SetPartApparentDegreesOfFreedom(Plugin* const plugin,
PartId const part_id,
QP const degrees_of_freedom) {
void principia__SetPartApparentDegreesOfFreedom(
Plugin* const plugin,
PartId const part_id,
QP const degrees_of_freedom,
QP const main_body_degrees_of_freedom) {
journal::Method<journal::SetPartApparentDegreesOfFreedom> m(
{plugin, part_id, degrees_of_freedom});
{plugin, part_id, degrees_of_freedom, main_body_degrees_of_freedom});
CHECK_NOTNULL(plugin);
plugin->SetPartApparentDegreesOfFreedom(
part_id,
FromQP<DegreesOfFreedom<World>>(degrees_of_freedom));
FromQP<DegreesOfFreedom<World>>(degrees_of_freedom),
FromQP<DegreesOfFreedom<World>>(main_body_degrees_of_freedom));
return m.Return();
}

@@ -817,6 +827,14 @@ void principia__SetVerboseLogging(int const level) {
return m.Return();
}

void principia__SetWorldRotationalReferenceFrame(Plugin* const plugin,
int const index) {
journal::Method<journal::SetWorldRotationalReferenceFrame> m({plugin, index});
CHECK_NOTNULL(plugin);
plugin->SetWorldRotationalReferenceFrame(index);
return m.Return();
}

XYZ principia__UnmanageableVesselVelocity(Plugin const* const plugin,
QP const degrees_of_freedom,
int const parent_index) {
95 changes: 70 additions & 25 deletions ksp_plugin/plugin.cpp
Original file line number Diff line number Diff line change
@@ -327,6 +327,15 @@ Time Plugin::CelestialRotationPeriod(Index const celestial_index) const {
return 2 * π * Radian / body.angular_frequency();
}

void Plugin::ClearWorldRotationalReferenceFrame() {
angular_velocity_of_world_ = AngularVelocity<Barycentric>();
}

void Plugin::SetWorldRotationalReferenceFrame(Index const celestial_index) {
SetMainBody(celestial_index);
angular_velocity_of_world_ = main_body_->angular_velocity();
}

Index Plugin::CelestialIndexOfBody(MassiveBody const& body) const {
return FindOrDie(name_to_index_, body.name());
}
@@ -421,17 +430,18 @@ void Plugin::InsertOrKeepLoadedPart(
MainBodyCentred::origin,
main_body_frame.ToThisFrameAtTime(previous_time).orthogonal_map() *
renderer_->WorldToBarycentric(PlanetariumRotation())},
AngularVelocity<World>(),
renderer_->BarycentricToWorld(PlanetariumRotation())(
-angular_velocity_of_world_),
main_body_degrees_of_freedom.velocity()};
auto const world_to_barycentric =
auto const world_to_barycentric_motion =
main_body_frame.FromThisFrameAtTime(previous_time) *
world_to_main_body_centred;

AddPart(vessel,
part_id,
name,
mass,
world_to_barycentric(part_degrees_of_freedom));
world_to_barycentric_motion(part_degrees_of_freedom));
}
vessel->KeepPart(part_id);
not_null<Part*> part = vessel->part(part_id);
@@ -524,15 +534,20 @@ void Plugin::FreeVesselsAndPartsAndCollectPileUps(Time const& Δt) {

void Plugin::SetPartApparentDegreesOfFreedom(
PartId const part_id,
DegreesOfFreedom<World> const& degrees_of_freedom) {
DegreesOfFreedom<World> const& degrees_of_freedom,
DegreesOfFreedom<World> const& main_body_degrees_of_freedom) {
// Define |ApparentBubble| as the reference frame with the axes of
// |Barycentric| centred on the current main body.
RigidMotion<World, ApparentBubble> world_to_apparent_bubble{
RigidTransformation<World, ApparentBubble>{
World::origin,
main_body_degrees_of_freedom.position(),
ApparentBubble::origin,
OrthogonalMap<Barycentric, ApparentBubble>::Identity() *
renderer_->WorldToBarycentric(PlanetariumRotation())},
AngularVelocity<World>{},
Velocity<World>{}};
renderer_->BarycentricToWorld(PlanetariumRotation())(
-angular_velocity_of_world_),
main_body_degrees_of_freedom.velocity()};

not_null<Vessel*> vessel = FindOrDie(part_id_to_vessel_, part_id);
CHECK(is_loaded(vessel));
not_null<Part*> const part = vessel->part(part_id);
@@ -544,36 +559,66 @@ void Plugin::SetPartApparentDegreesOfFreedom(
DegreesOfFreedom<World> Plugin::GetPartActualDegreesOfFreedom(
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>{
enum class LocalTag { tag };
using MainBodyCentred =
geometry::Frame<LocalTag, LocalTag::tag, /*frame_is_inertial=*/false>;
BodyCentredNonRotatingDynamicFrame<Barycentric, MainBodyCentred> const
main_body_frame{ephemeris_.get(), main_body_};

auto const barycentric_to_main_body_motion =
main_body_frame.ToThisFrameAtTime(current_time_);
// In coordinates, this rotation is the identity.
auto const barycentric_to_main_body_rotation =
barycentric_to_main_body_motion.rigid_transformation().linear_map();
auto const world_origin = barycentric_to_main_body_motion(
FindOrDie(part_id_to_vessel_, part_at_origin)->part(part_at_origin)->
degrees_of_freedom());

RigidMotion<MainBodyCentred, World> const main_body_to_world{
RigidTransformation<MainBodyCentred, World>{
world_origin.position(),
World::origin,
renderer_->BarycentricToWorld(PlanetariumRotation())},
AngularVelocity<Barycentric>{},
renderer_->BarycentricToWorld(PlanetariumRotation()) *
barycentric_to_main_body_rotation.Inverse()},
barycentric_to_main_body_rotation(angular_velocity_of_world_),
world_origin.velocity()};
return barycentric_to_world(FindOrDie(part_id_to_vessel_, part_id)->
part(part_id)->
degrees_of_freedom());

return (main_body_to_world * barycentric_to_main_body_motion)(
FindOrDie(part_id_to_vessel_,
part_id)->part(part_id)->degrees_of_freedom());
}

// TODO(egg): the following function is a near-exact replica of the preceding
// one. Factorize.
DegreesOfFreedom<World> Plugin::CelestialWorldDegreesOfFreedom(
Index const index,
PartId const part_at_origin,
Instant const& time) const {
auto const part =
FindOrDie(part_id_to_vessel_, part_at_origin)->part(part_at_origin);
auto const world_origin = part->degrees_of_freedom();
RigidMotion<Barycentric, World> barycentric_to_world{
RigidTransformation<Barycentric, World>{
enum class LocalTag { tag };
using MainBodyCentred =
geometry::Frame<LocalTag, LocalTag::tag, /*frame_is_inertial=*/false>;
BodyCentredNonRotatingDynamicFrame<Barycentric, MainBodyCentred> const
main_body_frame{ephemeris_.get(), main_body_};

auto const barycentric_to_main_body_motion =
main_body_frame.ToThisFrameAtTime(current_time_);
// In coordinates, this rotation is the identity.
auto const barycentric_to_main_body_rotation =
barycentric_to_main_body_motion.rigid_transformation().linear_map();
auto const world_origin = barycentric_to_main_body_motion(
FindOrDie(part_id_to_vessel_, part_at_origin)->part(part_at_origin)->
degrees_of_freedom());

RigidMotion<MainBodyCentred, World> const main_body_to_world{
RigidTransformation<MainBodyCentred, World>{
world_origin.position(),
World::origin,
renderer_->BarycentricToWorld(PlanetariumRotation())},
AngularVelocity<Barycentric>{},
renderer_->BarycentricToWorld(PlanetariumRotation()) *
barycentric_to_main_body_rotation.Inverse()},
barycentric_to_main_body_rotation(angular_velocity_of_world_),
world_origin.velocity()};
return barycentric_to_world(

return (main_body_to_world * barycentric_to_main_body_motion)(
FindOrDie(celestials_, index)->
trajectory().EvaluateDegreesOfFreedom(time));
}
11 changes: 9 additions & 2 deletions ksp_plugin/plugin.hpp
Original file line number Diff line number Diff line change
@@ -48,6 +48,7 @@ using base::not_null;
using base::Subset;
using base::ThreadPool;
using geometry::AffineMap;
using geometry::AngularVelocity;
using geometry::Displacement;
using geometry::Instant;
using geometry::OrthogonalMap;
@@ -144,6 +145,9 @@ class Plugin {
virtual Angle CelestialInitialRotation(Index celestial_index) const;
virtual Time CelestialRotationPeriod(Index celestial_index) const;

virtual void ClearWorldRotationalReferenceFrame();
virtual void SetWorldRotationalReferenceFrame(Index celestial_index);

virtual Index CelestialIndexOfBody(MassiveBody const& body) const;

// Inserts a new vessel with GUID |vessel_guid| if it does not already exist,
@@ -215,7 +219,8 @@ class Plugin {
// relevant part. This part must be in a loaded vessel.
virtual void SetPartApparentDegreesOfFreedom(
PartId part_id,
DegreesOfFreedom<World> const& degrees_of_freedom);
DegreesOfFreedom<World> const& degrees_of_freedom,
DegreesOfFreedom<World> const& main_body_degrees_of_freedom);

// Returns the degrees of freedom of the given part in |World|, assuming that
// the origin of |World| is fixed at the centre of mass of the
@@ -225,7 +230,8 @@ class Plugin {
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|.
// |Index|, identifying the origin of |World| with the centre of mass of the
// |Part| with the given |PartId|.
virtual DegreesOfFreedom<World> CelestialWorldDegreesOfFreedom(
Index const index,
PartId part_at_origin,
@@ -472,6 +478,7 @@ class Plugin {
std::unique_ptr<Renderer> renderer_;

RotatingBody<Barycentric> const* main_body_ = nullptr;
AngularVelocity<Barycentric> angular_velocity_of_world_;

// Do not |erase| from this list, use |Part::clear_pile_up| instead.
std::list<PileUp> pile_ups_;
Loading