From 812e27d36ffaf5d420c6572dcf656adbdaa329f3 Mon Sep 17 00:00:00 2001 From: Ivan Mahonin Date: Jan 12 2021 12:31:29 +0000 Subject: fix strokes --- diff --git a/src/drawing.c b/src/drawing.c index e5d4fd0..517aa0c 100644 --- a/src/drawing.c +++ b/src/drawing.c @@ -658,7 +658,8 @@ static void drawStroke(int close) { stroke.points = calloc(stroke.allocatedCount, sizeof(*stroke.points)); double w = 0.5*s->strokeWidth; - double precisionSqr = 1/(w*0.75); + double ps = heliGLGetPixelSize(); + double precisionSqr = ps > HELI_PRECISION ? ps : 0.5*w; precisionSqr *= precisionSqr; heliDrawingApplyTexture(s->strokeColor, &s->strokeTexture); diff --git a/src/geometry.c b/src/geometry.c index 26b61fe..47d0e14 100644 --- a/src/geometry.c +++ b/src/geometry.c @@ -55,7 +55,7 @@ int heliMatrix4Invert(double *r, const double *m) { r[12] = m[ 4]*(m[10]*m[13] - m[ 9]*m[14]) + m[ 5]*(m[ 8]*m[14] - m[10]*m[12]) + m[ 6]*(m[ 9]*m[12] - m[ 8]*m[13]); double det = m[ 0]*r[0] + m[ 1]*r[4] + m[ 2]*r[8] + m[ 3]*r[12]; - if (fabs(det) <= HELI_PRECISION) { + if (fabs(det) <= HELI_PRECISION_SQR*HELI_PRECISION) { memset(r, 0, sizeof(*r)*16); return FALSE; } diff --git a/src/gl.c b/src/gl.c index 98c95f2..821f2e9 100644 --- a/src/gl.c +++ b/src/gl.c @@ -60,6 +60,41 @@ double heliGLGetAAResolution() { } +double heliGLGetPixelSize() { + double proj[16] = {}; + double model[16] = {}; + glGetDoublev(GL_PROJECTION_MATRIX, proj); + glGetDoublev(GL_MODELVIEW_MATRIX, model); + + double full[16] = {}; + double fullinv[16] = {}; + heliMatrix4Mult(full, proj, model); + + full[8] = 0, full[9] = 0, full[10] = 1, full[11] = 0; // assume z is zero + if (!heliMatrix4Invert(fullinv, full)) return 0; + + if (fabs(fullinv[15]) <= HELI_PRECISION_SQR) return 0; // bad perspective + double k = 1/fullinv[15]; + + if ( fabs(fullinv[3]*k) > 1e-5 + || fabs(fullinv[7]*k) > 1e-5 ) return 0; // perspective distortion + + int rect[4] = {}; // x, y, w, h + glGetIntegerv(GL_VIEWPORT, rect); + double w = rect[2], h = rect[3]; + + double m00 = fullinv[0]*k*2/w, m01 = fullinv[1]*k*2/w, + m10 = fullinv[4]*k*2/h, m11 = fullinv[5]*k*2/h; + double l0 = sqrt(m00*m00 + m01*m01); + double l1 = sqrt(m10*m10 + m11*m11); + if (l0 > l1) { double l = l0; l0 = l1; l1 = l; } + if (l0 <= HELI_PRECISION && l1 <= HELI_PRECISION) return 0; + + double l = sqrt(l0*l1); + return l <= HELI_PRECISION ? 0 : l; +} + + static int isInteger(double x) { return fabs(floor(x + 0.5) - x) > 0.01; } diff --git a/src/private.h b/src/private.h index f95b701..79e8946 100644 --- a/src/private.h +++ b/src/private.h @@ -169,6 +169,7 @@ extern unsigned int heliGLWindowFramebufferReadId; extern unsigned int heliGLWindowFramebufferDrawId; double heliGLGetAAResolution(); +double heliGLGetPixelSize(); int heliGLIsIntegerClipping(); int heliGLBackTransform(double *x, double *y); void heliGLGetCommonState(HeliGLCommonState *state, unsigned int flags);