Note that there are some explanatory texts on larger screens.

plurals
  1. POMiddle point in line
    text
    copied!<h2>Introduction:</h2> <p>I register mouse events (mouseDragged, mouseDown) and convert their location to NSValue after some corrections. After that they are being added to NSMutableArray and later on they are taken back, converted back to CGPoint, added to GLFloat (vertex array) and drawn via OpenGL. But when mouse drag is done faster than objective-c can register events, there appears big spacings between points. I need to correct that. </p> <h2>More about my code:</h2> <p>Mouse event location point is being edited after registering it, to make 4 points from him, to draw glQuad later. It looks something like this:</p> <pre><code>locationPoint = [self convertPoint: [event locationInWindow] fromView:self]; //Top left corner of quad quadTopLeftCorner.x = locationPoint.x - someFloatValue; quadTopLeftCorner.y = locationPoint.y + someFloatValue; //Top right corner of quad quadTopRightCorner.x = locationPoint.x + someFloatValue; quadTopRightCorner.y = locationPoint.y + someFloatValue; //Bottom left corner of quad quadBottomLeftCorner.x = locationPoint.x - someFloatValue; quadBottomLeftCorner.y = locationPoint.y - someFloatValue; //Bottom right corner of quad quadBottomRightCorner.x = locationPoint.x + someFloatValue; quadBottomRightCorner.y = locationPoint.y - someFloatValue; </code></pre> <p>And they are being converted to NSValue and moved to NSMutableArray</p> <pre><code>someNSValueTopLeft = [NSValue valueWithPoint:quadTopLeftCorner]; someNSValueTopRight = [NSValue valueWithPoint:quadTopRightCorner]; someNSValueBottomLeft = [NSValue valueWithPoint:quadBottomLeftCorner]; someNSValueBottomRight = [NSValue valueWithPoint:quadBottomRightCorner]; [someNSMutableArray addObject:someNSValueTopLeft]; [someNSMutableArray addObject:someNSValueTopRight]; [someNSMutableArray addObject:someNSValueBottomLeft]; [someNSMutableArray addObject:someNSValueBottomRight]; </code></pre> <p>And I want to check if distance between last two points is bigger than <em>something</em>. And if yes, I want to add some points between them. So I tried do it like this:</p> <pre><code> NSValue *someNSValueForLastNSValueTopLeft = [someNSMutableArray objectAtIndex:([someNSMutableArray count]-4)]; CGPoint lastTopLeftQuadPoint = someNSValueForLastNSValueTopLeft.pointValue; int distx = (quadTopLeftCorner.x - lastTopLeftQuadPoint.x) * (quadTopLeftCorner.x - lastTopLeftQuadPoint.x); int disty = (quadTopLeftCorner.y - lastTopLeftQuadPoint.y) * (quadTopLeftCorner.y - lastTopLeftQuadPoint.y); int dist = sqrtf(distx + disty); if (dist &gt; someFloatValue) { someNewPointForTopLeft.x = ((quadTopLeftCorner.x + lastTopLeftQuadPoint.x)/2); someNewPointForTopLeft.y = ((quadTopLeftCorner.y + lastTopLeftQuadPoint.y)/2); someNewPointForTopRight.x = someNewPointForTopLeft.x + someFloatValue; someNewPointForTopRight.y = someNewPointForTopLeft.y; someNewPointForBottomRight.x = someNewPointForTopLeft.x + someFloatValue; someNewPointForBottomRight.y = someNewPointForTopLeft.y - someFloatValue; someNewPointForBottomLeft.x = someNewPointForTopLeft.x; someNewPointForBottomLeft.y = someNewPointForTopLeft.y - someFloatValue; someNSValueTopLeft = [NSValue valueWithPoint:someNewPointForTopLeft]; [vertices addObject:someNSValueTopLeft]; someNSValueTopRight = [NSValue valueWithPoint:someNewPointForTopRight]; [vertices addObject:someNSValueTopRight]; someNSValueBottomLeft = [NSValue valueWithPoint:someNewPointForBottomRight]; [vertices addObject:someNSValueBottomLeft]; someNSValueBottomRight = [NSValue valueWithPoint:someNewPointForBottomLeft]; [vertices addObject:someNSValueBottomRight]; } </code></pre> <p>But it doesn't works. Anyone could suggest me some different way?</p> <hr> <p>Result:</p> <p><img src="https://i.stack.imgur.com/SqBjG.png" alt="enter image description here"></p>
 

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