Note that there are some explanatory texts on larger screens.

plurals
  1. POiOS OpenGLES2.0 drawing point at correct size
    primarykey
    data
    text
    <p>Using the code below I am drawing lines from triangle strips of varying sizes. At the point of the final triangle I would like to add a GLpoint primitive so it looks like the line has a rounded end. How would I calculate the correct diameter for the GLpoint based upon the size of the final triangle? Please see attached image demonstrating what I have at the moment (the point is much too large).</p> <p><img src="https://i.stack.imgur.com/WtOvt.png" alt="enter image description here"></p> <pre><code> - (void)pan:(UIPanGestureRecognizer *)p { CGPoint v = [p velocityInView:self.view]; CGPoint l = [p locationInView:self.view]; float distance = sqrtf((l.x - previousPoint.x) * (l.x - previousPoint.x) + (l.y - previousPoint.y) * (l.y - previousPoint.y)); float velocityMagnitude = sqrtf(v.x*v.x + v.y*v.y); float clampedVelocityMagnitude = clamp(VELOCITY_CLAMP_MIN, VELOCITY_CLAMP_MAX, velocityMagnitude); float normalizedVelocity = (clampedVelocityMagnitude - VELOCITY_CLAMP_MIN) / (VELOCITY_CLAMP_MAX - VELOCITY_CLAMP_MIN); float lowPassFilterAlpha = STROKE_WIDTH_SMOOTHING; float newThickness = (STROKE_WIDTH_MAX - STROKE_WIDTH_MIN) * normalizedVelocity + STROKE_WIDTH_MIN; penThickness = penThickness * lowPassFilterAlpha + newThickness * (1 - lowPassFilterAlpha); glBindVertexArrayOES(vertexArrayTriangles); glBindBuffer(GL_ARRAY_BUFFER, vertexBufferTriangles); if ([p state] == UIGestureRecognizerStateBegan) { previousPoint = l; previousMidPoint = l; NISignaturePoint startPoint = { { (l.x / self.view.bounds.size.width * 2. - 1), ((l.y / self.view.bounds.size.height) * 2.0 - 1) * -1, 0}, {0,0,0} }; previousVertex = startPoint; previousThickness = penThickness; addVertexTriangles(&amp;lengthTriangles, startPoint); addVertexTriangles(&amp;lengthTriangles, previousVertex); } else if ([p state] == UIGestureRecognizerStateChanged) { CGPoint mid = CGPointMake((l.x + previousPoint.x) / 2.0, (l.y + previousPoint.y) / 2.0); if (distance &gt; QUADRATIC_DISTANCE_TOLERANCE) { // Plot quadratic bezier instead of line unsigned int i; int segments = (int) distance / 1.5; float startPenThickness = previousThickness; float endPenThickness = penThickness; previousThickness = penThickness; for (i = 0; i &lt; segments; i++) { penThickness = startPenThickness + ((endPenThickness - startPenThickness) / segments) * i; double t = (double)i / (double)segments; double a = pow((1.0 - t), 2.0); double b = 2.0 * t * (1.0 - t); double c = pow(t, 2.0); double x = a * previousMidPoint.x + b * previousPoint.x + c * mid.x; double y = a * previousMidPoint.y + b * previousPoint.y + c * mid.y; NISignaturePoint v = { { (x / self.view.bounds.size.width * 2. - 1), ((y / self.view.bounds.size.height) * 2.0 - 1) * -1, 0 }, strokeColor }; [self addTriangleStripPointsForPrevious:previousVertex next:v]; previousVertex = v; } } previousPoint = l; previousMidPoint = mid; } else if (p.state == UIGestureRecognizerStateEnded | p.state == UIGestureRecognizerStateCancelled) { addVertexTriangles(&amp;lengthTriangles, previousVertex); addVertexTriangles(&amp;lengthTriangles, previousVertex); glBindVertexArrayOES(vertexArrayPoints); glBindBuffer(GL_ARRAY_BUFFER, vertexBufferPoints); NISignaturePoint startPoint = { {previousVertex.vertex.x, previousVertex.vertex.y, 0}, strokeColor, ??? }; addVertexPoints(&amp;lengthPoints, startPoint); penThickness = STROKE_WIDTH_MIN; previousThickness = penThickness; } } - (void)addTriangleStripPointsForPrevious:(NISignaturePoint)previous next:(NISignaturePoint)next { float toTravel = penThickness / 2.0; //NSLog(@"add tri"); for (int i = 0; i &lt; 2; i++) { GLKVector3 p = perpendicular(previous, next); GLKVector3 p1 = next.vertex; GLKVector3 ref = GLKVector3Add(p1, p); float distance = GLKVector3Distance(p1, ref); float difX = p1.x - ref.x; float difY = p1.y - ref.y; float ratio = -1.0 * (toTravel / distance); difX = difX * ratio; difY = difY * ratio; NISignaturePoint stripPoint = { { p1.x + difX, p1.y + difY, 0.0 }, strokeColor }; addVertexTriangles(&amp;lengthTriangles, stripPoint); toTravel *= -1; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload