Add examples for SpiceTranslation (#3413)

This commit is contained in:
Alexander Bock
2024-09-23 11:35:01 +02:00
committed by GitHub
parent db23148af0
commit 5fdc2c4bb8
5 changed files with 131 additions and 18 deletions

View File

@@ -3,8 +3,9 @@
-- SceneGraphNode that only displays coordinate axes. The rotation of the coordinate axes
-- are determined by SPICE, in this case pretending that the coordinate axes are rotating
-- at the same rate as Earth.
-- For more information about SPICE see: https://naif.jpl.nasa.gov/naif/
-- Load the default SPICE kernels, which is the planetary constants and the DE430 kernel
-- Load the default SPICE kernels, which are the planetary constants and the DE430 kernel
asset.require("spice/core")
local Node = {

View File

@@ -0,0 +1,38 @@
-- Fixed Date
-- This asset creates a time-varying translation with information from a SPICE kernel and
-- applies it to a SceneGraphNode that only displays coordinate axes. The position of the
-- coordinate axes are determined by SPICE, in this case pretending that the axes are
-- orbiting the same way the Moon does around Earth. In this specific example, the
-- position is independent of the actual in-game time in OpenSpace and only uses a fixed
-- date of 2000 JAN 01 instead.
-- For more information about SPICE see: https://naif.jpl.nasa.gov/naif/
-- Load the default SPICE kernels, which are the planetary constants and the DE430 kernel
asset.require("spice/core")
local Node = {
Identifier = "SpiceTranslation_Example_FixedDate",
Transform = {
Translation = {
Type = "SpiceTranslation",
Target = "MOON",
Observer = "EARTH",
FixedDate = "2000 JAN 01 00:00:00.000"
}
},
Renderable = {
Type = "RenderableCartesianAxes"
},
GUI = {
Name = "SpiceTranslation - Fixed Date",
Path = "/Examples"
}
}
asset.onInitialize(function()
openspace.addSceneGraphNode(Node)
end)
asset.onDeinitialize(function()
openspace.removeSceneGraphNode(Node)
end)

View File

@@ -0,0 +1,37 @@
-- Reference Frame
-- This asset creates a time-varying translation with information from a SPICE kernel and
-- applies it to a SceneGraphNode that only displays coordinate axes. The position of the
-- coordinate axes are determined by SPICE, in this case pretending that the axes are
-- orbiting the same way the Moon does around Earth. The calculated position will be
-- provided in the rotating coordinate system of Earth itself.
-- For more information about SPICE see: https://naif.jpl.nasa.gov/naif/
-- Load the default SPICE kernels, which are the planetary constants and the DE430 kernel
asset.require("spice/core")
local Node = {
Identifier = "SpiceTranslation_Example_ReferenceFrame",
Transform = {
Translation = {
Type = "SpiceTranslation",
Target = "MOON",
Observer = "EARTH",
Frame = "IAU_EARTH"
}
},
Renderable = {
Type = "RenderableCartesianAxes"
},
GUI = {
Name = "SpiceTranslation - Reference Frame",
Path = "/Examples"
}
}
asset.onInitialize(function()
openspace.addSceneGraphNode(Node)
end)
asset.onDeinitialize(function()
openspace.removeSceneGraphNode(Node)
end)

View File

@@ -0,0 +1,35 @@
-- Basic
-- This asset creates a time-varying translation with information from a SPICE kernel and
-- applies it to a SceneGraphNode that only displays coordinate axes. The position of the
-- coordinate axes are determined by SPICE, in this case pretending that the axes are
-- orbiting the same way the Moon does around Earth.
-- For more information about SPICE see: https://naif.jpl.nasa.gov/naif/
-- Load the default SPICE kernels, which are the planetary constants and the DE430 kernel
asset.require("spice/core")
local Node = {
Identifier = "SpiceTranslation_Example",
Transform = {
Translation = {
Type = "SpiceTranslation",
Target = "MOON",
Observer = "EARTH"
}
},
Renderable = {
Type = "RenderableCartesianAxes"
},
GUI = {
Name = "SpiceTranslation - Basic",
Path = "/Examples"
}
}
asset.onInitialize(function()
openspace.addSceneGraphNode(Node)
end)
asset.onDeinitialize(function()
openspace.removeSceneGraphNode(Node)
end)

View File

@@ -41,34 +41,39 @@ namespace {
constexpr openspace::properties::Property::PropertyInfo TargetInfo = {
"Target",
"Target",
"This is the SPICE NAIF name for the body whose translation is to be computed by "
"the SpiceTranslation. It can either be a fully qualified name (such as 'EARTH') "
"or a NAIF integer id code (such as '399').",
"This is the SPICE name for the body whose translation is to be computed by the "
"SpiceTranslation. It can either be a fully qualified name (such as 'EARTH') or "
"a NAIF integer id code (such as '399'). The resulting translation will be a "
"vector leading from the `Target` to the `Observer`.",
openspace::properties::Property::Visibility::AdvancedUser
};
constexpr openspace::properties::Property::PropertyInfo ObserverInfo = {
"Observer",
"Observer",
"This is the SPICE NAIF name for the parent of the body whose translation is to "
"be computed by the SpiceTranslation. It can either be a fully qualified name "
"(such as 'SOLAR SYSTEM BARYCENTER') or a NAIF integer id code (such as '0').",
"This is the SPICE name for the parent of the body whose translation is to be "
"computed by the SpiceTranslation. It can either be a fully qualified name (such "
"as 'SOLAR SYSTEM BARYCENTER') or a NAIF integer id code (such as '0'). The "
"resulting translation will be a vector leading from the `Target` to the "
"`Observer`.",
openspace::properties::Property::Visibility::AdvancedUser
};
constexpr openspace::properties::Property::PropertyInfo FrameInfo = {
"Frame",
"Reference Frame",
"This is the SPICE NAIF name for the reference frame in which the position "
"should be retrieved. The default value is GALACTIC.",
"This is the SPICE name of the reference frame in which the position should be "
"calculated. The default value is GALACTIC.",
openspace::properties::Property::Visibility::AdvancedUser
};
constexpr openspace::properties::Property::PropertyInfo FixedDateInfo = {
"FixedDate",
"Fixed Date",
"A time to lock the position to. Setting this to an empty string will "
"unlock the time and return to position based on current simulation time.",
"If this value is specified, the position will be locked to a specific time "
"rather than following the in-game in the system. Setting this to an empty "
"string will unlock the time and return to position based on current simulation "
"time.",
openspace::properties::Property::Visibility::User
};
@@ -82,8 +87,8 @@ namespace {
std::optional<std::string> frame
[[codegen::annotation("A valid SPICE NAIF name for a reference frame")]];
std::optional<std::string> fixedDate
[[codegen::annotation("A date to lock the position to")]];
// [[codegen::verbatim(FixedDateInfo.description)]]
std::optional<std::string> fixedDate;
};
#include "spicetranslation_codegen.cpp"
} // namespace
@@ -155,16 +160,13 @@ SpiceTranslation::SpiceTranslation(const ghoul::Dictionary& dictionary)
glm::dvec3 SpiceTranslation::position(const UpdateData& data) const {
double lightTime = 0.0;
double time = data.time.j2000Seconds();
if (_fixedEphemerisTime.has_value()) {
time = *_fixedEphemerisTime;
}
// Spice handles positions in KM, but we use meters in OpenSpace
return SpiceManager::ref().targetPosition(
_cachedTarget,
_cachedObserver,
_cachedFrame,
{},
time,
_fixedEphemerisTime.value_or(data.time.j2000Seconds()),
lightTime
) * 1000.0;
}