Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-15-2008, 10:06 AM
Member
 
Join Date: Oct 2008
Posts: 44
Rep Power: 0
Unome is on a distinguished road
Default Rotating objects in Java Applets
I am trying to create an Archer in Java.

I want to create an Archer that fires an arrow onto a trajectory path. The trajectory can be changed by pressing the "UP" or "DOWN" arrow key. This will move the arm up and down.

I created the Archer graphic. Its a simple network of lines. To correctly move the Arm to the right cordinate, I solved for the x cordinante of a circle (x-h)^2 + (y-k)^2. That was simple enough. When I change the value for the Y (what you control with the arrow keys) the Arm maintains its size and moves the proper place.

THE PROBLEM

I want to mount a bow on the arm. The endpoint of the line for my arm is in the correct place, but if I place a bow on the arm it remains in the same spot. Is there a way to rotate objects in Java? I already move the arm in place, but to calculate the positions on the bow lines requires calculus... I have to find the tangent line to a circle and thats just to attach a single line to the bow... not to mention making a more complex bow. How do you rotate objects? Thats my main question. Is there a method I can call that I can rotate the rest of the object with? Is there any simpler method of undertaking this task? Its impossible that there isn't... theres so many simple flash games and I think I remember that my guns never skewed when I waved them up and down.

Help would bee appreciated


Archer Applet

PHP Code:
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Line2D;
    
public class 
Archer
{

        private 
double x;
        private 
double y;
        private 
double armY;
        private 
double armX;
        private 
double armxcord;
        private 
double armycord;
        private 
double bowslopex;
        private 
double bowslopey;
        
        public 
Archer(double aXdouble aYdouble yarm)
        {
            
aX;
            
aY;
            
armY yarm;
            if(
armY >= 10)
            {
                
armY 10;
            }
            
        }
        public 
void ArmX()
        {
            
armX Math.sqrt(-Math.pow(armY2)+100);
            
armxcord 18 armX;
            
armycord 10 armY;
        }
        public 
void Bowslant()
        {
            
bowslopex = (armxcord);
        }

        public 
void draw(Graphics2D g2)
        {
            
Ellipse2D.Double head = new Ellipse2D.Double(x,y,10,10);
            
Line2D.Double body = new Line2D.Double(x+4,y+10,x+4,y+10);
            
Line2D.Double arm = new Line2D.Double(x+4,y+10,armxcord armycord );
            
Line2D.Double bow1 = new Line2D.Double(armxcordarmycord,armxcord-armYarmycord-armX);
            
Line2D.Double bow2 = new Line2D.Double(armxcordarmycord,armxcord+armYarmycord+armX);
            
g2.setStroke(new BasicStroke(1));
            
g2.setColor(Color.black);
            
g2.draw(arm);
            
g2.setColor(Color.white);
            
g2.fill(head);
            
g2.setColor(Color.black);
            
g2.draw(head);
            
g2.draw(body);
            
g2.draw(bow1);
            
g2.draw(bow2);
            
            
g2.setStroke(new BasicStroke(1));
        }


Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 10-17-2008, 08:35 AM
Member
 
Join Date: Oct 2008
Posts: 44
Rep Power: 0
Unome is on a distinguished road
Default
I found that g2.rotate(theta, x, y) will rotate any object. I solved my own problem. You can close this if you want
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Rotating and flipping an image in SWT Java Tip SWT 0 07-02-2008 09:01 PM
Java Applets - lifecycle - II JavaForums Java Blogs 0 06-20-2008 04:53 AM
Java Applets - lifecycle - I JavaForums Java Blogs 0 06-20-2008 04:53 AM
reading dir in java applets willemjav Java Applets 3 02-07-2008 01:36 AM
Two Problems Rotating and collision detection help jaferris Java Applets 2 01-08-2008 12:19 AM


All times are GMT +2. The time now is 07:23 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org