mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-24 13:08:49 -05:00
Feature/night sky items (#2613)
* added night sky items and camera event --------- Co-authored-by: Alexander Bock <alexander.bock@liu.se>
This commit is contained in:
@@ -1,22 +1,22 @@
|
||||
openspace.globebrowsing.documentation = {
|
||||
{
|
||||
Name = "setNodePosition",
|
||||
Arguments = { nodeIdentifer = "String", globeIdentifier = "String", latitude = "Number", longitude = "Number", altitude = "Number" },
|
||||
Documentation =
|
||||
"Sets the position of a SceneGraphNode that has GlobeTranslation/GlobeRotations. " ..
|
||||
"Usage: openspace.globebrowsing.setNodePosition(" ..
|
||||
"\"Scale_StatueOfLiberty\", \"Earth\", 40.000, -117.5, optionalAltitude)"
|
||||
},
|
||||
{
|
||||
Name = "setNodePositionFromCamera",
|
||||
Arguments = { nodeIdentifer = "String", useAltitude = "Number" },
|
||||
Documentation =
|
||||
"Sets the position of a SceneGraphNode that has GlobeTranslation/GlobeRotations" ..
|
||||
" to match the camera. Only uses camera position not rotation. If useAltitude" ..
|
||||
" is true, then the position will also be updated to the camera's altitude." ..
|
||||
"Usage: openspace.globebrowsing.setNodePositionFromCamera(" ..
|
||||
"\"Scale_StatueOfLiberty\", optionalUseAltitude)"
|
||||
}
|
||||
{
|
||||
Name = "setNodePosition",
|
||||
Arguments = { nodeIdentifer = "String", globeIdentifier = "String", latitude = "Number", longitude = "Number", altitude = "Number" },
|
||||
Documentation =
|
||||
"Sets the position of a SceneGraphNode that has GlobeTranslation/GlobeRotations. " ..
|
||||
"Usage: openspace.globebrowsing.setNodePosition(" ..
|
||||
"\"Scale_StatueOfLiberty\", \"Earth\", 40.000, -117.5, optionalAltitude)"
|
||||
},
|
||||
{
|
||||
Name = "setNodePositionFromCamera",
|
||||
Arguments = { nodeIdentifer = "String", useAltitude = "Boolean" },
|
||||
Documentation =
|
||||
"Sets the position of a SceneGraphNode that has GlobeTranslation/GlobeRotations" ..
|
||||
" to match the camera. Only uses camera position not rotation. If useAltitude" ..
|
||||
" is true, then the position will also be updated to the camera's altitude." ..
|
||||
"Usage: openspace.globebrowsing.setNodePositionFromCamera(" ..
|
||||
"\"Scale_StatueOfLiberty\", optionalUseAltitude)"
|
||||
}
|
||||
}
|
||||
|
||||
openspace.globebrowsing.setNodePosition = function (node_identifer, globe_identifier, lat, lon, altitude)
|
||||
@@ -48,6 +48,3 @@ openspace.globebrowsing.setNodePositionFromCamera = function (node_identifer, us
|
||||
openspace.setPropertyValueSingle('Scene.' .. node_identifer .. '.Translation.Altitude', alt);
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -83,6 +83,14 @@ namespace {
|
||||
openspace::properties::Property::Visibility::User
|
||||
};
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo UseCameraInfo = {
|
||||
"UseCamera",
|
||||
"Use Camera",
|
||||
"If this value is 'true', the lat and lon are updated to match the camera",
|
||||
// @VISIBILITY(?)
|
||||
openspace::properties::Property::Visibility::AdvancedUser
|
||||
};
|
||||
|
||||
struct [[codegen::Dictionary(GlobeRotation)]] Parameters {
|
||||
// [[codegen::verbatim(GlobeInfo.description)]]
|
||||
std::string globe
|
||||
@@ -99,6 +107,9 @@ namespace {
|
||||
|
||||
// [[codegen::verbatim(UseHeightmapInfo.description)]]
|
||||
std::optional<bool> useHeightmap;
|
||||
|
||||
// [[codegen::verbatim(UseCameraInfo.description)]]
|
||||
std::optional<bool> useCamera;
|
||||
};
|
||||
#include "globerotation_codegen.cpp"
|
||||
} // namespace
|
||||
@@ -115,6 +126,7 @@ GlobeRotation::GlobeRotation(const ghoul::Dictionary& dictionary)
|
||||
, _longitude(LongitudeInfo, 0.0, -180.0, 180.0)
|
||||
, _angle(AngleInfo, 0.0, 0.0, 360.0)
|
||||
, _useHeightmap(UseHeightmapInfo, false)
|
||||
, _useCamera(UseCameraInfo, false)
|
||||
{
|
||||
const Parameters p = codegen::bake<Parameters>(dictionary);
|
||||
|
||||
@@ -140,6 +152,11 @@ GlobeRotation::GlobeRotation(const ghoul::Dictionary& dictionary)
|
||||
_angle = p.angle.value_or(_angle);
|
||||
_angle.onChange([this]() { setUpdateVariables(); });
|
||||
addProperty(_angle);
|
||||
|
||||
_useCamera = p.useCamera.value_or(_useCamera);
|
||||
_useCamera.onChange([this]() { setUpdateVariables(); });
|
||||
addProperty(_useCamera);
|
||||
|
||||
}
|
||||
|
||||
void GlobeRotation::findGlobe() {
|
||||
@@ -189,7 +206,7 @@ glm::vec3 GlobeRotation::computeSurfacePosition(double latitude, double longitud
|
||||
}
|
||||
|
||||
void GlobeRotation::update(const UpdateData& data) {
|
||||
if (_useHeightmap) {
|
||||
if (_useHeightmap || _useCamera) {
|
||||
// If we use the heightmap, we have to compute the height every frame
|
||||
setUpdateVariables();
|
||||
}
|
||||
@@ -211,21 +228,31 @@ glm::dmat3 GlobeRotation::matrix(const UpdateData&) const {
|
||||
return _matrix;
|
||||
}
|
||||
|
||||
double lat = _latitude;
|
||||
double lon = _longitude;
|
||||
|
||||
if (_useCamera) {
|
||||
GlobeBrowsingModule* mod = global::moduleEngine->module<GlobeBrowsingModule>();
|
||||
glm::dvec3 position = mod->geoPosition();
|
||||
lat = position.x;
|
||||
lon = position.y;
|
||||
}
|
||||
|
||||
// Compute vector that points out of globe surface
|
||||
glm::dvec3 yAxis = glm::dvec3(0.0);
|
||||
if (_useHeightmap) {
|
||||
const double angleDiff = 0.00001; // corresponds to a meter-ish
|
||||
const glm::vec3 posCenter = computeSurfacePosition(_latitude, _longitude);
|
||||
const glm::vec3 pos1 = computeSurfacePosition(_latitude, _longitude + angleDiff);
|
||||
const glm::vec3 pos2 = computeSurfacePosition(_latitude + angleDiff, _longitude);
|
||||
const glm::vec3 posCenter = computeSurfacePosition(lat, lon);
|
||||
const glm::vec3 pos1 = computeSurfacePosition(lat, lon + angleDiff);
|
||||
const glm::vec3 pos2 = computeSurfacePosition(lat + angleDiff, lon);
|
||||
|
||||
const glm::vec3 v1 = pos1 - posCenter;
|
||||
const glm::vec3 v2 = pos2 - posCenter;
|
||||
yAxis = glm::dvec3(glm::cross(v1, v2));
|
||||
}
|
||||
else {
|
||||
float latitudeRad = glm::radians(static_cast<float>(_latitude));
|
||||
float longitudeRad = glm::radians(static_cast<float>(_longitude));
|
||||
float latitudeRad = glm::radians(static_cast<float>(lat));
|
||||
float longitudeRad = glm::radians(static_cast<float>(lon));
|
||||
yAxis = _globeNode->ellipsoid().geodeticSurfaceNormal(
|
||||
{ latitudeRad, longitudeRad }
|
||||
);
|
||||
|
||||
@@ -54,6 +54,7 @@ private:
|
||||
properties::DoubleProperty _longitude;
|
||||
properties::DoubleProperty _angle;
|
||||
properties::BoolProperty _useHeightmap;
|
||||
properties::BoolProperty _useCamera;
|
||||
|
||||
RenderableGlobe* _globeNode = nullptr;
|
||||
|
||||
|
||||
@@ -84,6 +84,22 @@ namespace {
|
||||
openspace::properties::Property::Visibility::User
|
||||
};
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo UseCameraInfo = {
|
||||
"UseCamera",
|
||||
"Use Camera",
|
||||
"If this value is 'true', the lat and lon are updated to match the camera",
|
||||
// @VISIBILITY(?)
|
||||
openspace::properties::Property::Visibility::AdvancedUser
|
||||
};
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo UseCameraAltitudeInfo = {
|
||||
"UseCameraAltitude",
|
||||
"Use Camera Altitude",
|
||||
"If this value is 'true', the altitude is updated to match the camera",
|
||||
// @VISIBILITY(?)
|
||||
openspace::properties::Property::Visibility::AdvancedUser
|
||||
};
|
||||
|
||||
struct [[codegen::Dictionary(GlobeTranslation)]] Parameters {
|
||||
// [[codegen::verbatim(GlobeInfo.description)]]
|
||||
std::string globe
|
||||
@@ -100,6 +116,12 @@ namespace {
|
||||
|
||||
// [[codegen::verbatim(UseHeightmapInfo.description)]]
|
||||
std::optional<bool> useHeightmap;
|
||||
|
||||
// [[codegen::verbatim(UseCameraInfo.description)]]
|
||||
std::optional<bool> useCamera;
|
||||
|
||||
// [[codegen::verbatim(UseCameraAltitudeInfo.description)]]
|
||||
std::optional<bool> useCameraAltitude;
|
||||
};
|
||||
#include "globetranslation_codegen.cpp"
|
||||
} // namespace
|
||||
@@ -116,6 +138,8 @@ GlobeTranslation::GlobeTranslation(const ghoul::Dictionary& dictionary)
|
||||
, _longitude(LongitudeInfo, 0.0, -180.0, 180.0)
|
||||
, _altitude(AltitudeInfo, 0.0, -1e12, 1e12)
|
||||
, _useHeightmap(UseHeightmapInfo, false)
|
||||
, _useCamera(UseCameraInfo, false)
|
||||
, _useCameraAltitude(UseCameraAltitudeInfo, false)
|
||||
{
|
||||
const Parameters p = codegen::bake<Parameters>(dictionary);
|
||||
|
||||
@@ -143,6 +167,14 @@ GlobeTranslation::GlobeTranslation(const ghoul::Dictionary& dictionary)
|
||||
_useHeightmap = p.useHeightmap.value_or(_useHeightmap);
|
||||
_useHeightmap.onChange([this]() { setUpdateVariables(); });
|
||||
addProperty(_useHeightmap);
|
||||
|
||||
_useCamera = p.useCamera.value_or(_useCamera);
|
||||
_useCamera.onChange([this]() { setUpdateVariables(); });
|
||||
addProperty(_useCamera);
|
||||
|
||||
_useCameraAltitude = p.useCameraAltitude.value_or(_useCameraAltitude);
|
||||
_useCameraAltitude.onChange([this]() { setUpdateVariables(); });
|
||||
addProperty(_useCameraAltitude);
|
||||
}
|
||||
|
||||
void GlobeTranslation::fillAttachedNode() {
|
||||
@@ -168,7 +200,7 @@ void GlobeTranslation::setUpdateVariables() {
|
||||
}
|
||||
|
||||
void GlobeTranslation::update(const UpdateData& data) {
|
||||
if (_useHeightmap) {
|
||||
if (_useHeightmap || _useCamera) {
|
||||
// If we use the heightmap, we have to compute the height every frame
|
||||
setUpdateVariables();
|
||||
}
|
||||
@@ -192,11 +224,25 @@ glm::dvec3 GlobeTranslation::position(const UpdateData&) const {
|
||||
|
||||
GlobeBrowsingModule* mod = global::moduleEngine->module<GlobeBrowsingModule>();
|
||||
|
||||
double lat = _latitude;
|
||||
double lon = _longitude;
|
||||
double alt = _altitude;
|
||||
|
||||
if (_useCamera) {
|
||||
glm::dvec3 position = mod->geoPosition();
|
||||
lat = position.x;
|
||||
lon = position.y;
|
||||
if (_useCameraAltitude) {
|
||||
alt = position.z;
|
||||
}
|
||||
}
|
||||
|
||||
if (_useHeightmap) {
|
||||
|
||||
glm::vec3 groundPos = mod->cartesianCoordinatesFromGeo(
|
||||
*_attachedNode,
|
||||
_latitude,
|
||||
_longitude,
|
||||
lat,
|
||||
lon,
|
||||
0.0
|
||||
);
|
||||
|
||||
@@ -205,18 +251,18 @@ glm::dvec3 GlobeTranslation::position(const UpdateData&) const {
|
||||
|
||||
_position = mod->cartesianCoordinatesFromGeo(
|
||||
*_attachedNode,
|
||||
_latitude,
|
||||
_longitude,
|
||||
h.heightToSurface + _altitude
|
||||
lat,
|
||||
lon,
|
||||
h.heightToSurface + alt
|
||||
);
|
||||
return _position;
|
||||
}
|
||||
else {
|
||||
_position = mod->cartesianCoordinatesFromGeo(
|
||||
*_attachedNode,
|
||||
_latitude,
|
||||
_longitude,
|
||||
_altitude
|
||||
lat,
|
||||
lon,
|
||||
alt
|
||||
);
|
||||
_positionIsDirty = false;
|
||||
return _position;
|
||||
|
||||
@@ -53,6 +53,8 @@ private:
|
||||
properties::DoubleProperty _longitude;
|
||||
properties::DoubleProperty _altitude;
|
||||
properties::BoolProperty _useHeightmap;
|
||||
properties::BoolProperty _useCamera;
|
||||
properties::BoolProperty _useCameraAltitude;
|
||||
|
||||
RenderableGlobe* _attachedNode = nullptr;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user