Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2012
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.67 KB | None | 0 0
  1. #include "Vector.h"
  2.  
  3. float vec3Length(vec3 v){
  4.     return v.length();
  5. }
  6.  
  7. float vec3Dot(vec3 v){
  8.     return v.dot();
  9. }
  10.  
  11. float vec3Dot(const vec3 a, const vec3 b){
  12.     return a.x*b.x+a.y*b.y+a.z*b.z;
  13. }
  14.  
  15. vec3 vec3Normalize(vec3 v){
  16.     float l = vec3Length(v);
  17.     v.x /= l;
  18.     v.y /= l;
  19.     v.z /= l;
  20.  
  21.     return v;
  22. }
  23.  
  24. vec3 vec3Cross(const vec3 a, const vec3 b){
  25.     vec3 v;
  26.    
  27.     v.x = (a.y*b.z)-(a.z*b.y);
  28.     v.y = (a.z*b.x)-(a.x*b.z);
  29.     v.z = (a.x*b.y)-(a.y*b.x);
  30.  
  31.     return v;
  32. }
  33.  
  34. vec3 vec3Abs(vec3 v){
  35.     return vec3(abs(v.x), abs(v.y), abs(v.z));
  36. }
  37.  
  38. bool vec3HaveEqualComponent(const vec3 a, const vec3 b){
  39.     if(a.x == b.x || a.y == b.y || a.z == b.z){
  40.         return true;
  41.     }
  42.     else{
  43.         return false;
  44.     }
  45. }
  46.  
  47. float vec3Max(vec3 v){
  48.     float dxy = v.x-v.y;
  49.  
  50.     if(v.x == v.y && v.y == v.z){
  51.         return v.x;
  52.     }
  53.     else if(dxy > 0){
  54.         float dxz = v.x-v.z;
  55.  
  56.         if(dxz > 0){
  57.             return v.x;
  58.         }
  59.         else{
  60.             return v.z;
  61.         }
  62.     }
  63.     else{
  64.         float dyz = v.y-v.z;
  65.  
  66.         if(dyz > 0){
  67.             return v.y;
  68.         }
  69.         else{
  70.             return v.z;
  71.         }
  72.     }
  73. }
  74.  
  75. float vec2Dot(const vec2 v){
  76.     return v.x*v.x+v.y*v.y;
  77. }
  78.  
  79. float vec2Dot(const vec2 a, const vec2 b){
  80.     return a.x*b.x+a.y*b.y;
  81. }
  82.  
  83. float vec2Length(vec2 v){
  84.     return sqrtf(vec2Dot(v));
  85. }
  86.  
  87. vec2 vec2Normalize(vec2 v){
  88.     float l = vec2Length(v);
  89.     v.x /= l;
  90.     v.y /= l;
  91.  
  92.     return v;
  93. }
  94.  
  95. vec2 vec2Abs(vec2 v){
  96.     return vec2(abs(v.x), abs(v.y));
  97. }
  98.  
  99. bool vec2HaveEqualComponent(const vec2 a, const vec2 b){
  100.     if(a.x == b.x || a.y == b.y){
  101.         return true;
  102.     }
  103.     else{
  104.         return false;
  105.     }
  106. }
  107.  
  108. float vec2Max(vec2 v){
  109.     float d = v.x-v.y;
  110.  
  111.     if(d == 0){
  112.         return v.x;
  113.     }
  114.     else if(d > 0){
  115.         return v.x;
  116.     }
  117.     else{
  118.         return v.y;
  119.     }
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement