Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

using plus equal to

807589Jul 3 2008 — edited Jul 4 2008
hi
to explain what im doing, im trying to get my stick human like animation to move
and if any one can take some precious time out to help me would be much appreciated

what the animation does is that i have a shoulder position elbow position and hand position
the shoulder position doesn't move but the elbow position moves around the shoulder like a orbit
so to speak.

the elbow1curpos represents the current position of the elbow;

my question is why the hell doesn't this work (example below)
        for (double i = 0; i < eighthdeg; i += Math.PI / arc){
        
        elbow1curpos += i;    
        
        Human.xelbowpos = (int)(Human.xsholderpos + shelR * Math.cos(elbow1curpos));
        Human.yelbowpos = (int)(Human.ysholderpos + shelR * Math.sin(elbow1curpos));
        System.out.println(shelR); 
        
        try
        {
        Thread.sleep(50);    
        }
        catch(Exception e){
        System.out.print("Sleep didnt work");    
        }          
        repaint();
        
        }
        }

 // Declear Radius's
    final public double shelR = Math.sqrt( Math.pow((Human.xelbowpos - Human.xsholderpos) , 2) + Math.pow((Human.yelbowpos - Human.ysholderpos) ,2));    
    
    // Declear start position, current
    static public double startpos = Math.PI / 2;
    // current
    static public double elbow1curpos = startpos;
    static public double hand1curpos = startpos;
    
    // degree
    public double wholedeg = Math.PI * 2;
    public double halfdeg = Math.PI;
    public double forthdeg = Math.PI / 2;
    public double sixthdeg = Math.PI / 3;
    public double eighthdeg = Math.PI / 4;
but this does (example below)
        for (double i = 0; i < eighthdeg; i += Math.PI / arc){
        
        elbow1curpos = startpos + i;    
        
        Human.xelbowpos = (int)(Human.xsholderpos + shelR * Math.cos(elbow1curpos));
        Human.yelbowpos = (int)(Human.ysholderpos + shelR * Math.sin(elbow1curpos));
        System.out.println(shelR); 
        
        try
        {
        Thread.sleep(50);    
        }
        catch(Exception e){
        System.out.print("Sleep didn't work");    
        }          
        repaint();
        
        }
        }

 static public double elbow1curpos;
i must be missing something my math seems ok
all im changing is the e.g.
 elbow1curpos += i; 
for
 elbow1curpos = startpos + i;
the reason im using elbow1curpos += i; is that some where down the line ill need to use the current position.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 1 2008
Added on Jul 3 2008
20 comments
120 views