first edition of switch renderable

This commit is contained in:
lundkvistarn
2024-05-15 16:12:42 -04:00
parent c09e6da405
commit 858338f185
5 changed files with 151 additions and 0 deletions

View File

@@ -62,6 +62,7 @@ set(HEADER_FILES
rendering/renderablesphere.h
rendering/renderablesphereimagelocal.h
rendering/renderablesphereimageonline.h
rendering/renderableswitch.h
rendering/renderabletimevaryingsphere.h
rendering/renderabletrail.h
rendering/renderabletrailorbit.h
@@ -125,6 +126,7 @@ set(SOURCE_FILES
rendering/renderablesphere.cpp
rendering/renderablesphereimagelocal.cpp
rendering/renderablesphereimageonline.cpp
rendering/renderableswitch.cpp
rendering/renderabletimevaryingsphere.cpp
rendering/renderabletrail.cpp
rendering/renderabletrailorbit.cpp

View File

@@ -55,6 +55,7 @@
#include <modules/base/rendering/renderablenodeline.h>
#include <modules/base/rendering/renderablesphereimagelocal.h>
#include <modules/base/rendering/renderablesphereimageonline.h>
#include <modules/base/rendering/renderableswitch.h>
#include <modules/base/rendering/renderabletrailorbit.h>
#include <modules/base/rendering/renderabletrailtrajectory.h>
#include <modules/base/rendering/renderableplaneimagelocal.h>
@@ -162,6 +163,7 @@ void BaseModule::internalInitialize(const ghoul::Dictionary&) {
fRenderable->registerClass<RenderableSphereImageOnline>(
"RenderableSphereImageOnline"
);
fRenderable->registerClass<RenderableSwitch>("RenderableSwitch");
fRenderable->registerClass<RenderableSphericalGrid>("RenderableSphericalGrid");
fRenderable->registerClass<RenderableTrailOrbit>("RenderableTrailOrbit");
fRenderable->registerClass<RenderableTrailTrajectory>("RenderableTrailTrajectory");
@@ -245,6 +247,7 @@ std::vector<documentation::Documentation> BaseModule::documentations() const {
RenderableRadialGrid::Documentation(),
RenderableSphereImageLocal::Documentation(),
RenderableSphereImageOnline::Documentation(),
RenderableSwitch::Documentation(),
RenderableSphericalGrid::Documentation(),
RenderableTimeVaryingSphere::Documentation(),
RenderableTrailOrbit::Documentation(),

View File

@@ -26,6 +26,7 @@
#define __OPENSPACE_MODULE_BASE___RENDERABLEPLANEIMAGELOCAL___H__
#include <modules/base/rendering/renderableplane.h>
#include <iostream>
namespace ghoul::filesystem { class File; }
namespace ghoul::opengl { class Texture; }

View File

@@ -0,0 +1,66 @@
#include <modules/base/rendering/renderableswitch.h>
#include <openspace/documentation/documentation.h>
#include <openspace/documentation/verifier.h>
#include <ghoul/logging/logmanager.h>
namespace {
struct [[codegen::Dictionary(RenderableSwitch)]] Parameters {
ghoul::Dictionary Renderable1;
ghoul::Dictionary Renderable2;
float DistanceThreshold;
};
#include "renderableswitch_codegen.cpp"
} // namespace
namespace openspace {
documentation::Documentation RenderableSwitch::Documentation() {
return codegen::doc<Parameters>(
"base_renderable_switch"
);
}
RenderableSwitch::RenderableSwitch(const ghoul::Dictionary& dictionary)
: Renderable(dictionary)
{
const Parameters p = codegen::bake<Parameters>(dictionary);
_renderable1 = std::make_unique<RenderablePlaneImageLocal>(p.Renderable1);
_renderable2 = std::make_unique<RenderablePlaneImageLocal>(p.Renderable2);
_distanceThreshold = p.DistanceThreshold;
}
void RenderableSwitch::initializeGL() {
_renderable1->initializeGL();
_renderable2->initializeGL();
}
void RenderableSwitch::deinitializeGL() {
_renderable1->deinitializeGL();
_renderable2->deinitializeGL();
}
bool RenderableSwitch::isReady() const {
return _renderable1->isReady() && _renderable2->isReady();
}
void RenderableSwitch::update(const UpdateData& data) {
_renderable1->update(data);
_renderable2->update(data);
}
void RenderableSwitch::render(const RenderData& data, RendererTasks& tasks) {
if (_enabled) {
glm::dvec3 cameraPosition = data.camera.positionVec3();
glm::dvec3 modelPosition = data.modelTransform.translation;
//std::cout << "Distance: " << glm::distance(cameraPosition, modelPosition) << std::endl;
if (glm::distance(cameraPosition, modelPosition) < _distanceThreshold) {
_renderable1->render(data, tasks);
}
else {
_renderable2->render(data, tasks);
}
}
}
} // namespace openspace

View File

@@ -0,0 +1,79 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2024 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __OPENSPACE_MODULE_BASE___RENDERABLESWITCH___H__
#define __OPENSPACE_MODULE_BASE___RENDERABLESWITCH___H__
#include <modules/base/rendering/RenderablePlaneImageLocal.h>
#include <modules/base/rendering/renderableplane.h>
#include <glm/glm.hpp>
#include <glm/gtx/vector_angle.hpp>
#include <memory>
#include <modules/base/basemodule.h>
#include <openspace/documentation/documentation.h>
#include <openspace/documentation/verifier.h>
#include <openspace/engine/globals.h>
#include <openspace/rendering/renderengine.h>
#include <openspace/scene/scenegraphnode.h>
#include <openspace/util/updatestructures.h>
#include <ghoul/filesystem/file.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/io/texture/texturereader.h>
#include <ghoul/logging/logmanager.h>
#include <ghoul/misc/crc32.h>
#include <ghoul/misc/profiling.h>
#include <ghoul/opengl/texture.h>
#include <ghoul/opengl/textureunit.h>
namespace openspace {
struct RenderData;
struct UpdateData;
namespace documentation { struct Documentation; }
class RenderableSwitch : public Renderable {
public:
RenderableSwitch(const ghoul::Dictionary& dictionary);
void initializeGL() override;
void deinitializeGL() override;
bool isReady() const override;
void update(const UpdateData& data) override;
void render(const RenderData& data, RendererTasks& tasks) override;
static documentation::Documentation Documentation();
private:
std::unique_ptr<RenderablePlaneImageLocal> _renderable1;
std::unique_ptr<RenderablePlaneImageLocal> _renderable2;
float _distanceThreshold;
};
} // namespace openspace
#endif // __OPENSPACE_MODULE_BASE___RENDERABLESWITCH___H__