mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-29 15:29:26 -05:00
Change target when zooming to be crosshair and border with crosshair
This commit is contained in:
@@ -62,7 +62,7 @@ namespace openspace {
|
||||
properties::FloatProperty _showCrosshairThreshold;
|
||||
std::unique_ptr<ghoul::opengl::Texture> _texture;
|
||||
|
||||
UniformCache(modelTransform, viewProj, texture, showCrosshair, borderWidth, targetDimensions, borderColor) _uniformCache;
|
||||
UniformCache(modelTransform, viewProj, texture, showCrosshair, showCrosshairInTarget, borderWidth, targetDimensions, borderColor) _uniformCache;
|
||||
GLuint _vertexArray = 0;
|
||||
GLuint _vertexBuffer = 0;
|
||||
float _fieldOfView = 100.f;
|
||||
|
||||
@@ -2,6 +2,7 @@ uniform sampler2D texture1;
|
||||
uniform float borderWidth;
|
||||
uniform vec2 targetDimensions;
|
||||
uniform bool showCrosshair;
|
||||
uniform bool showCrosshairInTarget;
|
||||
uniform vec4 borderColor;
|
||||
|
||||
|
||||
@@ -11,8 +12,8 @@ in vec4 vs_position;
|
||||
|
||||
float crossLine(in float _width, in float _coord) {
|
||||
float center = 0.5f;
|
||||
float line = smoothstep(center, center+(_width/2) , _coord) -
|
||||
smoothstep(center-(_width/2), center, _coord);
|
||||
float line = smoothstep(center, center+(_width/2), _coord)
|
||||
- smoothstep(center-(_width/2), center, _coord);
|
||||
return line;
|
||||
}
|
||||
|
||||
@@ -23,16 +24,26 @@ Fragment getFragment() {
|
||||
|
||||
float ratio = targetDimensions.y / targetDimensions.x;
|
||||
|
||||
// draw crosshair
|
||||
float crossWidth = 0.1f;
|
||||
vec3 crosshair = vec3(crossLine(crossWidth*ratio, (vs_st).x) + crossLine(crossWidth, (vs_st).y));
|
||||
|
||||
// draw square border
|
||||
float borderBottomLeft = step(borderWidth*ratio, vs_st.x) * step(borderWidth*ratio, (1.0)-vs_st.x);
|
||||
float borderTopRight = step(borderWidth, vs_st.y) * step(borderWidth, (1.0)-vs_st.y);
|
||||
vec3 border = vec3(borderBottomLeft*borderTopRight);
|
||||
float border_bl = step(borderWidth*ratio, vs_st.x) * step(borderWidth*ratio, (1.0)-vs_st.x);
|
||||
float border_tr = step(borderWidth, vs_st.y) * step(borderWidth, (1.0)-vs_st.y);
|
||||
vec3 border = vec3(border_bl*border_tr);
|
||||
|
||||
// show crosshair or border
|
||||
// draw crosshair inside square border
|
||||
float crosshair_border_linewidth = 0.06f;
|
||||
float border_crosshair_bl = step(borderWidth*ratio*4, vs_st.x) * step(borderWidth*ratio*4, (1.0)-vs_st.x);
|
||||
float border_crosshair_tr = step(borderWidth*4, vs_st.y) * step(borderWidth*4, (1.0)-vs_st.y);
|
||||
vec3 crosshair_small = vec3(border_crosshair_bl*border_crosshair_tr);
|
||||
|
||||
vec3 crosshair_inside_border = vec3(crossLine(crosshair_small.x * crosshair_border_linewidth, (vs_st).x)
|
||||
+ crossLine(crosshair_small.y * crosshair_border_linewidth, (vs_st).y));
|
||||
vec3 crosshair_and_border = (1.0 - border) + crosshair_inside_border;
|
||||
|
||||
// draw crosshair
|
||||
float crosshair_linewidth = 0.14f;
|
||||
vec3 crosshair = vec3(crossLine(crosshair_linewidth*ratio*1.1, vs_st.x) + crossLine(crosshair_linewidth, vs_st.y));
|
||||
|
||||
// show crosshair or border or both
|
||||
frag.color = vec4(1,1,1,1);
|
||||
frag.color.rgba = vec4(borderColor);
|
||||
|
||||
@@ -42,6 +53,13 @@ Fragment getFragment() {
|
||||
frag.color.a = 0.0;
|
||||
}
|
||||
}
|
||||
else if(showCrosshairInTarget) {
|
||||
frag.color.rgba = vec4(borderColor);
|
||||
if(crosshair_and_border == vec3(0.0)) {
|
||||
frag.color.a = 0.0;
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
if(border == vec3(1.0)) {
|
||||
frag.color.a = 0.0;
|
||||
|
||||
@@ -38,8 +38,8 @@ namespace {
|
||||
"Set the dimensions of the SkyTarget according to the SkyBrowser ratio "
|
||||
};
|
||||
|
||||
constexpr const std::array<const char*, 7> UniformNames = {
|
||||
"ModelTransform", "ViewProjectionMatrix", "texture1", "showCrosshair", "borderWidth", "targetDimensions", "borderColor"
|
||||
constexpr const std::array<const char*, 8> UniformNames = {
|
||||
"ModelTransform", "ViewProjectionMatrix", "texture1", "showCrosshair", "showCrosshairInTarget", "borderWidth", "targetDimensions", "borderColor"
|
||||
};
|
||||
|
||||
constexpr const openspace::properties::Property::PropertyInfo BrowserIDInfo =
|
||||
@@ -77,7 +77,7 @@ namespace openspace {
|
||||
: ScreenSpaceRenderable(dictionary)
|
||||
, _targetDimensions(TargetDimensionInfo, glm::ivec2(1000.f), glm::ivec2(0.f), glm::ivec2(6000.f))
|
||||
, _skyBrowserID(BrowserIDInfo)
|
||||
, _showCrosshairThreshold(CrosshairThresholdInfo, 2.f, 1.f, 70.f)
|
||||
, _showCrosshairThreshold(CrosshairThresholdInfo, 0.6f, 0.1f, 70.f)
|
||||
, _borderColor(220, 220, 220)
|
||||
{
|
||||
// Handle target dimension property
|
||||
@@ -221,15 +221,19 @@ namespace openspace {
|
||||
glDisable(GL_CULL_FACE);
|
||||
|
||||
glm::mat4 modelTransform = globalRotationMatrix() * translationMatrix() * localRotationMatrix() * scaleMatrix();
|
||||
float borderWidth = 0.002f/_scale.value();
|
||||
float borderWidth = 0.0016f/_scale.value();
|
||||
float showCrosshairInTargetThreshold = 2.f; // show crosshair and target when browser FOV < 2 degrees
|
||||
glm::vec2 targetDim;
|
||||
bool showCrosshair;
|
||||
bool showCrosshairInTarget;
|
||||
_targetDimensions.value() == glm::vec2(0) ? targetDim = glm::vec2(1) : targetDim = _targetDimensions.value();
|
||||
_shader->activate();
|
||||
|
||||
_fieldOfView < showCrosshairInTargetThreshold && _fieldOfView > _showCrosshairThreshold ? showCrosshairInTarget = true : showCrosshairInTarget = false;
|
||||
_fieldOfView < _showCrosshairThreshold ? showCrosshair = true : showCrosshair = false;
|
||||
|
||||
_shader->setUniform(_uniformCache.showCrosshair, showCrosshair);
|
||||
_shader->setUniform(_uniformCache.showCrosshairInTarget, showCrosshairInTarget);
|
||||
_shader->setUniform(_uniformCache.borderWidth, borderWidth);
|
||||
_shader->setUniform(_uniformCache.targetDimensions, targetDim);
|
||||
_shader->setUniform(_uniformCache.modelTransform, modelTransform);
|
||||
|
||||
Reference in New Issue
Block a user