added pan and zoom

This commit is contained in:
zzzzrrr 2009-08-07 08:08:42 -04:00
parent f5e83a7af2
commit 072f43d502
3 changed files with 68 additions and 3 deletions

View File

@ -86,7 +86,19 @@ class Poly2TriDemo extends BasicGame("Poly2Tri") {
var currentModel = strange var currentModel = strange
var mouseButton = 0
var mousePressed = false
var mouseDrag = false
var mousePos = Point(0, 0)
var mousePosOld = Point(0, 0)
var deltaX = 0f
var deltaY = 0f
var scaleFactor = 1f
var gameContainer: GameContainer = null
def init(container: GameContainer) { def init(container: GameContainer) {
gameContainer = container
selectModel(currentModel) selectModel(currentModel)
} }
@ -101,6 +113,9 @@ class Poly2TriDemo extends BasicGame("Poly2Tri") {
g.drawString("'m' to show trapezoidal map (debug mode)", 10, 564) g.drawString("'m' to show trapezoidal map (debug mode)", 10, 564)
g.drawString("'e' to switch Seidel / EarClip", 10, 576) g.drawString("'e' to switch Seidel / EarClip", 10, 576)
g.scale(scaleFactor, scaleFactor)
g.translate(deltaX, deltaY)
val red = new Color(1f, 0f,0.0f) val red = new Color(1f, 0f,0.0f)
val blue = new Color(0f, 0f, 1f) val blue = new Color(0f, 0f, 1f)
val green = new Color(0f, 1f, 0f) val green = new Color(0f, 1f, 0f)
@ -180,6 +195,48 @@ class Poly2TriDemo extends BasicGame("Poly2Tri") {
} }
/**
* Handle mouseDown events.
* @param p The screen location that the mouse is down at.
*/
override def mousePressed(b: Int, x: Int, y: Int) {
mouseButton = b
mousePressed = true
mousePosOld = mousePos
mousePos = Point(x, y)
}
/**
* Handle mouseUp events.
*/
override def mouseReleased(b: Int, x: Int, y: Int) {
mousePosOld = mousePos
mousePos = Point(x,y)
mousePressed = false
}
/**
* Handle mouseMove events (TestbedMain also sends mouseDragged events here)
* @param p The new mouse location (screen coordinates)
*/
override def mouseMoved(oldX: Int, oldY: Int, x: Int, y: Int) {
mousePosOld = mousePos
mousePos = Point(x,y)
if(mousePressed) {
deltaX += mousePos.x - mousePosOld.x
deltaY += mousePos.y - mousePosOld.y
}
}
override def mouseWheelMoved(notches: Int) {
if (notches < 0) {
scaleFactor = Math.min(300f, scaleFactor * 1.05f);
}
else if (notches > 0) {
scaleFactor = Math.max(.02f, scaleFactor / 1.05f);
}
}
override def keyPressed(key:Int, c:Char) { override def keyPressed(key:Int, c:Char) {
// ESC // ESC

View File

@ -126,10 +126,15 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
// Implement sweep-line // Implement sweep-line
private def sweep { private def sweep {
//var cTri: Triangle = null //var cTri: Triangle = null
for(i <- 1 until points.size) { for(i <- 1 until 5 /*points.size*/) {
val point = points(i) val point = points(i)
// Process Point event // Process Point event
val triangle = pointEvent(point) var triangle: Triangle = null
try {
triangle = pointEvent(point)
} catch {
case e: Exception => println("Offending triangle = " + i)
}
// Process edge events // Process edge events
point.edges.foreach(e => edgeEvent(e, triangle)) point.edges.foreach(e => edgeEvent(e, triangle))
//if(i == 10) {cTri = triangle; mesh.debug += cTri} //if(i == 10) {cTri = triangle; mesh.debug += cTri}
@ -419,6 +424,7 @@ class CDT(val points: List[Point], val segments: List[Segment], iTriangle: Trian
t2.legalize(oPoint, point) t2.legalize(oPoint, point)
// Update neighbor pointers // Update neighbor pointers
val ccwNeighbor = t2.neighborCCW(oPoint) val ccwNeighbor = t2.neighborCCW(oPoint)
if(ccwNeighbor != null) { if(ccwNeighbor != null) {

View File

@ -54,7 +54,9 @@ class Triangle(val points: Array[Point], val neighbors: Array[Triangle]) {
neighbors(2) = triangle neighbors(2) = triangle
else { else {
mesh += triangle mesh += triangle
//throw new Exception("Neighbor update error") println(ccwPoint + "," + cwPoint)
printDebug
throw new Exception("Neighbor update error")
} }
} }