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

Commits on Mar 15, 2017

  1. that navball is flipped? O_o

    eggrobin committed Mar 15, 2017
    Copy the full SHA
    a6e9d11 View commit details
  2. Merge pull request #1263 from eggrobin/forward-the-surface-navball

    The surface navball
    pleroy authored Mar 15, 2017
    Copy the full SHA
    78eb6dc View commit details
Showing with 87 additions and 47 deletions.
  1. +56 −23 ksp_plugin/plugin.cpp
  2. +23 −24 ksp_plugin_adapter/ksp_plugin_adapter.cs
  3. +2 −0 physics/body_surface_dynamic_frame.hpp
  4. +6 −0 physics/body_surface_dynamic_frame_body.hpp
79 changes: 56 additions & 23 deletions ksp_plugin/plugin.cpp
Original file line number Diff line number Diff line change
@@ -32,6 +32,7 @@
#include "physics/body_centred_body_direction_dynamic_frame.hpp"
#include "physics/body_centred_non_rotating_dynamic_frame.hpp"
#include "physics/body_surface_dynamic_frame.hpp"
#include "physics/body_surface_frame_field.hpp"
#include "physics/dynamic_frame.hpp"
#include "physics/frame_field.hpp"
#include "physics/rotating_body.hpp"
@@ -70,6 +71,7 @@ using physics::KeplerianElements;
using physics::RotatingBody;
using physics::RigidMotion;
using physics::RigidTransformation;
using physics::BodySurfaceFrameField;
using quantities::Force;
using quantities::Length;
using quantities::si::Kilogram;
@@ -908,24 +910,29 @@ std::unique_ptr<FrameField<World, Navball>> Plugin::NavballFrameField(
public:
NavballFrameField(
not_null<Plugin const*> const plugin,
base::not_null<
std::unique_ptr<FrameField<Navigation, RightHandedNavball>>>
right_handed_navball_field,
not_null<std::unique_ptr<FrameField<Navigation, RightHandedNavball>>>
navigation_right_handed_field,
Position<World> const& sun_world_position)
: plugin_(plugin),
right_handed_navball_field_(std::move(right_handed_navball_field)),
navigation_right_handed_field_(
std::move(navigation_right_handed_field)),
sun_world_position_(sun_world_position) {}

NavballFrameField(
not_null<Plugin const*> const plugin,
not_null<std::unique_ptr<FrameField<Barycentric, RightHandedNavball>>>
barycentric_right_handed_field,
Position<World> const& sun_world_position)
: plugin_(plugin),
barycentric_right_handed_field_(
std::move(barycentric_right_handed_field)),
sun_world_position_(sun_world_position) {}

Rotation<Navball, World> FromThisFrame(
Position<World> const& q) const override {
Instant const& current_time = plugin_->current_time_;
plugin_->ephemeris_->Prolong(current_time);

OrthogonalMap<Navigation, World> const navigation_to_world =
plugin_->BarycentricToWorld() *
plugin_->plotting_frame_->FromThisFrameAtTime(current_time)
.orthogonal_map();

AffineMap<Barycentric, Navigation, Length, OrthogonalMap> const
barycentric_to_navigation =
plugin_->plotting_frame_->ToThisFrameAtTime(current_time)
@@ -934,35 +941,61 @@ std::unique_ptr<FrameField<World, Navball>> Plugin::NavballFrameField(
(barycentric_to_navigation *
plugin_->WorldToBarycentric(sun_world_position_))(q);

OrthogonalMap<RightHandedNavball, Barycentric>
right_handed_navball_to_barycentric =
barycentric_right_handed_field_ == nullptr
? plugin_->plotting_frame_->FromThisFrameAtTime(current_time)
.orthogonal_map() *
navigation_right_handed_field_
->FromThisFrame(q_in_navigation)
.Forget()
: barycentric_right_handed_field_
->FromThisFrame(
plugin_->WorldToBarycentric(sun_world_position_)(q))
.Forget();

// KSP's navball has x west, y up, z south.
// We want x north, y east, z down.
OrthogonalMap<Navball, World> const orthogonal_map =
navigation_to_world *
right_handed_navball_field_->FromThisFrame(q_in_navigation).Forget() *
plugin_->BarycentricToWorld() * right_handed_navball_to_barycentric *
Permutation<World, RightHandedNavball>(
Permutation<World, RightHandedNavball>::XZY)
.Forget() *
Permutation<World, RightHandedNavball>::XZY).Forget() *
Rotation<Navball, World>(π / 2 * Radian,
Bivector<double, World>({0, 1, 0}),
DefinesFrame<Navball>())
.Forget();
DefinesFrame<Navball>()).Forget();
CHECK(orthogonal_map.Determinant().Positive());
return orthogonal_map.rotation();
}

