Skip to content

More reasonable angular resolution based on the camera settings #4169

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

Merged
merged 11 commits into from
May 9, 2025
1 change: 1 addition & 0 deletions Principia.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=colour/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=colours/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=downsampling/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=equipotential/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Frenet/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=geopotential/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=gipfeli/@EntryIndexedValue">True</s:Boolean>
Expand Down
1 change: 1 addition & 0 deletions benchmarks/planetarium_benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ void BM_PlanetariumPlotMethod3(
satellites.goes_8_trajectory().end(),
now,
/*t_max=*/InfiniteFuture,
/*tan_angular_resolution=*/0.00080,
/*reverse=*/false,
/*add_point=*/
[&line](ScaledSpacePoint const& point) { line.push_back(point); },
Expand Down
47 changes: 43 additions & 4 deletions ksp_plugin/interface_planetarium.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Planetarium* __cdecl principia__PlanetariumCreate(
double const focal,
double const field_of_view,
double const inverse_scale_factor,
double const tan_angular_resolution,
XYZ const scaled_space_origin) {
journal::Method<journal::PlanetariumCreate> m({plugin,
sun_world_position,
Expand All @@ -60,6 +61,7 @@ Planetarium* __cdecl principia__PlanetariumCreate(
focal,
field_of_view,
inverse_scale_factor,
tan_angular_resolution,
scaled_space_origin});
Renderer const& renderer = CHECK_NOTNULL(plugin)->renderer();

Expand Down Expand Up @@ -88,9 +90,13 @@ Planetarium* __cdecl principia__PlanetariumCreate(
FromXYZ<Position<World>>(sun_world_position),
plugin->PlanetariumRotation());

// Angular resolution: My display has a height of 401 mm and 1600 pixels
// vertically. My eye is at least 550 mm from the centre. Hence the
// wolframalpha.com query: "ArcTan[(401/1600)/550] in arcmin" which yields
// 1.567'.
Planetarium::Parameters parameters(
/*sphere_radius_multiplier=*/1.0,
/*angular_resolution=*/0.4 * ArcMinute,
/*angular_resolution=*/1.567 * ArcMinute,
field_of_view * Radian);
Perspective<Navigation, Camera> perspective(
world_to_plotting_affine_map *
Expand Down Expand Up @@ -130,11 +136,19 @@ void __cdecl principia__PlanetariumPlotFlightPlanSegment(
char const* const vessel_guid,
int const index,
double const* const t_max,
double const tan_angular_resolution,
ScaledSpacePoint* const vertices,
int const vertices_size,
int* const vertex_count) {
journal::Method<journal::PlanetariumPlotFlightPlanSegment> m(
{planetarium, plugin, vessel_guid, index, t_max, vertices, vertices_size},
{planetarium,
plugin,
vessel_guid,
index,
t_max,
tan_angular_resolution,
vertices,
vertices_size},
{vertex_count});
CHECK_NOTNULL(plugin);
CHECK_NOTNULL(planetarium);
Expand All @@ -156,6 +170,7 @@ void __cdecl principia__PlanetariumPlotFlightPlanSegment(
segment->end(),
plugin->CurrentTime(),
t_max == nullptr ? InfiniteFuture : FromGameTime(*plugin, *t_max),
tan_angular_resolution,
/*reverse=*/false,
[vertices, vertex_count](ScaledSpacePoint const& vertex) {
vertices[(*vertex_count)++] = vertex;
Expand All @@ -172,11 +187,18 @@ void __cdecl principia__PlanetariumPlotPrediction(
Plugin const* const plugin,
char const* const vessel_guid,
double const* const t_max,
double const tan_angular_resolution,
ScaledSpacePoint* const vertices,
int const vertices_size,
int* const vertex_count) {
journal::Method<journal::PlanetariumPlotPrediction> m(
{planetarium, plugin, vessel_guid, t_max, vertices, vertices_size},
{planetarium,
plugin,
vessel_guid,
t_max,
tan_angular_resolution,
vertices,
vertices_size},
{vertex_count});
CHECK_NOTNULL(plugin);
CHECK_NOTNULL(planetarium);
Expand All @@ -189,6 +211,7 @@ void __cdecl principia__PlanetariumPlotPrediction(
prediction->end(),
plugin->CurrentTime(),
t_max == nullptr ? InfiniteFuture : FromGameTime(*plugin, *t_max),
tan_angular_resolution,
/*reverse=*/false,
[vertices, vertex_count](ScaledSpacePoint const& vertex) {
vertices[(*vertex_count)++] = vertex;
Expand All @@ -207,6 +230,7 @@ void __cdecl principia__PlanetariumPlotPsychohistory(
char const* const vessel_guid,
double const max_history_length,
double const* const t_max,
double const tan_angular_resolution,
ScaledSpacePoint* const vertices,
int const vertices_size,
int* const vertex_count) {
Expand All @@ -216,6 +240,7 @@ void __cdecl principia__PlanetariumPlotPsychohistory(
vessel_guid,
max_history_length,
t_max,
tan_angular_resolution,
vertices,
vertices_size},
{vertex_count});
Expand Down Expand Up @@ -246,6 +271,7 @@ void __cdecl principia__PlanetariumPlotPsychohistory(
psychohistory->end(),
/*now=*/plugin->CurrentTime(),
t_max == nullptr ? InfiniteFuture : FromGameTime(*plugin, *t_max),
tan_angular_resolution,
/*reverse=*/true,
[vertices, vertex_count](ScaledSpacePoint const& vertex) {
vertices[(*vertex_count)++] = vertex;
Expand All @@ -264,6 +290,7 @@ void __cdecl principia__PlanetariumPlotCelestialPastTrajectory(
Plugin const* const plugin,
int const celestial_index,
double const max_history_length,
double const tan_angular_resolution,
ScaledSpacePoint* const vertices,
int const vertices_size,
double* const minimal_distance_from_camera,
Expand All @@ -273,6 +300,7 @@ void __cdecl principia__PlanetariumPlotCelestialPastTrajectory(
plugin,
celestial_index,
max_history_length,
tan_angular_resolution,
vertices,
vertices_size},
{minimal_distance_from_camera, vertex_count});
Expand Down Expand Up @@ -303,6 +331,7 @@ void __cdecl principia__PlanetariumPlotCelestialPastTrajectory(
first_time,
/*last_time=*/plugin->CurrentTime(),
/*now=*/plugin->CurrentTime(),
tan_angular_resolution,
/*reverse=*/true,
[vertices, vertex_count](ScaledSpacePoint const& vertex) {
vertices[(*vertex_count)++] = vertex;
Expand All @@ -323,6 +352,7 @@ void __cdecl principia__PlanetariumPlotCelestialFutureTrajectory(
Plugin const* const plugin,
int const celestial_index,
char const* const vessel_guid,
double const tan_angular_resolution,
ScaledSpacePoint* const vertices,
int const vertices_size,
double* const minimal_distance_from_camera,
Expand All @@ -332,6 +362,7 @@ void __cdecl principia__PlanetariumPlotCelestialFutureTrajectory(
plugin,
celestial_index,
vessel_guid,
tan_angular_resolution,
vertices,
vertices_size},
{minimal_distance_from_camera, vertex_count});
Expand Down Expand Up @@ -362,6 +393,7 @@ void __cdecl principia__PlanetariumPlotCelestialFutureTrajectory(
/*first_time=*/plugin->CurrentTime(),
/*last_time=*/final_time,
/*now=*/plugin->CurrentTime(),
tan_angular_resolution,
/*reverse=*/false,
[vertices, vertex_count](ScaledSpacePoint const& vertex) {
vertices[(*vertex_count)++] = vertex;
Expand All @@ -379,11 +411,17 @@ void __cdecl principia__PlanetariumPlotEquipotential(
Planetarium const* const planetarium,
Plugin const* const plugin,
int const index,
double const tan_angular_resolution,
ScaledSpacePoint* const vertices,
int const vertices_size,
int* const vertex_count) {
journal::Method<journal::PlanetariumPlotEquipotential> m(
{planetarium, plugin, index, vertices, vertices_size},
{planetarium,
plugin,
index,
tan_angular_resolution,
vertices,
vertices_size},
{vertex_count});
CHECK_NOTNULL(plugin);
CHECK_NOTNULL(planetarium);
Expand All @@ -401,6 +439,7 @@ void __cdecl principia__PlanetariumPlotEquipotential(
equipotential.front().time,
equipotential.back().time,
plugin->CurrentTime(),
tan_angular_resolution,
/*reverse=*/false,
[vertices, vertex_count](ScaledSpacePoint const& vertex) {
vertices[(*vertex_count)++] = vertex;
Expand Down
11 changes: 9 additions & 2 deletions ksp_plugin/planetarium.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ void Planetarium::PlotMethod3(
DiscreteTrajectory<Barycentric>::iterator end,
Instant const& now,
Instant const& t_max,
double const tan_angular_resolution,
bool const reverse,
std::function<void(ScaledSpacePoint const&)> const& add_point,
int max_points) const {
Expand All @@ -281,8 +282,14 @@ void Planetarium::PlotMethod3(
auto const begin_time = std::max(begin->time, plotting_frame_->t_min());
auto const last_time =
std::min({last->time, plotting_frame_->t_max(), t_max});
PlotMethod3(
trajectory, begin_time, last_time, now, reverse, add_point, max_points);
PlotMethod3(trajectory,
begin_time,
last_time,
now,
tan_angular_resolution,
reverse,
add_point,
max_points);
}

std::vector<Sphere<Navigation>> Planetarium::ComputePlottableSpheres(
Expand Down
13 changes: 9 additions & 4 deletions ksp_plugin/planetarium.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ class Planetarium {
class Parameters final {
public:
// `sphere_radius_multiplier` defines the "dark area" around a celestial
// where we don't draw trajectories. `angular_resolution` defines the limit
// beyond which spheres don't participate in hiding. `field_of_view`
// is the half-angle of a cone outside of which not plotting takes place.
// where we don't draw trajectories. For methods 0 to 2,
// `angular_resolution` defines the limit beyond which spheres don't
// participate in hiding. `field_of_view` is the half-angle of a cone
// outside of which not plotting takes place.
explicit Parameters(double sphere_radius_multiplier,
Angle const& angular_resolution,
Angle const& field_of_view);
Expand Down Expand Up @@ -124,13 +125,16 @@ class Planetarium {
Length* minimal_distance = nullptr) const;

// A method similar to PlotMethod2, but which produces a three-dimensional
// trajectory in scaled space instead of projecting and hiding.
// trajectory in scaled space instead of projecting and hiding. Note that the
// angular resolution passed at construction is ignored and the parameter
// `tan_angular_resolution` is used instead.
void PlotMethod3(
Trajectory<Barycentric> const& trajectory,
DiscreteTrajectory<Barycentric>::iterator begin,
DiscreteTrajectory<Barycentric>::iterator end,
Instant const& now,
Instant const& t_max,
double tan_angular_resolution,
bool reverse,
std::function<void(ScaledSpacePoint const&)> const& add_point,
int max_points) const;
Expand All @@ -143,6 +147,7 @@ class Planetarium {
Instant const& first_time,
Instant const& last_time,
Instant const& now,
double tan_angular_resolution,
bool reverse,
std::function<void(ScaledSpacePoint const&)> const& add_point,
int max_points,
Expand Down
4 changes: 2 additions & 2 deletions ksp_plugin/planetarium_body.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ void Planetarium::PlotMethod3(
Instant const& first_time,
Instant const& last_time,
Instant const& now,
double const tan_angular_resolution,
bool const reverse,
std::function<void(ScaledSpacePoint const&)> const& add_point,
int const max_points,
Length* const minimal_distance) const {
double const tan²_angular_resolution =
Pow<2>(parameters_.tan_angular_resolution_);
double const tan²_angular_resolution = Pow<2>(tan_angular_resolution);
auto const final_time = reverse ? first_time : last_time;
auto previous_time = reverse ? last_time : first_time;

Expand Down
1 change: 1 addition & 0 deletions ksp_plugin_adapter/gl_lines.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public static DisposablePlanetarium NewPlanetarium(IntPtr plugin,
focal:1,
field_of_view,
ScaledSpace.InverseScaleFactor,
Plotter.TanAngularResolution(),
scaled_space_origin: (XYZ)ScaledSpace.ScaledToLocalSpace(
Vector3d.zero));
}
Expand Down
24 changes: 23 additions & 1 deletion ksp_plugin_adapter/main_window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public MainWindow(PrincipiaPluginAdapter adapter,
flight_planner_ = flight_planner;
orbit_analyser_ = orbit_analyser;
plotting_frame_selector_ = plotting_frame_selector;
cheeze_c.value = 0.65;
cheeze_x.value = -0.31;
Show();
}

Expand Down Expand Up @@ -167,8 +169,28 @@ public override void Save(ConfigNode node) {

protected override string Title => "Principia";

protected override void RenderWindowContents(int window_id) {
public static DifferentialSlider cheeze_c = new DifferentialSlider("c", "", -5, -1,
(x) => x.ToString("0.000"), zero_value: 0.65, min_value: 0.1, max_value: 4);
public static DifferentialSlider cheeze_x = new DifferentialSlider("x", "", -5, -1,
(x) => x.ToString("0.000"), zero_value: -0.31, min_value: -2, max_value: 0);

protected override void RenderWindowContents(int window_id) {
using (new UnityEngine.GUILayout.VerticalScope()) {
UnityEngine.GUILayout.Label("Cheeze constants: ");
cheeze_c.Render(true);
cheeze_x.Render(true);

UnityEngine.Camera camera = PlanetariumCamera.Camera;
float vertical_fov = camera.fieldOfView;
float horizontal_fov =
UnityEngine.Camera.VerticalToHorizontalFieldOfView(
vertical_fov,
camera.aspect);
UnityEngine.GUILayout.Label("vfov=" + vertical_fov);
UnityEngine.GUILayout.Label("hfov=" + horizontal_fov);
UnityEngine.GUILayout.Label("pixh=" + camera.pixelHeight);
UnityEngine.GUILayout.Label("pixw=" + camera.pixelWidth);

if (!adapter_.PluginRunning()) {
UnityEngine.GUILayout.Label(
text : L10N.CacheFormat("#Principia_MainWindow_PluginNotStarted"),
Expand Down
Loading