mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-05-04 09:59:44 -05:00
Rendering of clip maps is now more convenient.
This commit is contained in:
@@ -53,6 +53,7 @@ namespace {
|
||||
namespace openspace {
|
||||
ClipMapGlobe::ClipMapGlobe(const ghoul::Dictionary& dictionary)
|
||||
: _rotation("rotation", "Rotation", 0, 0, 360)
|
||||
, _clipMapPyramid(LatLon(M_PI / 2, M_PI / 2))
|
||||
{
|
||||
std::string name;
|
||||
bool success = dictionary.getValue(SceneGraphNode::KeyName, name);
|
||||
@@ -65,15 +66,6 @@ namespace openspace {
|
||||
if (_target != "")
|
||||
setBody(_target);
|
||||
|
||||
size_t numPatches = 10;
|
||||
for (size_t i = 0; i < numPatches; i++)
|
||||
{
|
||||
_patches.push_back(LatLonPatch(
|
||||
0.0,
|
||||
0.0,
|
||||
M_PI / (4 * pow(2, i)),
|
||||
M_PI / (4 * pow(2, i))));
|
||||
}
|
||||
// Mainly for debugging purposes @AA
|
||||
addProperty(_rotation);
|
||||
|
||||
@@ -109,18 +101,17 @@ namespace openspace {
|
||||
|
||||
void ClipMapGlobe::render(const RenderData& data)
|
||||
{
|
||||
// Set patches to follow camera
|
||||
for (size_t i = 0; i < _patches.size(); i++)
|
||||
{
|
||||
_patches[i].setCenter(LatLon::fromCartesian(data.camera.position().dvec3()));
|
||||
}
|
||||
// TODO : Choose the max depth and the min depth depending on the camera
|
||||
int maxDepth = 10;
|
||||
int minDepth = 0;
|
||||
// render patches
|
||||
for (size_t i = 0; i < _patches.size() - 1; i++)
|
||||
for (size_t i = minDepth; i < maxDepth; i++)
|
||||
{
|
||||
_patchRenderer->renderPatch(_patches[i], data, 6.3e6);
|
||||
LatLon patchSize = _clipMapPyramid.getPatchSizeAtLevel(i);
|
||||
_patchRenderer->renderPatch(patchSize, data, 6.3e6);
|
||||
}
|
||||
_smallestPatchRenderer->renderPatch(_patches[_patches.size() - 1], data, 6.3e6);
|
||||
|
||||
LatLon patchSize = _clipMapPyramid.getPatchSizeAtLevel(maxDepth);
|
||||
_smallestPatchRenderer->renderPatch(patchSize, data, 6.3e6);
|
||||
}
|
||||
|
||||
void ClipMapGlobe::update(const UpdateData& data) {
|
||||
|
||||
@@ -34,8 +34,7 @@
|
||||
#include <modules/globebrowsing/rendering/gridgeometry.h>
|
||||
#include <modules/globebrowsing/rendering/distanceswitch.h>
|
||||
#include <modules/globebrowsing/rendering/patchrenderer.h>
|
||||
|
||||
|
||||
#include <modules/globebrowsing/rendering/clipmappyramid.h>
|
||||
|
||||
namespace ghoul {
|
||||
namespace opengl {
|
||||
@@ -60,7 +59,8 @@ namespace openspace {
|
||||
private:
|
||||
std::unique_ptr<ClipMapPatchRenderer> _patchRenderer;
|
||||
std::unique_ptr<ClipMapPatchRenderer> _smallestPatchRenderer;
|
||||
std::vector<LatLonPatch> _patches;
|
||||
|
||||
ClipMapPyramid _clipMapPyramid;
|
||||
|
||||
properties::IntProperty _rotation;
|
||||
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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/clipmappyramid.h>
|
||||
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
|
||||
// ghoul includes
|
||||
#include <ghoul/misc/assert.h>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "ClipMapPyramid";
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
ClipMapPyramid::ClipMapPyramid(LatLon sizeLevel0)
|
||||
: _sizeLevel0(sizeLevel0)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ClipMapPyramid::~ClipMapPyramid()
|
||||
{}
|
||||
|
||||
LatLon ClipMapPyramid::getPatchSizeAtLevel(int level)
|
||||
{
|
||||
return LatLon(_sizeLevel0.lat / pow(2, level), _sizeLevel0.lon / pow(2, level));
|
||||
}
|
||||
|
||||
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,46 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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 __CLIPMAPPYRAMID_H__
|
||||
#define __CLIPMAPPYRAMID_H__
|
||||
|
||||
// open space includes
|
||||
#include <modules/globebrowsing/datastructures/latlon.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class ClipMapPyramid {
|
||||
public:
|
||||
ClipMapPyramid(LatLon sizeLevel0);
|
||||
~ClipMapPyramid();
|
||||
|
||||
LatLon getPatchSizeAtLevel(int level);
|
||||
|
||||
private:
|
||||
const LatLon _sizeLevel0;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __CLIPMAPPYRAMID_H__
|
||||
@@ -168,7 +168,7 @@ namespace openspace {
|
||||
}
|
||||
|
||||
void ClipMapPatchRenderer::renderPatch(
|
||||
const LatLonPatch& patch,
|
||||
const LatLon& patchSize,
|
||||
const RenderData& data,
|
||||
double radius)
|
||||
{
|
||||
@@ -183,20 +183,22 @@ namespace openspace {
|
||||
|
||||
// Snap patch position
|
||||
int segmentsPerPatch = 32;
|
||||
LatLon halfSize = patch.halfSize();
|
||||
LatLon stepSize = LatLon(
|
||||
halfSize.lat * 2 / segmentsPerPatch,
|
||||
halfSize.lon * 2 / segmentsPerPatch);
|
||||
patchSize.lat / segmentsPerPatch,
|
||||
patchSize.lon / segmentsPerPatch);
|
||||
ivec2 patchesToCoverGlobe = ivec2(
|
||||
M_PI / (halfSize.lat * 2) + 0.5,
|
||||
M_PI * 2 / (halfSize.lon * 2) + 0.5);
|
||||
M_PI / patchSize.lat + 0.5,
|
||||
M_PI * 2 / patchSize.lon + 0.5);
|
||||
LatLon cameraPosLatLon = LatLon::fromCartesian(data.camera.position().dvec3());
|
||||
ivec2 intSnapCoord = ivec2(
|
||||
patch.center().lat / (M_PI * 2) * segmentsPerPatch * patchesToCoverGlobe.y,
|
||||
patch.center().lon / (M_PI) * segmentsPerPatch * patchesToCoverGlobe.x);
|
||||
cameraPosLatLon.lat / (M_PI * 2) * segmentsPerPatch * patchesToCoverGlobe.y,
|
||||
cameraPosLatLon.lon / (M_PI) * segmentsPerPatch * patchesToCoverGlobe.x);
|
||||
LatLon newPatchCenter = LatLon(
|
||||
stepSize.lat * intSnapCoord.x,
|
||||
stepSize.lon * intSnapCoord.y);
|
||||
LatLonPatch newPatch(newPatchCenter, patch.halfSize());
|
||||
LatLonPatch newPatch(
|
||||
newPatchCenter,
|
||||
LatLon(patchSize.lat / 2, patchSize.lon / 2));
|
||||
|
||||
ivec2 contraction = ivec2(intSnapCoord.y % 2, intSnapCoord.x % 2);
|
||||
|
||||
@@ -206,7 +208,7 @@ namespace openspace {
|
||||
|
||||
|
||||
// Get the textures that should be used for rendering
|
||||
TileIndex tileIndex = _tileSet.getTileIndex(patch);
|
||||
TileIndex tileIndex = _tileSet.getTileIndex(newPatch);
|
||||
LatLonPatch tilePatch = _tileSet.getTilePositionAndScale(tileIndex);
|
||||
std::shared_ptr<ghoul::opengl::Texture> tile00 = _tileSet.getTile(tileIndex);
|
||||
glm::mat3 uvTransform = _tileSet.getUvTransformationPatchToTile(newPatch, tileIndex);
|
||||
@@ -218,9 +220,11 @@ namespace openspace {
|
||||
_programObject->setUniform("textureSampler", texUnit);
|
||||
_programObject->setUniform("uvTransformPatchToTile", mat3(uvTransform));
|
||||
|
||||
_programObject->setUniform("modelViewProjectionTransform", data.camera.projectionMatrix() * viewTransform * modelTransform);
|
||||
_programObject->setUniform(
|
||||
"modelViewProjectionTransform",
|
||||
data.camera.projectionMatrix() * viewTransform * modelTransform);
|
||||
_programObject->setUniform("minLatLon", vec2(newPatch.southWestCorner().toLonLatVec2()));
|
||||
_programObject->setUniform("lonLatScalingFactor", 2.0f * vec2(halfSize.toLonLatVec2()));
|
||||
_programObject->setUniform("lonLatScalingFactor", vec2(patchSize.toLonLatVec2()));
|
||||
_programObject->setUniform("globeRadius", float(radius));
|
||||
_programObject->setUniform("contraction", contraction);
|
||||
|
||||
|
||||
@@ -94,7 +94,7 @@ namespace openspace {
|
||||
ClipMapPatchRenderer(shared_ptr<Geometry> geometry);
|
||||
|
||||
void renderPatch(
|
||||
const LatLonPatch& patch,
|
||||
const LatLon& patchSize,
|
||||
const RenderData& data,
|
||||
double radius);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user