fixed pointer bug

This commit is contained in:
zzzzrrr 2009-08-11 16:24:04 -04:00
parent 8ce22caf63
commit 50848ab60c
4 changed files with 27 additions and 26 deletions

View File

@ -283,11 +283,9 @@ class Poly2TriDemo extends BasicGame("Poly2Tri") {
def selectModel(model: String) {
model match {
case "data/nazca_monkey.dat" =>
//CDT.clearPoint = 50
doCDT = false; drawCDT = false; drawcdtMesh = false
CDT.clearPoint = 50
loadModel(nazcaMonkey, 4.5f, Point(400, 300), 1500)
case "data/bird.dat" =>
doCDT = false; drawCDT = false; drawcdtMesh = false
CDT.clearPoint = 80
loadModel(bird, 25f, Point(400, 300), 350)
case "data/i.snake" =>
@ -307,8 +305,7 @@ class Poly2TriDemo extends BasicGame("Poly2Tri") {
CDT.clearPoint = 7
loadModel(i18, 20f, Point(600f, 500f), 20)
case "data/nazca_heron.dat" =>
doCDT = false; drawCDT = false; drawcdtMesh = false
//CDT.clearPoint = 7
CDT.clearPoint = 7
loadModel(nazcaHeron, 4.5f, Point(400f, 300f), 1500)
case "data/tank.dat" =>
//doCDT = false; drawCDT = false; drawcdtMesh = false

View File

@ -269,17 +269,15 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
// Apply constraint; traverse the AFront, and build triangles
val ahead = (edge.p.x > edge.q.x)
val point1 = if(ahead) edge.q else edge.p
val point2 = if(ahead) edge.p else edge.q
var node = aFront.locate(point1)
val first = node
val points = new ArrayBuffer[Point]
// Neighbor triangles
val nTriangles = new ArrayBuffer[Triangle]
var node = aFront.locate(point1)
val first = node
nTriangles += node.triangle
node = node.next
@ -297,20 +295,30 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
triangulate(points.toArray, endPoints, T)
// Update advancing front
aFront link (first, node, T.first)
// Select edge triangle
var edgeTri: Triangle = null
T.foreach(t =>
if(t.contains(first.point, node.point))
edgeTri = t
)
assert(edgeTri != null)
aFront link (first, node, edgeTri)
// Mark constrained edge
edgeTri mark(edge.p, edge.q)
// Update neighbors
edgeNeighbors(nTriangles, T)
// Mark constrained edge
T.first mark(edge.p, edge.q)
// Return original triangle
triangle
} else {
// Mark constrained edge
if(firstTriangle != null)
firstTriangle mark(edge.p, edge.q)
triangle
}
@ -439,7 +447,7 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
val t2 = node.triangle
val point = t1.points(0)
/*
val oPoint = t2 oppositePoint t1
// Try to avoid creating degenerate triangles
@ -468,13 +476,13 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
aFront.insertLegalized(t1.points(1), t1, node)
} else {
*/
// Update neighbor
t2.markNeighbor(t1)
// Update advancing front
aFront.insert(point, t1, node)
//}
}
}

View File

@ -286,11 +286,9 @@ class Triangle(val points: Array[Point]) {
// Initial mark edges sweep
def mark(p: Point, q: Point) {
if(contains(p) && contains(q)) {
markEdge(p, q)
markNeighborEdge(p, q)
}
}
// Finalize edge marking
def markEdges {

View File

@ -8,7 +8,7 @@ import shapes.Point
object Util {
// Almost zero
val COLLINEAR_SLOP = 0.25f
val COLLINEAR_SLOP = 0.01f
val epsilon = exactinit
val ccwerrboundA = (3.0 + 16.0 * epsilon) * epsilon
@ -124,11 +124,9 @@ object Util {
if ((det >= errbound) || (-det >= errbound)) {
return det
} else {
// Cheat a little bit.... we have a degenerate triangle
val c = pc * 1.00001f
return orient2d(pa, pb, c)
}
}