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: fa74acff8c82
Choose a base ref
...
head repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 652152ea7032
Choose a head ref
  • 3 commits
  • 7 files changed
  • 1 contributor

Commits on Jan 1, 2022

  1. SO(3) is not commutative

    eggrobin committed Jan 1, 2022
    Copy the full SHA
    e2a2167 View commit details
  2. alphabetize

    eggrobin committed Jan 1, 2022
    Copy the full SHA
    afe3f5a View commit details
  3. Merge pull request #3270 from eggrobin/camera-orientation

    SO(3) is not commutative
    eggrobin authored Jan 1, 2022
    Copy the full SHA
    652152e View commit details
Showing with 40 additions and 10 deletions.
  1. +12 −0 ksp_plugin/frames.hpp
  2. +2 −1 ksp_plugin/interface_renderer.cpp
  3. +9 −0 ksp_plugin/plugin.cpp
  4. +4 −0 ksp_plugin/plugin.hpp
  5. +8 −7 ksp_plugin/renderer.cpp
  6. +4 −2 ksp_plugin/renderer.hpp
  7. +1 −0 serialization/geometry.proto
12 changes: 12 additions & 0 deletions ksp_plugin/frames.hpp
Original file line number Diff line number Diff line change
@@ -99,6 +99,17 @@ using CameraReference = Frame<serialization::Frame::PluginTag,
Handedness::Left,
serialization::Frame::CAMERA_REFERENCE>;

// |CameraReference|, rotated about its y axis by the angle of the planetarium
// rotation. KSP compensates for the planetarium rotation so that the
// orientation of the camera remains inertially fixed regardless of whether
// World is rotating; we must undo this compensation in order for the camera to
// be fixed in |CameraReference|.
using CameraCompensatedReference =
Frame<serialization::Frame::PluginTag,
Arbitrary,
Handedness::Left,
serialization::Frame::CAMERA_COMPENSATED_REFERENCE>;

// A nonrotating referencence frame comoving with the sun with the same axes as
// |AliceWorld|. Since it is nonrotating (though not inertial), differences
// between velocities are consistent with those in an inertial reference frame.
@@ -162,6 +173,7 @@ using internal_frames::ApparentWorld;
using internal_frames::Barycentric;
using internal_frames::BodyWorld;
using internal_frames::Camera;
using internal_frames::CameraCompensatedReference;
using internal_frames::CameraReference;
using internal_frames::CelestialSphere;
using internal_frames::EccentricPart;
3 changes: 2 additions & 1 deletion ksp_plugin/interface_renderer.cpp
Original file line number Diff line number Diff line change
@@ -145,7 +145,8 @@ WXYZ __cdecl principia__CameraReferenceRotation(Plugin* const plugin) {
return m.Return(
ToWXYZ(GetRenderer(plugin)
.CameraReferenceRotation(plugin->CurrentTime(),
plugin->PlanetariumRotation())
plugin->PlanetariumRotation(),
plugin->CameraCompensation())
.quaternion()));
}

9 changes: 9 additions & 0 deletions ksp_plugin/plugin.cpp
Original file line number Diff line number Diff line change
@@ -1294,6 +1294,11 @@ Rotation<Barycentric, AliceSun> const& Plugin::PlanetariumRotation() const {
return *cached_planetarium_rotation_;
}

Rotation<CameraCompensatedReference, CameraReference> const&
Plugin::CameraCompensation() const {
return *camera_compensation_;
}

Renderer& Plugin::renderer() {
return *renderer_;
}
@@ -1574,6 +1579,10 @@ void Plugin::UpdatePlanetariumRotation() {
Bivector<double, PlanetariumFrame>({0, 0, 1}),
DefinesFrame<AliceSun>{}) *
to_planetarium;
camera_compensation_ = Rotation<CameraCompensatedReference, CameraReference>(
-planetarium_rotation_,
Bivector<double, CameraReference>({0, 1, 0}),
DefinesFrame<CameraCompensatedReference>{});
}

Velocity<World> Plugin::VesselVelocity(
4 changes: 4 additions & 0 deletions ksp_plugin/plugin.hpp
Original file line number Diff line number Diff line change
@@ -443,6 +443,8 @@ class Plugin {
// this change of basis is all that's required to convert relative velocities
// or displacements between simultaneous events.
virtual Rotation<Barycentric, AliceSun> const& PlanetariumRotation() const;
virtual Rotation<CameraCompensatedReference, CameraReference> const&
CameraCompensation() const;

virtual Renderer& renderer();
virtual Renderer const& renderer() const;
@@ -534,6 +536,8 @@ class Plugin {

Angle planetarium_rotation_;
std::optional<Rotation<Barycentric, AliceSun>> cached_planetarium_rotation_;
std::optional<Rotation<CameraCompensatedReference, CameraReference>>
camera_compensation_;
// The game epoch in real time.
Instant game_epoch_;
// The current in-game universal time.
15 changes: 8 additions & 7 deletions ksp_plugin/renderer.cpp
Original file line number Diff line number Diff line change
@@ -278,18 +278,19 @@ RigidTransformation<World, Navigation> Renderer::WorldToPlotting(
WorldToBarycentric(time, sun_world_position, planetarium_rotation);
}

Rotation<CameraReference, CelestialSphere> Renderer::CameraReferenceRotation(
Rotation<CameraCompensatedReference, World> Renderer::CameraReferenceRotation(
Instant const& time,
Rotation<Barycentric, AliceSun> const& planetarium_rotation) const {
Rotation<Barycentric, AliceSun> const& planetarium_rotation,
Rotation<CameraCompensatedReference, CameraReference> const&
camera_compensation) const {
Permutation<Barycentric, CelestialSphere> const celestial_mirror(
OddPermutation::XZY);
Permutation<CameraReference, Navigation> const camera_mirror(
OddPermutation::XZY);
auto const result =
celestial_mirror.Forget<OrthogonalMap>() *
GetPlottingFrame()->FromThisFrameAtTime(time).orthogonal_map() *
camera_mirror.Forget<OrthogonalMap>();
return result.AsRotation();
return (BarycentricToWorld(planetarium_rotation) *
GetPlottingFrame()->FromThisFrameAtTime(time).orthogonal_map() *
camera_mirror.Forget<OrthogonalMap>()).AsRotation() *
camera_compensation;
}

void Renderer::WriteToMessage(
6 changes: 4 additions & 2 deletions ksp_plugin/renderer.hpp
Original file line number Diff line number Diff line change
@@ -159,9 +159,11 @@ class Renderer {
Position<World> const& sun_world_position,
Rotation<Barycentric, AliceSun> const& planetarium_rotation) const;

virtual Rotation<CameraReference, CelestialSphere> CameraReferenceRotation(
virtual Rotation<CameraCompensatedReference, World> CameraReferenceRotation(
Instant const& time,
Rotation<Barycentric, AliceSun> const& planetarium_rotation) const;
Rotation<Barycentric, AliceSun> const& planetarium_rotation,
Rotation<CameraCompensatedReference, CameraReference> const&
camera_compensation) const;

virtual void WriteToMessage(not_null<serialization::Renderer*> message) const;

1 change: 1 addition & 0 deletions serialization/geometry.proto
Original file line number Diff line number Diff line change
@@ -159,6 +159,7 @@ message Frame {
BODY_WORLD = 9;
// BUBBLE = 13;
CAMERA = 14;
CAMERA_COMPENSATED_REFERENCE = 21;
CAMERA_REFERENCE = 17;
CELESTIAL_SPHERE = 8;
ECCENTRIC_PART = 20;