Advertisement
TheVideoVolcano

THelper Class

Jul 16th, 2015
473
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 2.25 KB | None | 0 0
  1. 'WRITTEN BY HAZARDX/CODEAPARAT/TIM
  2. 'TRANSLATED FROM C++ TO VB.NET BY THEVIDEOVOLCANO
  3.  
  4. Public Class THelper
  5.  
  6.  
  7.     Public Shared Function RadianToDegree(ByVal radians As Double) As Double
  8.  
  9.         Return radians * Convert.ToDouble(180.0 / Math.PI)
  10.  
  11.     End Function
  12.  
  13.     Public Shared Function DegreeToRadian(ByVal degrees As Double) As Double
  14.  
  15.         Return degrees * Convert.ToDouble(Math.PI / 180.0)
  16.  
  17.     End Function
  18.  
  19.     Public Shared Function DirectionToHeading(ByVal dir As GTA.Math.Vector3) As Double
  20.  
  21.         dir.Z = 0.0F
  22.         dir.Normalize()
  23.         Return RadianToDegree(-Math.Atan2(dir.X, dir.Y))
  24.  
  25.     End Function
  26.  
  27.     Public Shared Function HeadingToDirection(ByVal Heading As Double) As GTA.Math.Vector3
  28.  
  29.         Heading = DegreeToRadian(Heading)
  30.         Dim res As GTA.Math.Vector3
  31.         res.X = Convert.ToDouble(-Math.Sin(Heading))
  32.         res.Y = Convert.ToDouble(Math.Cos(Heading))
  33.         res.Z = 0.0F
  34.  
  35.         Return res
  36.     End Function
  37.  
  38.     Public Shared Function DirectionToRotation(ByVal dir As GTA.Math.Vector3, ByVal roll As Double)
  39.         dir = GTA.Math.Vector3.Normalize(dir)
  40.         Dim rotval As GTA.Math.Vector3
  41.         ' Z rotation calculated from the Floor - Vector of Direction . (Normal X and Z)
  42.         rotval.Z = -RadianToDegree(Math.Atan2(dir.X, dir.Y))
  43.         ' X rotation calculated from the angle between the length of the floor and the height Vectors
  44.         Dim rotpos As GTA.Math.Vector3 = GTA.Math.Vector3.Normalize(New GTA.Math.Vector3(dir.Z, New GTA.Math.Vector3(dir.X, dir.Y, 0.0F).Length(), 0.0F))
  45.         rotval.X = RadianToDegree(Math.Atan2(rotpos.X, rotpos.Y))
  46.         rotval.Y = roll 'Roll
  47.         Return rotval
  48.     End Function
  49.  
  50.     Public Shared Function RotationToDirection(ByVal Rotation As GTA.Math.Vector3) As GTA.Math.Vector3
  51.  
  52.         Dim rotZ As Double = DegreeToRadian(Rotation.Z)
  53.         Dim rotX As Double = DegreeToRadian(Rotation.X)
  54.         Dim multiXY As Double = Math.Abs(Convert.ToDouble(Math.Cos(rotX)))
  55.         Dim res As GTA.Math.Vector3
  56.  
  57.         res.X = Convert.ToDouble(-Math.Sin(rotZ)) * multiXY
  58.         res.Y = Convert.ToDouble(Math.Cos(rotZ)) * multiXY
  59.         res.Z = Convert.ToDouble(Math.Sin(rotX))
  60.  
  61.         Return res
  62.     End Function
  63.  
  64.  
  65. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement