From e5da8e98c86f0e1cb61c0821848a8fcd7849e349 Mon Sep 17 00:00:00 2001 From: zzzzrrr Date: Thu, 30 Jul 2009 21:24:39 -0400 Subject: [PATCH] fixed cdt fill --- src/org/poly2tri/Poly2Tri.scala | 4 +- src/org/poly2tri/cdt/AFront.scala | 7 ---- src/org/poly2tri/cdt/CDT.scala | 69 ++++++++++++++----------------- 3 files changed, 33 insertions(+), 47 deletions(-) diff --git a/src/org/poly2tri/Poly2Tri.scala b/src/org/poly2tri/Poly2Tri.scala index b07f11a..3e0e91e 100644 --- a/src/org/poly2tri/Poly2Tri.scala +++ b/src/org/poly2tri/Poly2Tri.scala @@ -85,7 +85,7 @@ class Poly2TriDemo extends BasicGame("Poly2Tri") { val strange = "data/strange.dat" val i18 = "data/i.18" - var currentModel = star + var currentModel = nazcaMonkey def init(container: GameContainer) { selectModel(currentModel) @@ -125,7 +125,7 @@ class Poly2TriDemo extends BasicGame("Poly2Tri") { } } - if(!debug && !drawEarClip) { + if(!debug && !drawEarClip && !drawCDT) { var i = 0 for(t <- seidel.polygons) { val poly = new Polygon diff --git a/src/org/poly2tri/cdt/AFront.scala b/src/org/poly2tri/cdt/AFront.scala index 0ab88a2..d7068b4 100644 --- a/src/org/poly2tri/cdt/AFront.scala +++ b/src/org/poly2tri/cdt/AFront.scala @@ -74,13 +74,6 @@ class AFront(iTriangle: Triangle) { node.triangle = triangle } - def -==(tuple: Tuple3[Node, Node, Triangle]) { - val (node, kNode, triangle) = tuple - kNode.prev.next = node - node.prev = kNode.prev - node.prev.triangle = triangle - } - } class Node(val point: Point, var triangle: Triangle) { diff --git a/src/org/poly2tri/cdt/CDT.scala b/src/org/poly2tri/cdt/CDT.scala index d7b9dce..48b3e4a 100644 --- a/src/org/poly2tri/cdt/CDT.scala +++ b/src/org/poly2tri/cdt/CDT.scala @@ -158,47 +158,40 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian def march(n: Node) { - var node = n - /* + var node = n.next // Update right - if(node.next != aFront.tail) { - var a = (node.point - node.next.point) - var b = (node.next.next.point - node.next.point) - var angle = Math.atan2(a cross b, a dot b) - while(node != aFront.tail && angle > -Math.Pi*0.5f) { - if(angle >= -Math.Pi*0.5f) { - val points = Array(node.next.point, node.next.next.point, node.point) - val neighbors = Array(null, node.triangle, node.next.triangle) - val triangle = new Triangle(points, neighbors) - mesh.map += triangle - aFront -= (node, node.next, triangle) - } - node = node.next - a = (node.point - node.next.point) - b = (node.next.next.point - node.next.point) - angle = Math.atan2(a cross b, a dot b) - } - } - */ - node = n - - // Update left - if(node.prev != aFront.head) { + if(node.next != null) { var angle = 0.0 - while(node != aFront.head.next && angle < Math.Pi*0.5f) { - val a = (node.point - node.prev.point) - val b = (node.prev.prev.point - node.prev.point) - angle = Math.abs(Math.atan2(a cross b, a dot b)) - if(angle <= Math.Pi*0.5f) { - val points = Array(node.prev.point, node.prev.prev.point, node.point) - val neighbors = Array(null, node.triangle, node.prev.triangle) - val triangle = new Triangle(points, neighbors) - mesh.map += triangle - aFront -== (node, node.prev, triangle) - } - node = node.prev - } + do { + angle = fill(node) + node = node.next + } while(angle <= Math.Pi*0.5 && node.next != null) } + + node = n.prev + // Update left + if(node.prev != null) { + var angle = 0.0 + do { + angle = fill(node) + node = node.prev + } while(angle <= Math.Pi*0.5f && node.prev != null) + } + } + + def fill(node: Node) = { + + val a = (node.prev.point - node.point) + val b = (node.next.point - node.point) + val angle = Math.abs(Math.atan2(a cross b, a dot b)) + if(angle <= Math.Pi*0.5f) { + val points = Array(node.point, node.next.point, node.prev.point) + val neighbors = Array(null, node.prev.triangle, node.triangle) + val triangle = new Triangle(points, neighbors) + mesh.map += triangle + aFront -= (node.prev, node, triangle) + } + angle } private def finalization {