private:
not_null<Plugin const*> const plugin_;
base::not_null<
std::unique_ptr<FrameField<Navigation, RightHandedNavball>>> const
right_handed_navball_field_;
std::unique_ptr<FrameField<Navigation, RightHandedNavball>> const
navigation_right_handed_field_;
std::unique_ptr<FrameField<Barycentric, RightHandedNavball>> const
barycentric_right_handed_field_;
Position<World> const sun_world_position_;
};

return std::make_unique<NavballFrameField>(
this,
base::make_not_null_unique<
CoordinateFrameField<Navigation, RightHandedNavball>>(),
sun_world_position);
std::unique_ptr<FrameField<Navigation, RightHandedNavball>> frame_field;
auto plotting_frame_as_body_surface_dynamic_frame =
dynamic_cast<BodySurfaceDynamicFrame<Barycentric, Navigation>*>(
&*plotting_frame_);
if (plotting_frame_as_body_surface_dynamic_frame != nullptr) {
return std::make_unique<NavballFrameField>(
this,
make_not_null_unique<
BodySurfaceFrameField<Barycentric, RightHandedNavball>>(
*ephemeris_,
current_time_,
plotting_frame_as_body_surface_dynamic_frame->centre()),
sun_world_position);
} else {
return std::make_unique<NavballFrameField>(
this,
make_not_null_unique<
CoordinateFrameField<Navigation, RightHandedNavball>>(),
sun_world_position);
}
}

