daily pastebin goal

Round direction vector from an angle

ShadowTzu Oct 2nd, 2014 (edited) 225 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  ''' <summary>
  2. ''' Round a direction vector from an angle in degree
  3. ''' </summary>
  4. Public Shared Function Round_Vector(Vector As Vector2, Angle_Degree As Single) As Vector2
  5.         Angle_Degree = DegToRad(Angle_Degree) 'degree to radian
  6.         Dim angle As Single = CSng(Math.Atan2(Vector.Y, Vector.X))
  7.         If (angle Mod Angle_Degree <> 0) Then
  8.                 Dim newAngle As Single = CSng(Math.Round(angle / Angle_Degree) * Angle_Degree)
  9.                 Return New Vector2(CInt(Math.Cos(newAngle)), CInt(Math.Sin(newAngle)))
  10.         Else
  11.                 Return Vector
  12.         End If
  13. End Function
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand