Advertisement
FocusedWolf

DebugVectors

Jul 13th, 2011
365
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 12.00 KB | None | 0 0
  1. // Random functions for debugging vectors.
  2.  
  3. function IsVecEqual(vec1, vec2)
  4.     if vec1.x ~= vec2.x or
  5.        vec1.y ~= vec2.y or
  6.        vec1.z ~= vec2.z then
  7.         return false
  8.     end
  9.     return true
  10. end
  11.  
  12. //opacity - optional parameter
  13. function SimpleColor(red, green, blue, opacity)
  14.     if opacity then
  15.         Color(red/255, green/255, blue/255, opacity/100)
  16.     end
  17.  
  18.     return Color(red/255, green/255, blue/255, 1)
  19. end
  20.  
  21. // The vector drawing functions can take an optional color parameter and these make them easier to use.
  22. red = SimpleColor(255, 0, 0)
  23. green = SimpleColor(0, 255, 0)
  24. blue = SimpleColor(0, 0, 255)
  25. white = SimpleColor(255, 255, 255)
  26. yellow = SimpleColor(255, 255, 0)
  27. cyan = SimpleColor(0, 255, 255)
  28. magenta = SimpleColor(255, 0, 255)
  29. orange = SimpleColor(255, 165, 0)
  30. purple = SimpleColor(160, 32, 240)
  31. lime = SimpleColor(50, 205, 50)
  32.  
  33. local lineLifetime = 0.1//0.05 //determines how long the lines linger (if set to small then when running ns2 windowed, the lines will disappear) (if set to large then you see multiple copies of lines if the point moves)
  34.  
  35. local xAxisColor = Color(1,0,0,1)
  36. local yAxisColor = Color(0,1,0,1)
  37. local zAxisColor = Color(0,0,1,1)
  38.  
  39. local xAxisAltColor = Color(0.8, 0.0, 0.5, 1)
  40. local yAxisAltColor = Color(0.0, 1.0, 0.0, 1)
  41. local zAxisAltColor = Color(0.0, 0.5, 0.8, 1)
  42.  
  43. //color - optional parameter
  44. function DrawLine(startPoint, endPoint, color)
  45.     if color then
  46.         DebugLine(startPoint, endPoint, lineLifetime, color.r, color.g, color.b, color.a)
  47.     else
  48.         DebugLine(startPoint, endPoint, lineLifetime, xAxisAltColor.r, xAxisAltColor.g, xAxisAltColor.b, xAxisAltColor.a)
  49.     end
  50. end
  51.  
  52. //based on DrawEntityAxis(entity)
  53. //color - optional parameter to override the axis colors
  54. function DrawEntityXZAxes(entity, color)
  55.  
  56.     // Draw x red, y green, z blue (like 3ds Max)
  57.     local lineLength = 1
  58.     local coords = entity:GetAngles():GetCoords()
  59.     local p0 = entity:GetOrigin()
  60.     p0.y = p0.y + 0.1
  61.  
  62.     if color then
  63.         DebugLine(p0, p0 + coords.xAxis*lineLength, lineLifetime,   color.r, color.g, color.b, color.a)
  64.         //DebugLine(p0, p0 + coords.yAxis*lineLength, lineLifetime, color.r, color.g, color.b, color.a)
  65.         DebugLine(p0, p0 + coords.zAxis*lineLength, lineLifetime,   color.r, color.g, color.b, color.a)
  66.     else
  67.         DebugLine(p0, p0 + coords.xAxis*lineLength, lineLifetime,   xAxisColor.r, xAxisColor.g, xAxisColor.b, xAxisColor.a)
  68.         //DebugLine(p0, p0 + coords.yAxis*lineLength, lineLifetime, yAxisColor.r, yAxisColor.g, yAxisColor.b, yAxisColor.a)
  69.         DebugLine(p0, p0 + coords.zAxis*lineLength, lineLifetime,   zAxisColor.r, zAxisColor.g, zAxisColor.b, zAxisColor.a)
  70.     end
  71. end
  72.  
  73. //based on DrawEntityAxis(entity)
  74. //draws world Axis on player
  75. //color - optional parameter to override the axis colors
  76. function DrawWorldXZAxes(entity, color)
  77.  
  78.     // Draw x red, y green, z blue, but used lighter colors to distinguish from DrawEntityXZAxis and DrawEntityAxis
  79.     local lineLength = 10
  80.     local shortLineLength = 1.25
  81.  
  82.     local p0 = entity:GetOrigin()
  83.     p0.y = p0.y + 0.1
  84.  
  85.     if color then
  86.         DebugLine(p0 - Vector.xAxis*shortLineLength , p0 + Vector.xAxis*lineLength, lineLifetime,   color.r, color.g, color.b, color.a)
  87.         //DebugLine(p0 - Vector.yAxis*shortLineLength , p0 + Vector.yAxis*lineLength, lineLifetime, color.r, color.g, color.b, color.a)
  88.         DebugLine(p0 - Vector.zAxis*shortLineLength , p0 + Vector.zAxis*lineLength, lineLifetime,   color.r, color.g, color.b, color.a)
  89.     else
  90.         DebugLine(p0 - Vector.xAxis*shortLineLength , p0 + Vector.xAxis*lineLength, lineLifetime,   xAxisColor.r, xAxisColor.g, xAxisColor.b, xAxisColor.a)
  91.         //DebugLine(p0 - Vector.yAxis*shortLineLength , p0 + Vector.yAxis*lineLength, lineLifetime, yAxisColor.r, yAxisColor.g, yAxisColor.b, yAxisColor.a)
  92.         DebugLine(p0 - Vector.zAxis*shortLineLength , p0 + Vector.zAxis*lineLength, lineLifetime,   zAxisColor.r, zAxisColor.g, zAxisColor.b, zAxisColor.a)
  93.     end
  94.  
  95. end
  96.  
  97. //color - optional parameter to override the axis colors
  98. function DrawVector(vec, color)
  99.     local vec = Vector(vec)
  100.  
  101.     // Draw x red, y green, z blue (like 3ds Max)
  102.     local lineLength = 0.25
  103.  
  104.     if color then
  105.         DebugLine(vec - Vector.xAxis*lineLength, vec + Vector.xAxis*lineLength, lineLifetime,   color.r, color.g, color.b, color.a)
  106.         //DebugLine(vec - Vector.yAxis*lineLength, vec + Vector.yAxis*lineLength, lineLifetime, color.r, color.g, color.b, color.a)
  107.         DebugLine(vec - Vector.zAxis*lineLength, vec + Vector.zAxis*lineLength, lineLifetime,   color.r, color.g, color.b, color.a)
  108.     else
  109.         DebugLine(vec - Vector.xAxis*lineLength, vec + Vector.xAxis*lineLength, lineLifetime,   xAxisColor.r, xAxisColor.g, xAxisColor.b, xAxisColor.a)
  110.         //DebugLine(vec - Vector.yAxis*lineLength, vec + Vector.yAxis*lineLength, lineLifetime, yAxisColor.r, yAxisColor.g, yAxisColor.b, yAxisColor.a)
  111.         DebugLine(vec - Vector.zAxis*lineLength, vec + Vector.zAxis*lineLength, lineLifetime,   zAxisColor.r, zAxisColor.g, zAxisColor.b, zAxisColor.a)
  112.     end
  113. end
  114.  
  115. //color - optional parameter to override the axis colors
  116. //groundHeight - height above ground, for example use player:GetOrigin().y + 0.1
  117. function DrawVectorOnGround(vec, groundHeight, color)
  118.     local vec = Vector(vec)
  119.  
  120.     // Draw x red, y green, z blue (like 3ds Max)
  121.     local lineLength = 0.25
  122.     vec.y = groundHeight
  123.  
  124.     if color then
  125.         DebugLine(vec, vec + Vector.xAxis*lineLength, lineLifetime,   color.r, color.g, color.b, color.a)
  126.         //DebugLine(vec, vec + Vector.yAxis*lineLength, lineLifetime, color.r, color.g, color.b, color.a)
  127.         DebugLine(vec, vec + Vector.zAxis*lineLength, lineLifetime,   color.r, color.g, color.b, color.a)
  128.     else
  129.         DebugLine(vec, vec + Vector.xAxis*lineLength, lineLifetime,   xAxisAltColor.r, xAxisAltColor.g, xAxisAltColor.b, xAxisAltColor.a)
  130.         //DebugLine(vec, vec + Vector.yAxis*lineLength, lineLifetime, yAxisAltColor.r, yAxisAltColor.g, yAxisAltColor.b, yAxisAltColor.a)
  131.         DebugLine(vec, vec + Vector.zAxis*lineLength, lineLifetime,   zAxisAltColor.r, zAxisAltColor.g, zAxisAltColor.b, zAxisAltColor.a)
  132.     end
  133. end
  134.  
  135. //color - optional parameter to override the axis colors
  136. function DrawVectorPoint(vec, color)
  137.     local vec = Vector(vec)
  138.  
  139.     // Draw x red, y green, z blue (like 3ds Max)
  140.     local lineLength = 0.25
  141.  
  142.     if color then
  143.         DebugLine(vec - Vector.xAxis*lineLength, vec + Vector.xAxis*lineLength, lineLifetime, color.r, color.g, color.b, color.a)
  144.         DebugLine(vec - Vector.yAxis*lineLength, vec + Vector.yAxis*lineLength, lineLifetime, color.r, color.g, color.b, color.a)
  145.         DebugLine(vec - Vector.zAxis*lineLength, vec + Vector.zAxis*lineLength, lineLifetime, color.r, color.g, color.b, color.a)
  146.     else
  147.         DebugLine(vec - Vector.xAxis*lineLength, vec + Vector.xAxis*lineLength, lineLifetime, xAxisAltColor.r, xAxisAltColor.g, xAxisAltColor.b, xAxisAltColor.a)
  148.         DebugLine(vec - Vector.yAxis*lineLength, vec + Vector.yAxis*lineLength, lineLifetime, yAxisAltColor.r, yAxisAltColor.g, yAxisAltColor.b, yAxisAltColor.a)
  149.         DebugLine(vec - Vector.zAxis*lineLength, vec + Vector.zAxis*lineLength, lineLifetime, zAxisAltColor.r, zAxisAltColor.g, zAxisAltColor.b, zAxisAltColor.a)
  150.     end
  151. end
  152.  
  153. //color - optional parameter to override the axis colors
  154. function DrawVectorPointBig(vec, color)
  155.     local vec = Vector(vec)
  156.  
  157.     // Draw x red, y green, z blue (like 3ds Max)
  158.     local lineLength = 0.5
  159.  
  160.     if color then
  161.         DebugLine(vec - Vector.xAxis*lineLength, vec + Vector.xAxis*lineLength, lineLifetime, color.r, color.g, color.b, color.a)
  162.         DebugLine(vec - Vector.yAxis*lineLength, vec + Vector.yAxis*lineLength, lineLifetime, color.r, color.g, color.b, color.a)
  163.         DebugLine(vec - Vector.zAxis*lineLength, vec + Vector.zAxis*lineLength, lineLifetime, color.r, color.g, color.b, color.a)
  164.     else
  165.         DebugLine(vec - Vector.xAxis*lineLength, vec + Vector.xAxis*lineLength, lineLifetime, xAxisAltColor.r, xAxisAltColor.g, xAxisAltColor.b, xAxisAltColor.a)
  166.         DebugLine(vec - Vector.yAxis*lineLength, vec + Vector.yAxis*lineLength, lineLifetime, yAxisAltColor.r, yAxisAltColor.g, yAxisAltColor.b, yAxisAltColor.a)
  167.         DebugLine(vec - Vector.zAxis*lineLength, vec + Vector.zAxis*lineLength, lineLifetime, zAxisAltColor.r, zAxisAltColor.g, zAxisAltColor.b, zAxisAltColor.a)
  168.     end
  169. end
  170.  
  171. //color - optional parameter to override the axis colors
  172. function DrawVectorPointLarge(vec, color) //dedicated to the gorge which is so fat that i coudn't see the point!
  173.     local vec = Vector(vec)
  174.  
  175.     // Draw x red, y green, z blue (like 3ds Max)
  176.     local lineLength = 1
  177.  
  178.     if color then
  179.         DebugLine(vec - Vector.xAxis*lineLength, vec + Vector.xAxis*lineLength, lineLifetime, color.r, color.g, color.b, color.a)
  180.         DebugLine(vec - Vector.yAxis*lineLength, vec + Vector.yAxis*lineLength, lineLifetime, color.r, color.g, color.b, color.a)
  181.         DebugLine(vec - Vector.zAxis*lineLength, vec + Vector.zAxis*lineLength, lineLifetime, color.r, color.g, color.b, color.a)
  182.     else
  183.         DebugLine(vec - Vector.xAxis*lineLength, vec + Vector.xAxis*lineLength, lineLifetime, xAxisAltColor.r, xAxisAltColor.g, xAxisAltColor.b, xAxisAltColor.a)
  184.         DebugLine(vec - Vector.yAxis*lineLength, vec + Vector.yAxis*lineLength, lineLifetime, yAxisAltColor.r, yAxisAltColor.g, yAxisAltColor.b, yAxisAltColor.a)
  185.         DebugLine(vec - Vector.zAxis*lineLength, vec + Vector.zAxis*lineLength, lineLifetime, zAxisAltColor.r, zAxisAltColor.g, zAxisAltColor.b, zAxisAltColor.a)
  186.     end
  187. end
  188.  
  189. //color - optional parameter to override the axis colors
  190. function DrawVectorPointHuge(vec, color) //dedicated to the gorge which is so fat that i coudn't see the point!
  191.     local vec = Vector(vec)
  192.  
  193.     // Draw x red, y green, z blue (like 3ds Max)
  194.     local lineLength = 3
  195.  
  196.     if color then
  197.         DebugLine(vec - Vector.xAxis*lineLength, vec + Vector.xAxis*lineLength, lineLifetime, color.r, color.g, color.b, color.a)
  198.         DebugLine(vec - Vector.yAxis*lineLength, vec + Vector.yAxis*lineLength, lineLifetime, color.r, color.g, color.b, color.a)
  199.         DebugLine(vec - Vector.zAxis*lineLength, vec + Vector.zAxis*lineLength, lineLifetime, color.r, color.g, color.b, color.a)
  200.     else
  201.         DebugLine(vec - Vector.xAxis*lineLength, vec + Vector.xAxis*lineLength, lineLifetime, xAxisAltColor.r, xAxisAltColor.g, xAxisAltColor.b, xAxisAltColor.a)
  202.         DebugLine(vec - Vector.yAxis*lineLength, vec + Vector.yAxis*lineLength, lineLifetime, yAxisAltColor.r, yAxisAltColor.g, yAxisAltColor.b, yAxisAltColor.a)
  203.         DebugLine(vec - Vector.zAxis*lineLength, vec + Vector.zAxis*lineLength, lineLifetime, zAxisAltColor.r, zAxisAltColor.g, zAxisAltColor.b, zAxisAltColor.a)
  204.     end
  205. end
  206.  
  207. //color - optional parameter to override the axis colors
  208. //groundHeight - height above ground, for example use player:GetOrigin().y + 0.1
  209. function DrawVectorPointOnGround(vec, groundHeight, color)
  210.     local vec = Vector(vec)
  211.  
  212.     // Draw x red, y green, z blue (like 3ds Max)
  213.     local lineLength = 0.25
  214.     vec.y = groundHeight
  215.  
  216.     if color then
  217.         DebugLine(vec - Vector.xAxis*lineLength, vec + Vector.xAxis*lineLength, lineLifetime,   color.r, color.g, color.b, color.a)
  218.         //DebugLine(vec - Vector.yAxis*lineLength, vec + Vector.yAxis*lineLength, lineLifetime, color.r, color.g, color.b, color.a)
  219.         DebugLine(vec - Vector.zAxis*lineLength, vec + Vector.zAxis*lineLength, lineLifetime,   color.r, color.g, color.b, color.a)
  220.     else
  221.         DebugLine(vec - Vector.xAxis*lineLength, vec + Vector.xAxis*lineLength, lineLifetime,   xAxisAltColor.r, xAxisAltColor.g, xAxisAltColor.b, xAxisAltColor.a)
  222.         //DebugLine(vec - Vector.yAxis*lineLength, vec + Vector.yAxis*lineLength, lineLifetime, yAxisAltColor.r, yAxisAltColor.g, yAxisAltColor.b, yAxisAltColor.a)
  223.         DebugLine(vec - Vector.zAxis*lineLength, vec + Vector.zAxis*lineLength, lineLifetime,   zAxisAltColor.r, zAxisAltColor.g, zAxisAltColor.b, zAxisAltColor.a)
  224.     end
  225. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement