mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-07 20:21:24 -06:00
Cleanup in projection classes
This commit is contained in:
@@ -301,8 +301,11 @@ bool RenderableModelProjection::deinitialize() {
|
||||
}
|
||||
|
||||
void RenderableModelProjection::render(const RenderData& data) {
|
||||
if (!_programObject) return;
|
||||
if (!_textureProj) return;
|
||||
if (!_programObject)
|
||||
return;
|
||||
if (!_textureProj)
|
||||
return;
|
||||
|
||||
_programObject->activate();
|
||||
_frameCount++;
|
||||
|
||||
@@ -413,8 +416,13 @@ void RenderableModelProjection::imageProjectGPU() {
|
||||
}
|
||||
|
||||
void RenderableModelProjection::attitudeParameters(double time) {
|
||||
_stateMatrix = SpiceManager::ref().positionTransformMatrix(_source, _destination, time);
|
||||
_instrumentMatrix = SpiceManager::ref().positionTransformMatrix(_instrumentID, _destination, time);
|
||||
try {
|
||||
_stateMatrix = SpiceManager::ref().positionTransformMatrix(_source, _destination, time);
|
||||
_instrumentMatrix = SpiceManager::ref().positionTransformMatrix(_instrumentID, _destination, time);
|
||||
}
|
||||
catch (const SpiceManager::SpiceException& e) {
|
||||
return;
|
||||
}
|
||||
|
||||
_transform = glm::mat4(1);
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
****************************************************************************************/
|
||||
|
||||
#include <modules/newhorizons/rendering/renderableplaneprojection.h>
|
||||
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/engine/configurationmanager.h>
|
||||
#include <openspace/scene/scenegraphnode.h>
|
||||
@@ -87,12 +88,7 @@ RenderablePlaneProjection::~RenderablePlaneProjection() {
|
||||
}
|
||||
|
||||
bool RenderablePlaneProjection::isReady() const {
|
||||
bool ready = true;
|
||||
if (!_shader)
|
||||
ready &= false;
|
||||
if (!_texture)
|
||||
ready &= false;
|
||||
return ready;
|
||||
return _shader && _texture;
|
||||
}
|
||||
|
||||
bool RenderablePlaneProjection::initialize() {
|
||||
@@ -106,7 +102,8 @@ bool RenderablePlaneProjection::initialize() {
|
||||
_shader = renderEngine.buildRenderProgram("Image Plane",
|
||||
"${MODULE_BASE}/shaders/imageplane_vs.glsl",
|
||||
"${MODULE_BASE}/shaders/imageplane_fs.glsl");
|
||||
if (!_shader) return false;
|
||||
if (!_shader)
|
||||
return false;
|
||||
}
|
||||
|
||||
setTarget(_defaultTarget);
|
||||
@@ -158,12 +155,9 @@ void RenderablePlaneProjection::render(const RenderData& data) {
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
|
||||
_shader->deactivate();
|
||||
|
||||
}
|
||||
|
||||
void RenderablePlaneProjection::update(const UpdateData& data) {
|
||||
|
||||
|
||||
double time = data.time;
|
||||
const Image img = openspace::ImageSequencer::ref().getLatestImageForInstrument(_instrument);
|
||||
|
||||
@@ -214,11 +208,11 @@ void RenderablePlaneProjection::loadTexture() {
|
||||
}
|
||||
|
||||
void RenderablePlaneProjection::updatePlane(const Image img, double currentTime) {
|
||||
|
||||
|
||||
std::string frame;
|
||||
std::vector<glm::dvec3> bounds;
|
||||
glm::dvec3 boresight;
|
||||
|
||||
|
||||
std::string target = _defaultTarget;
|
||||
// Turned on if the plane should be attached to the closest target,
|
||||
// rather than the target specified in img
|
||||
@@ -226,7 +220,7 @@ void RenderablePlaneProjection::updatePlane(const Image img, double currentTime)
|
||||
// target = findClosestTarget(currentTime);
|
||||
//}
|
||||
if (img.path != "")
|
||||
target = img.target;
|
||||
target = img.target;
|
||||
|
||||
setTarget(target);
|
||||
|
||||
@@ -236,7 +230,8 @@ void RenderablePlaneProjection::updatePlane(const Image img, double currentTime)
|
||||
frame = std::move(res.frameName);
|
||||
bounds = std::move(res.bounds);
|
||||
boresight = std::move(res.boresightVector);
|
||||
} catch (const SpiceManager::SpiceException& e) {
|
||||
}
|
||||
catch (const SpiceManager::SpiceException& e) {
|
||||
LERROR(e.what());
|
||||
}
|
||||
|
||||
@@ -256,12 +251,12 @@ void RenderablePlaneProjection::updatePlane(const Image img, double currentTime)
|
||||
for (int j = 0; j < bounds.size(); ++j) {
|
||||
bounds[j] = SpiceManager::ref().frameTransformationMatrix(frame, GalacticFrame, currentTime) * bounds[j];
|
||||
glm::dvec3 cornerPosition = glm::proj(vecToTarget, bounds[j]);
|
||||
|
||||
|
||||
if (!_moving) {
|
||||
cornerPosition -= vecToTarget;
|
||||
}
|
||||
cornerPosition = SpiceManager::ref().frameTransformationMatrix(GalacticFrame, _target.frame, currentTime) * cornerPosition;
|
||||
|
||||
|
||||
projection[j] = PowerScaledCoordinate::CreatePowerScaledCoordinate(cornerPosition[0], cornerPosition[1], cornerPosition[2]);
|
||||
projection[j][3] += 3;
|
||||
}
|
||||
@@ -305,7 +300,6 @@ void RenderablePlaneProjection::updatePlane(const Image img, double currentTime)
|
||||
}
|
||||
|
||||
void RenderablePlaneProjection::setTarget(std::string body) {
|
||||
|
||||
if (body == "")
|
||||
return;
|
||||
|
||||
@@ -314,8 +308,7 @@ void RenderablePlaneProjection::setTarget(std::string body) {
|
||||
bool hasBody, found = false;
|
||||
std::string targetBody;
|
||||
|
||||
for (auto node : nodes)
|
||||
{
|
||||
for (auto node : nodes) {
|
||||
possibleTarget = node->renderable();
|
||||
if (possibleTarget != nullptr) {
|
||||
hasBody = possibleTarget->hasBody();
|
||||
|
||||
@@ -24,11 +24,9 @@
|
||||
|
||||
// open space includes
|
||||
#include <modules/newhorizons/rendering/renderableplanetprojection.h>
|
||||
//#include <modules/newhorizons/rendering/planetgeometryprojection.h>
|
||||
|
||||
#include <modules/base/rendering/planetgeometry.h>
|
||||
|
||||
//#include <openspace/renderingo
|
||||
|
||||
#include <openspace/engine/configurationmanager.h>
|
||||
|
||||
@@ -247,16 +245,18 @@ bool RenderablePlanetProjection::initialize() {
|
||||
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
_programObject = renderEngine.buildRenderProgram("projectiveProgram",
|
||||
"${MODULES}/newhorizons/shaders/projectiveTexture_vs.glsl",
|
||||
"${MODULES}/newhorizons/shaders/projectiveTexture_fs.glsl");
|
||||
"${MODULE_NEWHORIZONS}/shaders/projectiveTexture_vs.glsl",
|
||||
"${MODULE_NEWHORIZONS}/shaders/projectiveTexture_fs.glsl"
|
||||
);
|
||||
|
||||
if (!_programObject)
|
||||
return false;
|
||||
}
|
||||
|
||||
_fboProgramObject = ghoul::opengl::ProgramObject::Build("fboPassProgram",
|
||||
"${MODULES}/newhorizons/shaders/fboPass_vs.glsl",
|
||||
"${MODULES}/newhorizons/shaders/fboPass_fs.glsl");
|
||||
"${MODULE_NEWHORIZONS}/shaders/fboPass_vs.glsl",
|
||||
"${MODULE_NEWHORIZONS}/shaders/fboPass_fs.glsl"
|
||||
);
|
||||
|
||||
loadTexture();
|
||||
loadProjectionTexture();
|
||||
@@ -273,7 +273,7 @@ bool RenderablePlanetProjection::initialize() {
|
||||
return completeSuccess;
|
||||
}
|
||||
|
||||
bool RenderablePlanetProjection::auxiliaryRendertarget(){
|
||||
bool RenderablePlanetProjection::auxiliaryRendertarget() {
|
||||
bool completeSuccess = true;
|
||||
if (!_texture) return false;
|
||||
|
||||
@@ -318,7 +318,7 @@ bool RenderablePlanetProjection::auxiliaryRendertarget(){
|
||||
return completeSuccess;
|
||||
}
|
||||
|
||||
bool RenderablePlanetProjection::deinitialize(){
|
||||
bool RenderablePlanetProjection::deinitialize() {
|
||||
_texture = nullptr;
|
||||
_textureProj = nullptr;
|
||||
_textureOriginal = nullptr;
|
||||
@@ -338,8 +338,7 @@ bool RenderablePlanetProjection::isReady() const {
|
||||
return _geometry && _programObject && _texture && _textureWhiteSquare;
|
||||
}
|
||||
|
||||
void RenderablePlanetProjection::imageProjectGPU(){
|
||||
|
||||
void RenderablePlanetProjection::imageProjectGPU() {
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
|
||||
// keep handle to the current bound FBO
|
||||
@@ -404,7 +403,7 @@ void RenderablePlanetProjection::imageProjectGPU(){
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
}
|
||||
|
||||
glm::mat4 RenderablePlanetProjection::computeProjectorMatrix(const glm::vec3 loc, glm::dvec3 aim, const glm::vec3 up){
|
||||
glm::mat4 RenderablePlanetProjection::computeProjectorMatrix(const glm::vec3 loc, glm::dvec3 aim, const glm::vec3 up) {
|
||||
//rotate boresight into correct alignment
|
||||
_boresight = _instrumentMatrix*aim;
|
||||
glm::vec3 uptmp(_instrumentMatrix*glm::dvec3(up));
|
||||
@@ -427,7 +426,7 @@ glm::mat4 RenderablePlanetProjection::computeProjectorMatrix(const glm::vec3 loc
|
||||
return projNormalizationMatrix*projProjectionMatrix*projViewMatrix;
|
||||
}
|
||||
|
||||
void RenderablePlanetProjection::attitudeParameters(double time){
|
||||
void RenderablePlanetProjection::attitudeParameters(double time) {
|
||||
// precomputations for shader
|
||||
_stateMatrix = SpiceManager::ref().positionTransformMatrix(_frame, _mainFrame, time);
|
||||
_instrumentMatrix = SpiceManager::ref().positionTransformMatrix(_instrumentID, _mainFrame, time);
|
||||
@@ -500,7 +499,7 @@ void RenderablePlanetProjection::project(){
|
||||
|
||||
//---- Old method --- //
|
||||
// @mm
|
||||
for (auto const &img : _imageTimes){
|
||||
for (const Image& img : _imageTimes) {
|
||||
RenderablePlanetProjection::attitudeParameters(img.startTime);
|
||||
if (_projectionTexturePath.value() != img.path){
|
||||
_projectionTexturePath = img.path; // path to current images
|
||||
@@ -510,7 +509,7 @@ void RenderablePlanetProjection::project(){
|
||||
_capture = false;
|
||||
}
|
||||
|
||||
void RenderablePlanetProjection::clearAllProjections(){
|
||||
void RenderablePlanetProjection::clearAllProjections() {
|
||||
float tmp = _fadeProjection;
|
||||
_fadeProjection = 1.f;
|
||||
_projectionTexturePath = _clearingImage;
|
||||
@@ -519,12 +518,14 @@ void RenderablePlanetProjection::clearAllProjections(){
|
||||
_clearAllProjections = false;
|
||||
}
|
||||
|
||||
|
||||
void RenderablePlanetProjection::render(const RenderData& data){
|
||||
if (!_programObject) return;
|
||||
if (!_textureProj) return;
|
||||
void RenderablePlanetProjection::render(const RenderData& data) {
|
||||
if (!_programObject)
|
||||
return;
|
||||
if (!_textureProj)
|
||||
return;
|
||||
|
||||
if (_clearAllProjections) clearAllProjections();
|
||||
if (_clearAllProjections)
|
||||
clearAllProjections();
|
||||
|
||||
_camScaling = data.camera.scaling();
|
||||
_up = data.camera.lookUpVector();
|
||||
@@ -536,7 +537,7 @@ void RenderablePlanetProjection::render(const RenderData& data){
|
||||
|
||||
double lt;
|
||||
glm::dvec3 p =
|
||||
openspace::SpiceManager::ref().targetPosition("SUN", _projecteeID, "GALACTIC", {}, _time, lt);
|
||||
SpiceManager::ref().targetPosition("SUN", _projecteeID, "GALACTIC", {}, _time, lt);
|
||||
psc sun_pos = PowerScaledCoordinate::CreatePowerScaledCoordinate(p.x, p.y, p.z);
|
||||
|
||||
// Main renderpass
|
||||
@@ -557,12 +558,14 @@ void RenderablePlanetProjection::render(const RenderData& data){
|
||||
_programObject->deactivate();
|
||||
}
|
||||
|
||||
void RenderablePlanetProjection::update(const UpdateData& data){
|
||||
void RenderablePlanetProjection::update(const UpdateData& data) {
|
||||
//if (data.isTimeJump) {
|
||||
if (_time >= Time::ref().currentTime()) {
|
||||
// if jump back in time -> empty queue.
|
||||
imageQueue = std::queue<Image>();
|
||||
}
|
||||
|
||||
//_time = data.time;
|
||||
_time = Time::ref().currentTime();
|
||||
_capture = false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user