Pushok

GMod GPU speedometer

Feb 19th, 2013
468
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.54 KB | None | 0 0
  1. #define MAX_SPEED 180
  2.  
  3. dclrscr blue;
  4. dsetwidth 2
  5. dsetsize 20
  6. timer 50
  7. Main();
  8. dexit;
  9.    
  10. float SpeedToAngle(float speed)
  11. {
  12.     float pi;
  13.     fpi pi;
  14.    
  15.     mov ecx, speed;
  16.     div ecx, 180;
  17.     mul ecx, pi;
  18.    
  19.     return ecx;
  20. }
  21.  
  22. void DrawKM()
  23. {
  24.     float pos[2];
  25.     float m, k, i, count;
  26.    
  27.     count = 0;
  28.    
  29.     for(m = count = 0; m <= 180 ; m += (MAX_SPEED / 18))
  30.     {
  31.         float j = SpeedToAngle(m);
  32.         mov ecx, j
  33.         fcos eax, ecx;
  34.         fsin edx, ecx;
  35.        
  36.         k = eax;
  37.         i = edx;
  38.        
  39.         k *= 220;
  40.         i *= 220;
  41.  
  42.         pos[0] = 250 - k;
  43.         pos[1] = 300 - i;
  44.        
  45.         dcolor black
  46.         dline center, pos
  47.         dcolor red
  48.         dwritei pos, m
  49.        
  50.         count += 10;
  51.     }
  52. }
  53.  
  54. float GetVelocity()
  55. {
  56.     float vel;
  57.     mov eax, port1
  58.     div eax, 6.2
  59.     mov vel, eax
  60.    
  61.     return vel
  62. }
  63.  
  64. void DrawArrow(float speed)
  65. {
  66.     if(speed > MAX_SPEED)
  67.         speed = MAX_SPEED;
  68.    
  69.     if(speed < 0)
  70.         speed = 0;
  71.    
  72.     float k, i;
  73.     float pos[2];
  74.    
  75.     float j = SpeedToAngle(speed);
  76.     mov ecx, j
  77.     fcos eax, ecx
  78.     fsin edx, ecx
  79.    
  80.     k = eax
  81.     i = edx
  82.    
  83.     k *= 220
  84.     i *= 220
  85.    
  86.     pos[0] = 250 - k;
  87.     pos[1] = 300 - i;
  88.    
  89.     dcolor green
  90.     dline center, pos
  91. }
  92.  
  93. void Main()
  94. {
  95.     DrawKM();
  96.     DrawArrow(GetVelocity());
  97. }
  98.  
  99.  
  100. color black, 0, 0, 0
  101. color red, 255, 0, 0
  102. color blue, 0, 0,255
  103. color green, 0, 255, 0
  104. vec2f size, 256, 256
  105. vec2f center, 256, 300
Advertisement
Add Comment
Please, Sign In to add comment