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]
solver
Jonathan Westhues 2008-05-24 05:23:25 -08:00
parent 70ccbebc8f
commit 097d0ddfa9
3 changed files with 8 additions and 3 deletions

View File

@ -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;

View File

@ -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();

View File

@ -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 {