Vector<double, World> Plugin::VesselTangent(GUID const& vessel_guid) const {
47 changes: 23 additions & 24 deletions ksp_plugin_adapter/ksp_plugin_adapter.cs
Original file line number Diff line number Diff line change
@@ -42,8 +42,6 @@ public partial class PrincipiaPluginAdapter
private IntPtr plugin_ = IntPtr.Zero;

private bool display_patched_conics_ = false;
[KSPField(isPersistant = true)]
private bool fix_navball_in_plotting_frame_ = true;

private readonly double[] prediction_length_tolerances_ =
{1e-3, 1e-2, 1e0, 1e1, 1e2, 1e3, 1e4};
@@ -118,6 +116,7 @@ private enum PluginSource {
private UnityEngine.Texture inertial_navball_texture_;
private UnityEngine.Texture barycentric_navball_texture_;
private bool navball_changed_ = true;
private FlightGlobals.SpeedDisplayModes previous_display_mode_;

// The RSAS is the component of the stock KSP autopilot that deals with
// orienting the vessel towards a specific direction (e.g. prograde).
@@ -571,23 +570,36 @@ private void LateUpdate() {
Action<UnityEngine.Texture> set_navball_texture = (texture) =>
navball_material.SetTexture("_MainTexture", texture);

if (navball_changed_) {
if (navball_changed_ ||
previous_display_mode_ != FlightGlobals.speedDisplayMode) {
// Texture the ball.
navball_changed_ = false;
previous_display_mode_ = FlightGlobals.speedDisplayMode;
// TODO(egg): switch over all frame types and have more navball textures
// when more frames are available.
if (!fix_navball_in_plotting_frame_ || !PluginRunning()) {
if (FlightGlobals.speedDisplayMode !=
FlightGlobals.SpeedDisplayModes.Orbit ||
!PluginRunning()) {
set_navball_texture(compass_navball_texture_);
} else if (plotting_frame_selector_.get().frame_type ==
ReferenceFrameSelector.FrameType.BODY_CENTRED_NON_ROTATING) {
set_navball_texture(inertial_navball_texture_);
} else {
set_navball_texture(barycentric_navball_texture_);
switch (plotting_frame_selector_.get().frame_type) {
case ReferenceFrameSelector.FrameType.BODY_SURFACE:
set_navball_texture(compass_navball_texture_);
break;
case ReferenceFrameSelector.FrameType.BODY_CENTRED_NON_ROTATING:
set_navball_texture(inertial_navball_texture_);
break;
case ReferenceFrameSelector.FrameType.BARYCENTRIC_ROTATING:
case ReferenceFrameSelector.FrameType.BODY_CENTRED_PARENT_DIRECTION:
set_navball_texture(barycentric_navball_texture_);
break;
}
}
}

// Orient the ball.
if (PluginRunning() && fix_navball_in_plotting_frame_) {
if (PluginRunning() && FlightGlobals.speedDisplayMode ==
FlightGlobals.SpeedDisplayModes.Orbit) {
navball_.navBall.rotation =
(UnityEngine.QuaternionD)navball_.attitudeGymbal * // sic.
(UnityEngine.QuaternionD)plugin_.NavballOrientation(
@@ -1307,17 +1319,6 @@ private void CrashOptions() {

private void ReferenceFrameSelection() {
if (PluginRunning()) {
bool was_fixing_navball_in_plotting_frame =
fix_navball_in_plotting_frame_;
fix_navball_in_plotting_frame_ =
UnityEngine.GUILayout.Toggle(
value : fix_navball_in_plotting_frame_,
text : "Fix navball in plotting frame");
if (was_fixing_navball_in_plotting_frame !=
fix_navball_in_plotting_frame_) {
navball_changed_ = true;
reset_rsas_target_ = true;
}
plotting_frame_selector_.get().RenderButton();
}
}
@@ -1506,10 +1507,8 @@ private void UpdateRenderingFrame(
NavigationFrameParameters frame_parameters) {
IntPtr new_plotting_frame = plugin_.NewNavigationFrame(frame_parameters);
plugin_.SetPlottingFrame(ref new_plotting_frame);
if (fix_navball_in_plotting_frame_) {
navball_changed_ = true;
reset_rsas_target_ = true;
}
navball_changed_ = true;
reset_rsas_target_ = true;
}

private void ResetPlugin() {
2 changes: 2 additions & 0 deletions physics/body_surface_dynamic_frame.hpp
Original file line number Diff line number Diff line change
@@ -44,6 +44,8 @@ class BodySurfaceDynamicFrame
RigidMotion<InertialFrame, ThisFrame> ToThisFrameAtTime(
Instant const& t) const override;

not_null<RotatingBody<InertialFrame> const*> centre() const;

void WriteToMessage(
not_null<serialization::DynamicFrame*> message) const override;

6 changes: 6 additions & 0 deletions physics/body_surface_dynamic_frame_body.hpp
Original file line number Diff line number Diff line change
@@ -45,6 +45,12 @@ BodySurfaceDynamicFrame<InertialFrame, ThisFrame>::ToThisFrameAtTime(
centre_degrees_of_freedom.velocity());
}

template<typename InertialFrame, typename ThisFrame>
not_null<RotatingBody<InertialFrame> const*>
BodySurfaceDynamicFrame<InertialFrame, ThisFrame>::centre() const {
return centre_;
}

template<typename InertialFrame, typename ThisFrame>
void BodySurfaceDynamicFrame<InertialFrame, ThisFrame>::
WriteToMessage(not_null<serialization::DynamicFrame*> const message) const {