moved angle property to stationsfov + overall improvements of the renderablecone and renderablestationsfov

This commit is contained in:
Lovisa Hassler
2019-01-23 16:14:18 -05:00
parent d60017e25d
commit 4e8201e25e
6 changed files with 116 additions and 58 deletions
@@ -11,13 +11,13 @@ local GoldstoneFOV = {
Identifier = "GoldstoneFOV",
Renderable = {
Type = "RenderableStationFov",
Enabled = false,
ApexPosition = "DSS14",
BaseCenterDirection = earthAsset.Earth.Identifier,
ReverseDirection = true,
Enabled = true,
Resolution = 50,
Opacity = 0.4,
Color = colors.GoldstoneColor
Color = colors.GoldstoneColor,
ViewAngle = 160.0
},
GUI = {
Name = "GoldstoneFOV",
@@ -28,13 +28,13 @@ local MadridFOV = {
Identifier = "MadridFOV",
Renderable = {
Type = "RenderableStationFov",
Enabled = false,
ApexPosition = "DSS63",
BaseCenterDirection = earthAsset.Earth.Identifier,
ReverseDirection = true,
Enabled = false,
Resolution = 50,
Opacity = 0.4,
Color = colors.MadridColor
Color = colors.MadridColor,
ViewAngle = 160.0
},
GUI = {
Name = "MadridFOV",
@@ -45,13 +45,13 @@ local CanberraFOV = {
Identifier = "CanberraFOV",
Renderable = {
Type = "RenderableStationFov",
Enabled = false,
ApexPosition = "DSS43",
BaseCenterDirection = earthAsset.Earth.Identifier,
ReverseDirection = true,
Enabled = false,
Resolution = 50,
Opacity = 0.4,
Color = colors.CanberraColor
Color = colors.CanberraColor,
ViewAngle = 160.0
},
GUI = {
Name = "CanberraFOV",
+33 -27
View File
@@ -78,10 +78,10 @@ namespace {
"Height",
"Height of the cone"
};
constexpr openspace::properties::Property::PropertyInfo AngleInfo = {
"Angle",
"Angle",
"Angle of the cone base"
constexpr openspace::properties::Property::PropertyInfo RadiusInfo = {
"Radius",
"Radius",
"Radius of the cone base"
};
constexpr openspace::properties::Property::PropertyInfo ResolutionInfo = {
"Resolution",
@@ -145,10 +145,10 @@ documentation::Documentation RenderableCone::Documentation() {
HeightInfo.description
},
{
AngleInfo.identifier,
RadiusInfo.identifier,
new DoubleVerifier,
Optional::Yes,
AngleInfo.description
RadiusInfo.description
},
{
ResolutionInfo.identifier,
@@ -174,10 +174,10 @@ documentation::Documentation RenderableCone::Documentation() {
RenderableCone::RenderableCone(const ghoul::Dictionary& dictionary)
: Renderable(dictionary)
, _height(HeightInfo, 0.8, 0.0, 1.0)
, _angle(AngleInfo, 160, 0.0, 180)
, _height(HeightInfo, 0.25, 0.0, 1.0)
, _radius(RadiusInfo, 0.8, 0.0, 1.0)
, _resolution(ResolutionInfo, 50, 4, 100)
, _wireframe(WireframeInfo, true)
, _wireframe(WireframeInfo, false)
, _color(
ColorInfo,
_defaultColor,
@@ -226,12 +226,16 @@ RenderableCone::RenderableCone(const ghoul::Dictionary& dictionary)
if (dictionary.hasKeyAndValue<bool>(WireframeInfo.identifier)) {
_wireframe = dictionary.value<bool>(WireframeInfo.identifier);
}
if (dictionary.hasKeyAndValue<double>(RadiusInfo.identifier)) {
_radius = dictionary.value<double>(RadiusInfo.identifier);
}
addProperty(_height);
addProperty(_angle);
addProperty(_radius);
addProperty(_resolution);
addProperty(_opacity);
addProperty(_wireframe);
addProperty(_color);
addProperty(_wireframe);
}
void RenderableCone::initializeGL() {
@@ -290,7 +294,11 @@ void RenderableCone::updateVertexAttributes() {
// Update the number of lines to render, same for both vertex arrays
_count = static_cast<GLsizei>(_vertexLateralSurfaceArray.size() / (_sizeThreeVal + _sizeFourVal));
};
}
float RenderableCone::calculateBaseRadius()
{
return _radius * _unit;
}
void RenderableCone::render(const RenderData& data, RendererTasks&) {
_programObject->activate();
@@ -361,12 +369,12 @@ void RenderableCone::createShaderProgram()
_programObject = BaseModule::ProgramObjectManager.request(
ProgramName,
[]() -> std::unique_ptr<ghoul::opengl::ProgramObject> {
return global::renderEngine.buildRenderProgram(
ProgramName,
absPath("${MODULE_DSN}/shaders/renderablecone_vs.glsl"),
absPath("${MODULE_DSN}/shaders/renderablecone_fs.glsl")
);
}
return global::renderEngine.buildRenderProgram(
ProgramName,
absPath("${MODULE_DSN}/shaders/renderablecone_vs.glsl"),
absPath("${MODULE_DSN}/shaders/renderablecone_fs.glsl")
);
}
);
}
@@ -399,10 +407,7 @@ void RenderableCone::update(const UpdateData& data) {
int numBaseVertices = _resolution;
double height = _height * _unit;
double angle = glm::radians(float(_angle));
angle = angle / 2.0; //Half of the full cone angle to get a right -angled triangle
double radius = height * tan(angle);
double radius = calculateBaseRadius();
float angleIncrement = glm::radians(360.0 / numBaseVertices);
glm::dvec3 e0 = glm::normalize(glm::cross(_baseCenterDirection, glm::dvec3(1.0, 0.0, 0.0)));
@@ -456,13 +461,14 @@ void RenderableCone::fillVertexArrays() {
glm::vec4 colorAndOpacity = { color, _opacity };
// add base vertices
addVertexToVertexArray(_vertexBaseArray, _baseCenterPosition, colorAndOpacity);
if (_showbase) {
addVertexToVertexArray(_vertexBaseArray, _baseCenterPosition, colorAndOpacity);
for (int i = 0; i < _baseVertices.size(); ++i) {
addVertexToVertexArray(_vertexBaseArray, _baseVertices[i], colorAndOpacity);
for (int i = 0; i < _baseVertices.size(); ++i) {
addVertexToVertexArray(_vertexBaseArray, _baseVertices[i], colorAndOpacity);
}
addVertexToVertexArray(_vertexBaseArray, _baseVertices[0], colorAndOpacity);
}
addVertexToVertexArray(_vertexBaseArray, _baseVertices[0], colorAndOpacity);
//add lateral surface vertices
addVertexToVertexArray(_vertexLateralSurfaceArray, _apexPosition, colorAndOpacity);
+2 -1
View File
@@ -63,6 +63,7 @@ namespace openspace {
virtual void createShaderProgram();
virtual void fillVertexArrays();
virtual void updateVertexAttributes();
virtual float calculateBaseRadius();
void render(const RenderData& data, RendererTasks& rendererTask) override;
void addVertexToVertexArray(std::vector<float> &_vertexArray, glm::dvec3 position, glm::vec4 color);
@@ -135,7 +136,7 @@ namespace openspace {
double _unit = 2.59E13;
properties::FloatProperty _height;
properties::FloatProperty _angle;
properties::FloatProperty _radius;
properties::IntProperty _resolution;
properties::Vec3Property _color;
properties::BoolProperty _wireframe;
+67 -19
View File
@@ -37,6 +37,17 @@ namespace {
constexpr const std::array <const char*, openspace::RenderableCone::uniformCacheSize> UniformNames = {
"modelView", "projectionTransform" };
constexpr openspace::properties::Property::PropertyInfo ViewAngleInfo = {
"ViewAngle",
"View Angle",
"Field of view angle"
};
constexpr openspace::properties::Property::PropertyInfo DistanceFadeInfo = {
"DistanceFade",
"Distance Fade",
"Fade applied linearly from viewpoint"
};
} // namespace
namespace openspace {
@@ -53,6 +64,18 @@ documentation::Documentation RenderableStationFov::Documentation() {
"Type",
new StringEqualVerifier("RenderableStationFov"),
Optional::No
},
{
ViewAngleInfo.identifier,
new DoubleVerifier,
Optional::Yes,
ViewAngleInfo.description
},
{
DistanceFadeInfo.identifier,
new BoolVerifier,
Optional::Yes,
ViewAngleInfo.description
}
}
};
@@ -72,8 +95,19 @@ documentation::Documentation RenderableStationFov::Documentation() {
RenderableStationFov::RenderableStationFov(const ghoul::Dictionary& dictionary)
: RenderableCone(dictionary)
, _angle(ViewAngleInfo, 160.0, 0.0, 180.0)
, _distanceFade(DistanceFadeInfo, true)
{
_showbase = false;
_directionIsReversed = true;
_wireframe = false;
if (dictionary.hasKeyAndValue<double>(ViewAngleInfo.identifier)) {
_angle = dictionary.value<double>(ViewAngleInfo.identifier);
}
addProperty(_distanceFade);
addProperty(_angle);
removeProperty(_radius);
}
void RenderableStationFov::createShaderProgram()
@@ -81,12 +115,12 @@ void RenderableStationFov::createShaderProgram()
_programObject = BaseModule::ProgramObjectManager.request(
ProgramName,
[]() -> std::unique_ptr<ghoul::opengl::ProgramObject> {
return global::renderEngine.buildRenderProgram(
ProgramName,
absPath("${MODULE_DSN}/shaders/renderablestationfov_vs.glsl"),
absPath("${MODULE_DSN}/shaders/renderablestationfov_fs.glsl")
);
}
return global::renderEngine.buildRenderProgram(
ProgramName,
absPath("${MODULE_DSN}/shaders/renderablestationfov_vs.glsl"),
absPath("${MODULE_DSN}/shaders/renderablestationfov_fs.glsl")
);
}
);
}
@@ -115,28 +149,32 @@ void RenderableStationFov::updateVertexAttributes()
void RenderableStationFov::fillVertexArrays()
{
glm::vec3 color = _color;
glm::vec4 colorAndOpacity = { color, _opacity };
glm::vec4 colorAndOpacity = { glm::vec3(_color), _opacity };
// add base vertices
addVertexToVertexArray(_vertexBaseArray, _baseCenterPosition, colorAndOpacity, 1.0);
for (int i = 0; i < _baseVertices.size(); ++i) {
addVertexToVertexArray(_vertexBaseArray, _baseVertices[i], colorAndOpacity, 0.0);
float apexFade = 1.0;
float baseVerticeFade = 1.0;
if(_distanceFade) {
baseVerticeFade = 0.0;
}
addVertexToVertexArray(_vertexBaseArray, _baseVertices[0], colorAndOpacity, 0.0);
// add base vertices
//addVertexToVertexArray(_vertexBaseArray, _baseCenterPosition, colorAndOpacity, apexFade);
//for (int i = 0; i < _baseVertices.size(); ++i) {
// addVertexToVertexArray(_vertexBaseArray, _baseVertices[i], colorAndOpacity, baseVerticeFade);
//}
//addVertexToVertexArray(_vertexBaseArray, _baseVertices[0], colorAndOpacity, baseVerticeFade);
//add lateral surface vertices
addVertexToVertexArray(_vertexLateralSurfaceArray, _apexPosition, colorAndOpacity, 1.0);
addVertexToVertexArray(_vertexLateralSurfaceArray, _apexPosition, colorAndOpacity, apexFade);
for (int i = 0; i < _baseVertices.size(); ++i) {
addVertexToVertexArray(_vertexLateralSurfaceArray, _baseVertices[i], colorAndOpacity, 0.0);
addVertexToVertexArray(_vertexLateralSurfaceArray, _baseVertices[i], colorAndOpacity, baseVerticeFade);
}
addVertexToVertexArray(_vertexLateralSurfaceArray, _baseVertices[0], colorAndOpacity, 0.0);
addVertexToVertexArray(_vertexLateralSurfaceArray, _baseVertices[0], colorAndOpacity, baseVerticeFade);
}
void RenderableStationFov::addVertexToVertexArray(std::vector<float>& vertexArray, glm::dvec3 position, glm::vec4 color, float distance)
void RenderableStationFov::addVertexToVertexArray(std::vector<float>& vertexArray, glm::dvec3 position, glm::vec4 color, float distanceFade)
{
vertexArray.push_back(position.x);
vertexArray.push_back(position.y);
@@ -145,7 +183,17 @@ void RenderableStationFov::addVertexToVertexArray(std::vector<float>& vertexArra
vertexArray.push_back(color.g);
vertexArray.push_back(color.b);
vertexArray.push_back(color.a);
vertexArray.push_back(distance);
vertexArray.push_back(distanceFade);
}
float RenderableStationFov::calculateBaseRadius()
{
double angle = glm::radians(float(_angle));
angle = angle / 2.0; //Half of the full cone angle to get a right -angled triangle
float radius = _height * _unit * tan(angle);
return radius;
}
} // namespace openspace
@@ -48,7 +48,10 @@ namespace openspace {
void createShaderProgram() override;
void addVertexToVertexArray(std::vector<float> &vertexArray, glm::dvec3 position,
glm::vec4 color, float distance);
float calculateBaseRadius() override;
properties::FloatProperty _angle;
properties::BoolProperty _distanceFade;
private:
/// The vertex attribute location for position
@@ -27,7 +27,7 @@
// layout locations must correspond to va locations in renderablesignals.cpp
layout(location = 0) in vec3 in_point_position;
layout(location = 1) in vec4 in_color;
layout(location = 2) in float in_distance_from_apex;
layout(location = 2) in float in_distance_fade;
out vec4 vs_positionScreenSpace;
@@ -46,5 +46,5 @@ void main() {
gl_Position.z = 0.f;
// pass variables with no calculations directly to fragment
vs_color = vec4(in_color.rgb, in_distance_from_apex);
vs_color = vec4(in_color.rgb, in_color.a * in_distance_fade);
}