Results 1 to 6 of 6
  1. #1
    lolmister is offline Member
    Join Date
    May 2012
    Posts
    11
    Rep Power
    0

    Question Smooth rotation to a desired direction

    I have an image with two variables, current direction, and desired direction. I want the Image to smoothly rotate to the desired direction with momentum, but I can't figure out a way to do this myself, andy help would be appreciated.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Smooth rotation to a desired direction

    Quote Originally Posted by lolmister View Post
    I have an image with two variables, current direction, and desired direction. I want the Image to smoothly rotate to the desired direction with momentum, but I can't figure out a way to do this myself, andy help would be appreciated.
    I can't imagine that we're going to be able to help you much based on this post above as it is way too short on details. Care to show us what you've tried so far? Can you give us a little context? Is this using BufferedImages and Graphics2D, JOGL graphics? Something completely different? Where specifically are you stuck? Come on, please help us out here.

  3. #3
    lolmister is offline Member
    Join Date
    May 2012
    Posts
    11
    Rep Power
    0

    Default Re: Smooth rotation to a desired direction

    sorry, I am using BufferedImages and Graphics2D. I can rotate the image, I just need help getting the rotation smooth. I have tried to have the Image rotate a certain amount every update towards the goal rotation like this:
    Java Code:
    if(currentrotation>desiredrotation)currentrotation-=1;
    		else currentrotation+=1;
    This doesn't compensate for the gap between 0 and 360, and the rotation doesn't have momentum so I am not happy with it.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Smooth rotation to a desired direction

    You have to expect discrete results when you use ints and degrees. Instead use a double variable and radians in your rotation matrix, and use a rotation step of < 1 degree (equivalent to Math.PI / 180 in radians). I assume that you're using an AffineTransform for your rotation. Play with your code and you'll likely smooth things out.

  5. #5
    lolmister is offline Member
    Join Date
    May 2012
    Posts
    11
    Rep Power
    0

    Default Re: Smooth rotation to a desired direction

    Ok, thanks for the tips

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,236
    Rep Power
    19

    Default Re: Smooth rotation to a desired direction

    Moved from Advanced Java

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Replies: 1
    Last Post: 02-13-2012, 02:51 PM
  2. How to scale an image to desired size?
    By asifzbaig in forum AWT / Swing
    Replies: 4
    Last Post: 06-26-2011, 09:07 PM
  3. displaying a desired out put
    By Cubswin in forum New To Java
    Replies: 3
    Last Post: 03-13-2011, 06:05 AM
  4. Replies: 20
    Last Post: 10-21-2009, 03:59 PM
  5. smooth-scroll
    By designer in forum Java Applets
    Replies: 1
    Last Post: 07-21-2009, 07:10 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •