mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-02-18 02:49:03 -06:00
Nurbs working to exactly define spherical patches. Ugly code but it can be cleaned up.
This commit is contained in:
@@ -3,7 +3,7 @@ return {
|
||||
CommonFolder = "common",
|
||||
Camera = {
|
||||
Focus = "DebugGlobe",
|
||||
Position = {1, 0, 0, 5},
|
||||
Position = {1, 0, 0, 7},
|
||||
},
|
||||
Modules = {
|
||||
"debugglobe",
|
||||
|
||||
@@ -25,16 +25,23 @@
|
||||
include(${OPENSPACE_CMAKE_EXT_DIR}/module_definition.cmake)
|
||||
|
||||
set(HEADER_FILES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableglobe.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/distanceswitch.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/geometry.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/gridgeometry.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/globemesh.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/latlonpatch.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/clipmapglobe.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/util/converter.h
|
||||
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableglobe.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/distanceswitch.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableglobe.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/distanceswitch.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/geometry.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/gridgeometry.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/globemesh.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/latlonpatch.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/clipmapglobe.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/chunklodglobe.h
|
||||
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/datastructures/chunknode.h
|
||||
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/util/converter.h
|
||||
|
||||
)
|
||||
source_group("Header Files" FILES ${HEADER_FILES})
|
||||
|
||||
set(SOURCE_FILES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableglobe.cpp
|
||||
@@ -44,8 +51,13 @@ set(SOURCE_FILES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/globemesh.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/latlonpatch.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/clipmapglobe.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/chunklodglobe.cpp
|
||||
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/datastructures/chunknode.cpp
|
||||
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/util/converter.cpp
|
||||
|
||||
|
||||
)
|
||||
source_group("Source Files" FILES ${SOURCE_FILES})
|
||||
|
||||
@@ -54,7 +66,7 @@ set(SHADER_FILES
|
||||
source_group("Shader Files" FILES ${SHADER_FILES})
|
||||
|
||||
create_new_module(
|
||||
"GlobeBrowsing"
|
||||
globebrowsing_module
|
||||
${HEADER_FILES} ${SOURCE_FILES} ${SHADER_FILES}
|
||||
"GlobeBrowsing"
|
||||
globebrowsing_module
|
||||
${HEADER_FILES} ${SOURCE_FILES} ${SHADER_FILES}
|
||||
)
|
||||
|
||||
168
modules/globebrowsing/datastructures/chunknode.cpp
Normal file
168
modules/globebrowsing/datastructures/chunknode.cpp
Normal file
@@ -0,0 +1,168 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* 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. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <modules/globebrowsing/datastructures/chunknode.h>
|
||||
#include <modules/globebrowsing/rendering/chunklodglobe.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
BoundingRect::BoundingRect(Scalar cx, Scalar cy, Scalar hsx, Scalar hsy)
|
||||
: center(Vec2(cx, cy)), halfSize(Vec2(hsx, hsy)) { }
|
||||
|
||||
BoundingRect::BoundingRect(const Vec2& center, const Vec2& halfSize)
|
||||
:center(center), halfSize(halfSize) { }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
ChunkNode::ChunkNode(ChunkLodGlobe& owner, const BoundingRect& bounds, ChunkNode* parent)
|
||||
: _owner(owner)
|
||||
, bounds(bounds)
|
||||
, _parent(parent)
|
||||
{
|
||||
_children[0] = nullptr;
|
||||
_children[1] = nullptr;
|
||||
_children[2] = nullptr;
|
||||
_children[3] = nullptr;
|
||||
}
|
||||
|
||||
ChunkNode::~ChunkNode() {
|
||||
|
||||
}
|
||||
|
||||
bool ChunkNode::isRoot() const {
|
||||
return _parent == nullptr;
|
||||
}
|
||||
|
||||
bool ChunkNode::isLeaf() const {
|
||||
return _children[0] == nullptr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool ChunkNode::initialize() {
|
||||
if (!isLeaf()) {
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
_children[i]->initialize();
|
||||
}
|
||||
}
|
||||
|
||||
return isReady();
|
||||
}
|
||||
|
||||
bool ChunkNode::deinitialize() {
|
||||
if (!isLeaf()) {
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
_children[i]->deinitialize();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ChunkNode::isReady() const{
|
||||
bool ready = true;
|
||||
return ready;
|
||||
}
|
||||
|
||||
void ChunkNode::render(const RenderData& data) {
|
||||
internalRender(data, 0);
|
||||
}
|
||||
|
||||
void ChunkNode::internalRender(const RenderData& data, int currLevel) {
|
||||
if (isLeaf()) {
|
||||
LatLonPatch& templatePatch = _owner.getTemplatePatch();
|
||||
templatePatch.setPositionLatLon(bounds.center);
|
||||
templatePatch.setSizeLatLon(bounds.halfSize);
|
||||
templatePatch.render(data);
|
||||
}
|
||||
else {
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
_children[i]->internalRender(data, currLevel+1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ChunkNode::update(const UpdateData& data) {
|
||||
internalUpdate(data, 0);
|
||||
}
|
||||
|
||||
void ChunkNode::internalUpdate(const UpdateData& data, int currLevel) {
|
||||
if (!isLeaf()) {
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
_children[i]->internalUpdate(data, currLevel + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ChunkNode::split(int depth) {
|
||||
if (depth > 0 && isLeaf()) {
|
||||
|
||||
// Defining short handles for center, halfSize and quarterSize
|
||||
const Vec2& c = bounds.center;
|
||||
const Vec2& hs = bounds.halfSize;
|
||||
Vec2 qs = 0.5 * bounds.halfSize;
|
||||
|
||||
// Subdivide bounds
|
||||
BoundingRect nwBounds = BoundingRect(c + Vec2(-qs.x, -qs.y), qs);
|
||||
BoundingRect neBounds = BoundingRect(c + Vec2(+qs.x, -qs.y), qs);
|
||||
BoundingRect swBounds = BoundingRect(c + Vec2(-qs.x, +qs.y), qs);
|
||||
BoundingRect seBounds = BoundingRect(c + Vec2(+qs.x, +qs.y), qs);
|
||||
|
||||
// Create new chunk nodes
|
||||
_children[Quad::NORTH_WEST] = std::unique_ptr<ChunkNode>(new ChunkNode(_owner, nwBounds, this));
|
||||
_children[Quad::NORTH_EAST] = std::unique_ptr<ChunkNode>(new ChunkNode(_owner, neBounds, this));
|
||||
_children[Quad::SOUTH_WEST] = std::unique_ptr<ChunkNode>(new ChunkNode(_owner, swBounds, this));
|
||||
_children[Quad::SOUTH_EAST] = std::unique_ptr<ChunkNode>(new ChunkNode(_owner, seBounds, this));
|
||||
}
|
||||
|
||||
if (depth - 1 > 0) {
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
_children[i]->split(depth - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ChunkNode::merge() {
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
if (_children[i] != nullptr) {
|
||||
_children[i]->merge();
|
||||
}
|
||||
_children[i] = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const ChunkNode& ChunkNode::getChild(Quad quad) const {
|
||||
return *_children[quad];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace openspace
|
||||
112
modules/globebrowsing/datastructures/chunknode.h
Normal file
112
modules/globebrowsing/datastructures/chunknode.h
Normal file
@@ -0,0 +1,112 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* 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 __QUADTREE_H__
|
||||
#define __QUADTREE_H__
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <ostream>
|
||||
|
||||
#include <modules/globebrowsing/rendering/latlonpatch.h>
|
||||
|
||||
|
||||
// forward declaration
|
||||
namespace openspace {
|
||||
class ChunkLodGlobe;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Using double precision
|
||||
typedef double Scalar;
|
||||
typedef glm::dvec2 Vec2;
|
||||
|
||||
namespace openspace {
|
||||
|
||||
enum Quad {
|
||||
NORTH_WEST,
|
||||
NORTH_EAST,
|
||||
SOUTH_WEST,
|
||||
SOUTH_EAST
|
||||
};
|
||||
|
||||
|
||||
|
||||
struct BoundingRect {
|
||||
BoundingRect(Scalar, Scalar, Scalar, Scalar);
|
||||
BoundingRect(const Vec2& center, const Vec2& halfSize);
|
||||
Vec2 center;
|
||||
Vec2 halfSize;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class ChunkNode : public Renderable{
|
||||
public:
|
||||
ChunkNode(ChunkLodGlobe&, const BoundingRect&, ChunkNode* parent = nullptr);
|
||||
~ChunkNode();
|
||||
|
||||
|
||||
void split(int depth = 1);
|
||||
void merge();
|
||||
|
||||
bool isRoot() const;
|
||||
bool isLeaf() const;
|
||||
|
||||
const ChunkNode& getChild(Quad quad) const;
|
||||
const BoundingRect bounds;
|
||||
|
||||
|
||||
|
||||
bool initialize() override;
|
||||
bool deinitialize() override;
|
||||
bool isReady() const override;
|
||||
|
||||
void render(const RenderData& data) override;
|
||||
void update(const UpdateData& data) override;
|
||||
|
||||
void internalRender(const RenderData& data, int currLevel);
|
||||
void internalUpdate(const UpdateData& data, int currLevel);
|
||||
|
||||
private:
|
||||
|
||||
|
||||
ChunkNode* _parent;
|
||||
std::unique_ptr<ChunkNode> _children[4];
|
||||
|
||||
ChunkLodGlobe& _owner;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
|
||||
|
||||
#endif // __QUADTREE_H__
|
||||
@@ -37,7 +37,7 @@
|
||||
namespace openspace {
|
||||
|
||||
GlobeBrowsingModule::GlobeBrowsingModule()
|
||||
: OpenSpaceModule("GlobeBrowsing")
|
||||
: OpenSpaceModule("GlobeBrowsing")
|
||||
{}
|
||||
|
||||
void GlobeBrowsingModule::internalInitialize() {
|
||||
|
||||
131
modules/globebrowsing/rendering/chunklodglobe.cpp
Normal file
131
modules/globebrowsing/rendering/chunklodglobe.cpp
Normal file
@@ -0,0 +1,131 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* 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. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <modules/globebrowsing/rendering/chunklodglobe.h>
|
||||
|
||||
#include <modules/globebrowsing/util/converter.h>
|
||||
|
||||
// open space includes
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <openspace/util/spicemanager.h>
|
||||
#include <openspace/scene/scenegraphnode.h>
|
||||
|
||||
// ghoul includes
|
||||
#include <ghoul/misc/assert.h>
|
||||
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "ChunkLodGlobe";
|
||||
|
||||
const std::string keyFrame = "Frame";
|
||||
const std::string keyGeometry = "Geometry";
|
||||
const std::string keyShading = "PerformShading";
|
||||
|
||||
const std::string keyBody = "Body";
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
|
||||
const BoundingRect ChunkLodGlobe::LEFT_HEMISPHERE = BoundingRect(0, -M_PI/2, M_PI/2, M_PI/2);
|
||||
const BoundingRect ChunkLodGlobe::RIGHT_HEMISPHERE = BoundingRect(0, M_PI/2, M_PI/2, M_PI/2);
|
||||
|
||||
|
||||
ChunkLodGlobe::ChunkLodGlobe(const ghoul::Dictionary& dictionary)
|
||||
: _leftRoot(new ChunkNode(*this, LEFT_HEMISPHERE))
|
||||
, _rightRoot(new ChunkNode(*this, RIGHT_HEMISPHERE))
|
||||
, _templatePatch(20,20, 0, 0, 0, 0)
|
||||
, _rotation("rotation", "Rotation", 0, 0, 360)
|
||||
{
|
||||
std::string name;
|
||||
bool success = dictionary.getValue(SceneGraphNode::KeyName, name);
|
||||
ghoul_assert(success,
|
||||
"ChunkLodGlobe need the '" << SceneGraphNode::KeyName << "' be specified");
|
||||
setName(name);
|
||||
|
||||
dictionary.getValue(keyFrame, _frame);
|
||||
dictionary.getValue(keyBody, _target);
|
||||
if (_target != "")
|
||||
setBody(_target);
|
||||
|
||||
// Mainly for debugging purposes @AA
|
||||
addProperty(_rotation);
|
||||
|
||||
|
||||
// ----- specific for this class only ------ //
|
||||
_leftRoot->split(1);
|
||||
_rightRoot->split(1);
|
||||
}
|
||||
|
||||
ChunkLodGlobe::~ChunkLodGlobe() {
|
||||
|
||||
}
|
||||
|
||||
LatLonPatch& ChunkLodGlobe::getTemplatePatch() {
|
||||
return _templatePatch;
|
||||
}
|
||||
|
||||
bool ChunkLodGlobe::initialize() {
|
||||
_templatePatch.initialize();
|
||||
_leftRoot->initialize();
|
||||
_rightRoot->initialize();
|
||||
return isReady();
|
||||
}
|
||||
|
||||
bool ChunkLodGlobe::deinitialize() {
|
||||
_templatePatch.deinitialize();
|
||||
_leftRoot->deinitialize();
|
||||
_rightRoot->deinitialize();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ChunkLodGlobe::isReady() const {
|
||||
bool ready = true;
|
||||
ready &= _templatePatch.isReady();
|
||||
ready &= _leftRoot->isReady();
|
||||
ready &= _rightRoot->isReady();
|
||||
return ready;
|
||||
}
|
||||
|
||||
void ChunkLodGlobe::render(const RenderData& data)
|
||||
{
|
||||
// Set patch to follow camera
|
||||
//_patch.setPositionLatLon(converter::cartesianToLatLon(data.camera.position().dvec3()));
|
||||
// render
|
||||
_leftRoot->render(data);
|
||||
_rightRoot->render(data);
|
||||
}
|
||||
|
||||
void ChunkLodGlobe::update(const UpdateData& data) {
|
||||
_templatePatch.update(data);
|
||||
// set spice-orientation in accordance to timestamp
|
||||
_stateMatrix = SpiceManager::ref().positionTransformMatrix(_frame, "GALACTIC", data.time);
|
||||
_time = data.time;
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace openspace
|
||||
92
modules/globebrowsing/rendering/chunklodglobe.h
Normal file
92
modules/globebrowsing/rendering/chunklodglobe.h
Normal file
@@ -0,0 +1,92 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* 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 __CHUNK_LOD_GLOBE__
|
||||
#define __CHUNK_LOD_GLOBE__
|
||||
|
||||
#include <memory>
|
||||
|
||||
// open space includes
|
||||
#include <openspace/rendering/renderable.h>
|
||||
|
||||
#include <openspace/properties/stringproperty.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
|
||||
#include <modules/globebrowsing/datastructures/chunknode.h>
|
||||
|
||||
#include <modules/globebrowsing/rendering/geometry.h>
|
||||
#include <modules/globebrowsing/rendering/gridgeometry.h>
|
||||
#include <modules/globebrowsing/rendering/distanceswitch.h>
|
||||
#include <modules/globebrowsing/rendering/latlonpatch.h>
|
||||
|
||||
namespace ghoul {
|
||||
namespace opengl {
|
||||
class ProgramObject;
|
||||
}
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class ChunkLodGlobe :
|
||||
public Renderable, public std::enable_shared_from_this<ChunkLodGlobe>{
|
||||
public:
|
||||
ChunkLodGlobe(const ghoul::Dictionary& dictionary);
|
||||
~ChunkLodGlobe();
|
||||
|
||||
LatLonPatch& getTemplatePatch();
|
||||
|
||||
bool initialize() override;
|
||||
bool deinitialize() override;
|
||||
bool isReady() const override;
|
||||
|
||||
void render(const RenderData& data) override;
|
||||
void update(const UpdateData& data) override;
|
||||
|
||||
|
||||
|
||||
private:
|
||||
|
||||
// Covers all negative longitudes
|
||||
std::unique_ptr<ChunkNode> _leftRoot;
|
||||
|
||||
// Covers all positive longitudes
|
||||
std::unique_ptr<ChunkNode> _rightRoot;
|
||||
|
||||
// the patch used for actual rendering
|
||||
LatLonPatch _templatePatch;
|
||||
|
||||
static const BoundingRect LEFT_HEMISPHERE;
|
||||
static const BoundingRect RIGHT_HEMISPHERE;
|
||||
|
||||
properties::IntProperty _rotation;
|
||||
|
||||
glm::dmat3 _stateMatrix;
|
||||
std::string _frame;
|
||||
std::string _target;
|
||||
double _time;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __CHUNK_LOD_GLOBE__
|
||||
@@ -31,11 +31,14 @@
|
||||
#include <openspace/properties/stringproperty.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
|
||||
|
||||
#include <modules/globebrowsing/rendering/geometry.h>
|
||||
#include <modules/globebrowsing/rendering/gridgeometry.h>
|
||||
#include <modules/globebrowsing/rendering/distanceswitch.h>
|
||||
#include <modules/globebrowsing/rendering/latlonpatch.h>
|
||||
|
||||
|
||||
|
||||
namespace ghoul {
|
||||
namespace opengl {
|
||||
class ProgramObject;
|
||||
|
||||
@@ -168,7 +168,7 @@ void Geometry::drawUsingActiveProgram() {
|
||||
|
||||
glBindVertexArray(_vaoID);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _elementBufferID);
|
||||
glDrawElements(GL_LINES, _elementData.size(), GL_UNSIGNED_INT, 0);
|
||||
glDrawElements(GL_TRIANGLES, _elementData.size(), GL_UNSIGNED_INT, 0);
|
||||
glBindVertexArray(0);
|
||||
}
|
||||
|
||||
|
||||
@@ -86,13 +86,13 @@ std::vector<GLuint> GridGeometry::CreateElements(unsigned int xRes, unsigned int
|
||||
|
||||
// add upper triangle
|
||||
elements.push_back(v00);
|
||||
elements.push_back(v10);
|
||||
elements.push_back(v01);
|
||||
|
||||
elements.push_back(v10);
|
||||
|
||||
// add lower triangle
|
||||
elements.push_back(v01);
|
||||
elements.push_back(v10);
|
||||
elements.push_back(v11);
|
||||
elements.push_back(v10);
|
||||
|
||||
//LDEBUG(v00 << ", " << v10 << ", " << v01);
|
||||
//LDEBUG(v01 << ", " << v10 << ", " << v11);
|
||||
|
||||
@@ -110,23 +110,40 @@ namespace openspace {
|
||||
// TODO : Not sure if double precision will be needed for all these calculations
|
||||
// Using doubles in case but might slow things down.
|
||||
// TODO : Need to get the radius of the globe
|
||||
double r = 6e6;
|
||||
double r = 6.3e6;
|
||||
|
||||
// Create control points and normals(double)
|
||||
glm::dvec3 p00, p01, p02, p10, p11, p12, p20, p21, p22;
|
||||
glm::dvec3 n00, n01, n02, n10, n11, n12, n20, n21, n22;
|
||||
glm::dvec3 nHorizontal0, nHorizontal1, nHorizontal2;
|
||||
float w10, w11, w12;
|
||||
|
||||
// Calculate positions of corner control points
|
||||
p00 = calculateCornerPointLeftBottom();
|
||||
p20 = calculateCornerPointRightBottom();
|
||||
p02 = calculateCornerPointLeftTop();
|
||||
p22 = calculateCornerPointRightTop();
|
||||
p00 = calculateCornerPointBottomLeft();
|
||||
p20 = calculateCornerPointBottomRight();
|
||||
p02 = calculateCornerPointTopLeft();
|
||||
p22 = calculateCornerPointTopRight();
|
||||
|
||||
// Calculate the horizontal normals
|
||||
nHorizontal0 = glm::normalize(converter::latLonToCartesian(
|
||||
0,
|
||||
_posLatLon.y - _sizeLatLon.y,
|
||||
r));
|
||||
nHorizontal1 = glm::normalize(converter::latLonToCartesian(
|
||||
0,
|
||||
_posLatLon.y,
|
||||
r));
|
||||
nHorizontal2 = glm::normalize(converter::latLonToCartesian(
|
||||
0,
|
||||
_posLatLon.y + _sizeLatLon.y,
|
||||
r));
|
||||
|
||||
// Get position of center control points
|
||||
p01 = calculateCenterPoint(p00, p02);
|
||||
p21 = calculateCenterPoint(p20, p22);
|
||||
p10 = calculateCenterPoint(p00, p20);
|
||||
p12 = calculateCenterPoint(p02, p22);
|
||||
p11 = calculateCenterPoint(p01, p21);
|
||||
p01 = calculateCenterPoint(p00, glm::normalize(p00), p02, glm::normalize(p02));
|
||||
p21 = calculateCenterPoint(p20, glm::normalize(p20), p22, glm::normalize(p22));
|
||||
p10 = calculateCenterPoint(p00, nHorizontal0, p20, nHorizontal2);
|
||||
p12 = calculateCenterPoint(p02, nHorizontal0, p22, nHorizontal2);
|
||||
p11 = calculateCenterPoint(p01, nHorizontal0, p21, nHorizontal2);
|
||||
|
||||
// Calculate normals from control point positions
|
||||
n00 = normalize(p00);
|
||||
@@ -139,6 +156,11 @@ namespace openspace {
|
||||
n21 = normalize(p21);
|
||||
n22 = normalize(p22);
|
||||
|
||||
// Calculate three weights to send to GPU for interpolation
|
||||
w10 = glm::dot(nHorizontal0, nHorizontal1);
|
||||
w11 = w10;
|
||||
w12 = w10;
|
||||
|
||||
// TODO : Transformation to world space from model space should also consider
|
||||
// rotations. Now it only uses translatation for simplicity. Should be done
|
||||
// With a matrix transform
|
||||
@@ -160,10 +182,13 @@ namespace openspace {
|
||||
glm::dvec3 camPos = data.camera.position().dvec3();
|
||||
glm::dvec3 camDir = glm::normalize(position - camPos);
|
||||
glm::dvec3 camUp = glm::dvec3(0,1,0);// data.camera.lookUpVector();
|
||||
|
||||
// Get camera transform matrix (double precision)
|
||||
glm::dmat4 viewTransform = glm::inverse(glm::translate(glm::dmat4(1.0), camPos));
|
||||
|
||||
//glm::dmat4 viewTransform = glm::lookAt(camPos, camPos + camDir, camUp);
|
||||
viewTransform = glm::dmat4( data.camera.viewRotationMatrix()) * viewTransform;
|
||||
viewTransform = glm::dmat4(data.camera.viewRotationMatrix())*viewTransform;
|
||||
|
||||
// Transform control points to camera space
|
||||
p00 = glm::dvec3(viewTransform * glm::dvec4(p00, 1.0));
|
||||
p10 = glm::dvec3(viewTransform * glm::dvec4(p10, 1.0));
|
||||
@@ -197,6 +222,11 @@ namespace openspace {
|
||||
_programObject->setUniform("p12", glm::vec3(p12));
|
||||
_programObject->setUniform("p22", glm::vec3(p22));
|
||||
|
||||
_programObject->setUniform("w10", w10);
|
||||
_programObject->setUniform("w11", w11);
|
||||
_programObject->setUniform("w12", w12);
|
||||
|
||||
/*
|
||||
_programObject->setUniform("n00", glm::vec3(n00));
|
||||
_programObject->setUniform("n10", glm::vec3(n10));
|
||||
_programObject->setUniform("n20", glm::vec3(n20));
|
||||
@@ -206,12 +236,12 @@ namespace openspace {
|
||||
_programObject->setUniform("n02", glm::vec3(n02));
|
||||
_programObject->setUniform("n12", glm::vec3(n12));
|
||||
_programObject->setUniform("n22", glm::vec3(n22));
|
||||
|
||||
*/
|
||||
_programObject->setUniform("Projection", data.camera.projectionMatrix());
|
||||
|
||||
// Render triangles (use texture coordinates to interpolate to new positions)
|
||||
glDisable(GL_CULL_FACE);
|
||||
//glCullFace(GL_BACK);
|
||||
glEnable(GL_CULL_FACE);
|
||||
glCullFace(GL_BACK);
|
||||
|
||||
// render
|
||||
_grid.drawUsingActiveProgram();
|
||||
@@ -228,43 +258,44 @@ namespace openspace {
|
||||
_posLatLon = posLatLon;
|
||||
}
|
||||
|
||||
glm::dvec3 LatLonPatch::calculateCornerPointLeftBottom() {
|
||||
glm::dvec3 LatLonPatch::calculateCornerPointBottomLeft() {
|
||||
double r = 6e6; // TODO : DEFINE r AS A MEMBER VARIABLE
|
||||
|
||||
return glm::dvec3(converter::latLonToCartesian(
|
||||
return converter::latLonToCartesian(
|
||||
_posLatLon.x - _sizeLatLon.x,
|
||||
_posLatLon.y - _sizeLatLon.y,
|
||||
r));
|
||||
r);
|
||||
}
|
||||
glm::dvec3 LatLonPatch::calculateCornerPointRightBottom() {
|
||||
glm::dvec3 LatLonPatch::calculateCornerPointBottomRight() {
|
||||
double r = 6e6; // TODO : DEFINE r AS A MEMBER VARIABLE
|
||||
|
||||
return glm::dvec3(converter::latLonToCartesian(
|
||||
_posLatLon.x + _sizeLatLon.x,
|
||||
_posLatLon.y - _sizeLatLon.y,
|
||||
r));
|
||||
}
|
||||
glm::dvec3 LatLonPatch::calculateCornerPointLeftTop() {
|
||||
double r = 6e6; // TODO : DEFINE r AS A MEMBER VARIABLE
|
||||
|
||||
return glm::dvec3(converter::latLonToCartesian(
|
||||
return converter::latLonToCartesian(
|
||||
_posLatLon.x - _sizeLatLon.x,
|
||||
_posLatLon.y + _sizeLatLon.y,
|
||||
r));
|
||||
r);
|
||||
}
|
||||
glm::dvec3 LatLonPatch::calculateCornerPointRightTop() {
|
||||
glm::dvec3 LatLonPatch::calculateCornerPointTopLeft() {
|
||||
double r = 6e6; // TODO : DEFINE r AS A MEMBER VARIABLE
|
||||
|
||||
return glm::dvec3(converter::latLonToCartesian(
|
||||
return converter::latLonToCartesian(
|
||||
_posLatLon.x + _sizeLatLon.x,
|
||||
_posLatLon.y - _sizeLatLon.y,
|
||||
r);
|
||||
}
|
||||
glm::dvec3 LatLonPatch::calculateCornerPointTopRight() {
|
||||
double r = 6e6; // TODO : DEFINE r AS A MEMBER VARIABLE
|
||||
|
||||
return converter::latLonToCartesian(
|
||||
_posLatLon.x + _sizeLatLon.x,
|
||||
_posLatLon.y + _sizeLatLon.y,
|
||||
r));
|
||||
r);
|
||||
}
|
||||
|
||||
glm::dvec3 LatLonPatch::calculateCenterPoint(glm::dvec3 p0, glm::dvec3 p2) {
|
||||
glm::dvec3 n0 = glm::normalize(p0);
|
||||
glm::dvec3 n2 = glm::normalize(p2);
|
||||
|
||||
glm::dvec3 LatLonPatch::calculateCenterPoint(
|
||||
glm::dvec3 p0,
|
||||
glm::dvec3 n0,
|
||||
glm::dvec3 p2,
|
||||
glm::dvec3 n2) {
|
||||
// Solution derived
|
||||
glm::dvec2 u = glm::dvec2(0, glm::dot(p2, n2) - glm::dot(p0, n2));
|
||||
double cosNormalAngle = glm::dot(n0, n2);
|
||||
@@ -274,4 +305,8 @@ namespace openspace {
|
||||
return p1;
|
||||
}
|
||||
|
||||
void LatLonPatch::setSizeLatLon(glm::dvec2 sizeLatLon) {
|
||||
_sizeLatLon = sizeLatLon;
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -60,18 +60,19 @@ namespace openspace {
|
||||
void update(const UpdateData& data) override;
|
||||
|
||||
void setPositionLatLon(glm::dvec2 posLatLon);
|
||||
void setSizeLatLon(glm::dvec2 posLatLon);
|
||||
|
||||
|
||||
glm::dvec3 calculateCornerPointLeftBottom();
|
||||
glm::dvec3 calculateCornerPointRightBottom();
|
||||
glm::dvec3 calculateCornerPointLeftTop();
|
||||
glm::dvec3 calculateCornerPointRightTop();
|
||||
glm::dvec3 calculateCornerPointBottomLeft();
|
||||
glm::dvec3 calculateCornerPointBottomRight();
|
||||
glm::dvec3 calculateCornerPointTopLeft();
|
||||
glm::dvec3 calculateCornerPointTopRight();
|
||||
|
||||
/**
|
||||
Finds a third control point between the two parameter points assuming
|
||||
they both lie on a sphere with the origin in the center.
|
||||
*/
|
||||
glm::dvec3 calculateCenterPoint(glm::dvec3 p0, glm::dvec3 p2);
|
||||
glm::dvec3 calculateCenterPoint(glm::dvec3 p0, glm::dvec3 n0, glm::dvec3 p2, glm::dvec3 n2);
|
||||
private:
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _programObject;
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
|
||||
#include <modules/globebrowsing/rendering/globemesh.h>
|
||||
#include <modules/globebrowsing/rendering/clipmapglobe.h>
|
||||
#include <modules/globebrowsing/rendering/chunklodglobe.h>
|
||||
|
||||
// open space includes
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
@@ -69,7 +70,8 @@ namespace openspace {
|
||||
// Mainly for debugging purposes @AA
|
||||
addProperty(_rotation);
|
||||
|
||||
addSwitchValue(std::shared_ptr<ClipMapGlobe>(new ClipMapGlobe(dictionary)), 1e9);
|
||||
//addSwitchValue(std::shared_ptr<ClipMapGlobe>(new ClipMapGlobe(dictionary)), 1e9);
|
||||
addSwitchValue(std::shared_ptr<ChunkLodGlobe>(new ChunkLodGlobe(dictionary)), 1e9);
|
||||
addSwitchValue(std::shared_ptr<GlobeMesh>(new GlobeMesh(dictionary)), 1e10);
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,11 @@ uniform vec3 p02;
|
||||
uniform vec3 p12;
|
||||
uniform vec3 p22;
|
||||
|
||||
uniform float w10;
|
||||
uniform float w11;
|
||||
uniform float w12;
|
||||
|
||||
/*
|
||||
uniform vec3 n00;
|
||||
uniform vec3 n10;
|
||||
uniform vec3 n20;
|
||||
@@ -45,10 +50,11 @@ uniform vec3 n21;
|
||||
uniform vec3 n02;
|
||||
uniform vec3 n12;
|
||||
uniform vec3 n22;
|
||||
|
||||
*/
|
||||
layout(location = 1) in vec2 in_UV;
|
||||
|
||||
out vec4 vs_position;
|
||||
out vec2 vs_uv;
|
||||
|
||||
#include "PowerScaling/powerScaling_vs.hglsl"
|
||||
|
||||
@@ -119,20 +125,21 @@ void getKnots(int n, int c, inout int x[7])
|
||||
|
||||
void main()
|
||||
{
|
||||
vs_uv = in_UV;
|
||||
|
||||
// Bilinear interpolation
|
||||
|
||||
/*
|
||||
vec3 p0 = (1 - in_UV.x) * p00 + in_UV.x * p20;
|
||||
vec3 p2 = (1 - in_UV.x) * p02 + in_UV.x * p22;
|
||||
vec3 p = (1 - in_UV.y) * p0 + in_UV.y * p2;
|
||||
*/
|
||||
|
||||
// Calculate three weights
|
||||
// These values of the weights will make the curves in to circle segments
|
||||
|
||||
|
||||
float w10 = dot(n00, normalize(n00 + n20));
|
||||
float w11 = dot(n01, normalize(n01 + n21));
|
||||
float w12 = dot(n02, normalize(n02 + n22));
|
||||
//float w10 = dot(n00, normalize(n00 + n20));
|
||||
//float w11 = dot(n01, normalize(n01 + n21));
|
||||
//float w12 = dot(n02, normalize(n02 + n22));
|
||||
|
||||
float basisFunctionValues[4];
|
||||
int order = 3; // Order of the NURBS curve
|
||||
@@ -141,45 +148,31 @@ void main()
|
||||
|
||||
// Interpolate in u direction
|
||||
// getKnots(npts, order, knotVector);
|
||||
nurbsBasis(order, in_UV.x, npts, knotVector, basisFunctionValues);
|
||||
nurbsBasis(order, in_UV.y, npts, knotVector, basisFunctionValues);
|
||||
vec3 p0 =
|
||||
basisFunctionValues[1] * p00 +
|
||||
basisFunctionValues[2] * p10 * w10 +
|
||||
basisFunctionValues[2] * p10 * w10+
|
||||
basisFunctionValues[3] * p20;
|
||||
vec3 p1 =
|
||||
basisFunctionValues[1] * p01 +
|
||||
basisFunctionValues[2] * p11 * w11 +
|
||||
basisFunctionValues[2] * p11 * w11+
|
||||
basisFunctionValues[3] * p21;
|
||||
vec3 p2 =
|
||||
basisFunctionValues[1] * p02 +
|
||||
basisFunctionValues[2] * p12 * w12 +
|
||||
basisFunctionValues[2] * p12 * w12+
|
||||
basisFunctionValues[3] * p22;
|
||||
|
||||
// Interpolate normals
|
||||
vec3 n0 =
|
||||
basisFunctionValues[1] * n00 +
|
||||
basisFunctionValues[2] * n10 * w10 +
|
||||
basisFunctionValues[3] * n20;
|
||||
vec3 n1 =
|
||||
basisFunctionValues[1] * n01 +
|
||||
basisFunctionValues[2] * n11 * w11 +
|
||||
basisFunctionValues[3] * n21;
|
||||
vec3 n2 =
|
||||
basisFunctionValues[1] * n02 +
|
||||
basisFunctionValues[2] * n12 * w12 +
|
||||
basisFunctionValues[3] * n22;
|
||||
|
||||
// Calculate the last weight
|
||||
float w1 = dot(n0, n1);
|
||||
float w1 = dot(normalize(p0), normalize(p1));
|
||||
|
||||
// Interpolate in v direction
|
||||
nurbsBasis(order, in_UV.y, npts, knotVector, basisFunctionValues);
|
||||
nurbsBasis(order, in_UV.x, npts, knotVector, basisFunctionValues);
|
||||
vec3 p =
|
||||
basisFunctionValues[1] * p0 +
|
||||
basisFunctionValues[2] * p1 * w1 +
|
||||
basisFunctionValues[2] * p1 * w1 * w11+
|
||||
basisFunctionValues[3] * p2;
|
||||
|
||||
//p = (1 - in_UV.y) * p0 + in_UV.y * p2;
|
||||
//p = (1 - in_UV.x) * p0 + in_UV.x * p2;
|
||||
|
||||
|
||||
vec4 position = Projection * vec4(p, 1);
|
||||
|
||||
@@ -36,6 +36,8 @@ uniform sampler2D texture1;
|
||||
uniform sampler2D nightTex;
|
||||
|
||||
in vec4 vs_position;
|
||||
in vec2 vs_uv;
|
||||
|
||||
|
||||
#include "PowerScaling/powerScaling_fs.hglsl"
|
||||
#include "fragment.glsl"
|
||||
@@ -43,7 +45,7 @@ in vec4 vs_position;
|
||||
Fragment getFragment() {
|
||||
Fragment frag;
|
||||
|
||||
frag.color = vec4(1,1,1,1);
|
||||
frag.color = vec4(vs_uv,1,1);
|
||||
frag.depth = pscDepth(vs_position);
|
||||
|
||||
return frag;
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
//#include <test_common.inl>
|
||||
//#include <test_spicemanager.inl>
|
||||
//#include <test_scenegraphloader.inl>
|
||||
#include <test_chunknode.inl>
|
||||
//#include <test_luaconversions.inl>
|
||||
//#include <test_powerscalecoordinates.inl>
|
||||
#include <test_latlonpatch.inl>
|
||||
@@ -50,17 +51,19 @@ using namespace ghoul::filesystem;
|
||||
using namespace ghoul::logging;
|
||||
|
||||
namespace {
|
||||
std::string _loggerCat = "OpenSpaceTest";
|
||||
std::string _loggerCat = "OpenSpaceTest";
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
std::vector<std::string> args;
|
||||
openspace::OpenSpaceEngine::create(argc, argv, std::make_unique<openspace::WindowWrapper>(), args);
|
||||
std::vector<std::string> args;
|
||||
openspace::OpenSpaceEngine::create(argc, argv, std::make_unique<openspace::WindowWrapper>(), args);
|
||||
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
int testResult = RUN_ALL_TESTS();
|
||||
|
||||
int hej;
|
||||
std::cin >> hej;
|
||||
return testResult;
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
|
||||
int returnVal = RUN_ALL_TESTS();
|
||||
|
||||
// keep console from closing down
|
||||
int dummy; std::cin >> dummy;
|
||||
|
||||
return returnVal;
|
||||
}
|
||||
|
||||
68
tests/test_chunknode.inl
Normal file
68
tests/test_chunknode.inl
Normal file
@@ -0,0 +1,68 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* 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. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include <openspace/scene/scenegraphnode.h>
|
||||
#include <openspace/../modules/globebrowsing/datastructures/chunknode.h>
|
||||
|
||||
#include <fstream>
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
using namespace openspace;
|
||||
|
||||
class ChunkNodeTest : public testing::Test {};
|
||||
|
||||
TEST_F(ChunkNodeTest, Split) {
|
||||
BoundingRect bounds(Vec2(2, 2), Vec2(2, 2));
|
||||
auto cn = std::shared_ptr<ChunkNode>(new ChunkNode(bounds));
|
||||
ASSERT_TRUE(cn->isRoot()) << "Chunk node is root";
|
||||
ASSERT_TRUE(cn->isLeaf()) << "Chunk node is leaf";
|
||||
|
||||
cn->split();
|
||||
ASSERT_TRUE(cn->isRoot()) << "Chunk node is root";
|
||||
ASSERT_FALSE(cn->isLeaf()) << "Chunk node is not leaf";
|
||||
|
||||
ASSERT_EQ(cn->bounds.center.x, cn->getChild(Quad::NORTH_WEST).bounds.center.x * 2);
|
||||
ASSERT_EQ(cn->bounds.center.x, cn->getChild(Quad::NORTH_EAST).bounds.center.x * 2/3);
|
||||
|
||||
ASSERT_EQ(cn->bounds.halfSize.x, cn->getChild(Quad::NORTH_WEST).bounds.halfSize.x * 2);
|
||||
ASSERT_EQ(cn->bounds.halfSize.y, cn->getChild(Quad::NORTH_WEST).bounds.halfSize.y * 2);
|
||||
}
|
||||
|
||||
TEST_F(ChunkNodeTest, Merge) {
|
||||
BoundingRect bounds(Vec2(2, 2), Vec2(2, 2));
|
||||
ChunkNode cn(bounds);
|
||||
ASSERT_TRUE(cn.isRoot()) << "Chunk node is root";
|
||||
ASSERT_TRUE(cn.isLeaf()) << "Chunk node is leaf";
|
||||
|
||||
cn.split();
|
||||
ASSERT_TRUE(cn.isRoot()) << "Chunk node is root";
|
||||
ASSERT_FALSE(cn.isLeaf()) << "Chunk node is not leaf";
|
||||
|
||||
cn.merge();
|
||||
ASSERT_TRUE(cn.isRoot()) << "Chunk node is root";
|
||||
ASSERT_TRUE(cn.isLeaf()) << "Chunk node is leaf";
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user