Results 1 to 7 of 7

Thread: I have no fooking idea...

  1. #1

    Thread Starter
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134

    I have no fooking idea...

    Why, instead of doing a spinning effect, the DrawStar function in this code makes it stretch and skew. Could anyone work this out for me?
    Attached Files Attached Files
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  2. #2
    Fanatic Member riis's Avatar
    Join Date
    Nov 2001
    Posts
    551
    I'll post the changes I've made. I haven't taken into account the performance of the program. Most surely it can be optimized quite a lot. Seeing your programming experience, I'm sure you're capable of it

    1) Two important constants:
    VB Code:
    1. Public Const PI = 3.1415927
    2. Public Const HALFPI = 1.5707963

    2) I've extended your Star UDT:
    VB Code:
    1. Public Type Star
    2.     Phase As Double
    3.     Colour As wRGB
    4.     DestX As Long
    5.     DestY As Long
    6.     Speed As Double
    7.     LumCap As Long
    8.     x As Long
    9.     y As Long
    10. [b]    dist As Long
    11.     ang As Double[/b]
    12. End Type
    Dist and ang will hold the distance and angle of the star, as seen from the center of the picture box (polar coordinates). These will be derived from x and y.

    3) Code modifications to make the starfield actually rotate
    VB Code:
    1. 'COMMENT TO NOT SPIN!
    2.             '.x = CentreX + Cos(Angle * (3.1415926 / 180)) * (CentreX - .x)
    3.             '.y = CentreY + Sin(Angle * (3.1415926 / 180)) * (CentreY - .y)
    4.            
    5.             .dist = Sqr((CentreX - .x) * (CentreX - .x) + (CentreY - .y) * (CentreY - .y))
    6.             .ang = Arctan2(CDbl(CentreY - .y), CDbl(CentreX - .x))
    7.             .x = CentreX + Cos(.ang + Angle * (PI / 180)) * .dist
    8.             .y = CentreY + Sin(.ang + Angle * (PI / 180)) * .dist
    9.         'COMMENT TO NOT SPIN!
    Dist is derived by simply applying Pythagoras.
    Ang is derived by a modified Atn function (named Arctan2) (see modification 4)
    X and Y are calculated accordingly.
    Tip: to reverse the spinning you need to swap either the result of the Cosine or the Sine, not both.

    4) The modified Atn function:
    VB Code:
    1. Public Function Arctan2(y As Double, x As Double) As Double
    2.     If x = 0 Then
    3.         If y > 0 Then
    4.             Arctan2 = HALFPI
    5.         Else
    6.             Arctan2 = -HALFPI
    7.         End If
    8.     ElseIf x > 0 Then
    9.         Arctan2 = Atn(y / x)
    10.     Else
    11.         If y < 0 Then
    12.             Arctan2 = Atn(y / x) - PI
    13.         Else
    14.             Arctan2 = Atn(y / x) + PI
    15.         End If
    16.     End If
    17.  
    18. End Function
    The advantage of this way is that, if you pass x and y separately (instead of y/x), you'll get the angle in the right quadrant of your coordinate system (instead of only the first or fourth quadrant).

  3. #3
    Fanatic Member riis's Avatar
    Join Date
    Nov 2001
    Posts
    551
    I've forgotten to mention a (literally!) side effect.
    Since the starfield is rotating now, there will be some black spaces, depending on the rotation angle. If the angle is 45 degrees (or 135, 225, 315), there are four opposite black triangles in the corners. At angles of 90 and 270 degrees, there are two black sidebars. You'll need to remember the position of those stars as well. (A star might be able to rotate out and into the screen.)
    The distance which you'll need to remember is sqr(2) * (longest side of your screen). In this case no black shapes will show at even square screens.

  4. #4

    Thread Starter
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Hrm thanks, yeah it hasn't been optimised, I made this in like an hour, so what did you expect

    But thanks for that...

    I still don't know why mine didn't work. Oh well.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  5. #5

    Thread Starter
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Works like a charm. However, I can get the top and left destinations to work, but not the bottom and right. I'll figure it out, it only happens when I use the Sqr(2) thing.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  6. #6
    Fanatic Member riis's Avatar
    Join Date
    Nov 2001
    Posts
    551
    You were scaling the starfield itself, not repositioning every individual star.
    Because the position of all stars were modified the same way (by Cos(Angle * (3.1415926 / 180) or Sin(...)) the modification was the same for all stars.
    This resulted in the rescaling and swapping of the entire starfield.

  7. #7

    Thread Starter
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    I dunno... okay I guess you're right, but it works and thats what I care
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

Posting Permissions

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



Click Here to Expand Forum to Full Width