diff --git a/modules/globebrowsing/CMakeLists.txt b/modules/globebrowsing/CMakeLists.txt index a7b3a9d59d..a3aeeacb32 100644 --- a/modules/globebrowsing/CMakeLists.txt +++ b/modules/globebrowsing/CMakeLists.txt @@ -30,6 +30,9 @@ set(HEADER_FILES ${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 ) source_group("Header Files" FILES ${HEADER_FILES}) @@ -39,12 +42,14 @@ set(SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/rendering/geometry.cpp ${CMAKE_CURRENT_SOURCE_DIR}/rendering/gridgeometry.cpp ${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}/util/converter.cpp ) source_group("Source Files" FILES ${SOURCE_FILES}) set(SHADER_FILES - # ${CMAKE_CURRENT_SOURCE_DIR}/shaders/crawlingline_fs.glsl ) source_group("Shader Files" FILES ${SHADER_FILES}) diff --git a/modules/globebrowsing/rendering/clipmapglobe.cpp b/modules/globebrowsing/rendering/clipmapglobe.cpp new file mode 100644 index 0000000000..ebcedeec5a --- /dev/null +++ b/modules/globebrowsing/rendering/clipmapglobe.cpp @@ -0,0 +1,101 @@ +/***************************************************************************************** +* * +* 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 + +// open space includes +#include +#include +#include +#include + +// ghoul includes +#include + +#define _USE_MATH_DEFINES +#include + +namespace { + const std::string _loggerCat = "ClipMapGlobe"; + + const std::string keyFrame = "Frame"; + const std::string keyGeometry = "Geometry"; + const std::string keyShading = "PerformShading"; + + const std::string keyBody = "Body"; +} + +namespace openspace { + ClipMapGlobe::ClipMapGlobe(const ghoul::Dictionary& dictionary) + : _patch(10, 10, 0, 0, M_PI / 6, M_PI / 6) + , _rotation("rotation", "Rotation", 0, 0, 360) + { + std::string name; + bool success = dictionary.getValue(SceneGraphNode::KeyName, name); + ghoul_assert(success, + "ClipMapGlobe 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); + } + + ClipMapGlobe::~ClipMapGlobe() { + } + + bool ClipMapGlobe::initialize() { + _patch.initialize(); + return isReady(); + } + + bool ClipMapGlobe::deinitialize() { + _patch.deinitialize(); + return true; + } + + bool ClipMapGlobe::isReady() const { + bool ready = true; + ready &= _patch.isReady(); + return ready; + } + + void ClipMapGlobe::render(const RenderData& data) + { + // render + _patch.render(data); + } + + void ClipMapGlobe::update(const UpdateData& data) { + _patch.update(data); + // set spice-orientation in accordance to timestamp + _stateMatrix = SpiceManager::ref().positionTransformMatrix(_frame, "GALACTIC", data.time); + _time = data.time; + } + +} // namespace openspace diff --git a/modules/globebrowsing/rendering/clipmapglobe.h b/modules/globebrowsing/rendering/clipmapglobe.h new file mode 100644 index 0000000000..6a5296f9ab --- /dev/null +++ b/modules/globebrowsing/rendering/clipmapglobe.h @@ -0,0 +1,72 @@ +/***************************************************************************************** +* * +* 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 __CLIPMAPGLOBE_H__ +#define __CLIPMAPGLOBE_H__ + +// open space includes +#include + +#include +#include + +#include +#include +#include +#include + +namespace ghoul { + namespace opengl { + class ProgramObject; + } +} + +namespace openspace { + + class ClipMapGlobe : public Renderable { + public: + ClipMapGlobe(const ghoul::Dictionary& dictionary); + ~ClipMapGlobe(); + + bool initialize() override; + bool deinitialize() override; + bool isReady() const override; + + void render(const RenderData& data) override; + void update(const UpdateData& data) override; + + private: + LatLonPatch _patch; + + properties::IntProperty _rotation; + + glm::dmat3 _stateMatrix; + std::string _frame; + std::string _target; + double _time; + }; + +} // namespace openspace + +#endif // __CLIPMAPGLOBE_H__ \ No newline at end of file diff --git a/modules/globebrowsing/rendering/globemesh.cpp b/modules/globebrowsing/rendering/globemesh.cpp index 995e8bec40..3362d62bf1 100644 --- a/modules/globebrowsing/rendering/globemesh.cpp +++ b/modules/globebrowsing/rendering/globemesh.cpp @@ -74,7 +74,6 @@ namespace openspace { RenderEngine& renderEngine = OsEng.renderEngine(); if (_programObject == nullptr) { - // Night texture program _programObject = renderEngine.buildRenderProgram( "simpleTextureProgram", "${MODULE_GLOBEBROWSING}/shaders/simple_vs.glsl", @@ -131,8 +130,25 @@ namespace openspace { _programObject->setUniform("ModelTransform", transform); setPscUniforms(*_programObject.get(), data.camera, data.position); - glEnable(GL_CULL_FACE); - glCullFace(GL_BACK); + glm::dmat4 cameraTransform = data.camera.viewMatrix(); // TODO : NEEDS TO BE DOUBLE PRECISION + glm::dmat4 cameraProjectionTransform = data.camera.viewProjectionMatrix(); // TODO : NEEDS TO BE DOUBLE PRECISION + + LDEBUG("cameraTransform = ( " << std::endl << cameraTransform[0][0] << " , " << cameraTransform[1][0] << " , " << cameraTransform[2][0] << std::endl << + cameraTransform[0][1] << " , " << cameraTransform[1][1] << " , " << cameraTransform[2][1] << std::endl << + cameraTransform[0][2] << " , " << cameraTransform[1][2] << " , " << cameraTransform[2][2] << std::endl << " ) "); + + LDEBUG("transform = ( " << std::endl << transform[0][0] << " , " << transform[1][0] << " , " << transform[2][0] << std::endl << + transform[0][1] << " , " << transform[1][1] << " , " << transform[2][1] << std::endl << + transform[0][2] << " , " << transform[1][2] << " , " << transform[2][2] << std::endl << " ) "); + + LDEBUG("cameraProjectionTransform = ( " << std::endl << cameraProjectionTransform[0][0] << " , " << cameraProjectionTransform[1][0] << " , " << cameraProjectionTransform[2][0] << std::endl << + cameraProjectionTransform[0][1] << " , " << cameraProjectionTransform[1][1] << " , " << cameraProjectionTransform[2][1] << std::endl << + cameraProjectionTransform[0][2] << " , " << cameraProjectionTransform[1][2] << " , " << cameraProjectionTransform[2][2] << std::endl << " ) "); + + + + glDisable(GL_CULL_FACE); + //glCullFace(GL_BACK); // render _grid.drawUsingActiveProgram(); diff --git a/modules/globebrowsing/rendering/latlonpatch.cpp b/modules/globebrowsing/rendering/latlonpatch.cpp new file mode 100644 index 0000000000..c7784c4b1b --- /dev/null +++ b/modules/globebrowsing/rendering/latlonpatch.cpp @@ -0,0 +1,188 @@ +/***************************************************************************************** +* * +* 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 + +#include + +// open space includes +#include +#include +// ghoul includes +#include + +#define _USE_MATH_DEFINES +#include + +namespace { + const std::string _loggerCat = "LatLonPatch"; + + const std::string keyFrame = "Frame"; + const std::string keyGeometry = "Geometry"; + const std::string keyShading = "PerformShading"; + + const std::string keyBody = "Body"; +} + +namespace openspace { + LatLonPatch::LatLonPatch( + unsigned int xRes, + unsigned int yRes, + double posLat, + double posLon, + double sizeLat, + double sizeLon) + : _grid( + xRes, + yRes, + Geometry::Positions::Yes, + Geometry::TextureCoordinates::Yes, + Geometry::Normals::No) + , _programObject(nullptr) + , _posLatLon(posLat, posLon) + , _sizeLatLon(sizeLat, sizeLon) + { + + } + + LatLonPatch::~LatLonPatch() { + + } + + + bool LatLonPatch::initialize() { + RenderEngine& renderEngine = OsEng.renderEngine(); + if (_programObject == nullptr) { + _programObject = renderEngine.buildRenderProgram( + "LatLonSphereMappingProgram", + "${MODULE_GLOBEBROWSING}/shaders/latlonpatch_spheremapping_vs.glsl", + "${MODULE_GLOBEBROWSING}/shaders/simple_fs.glsl"); + if (!_programObject) return false; + } + + using IgnoreError = ghoul::opengl::ProgramObject::IgnoreError; + _programObject->setIgnoreSubroutineUniformLocationError(IgnoreError::Yes); + + return isReady(); + } + + bool LatLonPatch::deinitialize() { + RenderEngine& renderEngine = OsEng.renderEngine(); + if (_programObject) { + renderEngine.removeRenderProgram(_programObject); + _programObject = nullptr; + } + + return true; + } + + bool LatLonPatch::isReady() const { + bool ready = true; + ready &= (_programObject != nullptr); + return ready; + } + + void LatLonPatch::render(const RenderData& data) { + // activate shader + _programObject->activate(); + + // TODO : Not sure if double precision will be needed for all these calculations + // Using doubles in case. + // TODO : Need to get the radius of the globe + double r = 6e6; + + // Create control points (double) + glm::dvec3 p00, p01, p10, p11; + + // Calculate global positions of control points + p00 = glm::dvec3(converter::latLonToCartesian( + _posLatLon.x - _sizeLatLon.x, + _posLatLon.y - _sizeLatLon.y, + r)); + p10 = glm::dvec3(converter::latLonToCartesian( + _posLatLon.x + _sizeLatLon.x, + _posLatLon.y - _sizeLatLon.y, + r)); + p01 = glm::dvec3(converter::latLonToCartesian( + _posLatLon.x - _sizeLatLon.x, + _posLatLon.y + _sizeLatLon.y, + r)); + p11 = glm::dvec3(converter::latLonToCartesian( + _posLatLon.x + _sizeLatLon.x, + _posLatLon.y + _sizeLatLon.y, + r)); + + // 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 + glm::dvec3 position = data.position.dvec3(); + p00 += position; + p10 += position; + p01 += position; + p11 += position; + + // Calculate global position of camera + // TODO : Should only need to fetch the camera transform and use directly + // Now the viewTransform is wrong due to the constant lookUpVector + 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::lookAt(camPos, camPos + camDir, camUp); + // Transform control points to camera space + p00 = glm::dvec3(viewTransform * glm::dvec4(p00, 1.0)); + p10 = glm::dvec3(viewTransform * glm::dvec4(p10, 1.0)); + p01 = glm::dvec3(viewTransform * glm::dvec4(p01, 1.0)); + p11 = glm::dvec3(viewTransform * glm::dvec4(p11, 1.0)); + + // Send control points to GPU to be used in shader + // TODO : Will need more control points or possibly normals to be able to + // do better than linear interpolation + _programObject->setUniform("p00", glm::vec3(p00)); + _programObject->setUniform("p10", glm::vec3(p10)); + _programObject->setUniform("p01", glm::vec3(p01)); + _programObject->setUniform("p11", glm::vec3(p11)); + + _programObject->setUniform("Projection", data.camera.projectionMatrix()); + + // Render triangles (use texture coordinates to interpolate to new positions) + glDisable(GL_CULL_FACE); + //glCullFace(GL_BACK); + + // render + _grid.drawUsingActiveProgram(); + + // disable shader + _programObject->deactivate(); + } + + void LatLonPatch::update(const UpdateData& data) { + + } + + void LatLonPatch::setPositionLatLon(glm::dvec2 posLatLon) { + _posLatLon = posLatLon; + } + +} // namespace openspace diff --git a/modules/globebrowsing/rendering/latlonpatch.h b/modules/globebrowsing/rendering/latlonpatch.h new file mode 100644 index 0000000000..5267f8f0eb --- /dev/null +++ b/modules/globebrowsing/rendering/latlonpatch.h @@ -0,0 +1,73 @@ +/***************************************************************************************** +* * +* 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 __LATLONPATCH_H__ +#define __LATLONPATCH_H__ + +#include + +// open space includes +#include + +#include + +namespace ghoul { +namespace opengl { + class ProgramObject; +} +} + + +namespace openspace { + class LatLonPatch : public Renderable + { + public: + LatLonPatch( + unsigned int xRes, + unsigned int yRes, + double posLat, + double posLon, + double sizeLat, + double sizeLon); + ~LatLonPatch(); + + bool initialize() override; + bool deinitialize() override; + bool isReady() const override; + + void render(const RenderData& data) override; + void update(const UpdateData& data) override; + + void setPositionLatLon(glm::dvec2 posLatLon); + + private: + std::unique_ptr _programObject; + + glm::dvec2 _posLatLon; + glm::dvec2 _sizeLatLon; + GridGeometry _grid; + }; +} // namespace openspace + +#endif // __LATLONPATCH_H__ \ No newline at end of file diff --git a/modules/globebrowsing/rendering/renderableglobe.cpp b/modules/globebrowsing/rendering/renderableglobe.cpp index 2111cc8a28..b2270c3124 100644 --- a/modules/globebrowsing/rendering/renderableglobe.cpp +++ b/modules/globebrowsing/rendering/renderableglobe.cpp @@ -25,6 +25,7 @@ #include #include +#include // open space includes #include @@ -68,7 +69,8 @@ namespace openspace { // Mainly for debugging purposes @AA addProperty(_rotation); - addSwitchValue(std::shared_ptr(new GlobeMesh(dictionary)), 1000000000); + addSwitchValue(std::shared_ptr(new ClipMapGlobe(dictionary)), 1e9); + addSwitchValue(std::shared_ptr(new GlobeMesh(dictionary)), 1e10); } RenderableGlobe::~RenderableGlobe() { diff --git a/modules/globebrowsing/shaders/latlonpatch_spheremapping_vs.glsl b/modules/globebrowsing/shaders/latlonpatch_spheremapping_vs.glsl new file mode 100644 index 0000000000..541470d16b --- /dev/null +++ b/modules/globebrowsing/shaders/latlonpatch_spheremapping_vs.glsl @@ -0,0 +1,49 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014 * + * * + * 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. * + ****************************************************************************************/ + +#version __CONTEXT__ + +uniform mat4 Projection; + +uniform vec3 p00; +uniform vec3 p10; +uniform vec3 p01; +uniform vec3 p11; + +layout(location = 1) in vec2 in_UV; + +out vec4 vs_position; + +#include "PowerScaling/powerScaling_vs.hglsl" + +void main() +{ + // Bilinear interpolation + vec3 p0 = (1 - in_UV.x) * p00 + in_UV.x * p10; + vec3 p1 = (1 - in_UV.x) * p01 + in_UV.x * p11; + vec3 p = (1 - in_UV.y) * p0 + in_UV.y * p1; + + vec4 position = Projection * vec4(p, 1); + gl_Position = z_normalization(position); +} \ No newline at end of file diff --git a/modules/globebrowsing/shaders/simple_vs.glsl b/modules/globebrowsing/shaders/simple_vs.glsl index ae2870f620..718ebfd048 100644 --- a/modules/globebrowsing/shaders/simple_vs.glsl +++ b/modules/globebrowsing/shaders/simple_vs.glsl @@ -36,8 +36,8 @@ out vec4 vs_position; void main() { // set variables - vs_position = in_position; - vec4 tmp = in_position; + vs_position = vec4(in_position.xyz * 60000000.0f, 1); + vec4 tmp = vec4(in_position.xyz * 60000000.0f, 1); vec4 position = pscTransform(tmp, ModelTransform); vs_position = tmp; diff --git a/modules/globebrowsing/util/converter.cpp b/modules/globebrowsing/util/converter.cpp new file mode 100644 index 0000000000..7364d8ae5e --- /dev/null +++ b/modules/globebrowsing/util/converter.cpp @@ -0,0 +1,45 @@ +/***************************************************************************************** +* * +* 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 + +// ghoul includes +#include + +#define _USE_MATH_DEFINES +#include + +namespace openspace { + +namespace converter { + + glm::dvec3 latLonToCartesian(double latitude, double longitude, double radius) { + return radius * glm::dvec3( + glm::cos(latitude) * glm::cos(longitude), + glm::cos(latitude) * glm::sin(longitude), + glm::sin(latitude)); + } + +} // namespace converter +} // namespace openspace diff --git a/modules/globebrowsing/util/converter.h b/modules/globebrowsing/util/converter.h new file mode 100644 index 0000000000..02549f6da5 --- /dev/null +++ b/modules/globebrowsing/util/converter.h @@ -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. * +****************************************************************************************/ + +#ifndef __CONVERTER_H__ +#define __CONVERTER_H__ + +// open space includes +#include + +#include +#include + +#include +#include +#include + + +namespace ghoul { +namespace opengl { + class ProgramObject; +} +} + + +namespace openspace { + +namespace converter { + + glm::dvec3 latLonToCartesian(double latitude, double longitude, double radius); + +} // namespace converter +} // namespace openspace + +#endif // __CONVERTER_H__ \ No newline at end of file