Make crosshair appear at all times with a fixed size

This commit is contained in:
Ylva Selling
2022-03-04 17:37:11 -05:00
parent 119016ee54
commit ae86396317
3 changed files with 23 additions and 24 deletions

View File

@@ -82,7 +82,7 @@ public:
private:
// Properties
properties::FloatProperty _showCrosshairThreshold;
properties::FloatProperty _crossHairSize;
properties::FloatProperty _showRectangleThreshold;
properties::FloatProperty _lineWidth;
properties::DoubleProperty _stopAnimationThreshold;
@@ -94,7 +94,7 @@ private:
bool _shouldLockAfterAnimation = false;
// Shader
UniformCache(modelTransform, viewProj, showCrosshair, showRectangle, lineWidth,
UniformCache(modelTransform, viewProj, crossHairSize, showRectangle, lineWidth,
dimensions, lineColor) _uniformCache;
GLuint _vertexArray = 0;
GLuint _vertexBuffer = 0;

View File

@@ -27,7 +27,7 @@ in vec4 vs_position;
uniform float lineWidth;
uniform vec2 dimensions;
uniform bool showCrosshair;
uniform float crossHairSize;
uniform bool showRectangle;
uniform vec4 lineColor;
@@ -43,6 +43,10 @@ float createLine(float lineCenter, float lineWidth, float coord) {
return step(startEdge, coord) - step(endEdge, coord);
}
float createFilledRectangle(float width, vec2 coord) {
return createLine(0.5, width, coord.x) * createLine(0.5, width, coord.y);
}
float createRectangle(float linewidthY, float ratio, vec2 coord) {
// Calculate the widths and centers for the lines
float linewidthX = linewidthY * ratio * VerticalThickness;
@@ -70,14 +74,11 @@ float createCrosshair(in float linewidth, in float ratio, in vec2 coord) {
Fragment getFragment() {
float ratio = dimensions.y / dimensions.x;
float crosshair = 0.0;
float rectangle = 0.0;
float crossHairBox = createFilledRectangle(crossHairSize/dimensions.x, vs_st);
if (showCrosshair) {
crosshair = createCrosshair(lineWidth, ratio, vs_st);
float border = 1.0 - createRectangle(lineWidth * 5.0, ratio, vs_st);
crosshair *= border;
}
float crosshair = createCrosshair(lineWidth, ratio, vs_st);
crosshair *= crossHairBox;
if (showRectangle) {
rectangle = createRectangle(lineWidth, ratio, vs_st);

View File

@@ -40,16 +40,15 @@ namespace {
constexpr const char* _loggerCat = "ScreenSpaceSkyTarget";
constexpr const std::array<const char*, 7> UniformNames = {
"modelTransform", "viewProj", "showCrosshair", "showRectangle", "lineWidth",
"modelTransform", "viewProj", "crossHairSize", "showRectangle", "lineWidth",
"dimensions", "lineColor"
};
constexpr const openspace::properties::Property::PropertyInfo CrosshairThresholdInfo =
constexpr const openspace::properties::Property::PropertyInfo crossHairSizeInfo =
{
"CrosshairThreshold",
"Crosshair Threshold",
"When the field of view is smaller than the crosshair threshold, a crosshair will"
"be rendered in the target."
"CrosshairSize",
"Crosshair Size",
"Determines the size of the crosshair."
};
constexpr const openspace::properties::Property::PropertyInfo RectangleThresholdInfo =
@@ -82,8 +81,8 @@ namespace {
};
struct [[codegen::Dictionary(ScreenSpaceSkyTarget)]] Parameters {
// [[codegen::verbatim(CrosshairThresholdInfo.description)]]
std::optional<float> crosshairThreshold;
// [[codegen::verbatim(crossHairSizeInfo.description)]]
std::optional<float> crossHairSize;
// [[codegen::verbatim(RectangleThresholdInfo.description)]]
std::optional<float> rectangleThreshold;
@@ -104,7 +103,7 @@ namespace {
namespace openspace {
ScreenSpaceSkyTarget::ScreenSpaceSkyTarget(const ghoul::Dictionary& dictionary)
: ScreenSpaceRenderable(dictionary)
, _showCrosshairThreshold(CrosshairThresholdInfo, 4.f, 0.1f, 70.f)
, _crossHairSize(crossHairSizeInfo, 0.05f, 0.005f, 0.2f)
, _showRectangleThreshold(RectangleThresholdInfo, 2.f, 0.1f, 70.f)
, _stopAnimationThreshold(AnimationThresholdInfo, 0.0005, 0.0, 0.005)
, _animationSpeed(AnimationSpeedInfo, 5.0, 0.1, 10.0)
@@ -113,12 +112,12 @@ ScreenSpaceSkyTarget::ScreenSpaceSkyTarget(const ghoul::Dictionary& dictionary)
{
// Handle target dimension property
const Parameters p = codegen::bake<Parameters>(dictionary);
_showCrosshairThreshold = p.crosshairThreshold.value_or(_showCrosshairThreshold);
_crossHairSize = p.crossHairSize.value_or(_crossHairSize);
_showRectangleThreshold = p.rectangleThreshold.value_or(_showRectangleThreshold);
_stopAnimationThreshold = p.crosshairThreshold.value_or(_stopAnimationThreshold);
_stopAnimationThreshold = p.crossHairSize.value_or(_stopAnimationThreshold);
_animationSpeed = p.animationSpeed.value_or(_animationSpeed);
addProperty(_showCrosshairThreshold);
addProperty(_crossHairSize);
addProperty(_showRectangleThreshold);
addProperty(_stopAnimationThreshold);
addProperty(_animationSpeed);
@@ -205,7 +204,6 @@ glm::ivec3 ScreenSpaceSkyTarget::borderColor() const {
}
void ScreenSpaceSkyTarget::render() {
bool showCrosshair = _verticalFov < _showCrosshairThreshold;
bool showRectangle = _verticalFov > _showRectangleThreshold;
glm::vec4 color = { glm::vec3(_borderColor) / 255.f, _opacity.value() };
@@ -216,10 +214,10 @@ void ScreenSpaceSkyTarget::render() {
glDisable(GL_CULL_FACE);
_shader->activate();
_shader->setUniform(_uniformCache.showCrosshair, showCrosshair);
_shader->setUniform(_uniformCache.crossHairSize, _crossHairSize);
_shader->setUniform(_uniformCache.showRectangle, showRectangle);
_shader->setUniform(_uniformCache.lineWidth, lineWidth);
_shader->setUniform(_uniformCache.dimensions, glm::vec2(_objectSize));
_shader->setUniform(_uniformCache.dimensions, screenSpaceDimensions());
_shader->setUniform(_uniformCache.modelTransform, modelTransform);
_shader->setUniform(_uniformCache.lineColor, color);
_shader->setUniform(