Advertisement
Guest User

Untitled

a guest
Mar 7th, 2014
424
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.92 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using UnityEngine;
  6.  
  7. namespace RustNetLib
  8. {
  9.     public class Angle2
  10.     {
  11.     //Manzarek
  12.         private static readonly float[] eights360;
  13.         public float X { get; set; }
  14.         public float Y { get; set; }
  15.  
  16.         static Angle2()
  17.         {
  18.             eights360 = new float[0x2000];
  19.             for (long i = 0L; i < 0x2000L; i += 1L)
  20.             {
  21.                 eights360[(int)((IntPtr)i)] = (float)((((double)i) / 65536.0) * 360.0);
  22.             }
  23.         }
  24.  
  25.  
  26.         public Angle2(float x, float y)
  27.         {
  28.             // TODO: Complete member initialization
  29.             this.X = x;
  30.             this.Y = y;
  31.         }
  32.  
  33.         public Angle2()
  34.         {
  35.             // TODO: Complete member initialization
  36.         }
  37.  
  38.         public int encoded
  39.         {
  40.             get
  41.             {
  42.                 return ((Encode360(this.Y) << 0x10) | Encode360(this.X));
  43.             }
  44.             set
  45.             {
  46.                 this.X = Decode360(value & 0xffff);
  47.                 this.Y = Decode360((value >> 0x10) & 0xffff);
  48.             }
  49.         }
  50.  
  51.         public Angle2 decoded
  52.         {
  53.             get
  54.             {
  55.                 Angle2 angle = this;
  56.                 angle.encoded = this.encoded;
  57.                 return angle;
  58.             }
  59.         }
  60.  
  61.         public static float Decode360(int x)
  62.         {
  63.             int num = x / 0x2000;
  64.             float num2 = (num * 45f) + eights360[x - (num * 0x2000)];
  65.             return ((num2 >= 180f) ? (num2 - 360f) : num2);
  66.         }
  67.  
  68.  
  69.         public static int Encode360(float x)
  70.         {
  71.             x = Mathf.DeltaAngle(0f, x);
  72.             if (x < 0f)
  73.             {
  74.                 x += 360f;
  75.             }
  76.             switch ((Mathf.FloorToInt(x) / 0x2d))
  77.             {
  78.                 case 0:
  79.                     return Mathf.RoundToInt((float)(x * 182.04444444444445));
  80.  
  81.                 case 1:
  82.                     return (Mathf.RoundToInt((float)((x - 45f) * 182.04444444444445)) + 0x2000);
  83.  
  84.                 case 2:
  85.                     return (Mathf.RoundToInt((float)((x - 90f) * 182.04444444444445)) + 0x4000);
  86.  
  87.                 case 3:
  88.                     return (Mathf.RoundToInt((float)((x - 135f) * 182.04444444444445)) + 0x6000);
  89.  
  90.                 case 4:
  91.                     return (Mathf.RoundToInt((float)((x - 180f) * 182.04444444444445)) + 0x8000);
  92.  
  93.                 case 5:
  94.                     return (Mathf.RoundToInt((float)((x - 225f) * 182.04444444444445)) + 0xa000);
  95.  
  96.                 case 6:
  97.                     return (Mathf.RoundToInt((float)((x - 270f) * 182.04444444444445)) + 0xc000);
  98.  
  99.                 case 7:
  100.                     return (Mathf.RoundToInt((float)((x - 315f) * 182.04444444444445)) + 0xe000);
  101.  
  102.                 case 8:
  103.                     return 0;
  104.             }
  105.             return -1;
  106.         }
  107.     }
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement