Results 1 to 3 of 3
Thread: Image Rotating Around Mouse
 06012011, 02:42 AM #1
Image Rotating Around Mouse
I'm trying to make an overhead shooter and I made some code to test my getAngle() method but its not working. It would be awesome if anybody could shed some light as to why the image doesn't rotate correctly.
Java Code:public void paint(Graphics g) { super.paint(g); Graphics2D g2 = (Graphics2D)g; g2.setColor(Color.BLUE); AffineTransform t = new AffineTransform(); t.rotate(turn,origin.x,origin.y); g2.transform(t); g2.fillRect(origin.x25,origin.y25,50,50); g2.fillRect(origin.x+25,origin.y5,50,10); } public void mouseMoved(MouseEvent e) { turn=getAngle(new Point(e.getX(),e.getY())); repaint(); } public double getAngle(Point p) { double rotate; int quad = 0; int width = 0, height = 0; if(p.x==origin.x && p.y>origin.y) { rotate = 90; }else if(p.x==origin.x && p.y<origin.y) { rotate = 90; }else if(p.x>origin.x && p.y==origin.y) { rotate = 0; }else if(p.x<origin.x && p.y==origin.y) { rotate = 180; }else { if(p.x<origin.x && p.y<origin.y) { quad = 1; width = origin.xp.x; height = origin.yp.y; }else if(p.x>origin.x && p.y<origin.y) { quad = 2; width = p.xorigin.x; height = origin.yp.y; }else if(p.x<origin.x && p.y>origin.y) { quad = 3; width = origin.xp.x; height = p.yorigin.y; }else if(p.x>origin.x && p.y>origin.y) { quad = 4; width = p.xorigin.x; height = p.yorigin.y; } rotate = Math.atan(height/width); if(quad==1) { rotate = (rotate*2) + 90; }else if(quad==2) { rotate = (rotate*2); }else if(quad==3) { rotate += 90; }else if(quad==4) { } } turn = rotate; return rotate; }
<Daniel>P.</Berry>
 06012011, 03:34 AM #2why the image doesn't rotate correctly
Also how about adding some comments to describe the logic you are using in the getAngle method
Hard to test this without a class and a main method.
 06012011, 03:36 AM #3Member
 Join Date
 Mar 2011
 Posts
 64
 Rep Power
 0
Similar Threads

Help with Image Rotating?
By Leospaceman in forum Java 2DReplies: 2Last Post: 05312011, 03:48 PM 
Problem in rotating an image
By newtoapplets in forum Java AppletsReplies: 0Last Post: 02282011, 07:12 AM 
Rotating Buffered Image distorts image
By VortexSpin in forum Java 2DReplies: 1Last Post: 02132011, 06:54 AM 
Rotating an image
By lackofcolor in forum Java 2DReplies: 3Last Post: 02282009, 12:54 AM 
Rotating Image?
By sciguy77 in forum Java AppletsReplies: 9Last Post: 02172009, 02:47 AM
Bookmarks