SoDatumLabel: Add arrowheads to angles. And improve arrowhead rendering.

This commit is contained in:
PaddleStroke
2024-02-01 13:58:13 +01:00
committed by Chris Hennes
parent ff4c22a1e7
commit 66de7f3968

View File

@@ -924,7 +924,7 @@ void SoDatumLabel::GLRender(SoGLRenderAction * action)
// Set GL Properties
glLineWidth(this->lineWidth.getValue());
glColor3f(t[0], t[1], t[2]);
float margin = this->imgHeight / 4.0;
float margin = this->imgHeight / 3.0;
SbVec3f perp1 = p1_ + normal * (length + offset1 * scale);
@@ -974,15 +974,17 @@ void SoDatumLabel::GLRender(SoGLRenderAction * action)
glVertex2f(par4[0], par4[1]);
glEnd();
float arrowWidth = margin * 0.5;
SbVec3f ar1 = par1 + ((flipTriang) ? -1 : 1) * dir * 0.866f * 2 * margin;
SbVec3f ar2 = ar1 + normal * margin;
ar1 -= normal * margin;
SbVec3f ar2 = ar1 + normal * arrowWidth;
ar1 -= normal * arrowWidth;
SbVec3f ar3 = par4 - ((flipTriang) ? -1 : 1) * dir * 0.866f * 2 * margin;
SbVec3f ar4 = ar3 + normal * margin ;
ar3 -= normal * margin;
SbVec3f ar4 = ar3 + normal * arrowWidth;
ar3 -= normal * arrowWidth;
//Draw a pretty arrowhead (Equilateral) (Eventually could be improved to other shapes?)
// Draw the arrowheads
glBegin(GL_TRIANGLES);
glVertex2f(par1[0], par1[1]);
glVertex2f(ar1[0], ar1[1]);
@@ -1059,13 +1061,14 @@ void SoDatumLabel::GLRender(SoGLRenderAction * action)
textOffset = pos;
float margin = this->imgHeight / 4.0;
float margin = this->imgHeight / 3.0;
// Create the arrowhead
float arrowWidth = margin * 0.5;
SbVec3f ar0 = p2;
SbVec3f ar1 = p2 - dir * 0.866f * 2 * margin;
SbVec3f ar2 = ar1 + normal * margin;
ar1 -= normal * margin;
SbVec3f ar2 = ar1 + normal * arrowWidth;
ar1 -= normal * arrowWidth;
SbVec3f p3 = pos + dir * (this->imgWidth / 2 + margin);
if ((p3-p1).length() > (p2-p1).length())
@@ -1094,8 +1097,8 @@ void SoDatumLabel::GLRender(SoGLRenderAction * action)
// create second arrowhead
SbVec3f ar0_1 = p1;
SbVec3f ar1_1 = p1 + dir * 0.866f * 2 * margin;
SbVec3f ar2_1 = ar1_1 + normal * margin;
ar1_1 -= normal * margin;
SbVec3f ar2_1 = ar1_1 + normal * arrowWidth;
ar1_1 -= normal * arrowWidth;
glBegin(GL_TRIANGLES);
glVertex2f(ar0_1[0], ar0_1[1]);
@@ -1125,7 +1128,7 @@ void SoDatumLabel::GLRender(SoGLRenderAction * action)
// Only the angle intersection point is needed
SbVec3f p0 = points[0];
float margin = this->imgHeight / 4.0;
float margin = this->imgHeight / 3.0;
// Load the Parameters
float length = this->param1.getValue();
@@ -1195,6 +1198,36 @@ void SoDatumLabel::GLRender(SoGLRenderAction * action)
glVertex2f(pnt4[0],pnt4[1]);
glEnd();
// Create the arrowheads
float arrowLength = margin * 2;
float arrowWidth = margin * 0.5;
// Normals for the arrowheads
SbVec3f dirStart(v1[1], -v1[0], 0);
SbVec3f dirEnd(-v2[1], v2[0], 0);
// Calculate arrowhead points for start angle
SbVec3f startArrowBase = p0 + r * v1;
SbVec3f startArrowLeft = startArrowBase - arrowLength * dirStart + arrowWidth * v1;
SbVec3f startArrowRight = startArrowBase - arrowLength * dirStart - arrowWidth * v1;
// Calculate arrowhead points for end angle
SbVec3f endArrowBase = p0 + r * v2;
SbVec3f endArrowLeft = endArrowBase - arrowLength * dirEnd + arrowWidth * v2;
SbVec3f endArrowRight = endArrowBase - arrowLength * dirEnd - arrowWidth * v2;
// Draw arrowheads
glBegin(GL_TRIANGLES);
// Start angle arrowhead
glVertex2f(startArrowBase[0], startArrowBase[1]);
glVertex2f(startArrowLeft[0], startArrowLeft[1]);
glVertex2f(startArrowRight[0], startArrowRight[1]);
// End angle arrowhead
glVertex2f(endArrowBase[0], endArrowBase[1]);
glVertex2f(endArrowLeft[0], endArrowLeft[1]);
glVertex2f(endArrowRight[0], endArrowRight[1]);
glEnd();
}
else if (this->datumtype.getValue() == SYMMETRIC) {