From 097d0ddfa90b845b09ef6dc3a8c9b21bf71dde85 Mon Sep 17 00:00:00 2001 From: Jonathan Westhues Date: Sat, 24 May 2008 05:23:25 -0800 Subject: [PATCH] Add a workaround for OpenGL, which likes to tesselate with zero-area triangles, apparently. And make the number of line segments used to approximate a triangle depend on its scale on screen. [git-p4: depot-paths = "//depot/solvespace/": change = 1738] --- entity.cpp | 5 +++-- graphicswin.cpp | 2 +- mesh.cpp | 4 ++++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/entity.cpp b/entity.cpp index 1e6e412..8f7c5d7 100644 --- a/entity.cpp +++ b/entity.cpp @@ -746,6 +746,7 @@ void Entity::DrawOrGetDistance(int order) { break; } +#define CIRCLE_SIDES(r) (7 + (int)(10*((sqrt(r))*SS.GW.scale)/20)) case ARC_OF_CIRCLE: { if(order >= 0 && order != 1) break; Vector c = SS.GetEntity(point[0])->PointGetNum(); @@ -760,7 +761,7 @@ void Entity::DrawOrGetDistance(int order) { double thetaa, thetab, dtheta; ArcGetAngles(&thetaa, &thetab, &dtheta); - int i, n = (int)((20*dtheta)/(2*PI)); + int i, n = 3 + (int)(CIRCLE_SIDES(ra)*dtheta/(2*PI)); Vector prev = pa; for(i = 1; i <= n; i++) { double theta = thetaa + (dtheta*i)/n; @@ -781,7 +782,7 @@ void Entity::DrawOrGetDistance(int order) { Vector center = SS.GetEntity(point[0])->PointGetNum(); Vector u = q.RotationU(), v = q.RotationV(); - int i, c = 20; + int i, c = CIRCLE_SIDES(r); Vector prev = u.ScaledBy(r).Plus(center); for(i = 1; i <= c; i++) { double phi = (2*PI*i)/c; diff --git a/graphicswin.cpp b/graphicswin.cpp index 8636253..aaac850 100644 --- a/graphicswin.cpp +++ b/graphicswin.cpp @@ -1203,7 +1203,7 @@ void GraphicsWindow::Paint(int w, int h) { glDisable(GL_LIGHTING); glxLockColorTo(0, 1, 0); glEnable(GL_DEPTH_TEST); -// glxDebugMesh(&br); + glxDebugMesh(&br); br.Clear(); FreeAllTemporary(); diff --git a/mesh.cpp b/mesh.cpp index ef1fd72..b5fd3bf 100644 --- a/mesh.cpp +++ b/mesh.cpp @@ -7,6 +7,10 @@ void SMesh::Clear(void) { void SMesh::AddTriangle(Vector n, Vector a, Vector b, Vector c) { Vector ab = b.Minus(a), bc = c.Minus(b); Vector np = ab.Cross(bc); + if(np.Magnitude() < 1e-10) { + // ugh; gl sometimes tesselates to collinear triangles + return; + } if(np.Dot(n) > 0) { AddTriangle(a, b, c); } else {