Hello,
I am having a problem using intersects method of a class I made that extends Polygon. Basically, I am trying to write code that allows the user to drag these polygons. I create a 1x1 rectangle on a mouse press and look through an array to see if the rectangle intersects the polygon. If it does, then I call the polygon's move class, passing the x and y coordinates while the user is dragging. Problem is that it works the first time, but the each time after that, the intersects method is more and more likely to return false. I even drew the rectangle and I can see that the rectangle is sitting right on top of these shapes. Here is the move method of the polygon:
Here is the code in the mouse press that sets the reference to the polygon I want to move:
And here is the code during the drag that actually moves the polygon (works fine if p.intersects(r) above returns true:
I am relatively new to Java and am trying to teach myself, so if I've left out anything that might be critical to anyone being able to help me, please let me know. This has been driving me nuts all night.
Thanks,
Josh
I am having a problem using intersects method of a class I made that extends Polygon. Basically, I am trying to write code that allows the user to drag these polygons. I create a 1x1 rectangle on a mouse press and look through an array to see if the rectangle intersects the polygon. If it does, then I call the polygon's move class, passing the x and y coordinates while the user is dragging. Problem is that it works the first time, but the each time after that, the intersects method is more and more likely to return false. I even drew the rectangle and I can see that the rectangle is sitting right on top of these shapes. Here is the move method of the polygon:
Code:
public void Move(int x_pos, int y_pos) { for (int myY = 0; myY<this.ypoints.length; myY++) this.ypoints[myY] = this.ypoints[myY] + (y_pos-this.y_position); for (int myX=0; myX<this.xpoints.length; myX++) this.xpoints[myX] = this.xpoints[myX] + (x_pos-this.x_position); this.x_position = x_pos; this.y_position = y_pos; }
Code:
for (PenroseShape p : pShapes) { System.out.println(p.x_position + "," + p.y_position); if (p.intersects(r)) { Mover = p; OriginalX = p.x_position; OriginalY = p.y_position; dragging=true; System.out.println("Intersection Found"); } }
Code:
if(dragging) { Mover.Move(OriginalX + (e.getX()-StartDragX),OriginalY+(e.getY()-StartDragY)); System.out.println(Mover.x_position + "," + Mover.y_position); repaint(); }
Thanks,
Josh
Comment