Thread: Angle of rotation formula depending on sprite position

  1. #31
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    Quote Originally Posted by tabstop View Post
    If you go further to say 120 degrees, cos(120) is -0.5 and sin(120) is 0.866, so when your arrow points to 11 o'clock you get the point (-0.5, 0.866) which matches.
    yep x is -0.5 and y is -0.866 at 11
    but at 12 y = 1 x = 0
    i get y = -cos i get why we are using cos..but not why negative cos
    i know we're going left from 3,2,...12,11 0,90,120,180.. but how do you know going left is negative?
    You ended that sentence with a preposition...Bastard!

  2. #32
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    Quote Originally Posted by Sipher View Post
    Hey, stop abusing my image!
    ha ha sorry! It was begging to be abused :P
    You ended that sentence with a preposition...Bastard!

  3. #33
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Do you not see "-1" in your picture? We don't use -cos(), it's that cos itself is negative.

  4. #34
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    that was why I asking if maybe that -1 was relevant....
    I was looking for a site to see if it could explain further
    I found this:
    Quadrant trigonometry facts
    all positive from 0-90 on the first quadrant...
    and since the ships heading on the first picture is 90 degrees (the arrow is at 12 o'clock) ..sin and cos are positive..yeah?
    so why -cos(angle)..it doesn't make sense unless we're reading from 90-180 degrees (12 to 9 o'clock) then cos is -
    if so at which point do we decide we are at 12-9 instead of 3-12 when the arrow is facing at 12 o'clock?
    But I think I'm close to understanding this...
    You ended that sentence with a preposition...Bastard!

  5. #35
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    Quote Originally Posted by Eman View Post
    it doesn't make sense unless we're reading from 90-180 degrees (12 to 9 o'clock) then cos is -
    Exactly! Now you're talking! Remember what I said? That your second sprite's angle is +90 the first?

    Quote Originally Posted by Eman View Post
    if so at which point do we decide we are at 12-9 instead of 3-12 when the arrow is facing at 12 o'clock?
    Well, it really doesn't matter. Both give the same result, but i'm not sure i understood your question...
    Devoted my life to programming...

  6. #36
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    Quote Originally Posted by Sipher View Post
    Exactly! Now you're talking! Remember what I said? That your second sprite's angle is +90 the first?
    yep, that you did but then I didn't know about the quadrant's rule my bad .

    Well, it really doesn't matter. Both give the same result, but i'm not sure i understood your question...
    What I mean is since 0 to 90 is +cos
    and 90 to 180 is -cos
    how do I know which of the rule to choose from if it is 90 degrees on the dot?
    You ended that sentence with a preposition...Bastard!

  7. #37
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    Yes, as I said, it doesn't matter because both yield the same result. cos90 is 0.
    Devoted my life to programming...

  8. #38
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    Quote Originally Posted by Sipher View Post
    Yes, as I said, it doesn't matter because both yield the same result. cos90 is 0.
    Yeah, except it won't work until I use a negative cos to find the y axis..i know it yields the same result on the unit circle..but to apply which rule to use for the ships heading makes all the difference
    You ended that sentence with a preposition...Bastard!

  9. #39
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    unless the answer is if the angle is exactly on the dot..if the arrow is pointing straight at 90 we cannot know if it is positive or negative cos..we can only try the one or the other...and whichever works tells us which quadrant in the unit circle we're dealing with.
    You ended that sentence with a preposition...Bastard!

  10. #40
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    Nononono...

    Look, for your first sprite:
    velX = cos(angle)
    velY = sin(angle)

    And for your second sprite:
    velX = sin(angle)
    velY = -cos(angle)

    That's all there is to is!
    Devoted my life to programming...

  11. #41
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    aaah, but why for the 2nd one especially?

    Ok what if the ship was facing 180 degrees? (will check it now)
    You ended that sentence with a preposition...Bastard!

  12. #42
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    lol I tried the formula
    x = -Math.cos(angle)
    y = -Math.sin(angle)
    for 180 degrees
    it worked perfectly for the up why is it not working when going down?..trig is beautiful and confusing as hell..I wish I understood it in secondary school :O

    EDIT:
    it worked with that formula..was editing the wrong file..nifty stuff..
    Thanks lads..gave me a good trig lesson ha ha..sorry I was slow
    Last edited by Eman; 06-01-2011 at 10:58 AM.
    You ended that sentence with a preposition...Bastard!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sprite Rotation and in Direction C# and XNA
    By Eman in forum Game Programming
    Replies: 9
    Last Post: 02-21-2011, 11:06 PM
  2. Sprite Rotation With Sdl
    By Warlax in forum Game Programming
    Replies: 4
    Last Post: 08-15-2006, 12:49 PM
  3. Sprite/Image Rotation in SDL
    By Blizzarddog in forum Game Programming
    Replies: 4
    Last Post: 03-18-2005, 11:19 AM
  4. Sprite rotation
    By kawk in forum Game Programming
    Replies: 1
    Last Post: 01-25-2005, 01:39 PM
  5. sprite rotation in allegro
    By thedumbmutt in forum Game Programming
    Replies: 4
    Last Post: 01-14-2003, 08:43 AM