-
Notifications
You must be signed in to change notification settings - Fork 26
/
Satellite.cpp
86 lines (60 loc) · 3.03 KB
/
Satellite.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
////////////////////////////////////////////////////////////////////////////////////////////////////
// This file is part of CosmoScout VR //
////////////////////////////////////////////////////////////////////////////////////////////////////
// SPDX-FileCopyrightText: German Aerospace Center (DLR) <cosmoscout@dlr.de>
// SPDX-License-Identifier: MIT
#include "Satellite.hpp"
#include <VistaKernel/GraphicsManager/VistaNodeBridge.h>
#include <VistaKernel/GraphicsManager/VistaTransformNode.h>
#include <VistaKernel/VistaSystem.h>
#include <VistaKernelOpenSGExt/VistaOpenSGMaterialTools.h>
#include "../../../src/cs-core/Settings.hpp"
#include "../../../src/cs-core/SolarSystem.hpp"
#include "../../../src/cs-graphics/GltfLoader.hpp"
#include "../../../src/cs-utils/convert.hpp"
#include "../../../src/cs-utils/utils.hpp"
#include <glm/gtc/type_ptr.hpp>
#include <utility>
namespace csp::satellites {
////////////////////////////////////////////////////////////////////////////////////////////////////
Satellite::Satellite(Plugin::Settings::Satellite const& config, std::string objectName,
VistaSceneGraph* sceneGraph, std::shared_ptr<cs::core::Settings> settings,
std::shared_ptr<cs::core::SolarSystem> solarSystem)
: mSceneGraph(sceneGraph)
, mSettings(std::move(settings))
, mSolarSystem(std::move(solarSystem))
, mModel(std::make_unique<cs::graphics::GltfLoader>(config.mModelFile, config.mEnvironmentMap))
, mObjectName(std::move(objectName)) {
mModel->setLightIntensity(15.0);
mModel->setIBLIntensity(1.5);
mModel->setLightColor(1.0, 1.0, 1.0);
mAnchor.reset(sceneGraph->NewTransformNode(sceneGraph->GetRoot()));
mModel->attachTo(sceneGraph, mAnchor.get());
VistaOpenSGMaterialTools::SetSortKeyOnSubtree(
mAnchor.get(), static_cast<int>(cs::utils::DrawOrder::eOpaqueItems));
mAnchor->SetIsEnabled(false);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
Satellite::~Satellite() {
mSceneGraph->GetRoot()->DisconnectChild(mAnchor.get());
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void Satellite::update() {
auto object = mSolarSystem->getObject(mObjectName);
bool visible = object && object->getIsBodyVisible();
mAnchor->SetIsEnabled(visible);
if (visible) {
auto const& transform = object->getObserverRelativeTransform();
mAnchor->SetTransform(glm::value_ptr(transform), true);
float sunIlluminance(1.F);
auto sunDirection = glm::vec3(mSolarSystem->getSunDirection(transform[3]));
mModel->setLightDirection(sunDirection.x, sunDirection.y, sunDirection.z);
if (mSettings->mGraphics.pEnableHDR.get()) {
mModel->setEnableHDR(true);
sunIlluminance = static_cast<float>(mSolarSystem->getSunIlluminance(transform[3]));
}
mModel->setLightIntensity(sunIlluminance);
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
} // namespace csp::satellites