mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-04 10:40:09 -06:00
Created classes for PlanetGeometry
Added SimpleSphereGeometry Created infrastructure for added other geometries
This commit is contained in:
@@ -35,9 +35,11 @@ namespace properties {
|
||||
|
||||
class PropertyOwner {
|
||||
public:
|
||||
PropertyOwner();
|
||||
virtual ~PropertyOwner();
|
||||
|
||||
virtual const std::string& name() const = 0;
|
||||
void setName(std::string name);
|
||||
virtual const std::string& name() const;
|
||||
const std::vector<Property*>& properties() const;
|
||||
Property* property(const std::string& id) const;
|
||||
|
||||
@@ -52,6 +54,7 @@ protected:
|
||||
void removeProperty(Property& prop);
|
||||
|
||||
private:
|
||||
std::string _name;
|
||||
std::vector<Property*> _properties;
|
||||
std::map<std::string, std::string> _groupNames;
|
||||
};
|
||||
|
||||
53
include/openspace/rendering/planets/planetgeometry.h
Normal file
53
include/openspace/rendering/planets/planetgeometry.h
Normal file
@@ -0,0 +1,53 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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. *
|
||||
****************************************************************************************/
|
||||
|
||||
#ifndef __PLANETGEOMETRY_H__
|
||||
#define __PLANETGEOMETRY_H__
|
||||
|
||||
#include <openspace/properties/propertyowner.h>
|
||||
#include <openspace/rendering/planets/renderableplanet.h>
|
||||
#include <ghoul/misc/dictionary.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
namespace planetgeometry {
|
||||
|
||||
class PlanetGeometry : public properties::PropertyOwner {
|
||||
public:
|
||||
static PlanetGeometry* createFromDictionary(const ghoul::Dictionary& dictionary);
|
||||
|
||||
PlanetGeometry();
|
||||
virtual ~PlanetGeometry();
|
||||
virtual void initialize(RenderablePlanet* parent);
|
||||
virtual void deinitialize();
|
||||
virtual void render() = 0;
|
||||
|
||||
protected:
|
||||
RenderablePlanet* _parent;
|
||||
};
|
||||
|
||||
} // namespace planetgeometry
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __PLANETGEOMETRY_H__
|
||||
@@ -27,10 +27,8 @@
|
||||
|
||||
// open space includes
|
||||
#include <openspace/rendering/renderable.h>
|
||||
#include <openspace/util/powerscaledsphere.h>
|
||||
#include <openspace/properties/scalarproperty.h>
|
||||
|
||||
#include <openspace/properties/stringproperty.h>
|
||||
#include <openspace/properties/vectorproperty.h>
|
||||
|
||||
// ghoul includes
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
@@ -38,6 +36,10 @@
|
||||
|
||||
namespace openspace {
|
||||
|
||||
namespace planetgeometry {
|
||||
class PlanetGeometry;
|
||||
}
|
||||
|
||||
class RenderablePlanet : public Renderable {
|
||||
public:
|
||||
RenderablePlanet(const ghoul::Dictionary& dictionary);
|
||||
@@ -53,17 +55,14 @@ public:
|
||||
void update() override;
|
||||
|
||||
protected:
|
||||
void createSphere();
|
||||
void loadTexture();
|
||||
|
||||
private:
|
||||
properties::Vec2Property _radius;
|
||||
properties::IntProperty _segments;
|
||||
properties::StringProperty _colorTexturePath;
|
||||
|
||||
ghoul::opengl::ProgramObject* _programObject;
|
||||
ghoul::opengl::Texture* _texture;
|
||||
PowerScaledSphere* _planet;
|
||||
planetgeometry::PlanetGeometry* _geometry;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
61
include/openspace/rendering/planets/simplespheregeometry.h
Normal file
61
include/openspace/rendering/planets/simplespheregeometry.h
Normal file
@@ -0,0 +1,61 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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. *
|
||||
****************************************************************************************/
|
||||
|
||||
#ifndef __SIMPLESPHEREGEOMETRY_H__
|
||||
#define __SIMPLESPHEREGEOMETRY_H__
|
||||
|
||||
#include <openspace/rendering/planets/planetgeometry.h>
|
||||
#include <openspace/properties/vectorproperty.h>
|
||||
#include <openspace/properties/scalarproperty.h>
|
||||
#include <openspace/util/powerscaledsphere.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class RenderablePlanet;
|
||||
|
||||
namespace planetgeometry {
|
||||
|
||||
class SimpleSphereGeometry : public PlanetGeometry {
|
||||
public:
|
||||
SimpleSphereGeometry(const ghoul::Dictionary& dictionary);
|
||||
~SimpleSphereGeometry();
|
||||
|
||||
|
||||
void initialize(RenderablePlanet* parent) override;
|
||||
void deinitialize() override;
|
||||
void render() override;
|
||||
|
||||
private:
|
||||
void createSphere();
|
||||
|
||||
properties::Vec2Property _radius;
|
||||
properties::IntProperty _segments;
|
||||
|
||||
PowerScaledSphere* _planet;
|
||||
};
|
||||
|
||||
} // namespace planetgeometry
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __SIMPLESPHEREGEOMETRY_H__
|
||||
@@ -42,9 +42,6 @@ public:
|
||||
Renderable(const ghoul::Dictionary& dictionary);
|
||||
virtual ~Renderable();
|
||||
|
||||
void setName(std::string name);
|
||||
const std::string& name() const override;
|
||||
|
||||
virtual bool initialize() = 0;
|
||||
virtual bool deinitialize() = 0;
|
||||
|
||||
@@ -57,8 +54,6 @@ public:
|
||||
protected:
|
||||
// Renderable();
|
||||
private:
|
||||
std::string _name;
|
||||
|
||||
pss boundingSphere_;
|
||||
};
|
||||
|
||||
|
||||
@@ -55,9 +55,19 @@ namespace renderable {
|
||||
const std::string keyType = "Type";
|
||||
} // namespace renderable
|
||||
|
||||
namespace renderableplanet {
|
||||
const std::string keyGeometry = "Geometry";
|
||||
} // namespace renderableplanet
|
||||
|
||||
namespace planetgeometry {
|
||||
const std::string keyType = "Type";
|
||||
} // namespace planetgeometry
|
||||
|
||||
|
||||
|
||||
namespace ephemeris {
|
||||
const std::string keyType = "Type";
|
||||
}
|
||||
} // namespace ephemeris
|
||||
|
||||
} // namespace constants
|
||||
} // namespace openspace
|
||||
|
||||
@@ -29,9 +29,6 @@
|
||||
#include <ghoul/misc/templatefactory.h>
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
|
||||
#include <openspace/scenegraph/ephemeris.h>
|
||||
#include <openspace/rendering/renderable.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class FactoryManager {
|
||||
@@ -54,7 +51,7 @@ public:
|
||||
void addFactory(ghoul::TemplateFactoryBase* factory);
|
||||
|
||||
template <class T>
|
||||
ghoul::TemplateFactory<T>* factory();
|
||||
ghoul::TemplateFactory<T>* factory() const;
|
||||
|
||||
private:
|
||||
FactoryManager();
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
namespace openspace {
|
||||
|
||||
template <class T>
|
||||
ghoul::TemplateFactory<T>* FactoryManager::factory()
|
||||
ghoul::TemplateFactory<T>* FactoryManager::factory() const
|
||||
{
|
||||
for (ghoul::TemplateFactoryBase* factory : _factories) {
|
||||
if (factory->baseClassType() == typeid(T))
|
||||
|
||||
@@ -31,20 +31,31 @@ namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "PropertyOwner";
|
||||
const std::string _loggerCat = "PropertyOwner";
|
||||
|
||||
bool propertyLess(Property* lhs, Property* rhs) {
|
||||
return lhs->identifier() < rhs->identifier();
|
||||
}
|
||||
bool propertyLess(Property* lhs, Property* rhs)
|
||||
{
|
||||
return lhs->identifier() < rhs->identifier();
|
||||
}
|
||||
}
|
||||
|
||||
PropertyOwner::~PropertyOwner() {}
|
||||
PropertyOwner::PropertyOwner()
|
||||
: _name("")
|
||||
{
|
||||
|
||||
const std::vector<Property*>& PropertyOwner::properties() const {
|
||||
}
|
||||
|
||||
PropertyOwner::~PropertyOwner()
|
||||
{
|
||||
}
|
||||
|
||||
const std::vector<Property*>& PropertyOwner::properties() const
|
||||
{
|
||||
return _properties;
|
||||
}
|
||||
|
||||
Property* PropertyOwner::property(const std::string& id) const {
|
||||
Property* PropertyOwner::property(const std::string& id) const
|
||||
{
|
||||
assert(std::is_sorted(_properties.begin(), _properties.end(), propertyLess));
|
||||
|
||||
std::vector<Property*>::const_iterator it
|
||||
@@ -59,11 +70,13 @@ Property* PropertyOwner::property(const std::string& id) const {
|
||||
return *it;
|
||||
}
|
||||
|
||||
void PropertyOwner::setPropertyGroupName(std::string groupID, std::string name) {
|
||||
void PropertyOwner::setPropertyGroupName(std::string groupID, std::string name)
|
||||
{
|
||||
_groupNames[std::move(groupID)] = std::move(name);
|
||||
}
|
||||
|
||||
const std::string& PropertyOwner::propertyGroupName(const std::string& groupID) const {
|
||||
const std::string& PropertyOwner::propertyGroupName(const std::string& groupID) const
|
||||
{
|
||||
auto it = _groupNames.find(groupID);
|
||||
if (it == _groupNames.end())
|
||||
return groupID;
|
||||
@@ -71,7 +84,8 @@ const std::string& PropertyOwner::propertyGroupName(const std::string& groupID)
|
||||
return it->second;
|
||||
}
|
||||
|
||||
void PropertyOwner::addProperty(Property* prop) {
|
||||
void PropertyOwner::addProperty(Property* prop)
|
||||
{
|
||||
assert(prop != nullptr);
|
||||
assert(std::is_sorted(_properties.begin(), _properties.end(), propertyLess));
|
||||
|
||||
@@ -82,51 +96,62 @@ void PropertyOwner::addProperty(Property* prop) {
|
||||
|
||||
// See if we can find the identifier of the property to add in the properties list
|
||||
std::vector<Property*>::iterator it
|
||||
= std::lower_bound(_properties.begin(), _properties.end(), prop->identifier(),
|
||||
[](Property* prop, const std::string& str) {
|
||||
return prop->identifier() < str;
|
||||
});
|
||||
= std::lower_bound(_properties.begin(), _properties.end(), prop->identifier(),
|
||||
[](Property* prop, const std::string& str) {
|
||||
return prop->identifier() < str;
|
||||
});
|
||||
|
||||
// If we found the property identifier, we need to bail out
|
||||
if (it != _properties.end() && (*it)->identifier() == prop->identifier()) {
|
||||
LERROR("Property identifier '" << prop->identifier()
|
||||
<< "' already present in PropertyOwner");
|
||||
return;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// Otherwise we have found the correct position to add it in
|
||||
_properties.insert(it, prop);
|
||||
prop->setPropertyOwner(this);
|
||||
}
|
||||
}
|
||||
|
||||
void PropertyOwner::addProperty(Property& prop) {
|
||||
void PropertyOwner::addProperty(Property& prop)
|
||||
{
|
||||
addProperty(&prop);
|
||||
}
|
||||
|
||||
void PropertyOwner::removeProperty(Property* prop) {
|
||||
void PropertyOwner::removeProperty(Property* prop)
|
||||
{
|
||||
assert(prop != nullptr);
|
||||
|
||||
// See if we can find the identifier of the property to add in the properties list
|
||||
std::vector<Property*>::iterator it
|
||||
= std::lower_bound(_properties.begin(), _properties.end(), prop->identifier(),
|
||||
[](Property* prop, const std::string& str) {
|
||||
return prop->identifier() < str;
|
||||
});
|
||||
= std::lower_bound(_properties.begin(), _properties.end(), prop->identifier(),
|
||||
[](Property* prop, const std::string& str) {
|
||||
return prop->identifier() < str;
|
||||
});
|
||||
|
||||
// If we found the property identifier, we can delete it
|
||||
if (it != _properties.end() && (*it)->identifier() == prop->identifier()) {
|
||||
(*it)->setPropertyOwner(nullptr);
|
||||
_properties.erase(it);
|
||||
}
|
||||
else
|
||||
} else
|
||||
LERROR("Property with identifier '" << prop->identifier()
|
||||
<< "' not found for removal.");
|
||||
}
|
||||
|
||||
void PropertyOwner::removeProperty(Property& prop) {
|
||||
void PropertyOwner::removeProperty(Property& prop)
|
||||
{
|
||||
removeProperty(&prop);
|
||||
}
|
||||
|
||||
void PropertyOwner::setName(std::string name)
|
||||
{
|
||||
_name = std::move(name);
|
||||
}
|
||||
|
||||
const std::string& PropertyOwner::name() const
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
|
||||
} // namespace properties
|
||||
} // namespace openspace
|
||||
|
||||
81
src/rendering/planets/planetgeometry.cpp
Normal file
81
src/rendering/planets/planetgeometry.cpp
Normal file
@@ -0,0 +1,81 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <openspace/rendering/planets/planetgeometry.h>
|
||||
#include <openspace/util/factorymanager.h>
|
||||
#include <openspace/util/constants.h>
|
||||
#include <openspace/util/factorymanager.h>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "PlanetGeometry";
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
namespace planetgeometry {
|
||||
|
||||
PlanetGeometry* PlanetGeometry::createFromDictionary(const ghoul::Dictionary& dictionary)
|
||||
{
|
||||
std::string name;
|
||||
dictionary.getValue(constants::scenegraphnode::keyName, name);
|
||||
|
||||
if (!dictionary.hasValue<std::string>(constants::planetgeometry::keyType)) {
|
||||
LERROR("PlanetGeometry for '" << name << "' did not contain a '"
|
||||
<< constants::planetgeometry::keyType << "' key");
|
||||
return nullptr;
|
||||
}
|
||||
std::string geometryType;
|
||||
dictionary.getValue(constants::planetgeometry::keyType, geometryType);
|
||||
|
||||
ghoul::TemplateFactory<PlanetGeometry>* factory
|
||||
= FactoryManager::ref().factory<PlanetGeometry>();
|
||||
|
||||
PlanetGeometry* result = factory->create(geometryType, dictionary);
|
||||
if (result == nullptr) {
|
||||
LERROR("Failed to create a PlanetGeometry object of type '" << geometryType
|
||||
<< "'");
|
||||
return nullptr;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
PlanetGeometry::PlanetGeometry()
|
||||
: _parent(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
PlanetGeometry::~PlanetGeometry()
|
||||
{
|
||||
}
|
||||
|
||||
void PlanetGeometry::initialize(RenderablePlanet* parent)
|
||||
{
|
||||
_parent = parent;
|
||||
}
|
||||
|
||||
void PlanetGeometry::deinitialize()
|
||||
{
|
||||
}
|
||||
|
||||
} // namespace planetgeometry
|
||||
} // namespace openspace
|
||||
@@ -25,6 +25,7 @@
|
||||
// open space includes
|
||||
#include <openspace/rendering/planets/renderableplanet.h>
|
||||
#include <openspace/util/constants.h>
|
||||
#include <openspace/rendering/planets/planetgeometry.h>
|
||||
|
||||
#include <ghoul/opengl/texturereader.h>
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
@@ -33,43 +34,32 @@
|
||||
#include <sgct.h>
|
||||
|
||||
namespace {
|
||||
std::string _loggerCat = "RenderablePlanet";
|
||||
const std::string _loggerCat = "RenderablePlanet";
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
|
||||
RenderablePlanet::RenderablePlanet(const ghoul::Dictionary& dictionary)
|
||||
: Renderable(dictionary)
|
||||
, _radius("radius", "Radius", glm::vec2(1.f, 0.f), glm::vec2(-10.f, -20.f),
|
||||
glm::vec2(10.f, 20.f))
|
||||
, _segments("segments", "Segments", 20, 1, 1000)
|
||||
, _colorTexturePath("colorTexture", "Color Texture")
|
||||
, _programObject(nullptr)
|
||||
, _texture(nullptr)
|
||||
, _planet(nullptr)
|
||||
//, _planet(nullptr)
|
||||
, _geometry(nullptr)
|
||||
{
|
||||
double value = 1.0f, exponent = 0.0f;
|
||||
int segments = 20;
|
||||
std::string path;
|
||||
dictionary.getValue(constants::scenegraph::keyPathModule, path);
|
||||
|
||||
if (dictionary.hasKey("Geometry.Radius.1"))
|
||||
dictionary.getValue("Geometry.Radius.1", value);
|
||||
if (dictionary.hasKey(constants::renderableplanet::keyGeometry)) {
|
||||
ghoul::Dictionary geometryDictionary;
|
||||
dictionary.getValue(constants::renderableplanet::keyGeometry, geometryDictionary);
|
||||
geometryDictionary.setValue(constants::scenegraph::keyPathModule, path);
|
||||
geometryDictionary.setValue(constants::scenegraphnode::keyName, name());
|
||||
|
||||
if (dictionary.hasKey("Geometry.Radius.2"))
|
||||
dictionary.getValue("Geometry.Radius.2", exponent);
|
||||
|
||||
_radius = glm::vec2(value, exponent);
|
||||
|
||||
if (dictionary.hasKey("Geometry.Segments"))
|
||||
dictionary.getValue("Geometry.Segments", segments);
|
||||
|
||||
_segments = segments;
|
||||
|
||||
// get path if available
|
||||
std::string path = "";
|
||||
if (dictionary.hasKey(constants::scenegraph::keyPathModule)) {
|
||||
dictionary.getValue(constants::scenegraph::keyPathModule, path);
|
||||
path += "/";
|
||||
_geometry
|
||||
= planetgeometry::PlanetGeometry::createFromDictionary(geometryDictionary);
|
||||
}
|
||||
path += "/";
|
||||
|
||||
std::string texturePath = "";
|
||||
if (dictionary.hasKey("Textures.Color"))
|
||||
@@ -77,16 +67,13 @@ RenderablePlanet::RenderablePlanet(const ghoul::Dictionary& dictionary)
|
||||
|
||||
_colorTexturePath = path + texturePath;
|
||||
|
||||
for (properties::Property* p : _geometry->properties())
|
||||
addProperty(p);
|
||||
|
||||
addProperty(_radius);
|
||||
_radius.onChange(std::bind(&RenderablePlanet::createSphere, this));
|
||||
addProperty(_segments);
|
||||
_segments.onChange(std::bind(&RenderablePlanet::createSphere, this));
|
||||
//addProperty(_colorTexturePath);
|
||||
//_colorTexturePath.onChange(std::bind(&RenderablePlanet::loadTexture, this));
|
||||
|
||||
addProperty(_colorTexturePath);
|
||||
_colorTexturePath.onChange(std::bind(&RenderablePlanet::loadTexture, this));
|
||||
|
||||
createSphere();
|
||||
//createSphere();
|
||||
}
|
||||
|
||||
RenderablePlanet::~RenderablePlanet() {
|
||||
@@ -101,14 +88,17 @@ bool RenderablePlanet::initialize() {
|
||||
loadTexture();
|
||||
completeSuccess &= (_texture != nullptr);
|
||||
|
||||
_planet->initialize();
|
||||
_geometry->initialize(this);
|
||||
|
||||
return completeSuccess;
|
||||
}
|
||||
|
||||
bool RenderablePlanet::deinitialize() {
|
||||
delete _planet;
|
||||
_geometry->deinitialize();
|
||||
delete _geometry;
|
||||
_geometry = nullptr;
|
||||
delete _texture;
|
||||
_texture = nullptr;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -155,26 +145,13 @@ void RenderablePlanet::render(const Camera *camera, const psc &thisPosition) {
|
||||
_programObject->setUniform("texture1", 0);
|
||||
|
||||
// render
|
||||
_planet->render();
|
||||
_geometry->render();
|
||||
|
||||
// disable shader
|
||||
_programObject->deactivate();
|
||||
|
||||
}
|
||||
|
||||
void RenderablePlanet::update() {
|
||||
|
||||
}
|
||||
|
||||
void RenderablePlanet::createSphere() {
|
||||
// create the power scaled scalar
|
||||
|
||||
pss planetSize(_radius);
|
||||
setBoundingSphere(planetSize);
|
||||
|
||||
delete _planet;
|
||||
_planet = new PowerScaledSphere(planetSize, _segments);
|
||||
_planet->initialize();
|
||||
}
|
||||
|
||||
void RenderablePlanet::loadTexture() {
|
||||
|
||||
118
src/rendering/planets/simplespheregeometry.cpp
Normal file
118
src/rendering/planets/simplespheregeometry.cpp
Normal file
@@ -0,0 +1,118 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <openspace/rendering/planets/simplespheregeometry.h>
|
||||
#include <openspace/util/constants.h>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "SimpleSphereGeometry";
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
|
||||
namespace constants {
|
||||
namespace simplespheregeometry {
|
||||
const std::string keyRadius = "Radius";
|
||||
const std::string keySegments = "Segments";
|
||||
} // namespace simplespheregeometry
|
||||
}
|
||||
|
||||
namespace planetgeometry {
|
||||
|
||||
SimpleSphereGeometry::SimpleSphereGeometry(const ghoul::Dictionary& dictionary)
|
||||
: PlanetGeometry()
|
||||
, _radius("radius", "Radius", glm::vec2(1.f, 0.f), glm::vec2(-10.f, -20.f),
|
||||
glm::vec2(10.f, 20.f))
|
||||
, _segments("segments", "Segments", 20, 1, 1000)
|
||||
, _planet(nullptr)
|
||||
{
|
||||
if (!dictionary.hasValue<glm::vec2>(constants::simplespheregeometry::keyRadius)) {
|
||||
std::string name;
|
||||
dictionary.getValue(constants::scenegraphnode::keyName, name);
|
||||
LERROR("SimpleSphereGeometry of '" << name << "' did not provide a key '"
|
||||
<< constants::simplespheregeometry::keyRadius
|
||||
<< "'");
|
||||
}
|
||||
else {
|
||||
glm::vec2 radius;
|
||||
dictionary.getValue(constants::simplespheregeometry::keyRadius, radius);
|
||||
_radius = radius;
|
||||
}
|
||||
|
||||
if (!dictionary.hasValue<float>(constants::simplespheregeometry::keySegments)) {
|
||||
std::string name;
|
||||
dictionary.getValue(constants::scenegraphnode::keyName, name);
|
||||
LERROR("SimpleSphereGeometry of '" << name << "' did not provide a key '"
|
||||
<< constants::simplespheregeometry::keySegments
|
||||
<< "'");
|
||||
}
|
||||
else {
|
||||
float segments;
|
||||
dictionary.getValue(constants::simplespheregeometry::keySegments, segments);
|
||||
_segments = static_cast<int>(segments);
|
||||
}
|
||||
|
||||
addProperty(_radius);
|
||||
_radius.onChange(std::bind(&SimpleSphereGeometry::createSphere, this));
|
||||
addProperty(_segments);
|
||||
_segments.onChange(std::bind(&SimpleSphereGeometry::createSphere, this));
|
||||
|
||||
//createSphere();
|
||||
}
|
||||
|
||||
SimpleSphereGeometry::~SimpleSphereGeometry()
|
||||
{
|
||||
}
|
||||
|
||||
void SimpleSphereGeometry::initialize(RenderablePlanet* parent)
|
||||
{
|
||||
PlanetGeometry::initialize(parent);
|
||||
createSphere();
|
||||
}
|
||||
|
||||
void SimpleSphereGeometry::deinitialize()
|
||||
{
|
||||
delete _planet;
|
||||
_planet = nullptr;
|
||||
}
|
||||
|
||||
void SimpleSphereGeometry::render()
|
||||
{
|
||||
_planet->render();
|
||||
}
|
||||
|
||||
void SimpleSphereGeometry::createSphere()
|
||||
{
|
||||
//create the power scaled scalar
|
||||
|
||||
pss planetSize(_radius);
|
||||
_parent->setBoundingSphere(planetSize);
|
||||
|
||||
delete _planet;
|
||||
_planet = new PowerScaledSphere(planetSize, _segments);
|
||||
_planet->initialize();
|
||||
}
|
||||
|
||||
} // namespace planetgeometry
|
||||
} // namespace openspace
|
||||
@@ -33,10 +33,6 @@ const std::string _loggerCat = "Renderable";
|
||||
|
||||
namespace openspace {
|
||||
|
||||
//Renderable::Renderable()
|
||||
// : _name("")
|
||||
//{}
|
||||
|
||||
Renderable* Renderable::createFromDictionary(const ghoul::Dictionary& dictionary)
|
||||
{
|
||||
std::string name;
|
||||
@@ -53,7 +49,7 @@ Renderable* Renderable::createFromDictionary(const ghoul::Dictionary& dictionary
|
||||
= FactoryManager::ref().factory<Renderable>();
|
||||
Renderable* result = factory->create(renderableType, dictionary);
|
||||
if (result == nullptr) {
|
||||
LERROR("Failed creating Renderable object of type '" << renderableType << "'");
|
||||
LERROR("Failed to create a Renderable object of type '" << renderableType << "'");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -63,22 +59,14 @@ Renderable* Renderable::createFromDictionary(const ghoul::Dictionary& dictionary
|
||||
}
|
||||
|
||||
Renderable::Renderable(const ghoul::Dictionary& dictionary)
|
||||
: _name("")
|
||||
{
|
||||
std::string name;
|
||||
dictionary.getValue(constants::scenegraphnode::keyName, name);
|
||||
setName(name);
|
||||
}
|
||||
|
||||
Renderable::~Renderable() {
|
||||
|
||||
}
|
||||
|
||||
void Renderable::setName(std::string name)
|
||||
Renderable::~Renderable()
|
||||
{
|
||||
_name = std::move(name);
|
||||
}
|
||||
|
||||
const std::string& Renderable::name() const
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
|
||||
void Renderable::setBoundingSphere(const pss& boundingSphere)
|
||||
@@ -95,4 +83,4 @@ void Renderable::update()
|
||||
{
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
} // namespace openspace
|
||||
@@ -37,6 +37,8 @@
|
||||
#include <openspace/scenegraph/staticephemeris.h>
|
||||
#include <openspace/scenegraph/spiceephemeris.h>
|
||||
|
||||
#include <openspace/rendering/planets/simplespheregeometry.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
FactoryManager* FactoryManager::_manager = nullptr;
|
||||
@@ -66,7 +68,10 @@ void FactoryManager::initialize()
|
||||
_manager->factory<Ephemeris>()->registerClass<StaticEphemeris>("Static");
|
||||
_manager->factory<Ephemeris>()->registerClass<SpiceEphemeris>("Spice");
|
||||
|
||||
|
||||
// Add PlanetGeometry
|
||||
_manager->addFactory(new ghoul::TemplateFactory<planetgeometry::PlanetGeometry>);
|
||||
_manager->factory<planetgeometry::PlanetGeometry>()
|
||||
->registerClass<planetgeometry::SimpleSphereGeometry>("SimpleSphere");
|
||||
}
|
||||
|
||||
void FactoryManager::deinitialize()
|
||||
|
||||
Reference in New Issue
Block a user