IMKYZABITCHES

Vector (Advanced) - Bitwise

Aug 21st, 2014
621
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 23.90 KB | None | 0 0
  1. //vector.h
  2. #include"stdafx.h"
  3. #include<math.h>
  4. #include<string>
  5. /////////////          ~!DAS!~          //////////////
  6. ////////////////     ~!BITWISE!~     ////////////////
  7. ///////////          ~!MEISTER!~       /////////////
  8. namespace Vector
  9. {
  10.     class V2
  11.     {
  12.     public:
  13.         float x, y;
  14.         V2() : x(0), y(0) {}
  15.         V2(V2&vec) : x(vec.x), y(vec.y) {}
  16.         V2(float xx, float yy) : x(xx), y(yy) {}
  17.         V2(int addr) :  x(*(float*)(addr)), y(*(float*)(addr+4)) {}
  18.         void memset(int addr);
  19.         void debugVector();
  20.         V2 & operator++();
  21.         V2 & operator--();
  22.         bool operator==(V2&vec);
  23.         bool operator!=(V2&vec);
  24.         bool operator>(V2&vec);
  25.         bool operator<(V2&vec);
  26.         bool operator!();
  27.         V2 & operator=(V2&vec);
  28.         V2 & operator=(float value);
  29.         V2 & operator+(V2&vec);
  30.         V2 & operator+(float value);
  31.         V2 & operator-(V2&vec);
  32.         V2 & operator-(float value);
  33.         V2 & operator/(V2&vec);
  34.         V2 & operator/(float vec);
  35.         V2 & operator+=(V2&vec);
  36.         V2 & operator+=(float value);
  37.         V2 & operator-=(V2&vec);
  38.         V2 & operator-=(float value);
  39.         V2 & operator/=(V2&vec);
  40.         V2 & operator/=(float value);
  41.         V2 & operator<<(unsigned int bit);
  42.         V2 & operator<<=(unsigned int bit);
  43.         V2 & operator>>(unsigned int bit);
  44.         V2 & operator>>=(unsigned int bit);
  45.         V2 & operator|(V2&vec);
  46.         V2 & operator|(float value);
  47.         V2 & operator|=(V2&vec);
  48.         V2 & operator|=(float value);
  49.         V2&operator^(V2&vec);
  50.         V2&operator^(float value);
  51.         V2&operator^=(V2&vec);
  52.         V2&operator^=(float value);
  53.         V2&operator&(V2&vec);
  54.         V2&operator&(float value);
  55.         V2&operator&=(V2&vec);
  56.         V2&operator&=(float value);
  57.         V2&operator~();
  58.         V2&operator*(V2&vec);
  59.         V2&operator*(float value);
  60.         V2&operator*=(V2&vec);
  61.         V2&operator*=(float value);
  62.         V2&operator%(V2&vec);
  63.         V2&operator%(float value);
  64.         V2&operator%=(V2&vec);
  65.         V2&operator%=(float value);
  66.         float Length();
  67.         float LengthSquared();
  68.         float Distance(V2&vec);
  69.         float DistanceSquared(V2&vec);
  70.         float Dot(V2&vec);
  71.         float V2Normalize();
  72.         V2&Sin(), &Cos(), &Tan(), &ASin(), &ACos(), &ATan();
  73.         V2&Sin2(), &Cos2(), &Tan2(), &ASin2(), &ACos2(), &ATan2();
  74.         V2&Floor(), &Ceil(), &Sqrt();
  75.         V2&Max(V2&vec);
  76.         V2&vrand(V2&max);
  77.         V2&Normalize();
  78.         bool Closer(V2&line1, V2&line2);
  79.     };
  80.     class V3
  81.     {
  82.     public:
  83.         float x, y, z;
  84.         V3() : x(0), y(0), z(0) {}
  85.         V3(V3&vec) : x(vec.x), y(vec.y), z(vec.z) {}
  86.         V3(float xx, float yy, float zz) : x(xx), y(yy), z(zz) {}
  87.         V3(int addr) : x(*(float*)(addr)), y(*(float*)(addr+4)), z(*(float*)(addr+8)) {}
  88.         void memset(int addr);
  89.         void debugVec();
  90.         V3&operator()(float xx, float yy, float zz);
  91.         V3&operator++();
  92.         V3&operator--();
  93.         bool operator==(V3&vec);
  94.         bool operator!=(V3&vec);
  95.         bool operator>(V3&vec);
  96.         bool operator<(V3&vec);
  97.         bool operator!();
  98.         V3&operator=(V3&vec);
  99.         V3&operator=(float value);
  100.         V3&operator+(V3&vec);
  101.         V3&operator+(float value);
  102.         V3&operator-(V3&vec);
  103.         V3&operator-(float value);
  104.         V3&operator/(V3&vec);
  105.         V3&operator/(float vec);
  106.         V3&operator+=(V3&vec);
  107.         V3&operator+=(float value);
  108.         V3&operator-=(V3&vec);
  109.         V3&operator-=(float value);
  110.         V3&operator/=(V3&vec);
  111.         V3&operator/=(float value);
  112.         V3&operator<<(unsigned int bit);
  113.         V3&operator<<=(unsigned int bit);
  114.         V3&operator>>(unsigned int bit);
  115.         V3&operator>>=(unsigned int bit);
  116.         V3&operator|(V3&vec);
  117.         V3&operator|(float value);
  118.         V3&operator|=(V3&vec);
  119.         V3&operator|=(float value);
  120.         V3&operator^(V3&vec);
  121.         V3&operator^(float value);
  122.         V3&operator^=(V3&vec);
  123.         V3&operator^=(float value);
  124.         V3&operator&(V3&vec);
  125.         V3&operator&(float value);
  126.         V3&operator&=(V3&vec);
  127.         V3&operator&=(float value);
  128.         V3&operator~();
  129.         V3&operator*(V3&vec);
  130.         V3&operator*(float value);
  131.         V3&operator*=(V3&vec);
  132.         V3&operator*=(float value);
  133.         V3&operator%(V3&vec);
  134.         V3&operator%(float value);
  135.         V3&operator%=(V3&vec);
  136.         V3&operator%=(float value);
  137.         float Length();
  138.         float LengthSquared();
  139.         float Distance(V3&vec);
  140.         float DistanceSquared(V3&vec);
  141.         float Dot(V3&vec);
  142.         float V3Normalize();
  143.         V3&Sin(), &Cos(), &Tan(), &ASin(), &ACos(), &ATan();
  144.         V3&Sin2(), &Cos2(), &Tan2(), &ASin2(), &ACos2(), &ATan2();
  145.         V3&Floor(), &Ceil(), &Sqrt();
  146.         V3&Max(V3&vec);
  147.         V3&vrand(V3&max);
  148.         V3&Normalize();
  149.         V3&Lerp(V3&vec, float lerp);
  150.         bool Closer(V3&line1, V3&line2);
  151.     };
  152.     class V4
  153.     {
  154.     public:
  155.         float x, y, z, w;
  156.         V4() : x(0), y(0), z(0), w(0) {}
  157.         V4(float xx, float yy, float zz, float ww) :  x(xx), y(yy), z(zz), w(ww) {}
  158.         V4(V4&vec) : x(vec.x), y(vec.y), z(vec.z), w(vec.w) {}
  159.         V4(int addr) :  x(*(float*)(addr)), y(*(float*)((addr)+4)), z(*(float*)((addr)+8)), w(*(float*)((addr)+0xC)) {}
  160.         void memset(int addr);
  161.         void debugVec();
  162.         V4&operator()(float xx, float yy, float zz, float ww);
  163.         V4&operator++();
  164.         V4&operator--();
  165.         bool operator==(V4&vec);
  166.         bool operator!=(V4&vec);
  167.         bool operator>(V4&vec);
  168.         bool operator<(V4&vec);
  169.         bool operator!();
  170.         V4&operator=(V3&vec);
  171.         V4&operator=(float value);
  172.         V4&operator+(V4&vec);
  173.         V4&operator+(float value);
  174.         V4&operator-(V4&vec);
  175.         V4&operator-(float value);
  176.         V4&operator/(V4&vec);
  177.         V4&operator/(float vec);
  178.         V4&operator+=(V4&vec);
  179.         V4&operator+=(float value);
  180.         V4&operator-=(V4&vec);
  181.         V4&operator-=(float value);
  182.         V4&operator/=(V4&vec);
  183.         V4&operator/=(float value);
  184.         V4&operator<<(unsigned int bit);
  185.         V4&operator<<=(unsigned int bit);
  186.         V4&operator>>(unsigned int bit);
  187.         V4&operator>>=(unsigned int bit);
  188.         V4&operator|(V4&vec);
  189.         V4&operator|(float value);
  190.         V4&operator|=(V4&vec);
  191.         V4&operator|=(float value);
  192.         V4&operator^(V4&vec);
  193.         V4&operator^(float value);
  194.         V4&operator^=(V4&vec);
  195.         V4&operator^=(float value);
  196.         V4&operator&(V4&vec);
  197.         V4&operator&(float value);
  198.         V4&operator&=(V4&vec);
  199.         V4&operator&=(float value);
  200.         V4&operator~();
  201.         V4&operator*(V4&vec);
  202.         V4&operator*(float value);
  203.         V4&operator*=(V4&vec);
  204.         V4&operator*=(float value);
  205.         V4&operator%(V4&vec);
  206.         V4&operator%(float value);
  207.         V4&operator%=(V4&vec);
  208.         V4&operator%=(float value);
  209.         V4&QuatLerp(V4&qb, float frac);
  210.     };
  211. }
  212.  
  213. typedef Vector::V2 vec2;
  214. typedef Vector::V3 vec3;
  215. typedef Vector::V4 vec4;
  216. //vector.cpp
  217. #include"stdafx.h"
  218. #include "vector.h"
  219. #include<random>
  220. #include<time.h>
  221.  
  222. #pragma region Vector2
  223. void vec2::memset(int addr)
  224. {
  225.     *(float*)(addr) = x, *(float*)(addr+4) = y;
  226. }
  227. vec2& vec2::operator++()
  228. {
  229.     x++, y++;
  230.     return V2(x, y);
  231. }
  232. vec2& vec2::operator--()
  233. {
  234.     x--, y--;
  235.     return V2(x, y);
  236. }
  237. bool vec2::operator==(V2&vec)
  238. {
  239.     return (x==vec.x&&y==vec.y);
  240. }
  241. bool vec2::operator!=(V2&vec)
  242. {
  243.     return (x!=vec.x&&y!=vec.y);
  244. }
  245. bool vec2::operator<(V2&vec)
  246. {
  247.     return (x<vec.x&&y<vec.y);
  248. }
  249. bool vec2::operator>(V2&vec)
  250. {
  251.     return (x>vec.x&&y>vec.y);
  252. }
  253. vec2& vec2::operator=(V2&vec)
  254. {
  255.     return V2((x=vec.x), (y=vec.y));
  256. }
  257. vec2& vec2::operator=(float value)
  258. {
  259.     return V2((x=value), (y=value));
  260. }
  261. vec2& vec2::operator-(V2&vec)
  262. {
  263.     return V2(x-vec.x, y-vec.y);
  264. }
  265.  
  266. vec2& vec2::operator<<(unsigned int bit)
  267. {
  268.     int xx = 0, yy = 0;
  269.     while(bit <= 31){
  270.         xx = int(int(x)<< bit), yy = int(int(y) << bit);
  271.         break;
  272.     }
  273.     return V2(float(xx), float(yy));
  274. }
  275. vec2& vec2::operator<<=(unsigned int bit)
  276. {
  277.     int xx = 0, yy = 0;
  278.     while(bit <= 31){
  279.         xx = int(int(x) << bit), yy = int(int(y) << bit);
  280.     }
  281.     return V2(x = float(xx), y = float(yy));
  282. }
  283. vec2& vec2::operator>>(unsigned int bit)
  284. {
  285.     int xx=0,yy=0;
  286.     while(bit <= 31){
  287.         xx = int(int(x) >> bit), yy = int(int(y) >> bit);
  288.         break;
  289.     }
  290.     return V2(float(xx), float(yy));
  291. }
  292. vec2& vec2::operator>>=(unsigned int bit)
  293. {
  294.     int xx=0,yy=0;
  295.     while(bit <= 31){
  296.         xx = int(int(x) >> bit), yy = int(int(y) >> bit);
  297.         break;
  298.     }
  299.     return V2(float(xx), float(yy));
  300. }
  301. vec2& vec2::operator|(V2&vec)
  302. {
  303.     int xx[2] = { int(x), int(vec.x) },
  304.         yy[2] = { int(y), int(vec.y) };
  305.     return V2(float(xx[0] | xx[1]), float(yy[0]|yy[1]));
  306. }
  307. vec2& vec2::operator|(float value)
  308. {
  309.     int xx[2] = { int(x), int(value) },
  310.         yy = int(y);
  311.     return V2(float(xx[0]|xx[1]), float(yy|xx[1]));
  312. }
  313. vec2& vec2::operator|=(V2&vec)
  314. {
  315.     int xx[2] = { int(x), int(vec.x) },
  316.         yy[2] = { int(y), int(vec.y) };
  317.     return V2(x = float(xx[0|xx[1]]), y = float(yy[0]|yy[1]));
  318. }
  319. vec2& vec2::operator|=(float value)
  320. {
  321.     int xx[2] = { int(x), int(value) },
  322.         yy = int(y);
  323.     return V2(x = float(xx[0]|xx[1]), y = float(yy|xx[1]));
  324. }
  325.  
  326. vec2& vec2::operator^(V2&vec)
  327. {
  328.     int xx[2] = { int(x), int(vec.x) },
  329.         yy[2] = { int(y), int(vec.y) };
  330.     return V2(float(xx[0]^xx[1]), float(yy[0]^yy[1]));
  331. }
  332.  
  333. vec2&vec2::operator^(float value)
  334. {
  335.     int xx[2] = { int(x), int(value) },
  336.         yy = int(y);
  337.     return V2(float(xx[0]^xx[1]), float(yy^xx[1]));
  338. }
  339. vec2&vec2::operator^=(V2&vec)
  340. {
  341.     int xx[2] = { int(x), int(vec.x) },
  342.         yy[2] = { int(y), int(vec.y) };
  343.     return V2(x = float(xx[0]^xx[1]), y = float(yy[0]^yy[1]));
  344. }
  345.  
  346. vec2&vec2::operator^=(float value)
  347. {
  348.     int xx[2] = { int(x), int(value) },
  349.         yy = int(y);
  350.     return V2(x = float(xx[0]^xx[1]), y = float(yy^xx[1]));
  351. }
  352.  
  353. vec2& vec2::operator&(V2&vec)
  354. {
  355.     int xx[2] = { int(x), int(vec.x) },
  356.         yy[2] = { int(y), int(vec.y) };
  357.     return V2(float(xx[0]&xx[1]), float(yy[0]&yy[1]));
  358. }
  359. vec2&vec2::operator&(float value)
  360. {
  361.     int xx[2] = { int(x), int(value) },
  362.         yy = int(y);
  363.     return V2(float(xx[0]&xx[1]), float(yy&xx[1]));
  364. }
  365. vec2& vec2::operator&=(V2&vec)
  366. {
  367.     int xx[2] = { int(x), int(vec.x) },
  368.         yy[2] = { int(y), int(vec.y) };
  369.     return V2(x = float(xx[0]&xx[1]), y = float(yy[0]&yy[1]));
  370. }
  371. vec2&vec2::operator&=(float value)
  372. {
  373.     int xx[2] = { int(x), int(value) },
  374.         yy = int(y);
  375.     return V2(x = float(xx[0]&xx[1]), y = float(yy&xx[1]));
  376. }
  377. vec2& vec2::operator~()
  378. {
  379.     int xy[2] = { int(x), int(y) };
  380.     return V2(float(~xy[0]), float(~xy[1]));
  381. }
  382.  
  383. vec2& vec2::operator*(V2&vec)
  384. {
  385.     return V2(x*vec.x,y*vec.y);
  386. }
  387.  
  388. vec2& vec2::operator*(float value)
  389. {
  390.     return V2(x*value, y*value);
  391. }
  392. vec2 & vec2::operator+(float value)
  393. {
  394.     return V2(x+value, y+value);
  395. }
  396.  
  397. vec2&vec2::operator+(V2&vec)
  398. {
  399.     return V2(x+vec.x, y+vec.y);
  400. }
  401.  
  402. vec2& vec2::operator-(float value)
  403. {
  404.     return V2(x-value, y-value);
  405. }
  406.  
  407. vec2& vec2::operator/(V2&vec)
  408. {
  409.     while(vec.x &&  vec.y){
  410.         return V2(x/vec.x, y/vec.y);}
  411.     return V2(0, 0);
  412. }
  413.  
  414. vec2& vec2::operator/(float value)
  415. {
  416.     while(value){
  417.         return V2(x/value, y/value);}
  418.     return V2(0, 0);
  419. }
  420.  
  421. vec2& vec2::operator+=(V2 & vec)
  422. {
  423.     return V2(x += vec.x, y += vec.y);
  424. }
  425.  
  426. vec2&vec2::operator+=(float value)
  427. {
  428.     return V2(x += value, y += value);
  429. }
  430.  
  431. vec2& vec2::operator-=(V2 & vec)
  432. {
  433.     return V2(x -= vec.x, y -= vec.y);
  434. }
  435.  
  436. vec2&vec2::operator-=(float value)
  437. {
  438.     return V2(x -= value, y -= value);
  439. }
  440.  
  441. vec2& vec2::operator/=(V2 & vec)
  442. {
  443.     while(vec.x && vec.y){
  444.         return V2(x /= vec.x, y /= vec.y);}
  445.     return V2(0, 0);
  446. }
  447.  
  448. vec2&vec2::operator/=(float value)
  449. {
  450.     return V2(x /= value, y /= value);
  451. }
  452. vec2&vec2::operator*=(V2&vec)
  453. {
  454.     return V2(x *= vec.x, y *= vec.y);
  455. }
  456. vec2&vec2::operator*=(float value)
  457. {
  458.     return V2(x *= value, y *= value);
  459. }
  460.  
  461. vec2&vec2::operator%(V2&vec)
  462. {
  463.     int xx[2] = { int(x), int(vec.x) },
  464.         yy[2] = { int(y), int(vec.y) };
  465.     xx[0] %= xx[1];
  466.     yy[0] %= yy[1];
  467.     return V2(float(xx[0]), float(yy[0]));
  468. }
  469. vec2&vec2::operator%(float value)
  470. {
  471.     int xx[2] = { int(x), int(value) },
  472.         yy = int(y);
  473.     xx[0] %= xx[1];
  474.     yy %= xx[1];
  475.     return V2(float(xx[0]), float(yy));
  476. }
  477. vec2&vec2::operator%=(V2&vec)
  478. {
  479.     int xx[2] = { int(x), int(vec.x) },
  480.         yy[2] = { int(y), int(vec.y) };
  481.     xx[0] %= xx[1];
  482.     yy[0] %= yy[1];
  483.     return V2(x = float(xx[0]), y = float(yy[0]));
  484. }
  485. vec2&vec2::operator%=(float value)
  486. {
  487.     int xx[2] = { int(x), int(value) },
  488.         yy = int(y);
  489.     xx[0] %= xx[1];
  490.     yy %= xx[1];
  491.     return V2(x = float(xx[0]), y = float(yy));
  492. }
  493.  
  494. float vec2::Length()
  495. {
  496.     return sqrt(y*y+x*x);
  497. }
  498.  
  499. float vec2::LengthSquared()
  500. {
  501.     return (y*y+x*x);
  502. }
  503.  
  504. float vec2::Distance(V2&vec)
  505. {
  506.     return sqrt((x - vec.x)*(x - vec.x) + (x - vec.y) * (x - vec.y));
  507. }
  508.  
  509. float vec2::DistanceSquared(V2&vec)
  510. {
  511.     return ((x - vec.x)*(x - vec.x) + (x - vec.y) * (x - vec.y));
  512. }
  513. vec2& vec2::Sin()
  514. {
  515.     return V2(sin(x), sin(y));
  516. }
  517. vec2& vec2::Cos()
  518. {
  519.     return V2(cos(x), cos(y));
  520. }
  521. vec2& vec2::Tan()
  522. {
  523.     return V2(tan(x), tan(y));
  524. }
  525. vec2& vec2::ASin()
  526. {
  527.     return V2(asin(x), asin(y));
  528. }
  529.  
  530. vec2& vec2::ACos()
  531. {
  532.     return V2(acos(x), acos(y));
  533. }
  534.  
  535. vec2& vec2::ATan()
  536. {
  537.     return V2(atan(x), atan(y));
  538. }
  539.  
  540. vec2& vec2::Sin2()
  541. {
  542.     return V2(sin(x*0.017453292), sin(y*0.017453292));
  543. }
  544.  
  545. vec2& vec2::Cos2()
  546. {
  547.     return V2(cos(x*0.017453292), cos(y*0.017453292));
  548. }
  549.  
  550. vec2& vec2::Tan2()
  551. {
  552.     return V2(tan(x*0.017453292), tan(y*0.017453292));
  553. }
  554.  
  555. vec2& vec2::ASin2()
  556. {
  557.     return V2(asin(x*0.017453292), asin(y*0.017453292));
  558. }
  559.  
  560. vec2& vec2::ACos2()
  561. {
  562.     return V2(acos(x*0.017453292), acos(y*0.017453292));
  563. }
  564.  
  565. vec2&vec2::ATan2()
  566. {
  567.     return V2(atan(x*0.017453292), atan(y*0.017453292));
  568. }
  569.  
  570. vec2& vec2::Floor()
  571. {
  572.     return V2(floor(x), floor(y));
  573. }
  574.  
  575. vec2&vec2::Ceil()
  576. {
  577.     return V2(ceil(x), ceil(y));
  578. }
  579.  
  580. vec2&vec2::Sqrt()
  581. {
  582.     return V2(sqrt(x), sqrt(y));
  583. }
  584.  
  585. bool vec2::operator!()
  586. {
  587.     return (!x && !y);
  588. }
  589.  
  590. vec2&vec2::vrand(V2&max)
  591. {
  592.     float diff = (max.x - x) + (max.y - y);
  593.     srand(time(0) * (int)(time(0) % (int)diff));
  594.     return V2(rand() + int(x)+1 % int(max.x)+1, rand() + int(y)+1 % int(max.y)+1);
  595. }
  596.  
  597. float vec2::Dot(V2&vec)
  598. {
  599.     return ((y*vec.y) + (vec.x * x));
  600. }
  601.  
  602. float vec2::V2Normalize()
  603. {
  604.     float math = 0;
  605.     if(-sqrt(x*x+y*y) < 0) { math = 1.0; } else { math = sqrt(y*y+x*x); }
  606.     x = x * (math / 1.0);
  607.     y = y * (math / 1.0);
  608.     return sqrt(x*x+y*y);
  609. }
  610.  
  611. vec2& vec2::Normalize()
  612. {
  613.     vec2 normal;
  614.     normal.V2Normalize();
  615.     return normal;
  616. }
  617.  
  618. bool vec2::Closer(V2&line1, V2&line2)
  619. {
  620.     return (line1.DistanceSquared(vec2(x, y)) < line2.DistanceSquared(vec2(x, y)));
  621. }
  622.  
  623. vec2& vec2::Max(V2&vec)
  624. {
  625.     return V2(x, y) < vec ? vec : V2(x, y);
  626. }
  627.  
  628. void vec2::debugVector()
  629. {
  630.     printf("x = %f\ny = %f\n", x, y);
  631. }
  632. #pragma endregion
  633. #pragma region Vector3
  634. void vec3::memset(int addr)
  635. {
  636.     *(float*)(addr) = x, *(float*)(addr+4) = y, *(float*)(addr+8) = z;
  637. }
  638.  
  639. void vec3::debugVec()
  640. {
  641.     printf("x = %f\ny = %f\nz = %f\n", x, y, z);
  642. }
  643. vec3& vec3::operator++()
  644. {
  645.     x++, y++, z++;
  646.     return V3(x, y, z);
  647. }
  648. vec3& vec3::operator--()
  649. {
  650.     x--, y--, z--;
  651.     return V3(x, y, z);
  652. }
  653. bool vec3::operator==(V3&vec)
  654. {
  655.     return (x==vec.x&&y==vec.y&&z==vec.z);
  656. }
  657. bool vec3::operator!=(V3&vec)
  658. {
  659.     return (x!=vec.x&&y!=vec.y&&vec.z!=z);
  660. }
  661. bool vec3::operator<(V3&vec)
  662. {
  663.     return (x<vec.x&&y<vec.y&&z<vec.z);
  664. }
  665. bool vec3::operator>(V3&vec)
  666. {
  667.     return (x>vec.x&&y>vec.y&&z>vec.x);
  668. }
  669. vec3& vec3::operator=(V3&vec)
  670. {
  671.     return vec3(x=vec.x, y=vec.y, z=vec.z);
  672. }
  673. vec3& vec3::operator=(float value)
  674. {
  675.     return V3(x = value, y = value, z = value);
  676. }
  677. vec3& vec3::operator-(V3&vec)
  678. {
  679.     return V3(x-vec.x, y-vec.y, z-vec.z);
  680. }
  681.  
  682. vec3& vec3::operator<<(unsigned int bit)
  683. {
  684.     int xx = 0, yy = 0, zz = 0;
  685.     while(bit <= 31){
  686.         xx = int(int(x)<< bit), yy = int(int(y) << bit), zz = int(int(z) << bit);
  687.         break;
  688.     }
  689.     return V3(float(xx), float(yy), float(zz));
  690. }
  691. vec3& vec3::operator<<=(unsigned int bit)
  692. {
  693.     int xx = 0, yy, zz = 0;
  694.     while(bit <= 31){
  695.         xx = int(int(x) << bit), yy = int(int(y) << bit), zz = int(int(z) << bit);
  696.         break;}
  697.     return V3(x = float(xx), y = float(yy), z = float(zz));
  698. }
  699. vec3& vec3::operator>>(unsigned int bit)
  700. {
  701.     int xx=0,yy=0,zz=0;
  702.     while(bit <= 31){
  703.         xx = int(int(x) >> bit), yy = int(int(y) >> bit), zz - int(int(z) >> bit);
  704.         break;}
  705.     return V3(float(xx), float(yy), float(zz));
  706. }
  707. vec3& vec3::operator>>=(unsigned int bit)
  708. {
  709.     int xx=0,yy=0,zz=0;
  710.     while(bit <= 31){
  711.         xx = int(int(x) >> bit), yy = int(int(y) >> bit), zz = int(int(z) << bit);
  712.         break;}
  713.     return V3(x = float(xx), y = float(yy), z = float(zz));
  714. }
  715.  
  716. vec3& vec3::operator|(V3&vec)
  717. {
  718.     int xx[2] = { int(x), int(vec.x) },
  719.         yy[2] = { int(y), int(vec.y) },
  720.         zz[2] = { int(z), int(vec.z) };
  721.     return V3(float(xx[0] | xx[1]), float(yy[0]|yy[1]), float(zz[0]|zz[1]));
  722. }
  723. vec3& vec3::operator|(float value)
  724. {
  725.     int xx[2] = { int(x), int(value) },
  726.         yy = int(y),
  727.         zz = int(z);
  728.     return V3(float(xx[0]|xx[1]), float(yy|xx[1]), float(zz|xx[1]));
  729. }
  730. vec3& vec3::operator|=(V3&vec)
  731. {
  732.     int xx[2] = { int(x), int(vec.x) },
  733.         yy[2] = { int(y), int(vec.y) },
  734.         zz[2] = { int(z), int(vec.z) };
  735.     return V3(x = float(xx[0|xx[1]]), y = float(yy[0]|yy[1]), float(zz[0]|zz[1]));;
  736. }
  737. vec3& vec3::operator|=(float value)
  738. {
  739.     int xx[2] = { int(x), int(value) },
  740.         yy = int(y),
  741.         zz = int(z);
  742.     return V3(x = float(xx[0]|xx[1]), y = float(yy|xx[1]), z = float(zz|xx[1]));
  743. }
  744.  
  745. vec3& vec3::operator^(V3&vec)
  746. {
  747.     int xx[2] = { int(x), int(vec.x) },
  748.         yy[2] = { int(y), int(vec.y) },
  749.         zz[2] = { int(z), int(vec.z) };
  750.     return V3(float(xx[0]^xx[1]), float(yy[0]^yy[1]), float(zz[0]^zz[1]));
  751. }
  752.  
  753. vec3&vec3::operator^(float value)
  754. {
  755.     int xx[2] = { int(x), int(value) },
  756.         yy = int(y),
  757.         zz = int(z);
  758.     return V3(float(xx[0]^xx[1]), float(yy^xx[1]), float(zz^xx[1]));
  759. }
  760. vec3&vec3::operator^=(V3&vec)
  761. {
  762.     int xx[2] = { int(x), int(vec.x) },
  763.         yy[2] = { int(y), int(vec.y) },
  764.         zz[2] = { int(z), int(vec.z) };
  765.     return V3(x = float(xx[0]^xx[1]), y = float(yy[0]^yy[1]), z = float(zz[0]^zz[1]));
  766. }
  767.  
  768. vec3&vec3::operator^=(float value)
  769. {
  770.     int xx[2] = { int(x), int(value) },
  771.         yy = int(y),
  772.         zz = int(z);
  773.     return V3(x = float(xx[0]^xx[1]), y = float(yy^xx[1]), z = float(zz^xx[1]));
  774. }
  775.  
  776. vec3& vec3::operator&(V3&vec)
  777. {
  778.     int xx[2] = { int(x), int(vec.x) },
  779.         yy[2] = { int(y), int(vec.y) },
  780.         zz[2] = { int(z), int(vec.z) };
  781.     return V3(float(xx[0]&xx[1]), float(yy[0]&yy[1]), float(zz[0]&zz[1]));
  782. }
  783. vec3&vec3::operator&(float value)
  784. {
  785.     int xx[2] = { int(x), int(value) },
  786.         yy = int(y),
  787.         zz = int(z);
  788.     return V3(float(xx[0]&xx[1]), float(yy&xx[1]), float(zz&xx[1]));
  789. }
  790. vec3& vec3::operator&=(V3&vec)
  791. {
  792.     int xx[2] = { int(x), int(vec.x) },
  793.         yy[2] = { int(y), int(vec.y) },
  794.         zz[2] = { int(z), int(vec.z) };
  795.     return V3(x = float(xx[0]&xx[1]), y = float(yy[0]&yy[1]), z = float(zz[0]&zz[1]));
  796. }
  797. vec3&vec3::operator&=(float value)
  798. {
  799.     int xx[2] = { int(x), int(value) },
  800.         yy = int(y),
  801.         zz = int(z);
  802.     return V3(x = float(xx[0]&xx[1]), y = float(yy&xx[1]), z = float(zz&xx[1]));
  803. }
  804. vec3& vec3::operator~()
  805. {
  806.     int xyz[3] = { int(x), int(y), int(z) };
  807.     return V3(float(~xyz[0]), float(~xyz[1]), float(~xyz[2]));
  808. }
  809.  
  810. vec3& vec3::operator*(V3&vec)
  811. {
  812.     return V3(x*vec.x,y*vec.y,z*vec.z);
  813. }
  814.  
  815. vec3& vec3::operator*(float value)
  816. {
  817.     return V3(x*value, y*value, z*value);
  818. }
  819. vec3 & vec3::operator+(float value)
  820. {
  821.     return V3(x+value, y+value, z+value);
  822. }
  823.  
  824. vec3&vec3::operator+(V3&vec)
  825. {
  826.     return V3(x+vec.x, y+vec.y, z+vec.z);
  827. }
  828. vec3& vec3::operator-(float value)
  829. {
  830.     return V3(x-value, y-value, z-value);
  831. }
  832.  
  833. vec3& vec3::operator+=(V3 & vec)
  834. {
  835.     return V3(x += vec.x, y += vec.y, z += vec.z);
  836. }
  837.  
  838. vec3&vec3::operator+=(float value)
  839. {
  840.     return V3(x += value, y += value, z += value);
  841. }
  842.  
  843. vec3& vec3::operator-=(V3 & vec)
  844. {
  845.     return V3(x -= vec.x, y -= vec.y, z -= vec.z);
  846. }
  847.  
  848. vec3&vec3::operator-=(float value)
  849. {
  850.     return V3(x -= value, y -= value, z -= value);
  851. }
  852.  
  853. vec3& vec3::operator/=(V3 & vec)
  854. {
  855.     return V3(x /= vec.x, y /= vec.y, z /= vec.z);
  856. }
  857.  
  858. vec3&vec3::operator/=(float value)
  859. {
  860.     return V3(x /= value, y /= value, z /= value);
  861. }
  862. vec3&vec3::operator*=(V3&vec)
  863. {
  864.     return V3(x *= vec.x, y *= vec.y, z *= vec.z);
  865. }
  866. vec3&vec3::operator*=(float value)
  867. {
  868.     return V3(x *= value, y *= value, z *= value);
  869. }
  870.  
  871. vec3&vec3::operator%(V3&vec)
  872. {
  873.     int xx[2] = { int(x), int(vec.x) },
  874.         yy[2] = { int(y), int(vec.y) },
  875.         zz[2] = { int(z), int(vec.z) };
  876.     return V3(float(xx[0]%xx[1]), float(yy[0]%yy[1]), float(zz[0]%zz[1]));
  877. }
  878. vec3&vec3::operator%(float value)
  879. {
  880.     int xx[2] = { int(x), int(value) },
  881.         yy = int(y),
  882.         zz = int(z);
  883.     return V3(float(xx[0]%xx[1]), float(yy%xx[1]), float(zz%xx[1]));
  884. }
  885. vec3&vec3::operator%=(V3&vec)
  886. {
  887.     int xx[2] = { int(x), int(vec.x) },
  888.         yy[2] = { int(y), int(vec.y) },
  889.         zz[2] = { int(z), int(vec.z) };
  890.     return V3(x = float(xx[0]%xx[1]), y = float(yy[0]%yy[1]), z = float(zz[0]%zz[1]));
  891. }
  892. vec3&vec3::operator%=(float value)
  893. {
  894.     int xx[2] = { int(x), int(value) },
  895.         yy = int(y),
  896.         zz = int(z);
  897.     return V3(x = float(xx[0]%xx[1]), y = float(yy%xx[1]), z = float(zz%xx[1]));
  898. }
  899.  
  900. vec3& vec3::Max(vec3&vec)
  901. {
  902.     if(V3(x, y, z) < vec)
  903.     {
  904.         return vec;
  905.     }
  906.     return V3(x, y, z);
  907. }
  908.  
  909. float vec3::Length()
  910. {
  911.     return sqrt(z*z+y*y+x*x);
  912. }
  913.  
  914. float vec3::LengthSquared()
  915. {
  916.     return (z*z+y*y+x*x);
  917. }
  918.  
  919. float vec3::Distance(V3&vec)
  920. {
  921.     return sqrt((y-vec.y)*(y-vec.y) + (z-vec.z)*(z-vec.z) + (x-vec.x)*(x-vec.x));
  922. }
  923.  
  924. float vec3::DistanceSquared(V3&vec)
  925. {
  926.     return ((y-vec.y)*(y-vec.y) + (z-vec.z)*(z-vec.z) + (x-vec.x)*(x-vec.x));
  927. }
  928.  
  929. float vec3::Dot(V3&vec)
  930. {
  931.     return z*vec.z + (y*vec.y + vec.x * x);
  932. }
  933.  
  934. float vec3::V3Normalize()
  935. {
  936.     float math = 0;
  937.     if(-sqrt(x*x+y*y+z*z) < 0) { math = 1.0; } else { math = sqrt(y*y+x*x+z*z); }
  938.     x = x * (math / 1.0);
  939.     y = y * (math / 1.0);
  940.     z = z * (math / 1.0);
  941.     return sqrt(x*x+y*y+z*z);
  942. }
  943.  
  944. vec3& vec3::Normalize()
  945. {
  946.     vec3 normal;
  947.     normal.V3Normalize();
  948.     return normal;
  949. }
  950.  
  951. vec3& vec3::Sin()
  952. {
  953.     return V3(sin(x), sin(y), sin(z));
  954. }
  955. vec3& vec3::Cos()
  956. {
  957.     return V3(cos(x), cos(y), cos(z));
  958. }
  959. vec3& vec3::Tan()
  960. {
  961.     return V3(tan(x), tan(y), tan(z));
  962. }
  963. vec3& vec3::ASin()
  964. {
  965.     return V3(asin(x), asin(y), asin(z));
  966. }
  967.  
  968. vec3& vec3::ACos()
  969. {
  970.     return V3(acos(x), acos(y), acos(z));
  971. }
  972.  
  973. vec3& vec3::ATan()
  974. {
  975.     return V3(atan(x), atan(y), atan(z));
  976. }
  977.  
  978. vec3& vec3::Sin2()
  979. {
  980.     return V3(sin(x*0.017453292), sin(y*0.017453292), sin(z*0.017453292));
  981. }
  982.  
  983. vec3& vec3::Cos2()
  984. {
  985.     return V3(cos(x*0.017453292), cos(y*0.017453292), cos(z*0.017453292));
  986. }
  987.  
  988. vec3& vec3::Tan2()
  989. {
  990.     return V3(tan(x*0.017453292), tan(y*0.017453292), tan(z*0.017453292));
  991. }
  992.  
  993. vec3& vec3::ASin2()
  994. {
  995.     return V3(asin(x*0.017453292), asin(y*0.017453292), asin(z*0.017453292));
  996. }
  997.  
  998. vec3& vec3::ACos2()
  999. {
  1000.     return V3(acos(x*0.017453292), acos(y*0.017453292), acos(z*0.017453292));
  1001. }
  1002.  
  1003. vec3& vec3::ATan2()
  1004. {
  1005.     return V3(atan(x*0.017453292), atan(y*0.017453292), atan(z*0.017453292));
  1006. }
  1007.  
  1008. vec3& vec3::Floor()
  1009. {
  1010.     return V3(floor(x), floor(y), floor(z));
  1011. }
  1012.  
  1013. vec3&vec3::Ceil()
  1014. {
  1015.     return V3(ceil(x), ceil(y), ceil(z));
  1016. }
  1017.  
  1018. vec3&vec3::Sqrt()
  1019. {
  1020.     return V3(sqrt(x), sqrt(y), sqrt(z));
  1021. }
  1022.  
  1023. vec3& vec3::operator()(float xx, float yy, float zz)
  1024. {
  1025.     return V3(xx, yy, zz);
  1026. }
  1027.  
  1028. bool vec3::Closer(V3&line1, V3&line2)
  1029. {
  1030.     return (line1.DistanceSquared(vec3(x, y, z)) < line2.DistanceSquared(vec3(x, y, z)));
  1031. }
  1032.  
  1033. vec3&vec3::vrand(V3&max)
  1034. {
  1035.     float diff = (max.x - x) + (max.y - y) + (max.z - z);
  1036.     srand(time(0) * (int)(time(0) % (int)diff));
  1037.     return V3(rand() + int(x)+1 % int(max.x)+1, rand() + int(y)+1 % int(max.y)+1, rand() + int(z)+1);
  1038. }
  1039.  
  1040. vec3&vec3::Lerp(V3&vec, float lerp)//Seems a lil buggy to me, use with caution
  1041. {
  1042.     return ((V3(x, y, z) - vec) * lerp) + V3(x, y, z);
  1043. }
  1044. #pragma endregion
  1045. //Vector4 still in the works, trying to find some good stuff to include into the class.
  1046.  
  1047. ///////////////////////// Examples //////////////////////////
  1048. /*
  1049.  
  1050.  
  1051.         vec2 vec(0x820000000); //vec will now hold the single precision value of the 2d dynamic array from the current memory pool
  1052.         vec *= 10; //This will multiply each element of the 2d vec with 10, and store it back into itself.
  1053.         vec--; //this will decrease each element
  1054.         vec.memset(0x820001234); //this will set the 2d vec we recently read and set it to a new 2d single precision array
  1055.  
  1056.  
  1057.         vec3 vec(123, 456, 789); //vec will each the 3d vector of each argument, in the exact same order, (x, y, z)
  1058.         if(vec == getOrigin()){ ... } //I have logical operator support, this will return true if each element of vec holds the same value as-
  1059.                                       //what it inside the object getOrigin.
  1060.         vec <<= 16; //I added bitwise support. Normally bitwise operations aren't supported outside of integral data types, but I have added support.
  1061.                     //This will shift each element of vec left by 16 bits, leaving the result looking like (8060928.0, 29884416, 51707904.0)
  1062.         vec |= 10; //This will OR 10 to each element of the vector. The result in this example looking like (80600938.0, 29884426.0, 51707914.0)
  1063.         vec.memset(0x81234567); //Set the 3d vector into a dynamic 3d single precision array in memory
  1064. */
Add Comment
Please, Sign In to add comment