cgprojectsfx

Odd

Feb 13th, 2018
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 16.06 KB | None | 0 0
  1. #pragma once
  2.  
  3. class ulong64;
  4.  
  5. template<typename atype> class aeVector4 {
  6. public:
  7.     aeVector4();
  8.     aeVector4(atype xin, atype yin, atype zin, atype hin);
  9.     virtual ~aeVector4();
  10.  
  11.     // standard arithmetic operators
  12.     inline aeVector4<atype> operator+(const aeVector4<atype>& param);
  13.     inline aeVector4<atype> operator-(const aeVector4<atype>& param);
  14.     inline aeVector4<atype> operator*(const aeVector4<atype>& param);
  15.     inline aeVector4<atype> operator/(const aeVector4<atype>& param);
  16.     inline aeVector4<atype> operator%(const aeVector4<atype>& param);
  17.     inline aeVector4<atype> operator+=(const aeVector4<atype>& param);
  18.     inline aeVector4<atype> operator-=(const aeVector4<atype>& param);
  19.     inline aeVector4<atype> operator*=(const aeVector4<atype>& param);
  20.     inline aeVector4<atype> operator/=(const aeVector4<atype>& param);
  21.     inline aeVector4<atype> operator%=(const aeVector4<atype>& param);
  22.  
  23.     // bitwise operators
  24.     inline aeVector4<atype> operator~();;
  25.     inline aeVector4<atype> operator&(const aeVector4<atype>& param);
  26.     inline aeVector4<atype> operator|(const aeVector4<atype>& param);
  27.     inline aeVector4<atype> operator^(const aeVector4<atype>& param);
  28.     inline aeVector4<atype> operator<<(const aeVector4<atype>& param);
  29.     inline aeVector4<atype> operator>>(const aeVector4<atype>& param);
  30.     inline aeVector4<atype> operator&=(const aeVector4<atype>& param);
  31.     inline aeVector4<atype> operator^=(const aeVector4<atype>& param);
  32.     inline aeVector4<atype> operator|=(const aeVector4<atype>& param);
  33.     inline aeVector4<atype> operator<<=(const aeVector4<atype>& param);
  34.     inline aeVector4<atype> operator>>=(const aeVector4<atype>& param);
  35.  
  36.     // standard arithmetic operators
  37.     inline aeVector4<atype> operator+(const atype& param);
  38.     inline aeVector4<atype> operator-(const atype& param);
  39.     inline aeVector4<atype> operator*(const atype& param);
  40.     inline aeVector4<atype> operator/(const atype& param);
  41.     inline aeVector4<atype> operator%(const atype& param);
  42.     inline aeVector4<atype> operator+=(const atype& param);
  43.     inline aeVector4<atype> operator-=(const atype& param);
  44.     inline aeVector4<atype> operator*=(const atype& param);
  45.     inline aeVector4<atype> operator/=(const atype& param);
  46.     inline aeVector4<atype> operator%=(const atype& param);
  47.  
  48.     inline aeVector4<atype> operator/(const atype val) const;
  49.  
  50.     // bitwise operators
  51.     inline aeVector4<atype> operator&(const atype& param);
  52.     inline aeVector4<atype> operator|(const atype& param);
  53.     inline aeVector4<atype> operator^(const atype& param);
  54.     inline aeVector4<atype> operator<<(const atype& param);
  55.     inline aeVector4<atype> operator>>(const atype& param);
  56.     inline aeVector4<atype> operator&=(const atype& param);
  57.     inline aeVector4<atype> operator^=(const atype& param);
  58.     inline aeVector4<atype> operator|=(const atype& param);
  59.     inline aeVector4<atype> operator<<=(const atype& param);
  60.     inline aeVector4<atype> operator>>=(const atype& param);
  61.  
  62.     // non standard
  63.     inline aeVector4<atype> operator-(aeVector4<atype> param) const;
  64.     inline aeVector4<atype> operator+(aeVector4<atype> param) const;
  65.  
  66.     // Math Functions;
  67.     inline atype Dot(const aeVector4<atype> param) const;
  68.     inline atype GetLength() const;
  69.     inline atype SquaredLength() const;
  70.     inline aeVector4<atype> GetNormalized() const;
  71.     inline aeVector4<atype> Normalize();
  72.  
  73.     // Get position
  74.     inline Vector3 GetVector3() const;
  75.     inline atype GetHeight() const;
  76.  
  77.     // three default values
  78.     atype x;
  79.     atype y;
  80.     atype z;
  81.     atype h;
  82. };
  83.  
  84. // code
  85.  
  86. // constructor
  87. template<typename atype> aeVector4<atype>::aeVector4() :
  88.         x(0), y(0), z(0), h(0) {
  89.     return;
  90. }
  91.  
  92. // constructor
  93. template<typename atype> aeVector4<atype>::aeVector4(atype inx, atype iny, atype inz, atype inh) :
  94.         x(inx), y(iny), z(inz), h(inh) {
  95.     return;
  96. }
  97.  
  98. // deconstructor
  99. template<typename atype> aeVector4<atype>::~aeVector4() {
  100.     return;
  101. }
  102.  
  103.  
  104. template<typename atype> aeVector4<atype> aeVector4<atype>::operator/(const atype val) const
  105. {
  106.   return aeVector4(x / val, y / val, z / val, h/val);
  107. }
  108.  
  109. // operator functions
  110. template<typename atype> aeVector4<atype> aeVector4<atype>::operator+(
  111.         const aeVector4<atype>& param) {
  112.     // create a temp
  113.     aeVector4<atype> temp;
  114.  
  115.     // add values
  116.     temp.x = x + param.x;
  117.     temp.y = y + param.y;
  118.     temp.z = z + param.z;
  119.     temp.h = h + param.h;
  120.  
  121.     return temp;
  122. }
  123.  
  124. // operator functions
  125. template<typename atype> aeVector4<atype> aeVector4<atype>::operator-(
  126.         const aeVector4<atype>& param) {
  127.     // create a temp
  128.     aeVector4<atype> temp;
  129.  
  130.     // add values
  131.     temp.x = x - param.x;
  132.     temp.y = y - param.y;
  133.     temp.z = z - param.z;
  134.     temp.h = h - param.h;
  135.  
  136.     return temp;
  137. }
  138.  
  139. // operator functions
  140. template<typename atype> aeVector4<atype> aeVector4<atype>::operator*(
  141.         const aeVector4<atype>& param) {
  142.     // create a temp
  143.     aeVector4<atype> temp;
  144.  
  145.     // add values
  146.     temp.x = x * param.x;
  147.     temp.y = y * param.y;
  148.     temp.z = z * param.z;
  149.     temp.h = h * param.h;
  150.  
  151.     return temp;
  152. }
  153.  
  154. // operator functions
  155. template<typename atype> aeVector4<atype> aeVector4<atype>::operator/(
  156.         const aeVector4<atype>& param) {
  157.     // create a temp
  158.     aeVector4<atype> temp;
  159.  
  160.     // add values
  161.     temp.x = x / param.x;
  162.     temp.y = y / param.y;
  163.     temp.z = z / param.z;
  164.     temp.h = h / param.h;
  165.  
  166.     return temp;
  167. }
  168.  
  169. // operator functions
  170. template<typename atype> aeVector4<atype> aeVector4<atype>::operator%(
  171.         const aeVector4<atype>& param) {
  172.     // create a temp
  173.     aeVector4<atype> temp;
  174.  
  175.     // add values
  176.     temp.x = x % param.x;
  177.     temp.y = y % param.y;
  178.     temp.z = z % param.z;
  179.     temp.h = h % param.h;
  180.  
  181.     return temp;
  182. }
  183.  
  184. // bitwise operators
  185. // bitwise NOT
  186. template<typename atype> aeVector4<atype> aeVector4<atype>::operator~() {
  187.  
  188.     // add values
  189.     ~x;
  190.     ~y;
  191.     ~z;
  192.     ~h;
  193.  
  194.     return *this;
  195. }
  196.  
  197. // bitwise AND
  198. template<typename atype> aeVector4<atype> aeVector4<atype>::operator&(
  199.         const aeVector4<atype>& param) {
  200.     // create a temp
  201.     aeVector4<atype> temp;
  202.  
  203.     // add values
  204.     temp.x = x & param.x;
  205.     temp.y = y & param.y;
  206.     temp.z = z & param.z;
  207.     temp.h = h & param.h;
  208.  
  209.     return temp;
  210. }
  211.  
  212. //bitwise OR
  213. template<typename atype> aeVector4<atype> aeVector4<atype>::operator|(
  214.         const aeVector4<atype>& param) {
  215.     // create a temp
  216.     aeVector4<atype> temp;
  217.  
  218.     // add values
  219.     temp.x = x | param.x;
  220.     temp.y = y | param.y;
  221.     temp.z = z | param.z;
  222.     temp.h = h | param.h;
  223.  
  224.  
  225.     return temp;
  226. }
  227.  
  228. //bitwise XOR
  229. template<typename atype> aeVector4<atype> aeVector4<atype>::operator^(
  230.         const aeVector4<atype>& param) {
  231.     // create a temp
  232.     aeVector4<atype> temp;
  233.  
  234.     // add values
  235.     temp.x = x ^ param.x;
  236.     temp.y = y ^ param.y;
  237.     temp.z = z ^ param.z;
  238.     temp.h = h ^ param.h;
  239.  
  240.     return temp;
  241. }
  242.  
  243. //bitwise left
  244. template<typename atype> aeVector4<atype> aeVector4<atype>::operator<<(
  245.         const aeVector4<atype>& param) {
  246.     // create a temp
  247.     aeVector4<atype> temp;
  248.  
  249.     // add values
  250.     temp.x = x << param.x;
  251.     temp.y = y << param.y;
  252.     temp.z = z << param.z;
  253.     temp.h = h << param.h;
  254.  
  255.     return temp;
  256. }
  257.  
  258. // bitwise right
  259. template<typename atype> aeVector4<atype> aeVector4<atype>::operator>>(
  260.         const aeVector4<atype>& param) {
  261.     // create a temp
  262.     aeVector4<atype> temp;
  263.  
  264.     // add values
  265.     temp.x = x >> param.x;
  266.     temp.y = y >> param.y;
  267.     temp.z = z >> param.z;
  268.     temp.h = h >> param.h;
  269.  
  270.     return temp;
  271. }
  272.  
  273. //bitwise AND=
  274. template<typename atype> aeVector4<atype> aeVector4<atype>::operator&=(
  275.         const aeVector4<atype>& param) {
  276.     // create a temp
  277.     aeVector4<atype> temp;
  278.  
  279.     // add values
  280.     x &= param.x;
  281.     y &= param.y;
  282.     z &= param.z;
  283.     h &= param.h;
  284.  
  285.     return *this;
  286. }
  287.  
  288. // bitwise OR =
  289. template<typename atype> aeVector4<atype> aeVector4<atype>::operator|=(
  290.         const aeVector4<atype>& param) {
  291.     // create a temp
  292.     aeVector4<atype> temp;
  293.  
  294.     // add values
  295.     x |= param.x;
  296.     y |= param.y;
  297.     z |= param.z;
  298.     h |= param.h;
  299.  
  300.     return *this;
  301. }
  302.  
  303. // bitwise XOR =
  304. template<typename atype> aeVector4<atype> aeVector4<atype>::operator^=(
  305.         const aeVector4<atype>& param) {
  306.     // create a temp
  307.     aeVector4<atype> temp;
  308.  
  309.     // add values
  310.     x ^= param.x;
  311.     y ^= param.y;
  312.     z ^= param.z;
  313.     h ^= param.h;
  314.  
  315.     return *this;
  316. }
  317.  
  318. // bitwise left by x =
  319. template<typename atype> aeVector4<atype> aeVector4<atype>::operator<<=(
  320.         const aeVector4<atype>& param) {
  321.     x <<= param.x;
  322.     y <<= param.y;
  323.     z <<= param.z;
  324.     h <<= param.h;
  325.  
  326.     return *this;
  327. }
  328.  
  329. // bitwise right by x=
  330. template<typename atype> aeVector4<atype> aeVector4<atype>::operator>>=(
  331.         const aeVector4<atype>& param) {
  332.     x >>= param.x;
  333.     y >>= param.y;
  334.     z >>= param.z;
  335.     h >>= param.h;
  336.  
  337.     return *this;
  338. }
  339.  
  340. // operator functions
  341. template<typename atype> aeVector4<atype> aeVector4<atype>::operator+=(
  342.         const aeVector4<atype>& param) {
  343.  
  344.     // add values
  345.     x += param.x;
  346.     y += param.y;
  347.     z += param.z;
  348.     h += param.h;
  349.  
  350.     return *this;
  351. }
  352.  
  353. // operator functions
  354. template<typename atype> aeVector4<atype> aeVector4<atype>::operator-=(
  355.         const aeVector4<atype>& param) {
  356.     // create a temp
  357.     // add values
  358.     x -= param.x;
  359.     y -= param.y;
  360.     z -= param.z;
  361.     h -= param.h;
  362.  
  363.     return *this;
  364. }
  365.  
  366. // operator functions
  367. template<typename atype> aeVector4<atype> aeVector4<atype>::operator*=(
  368.         const aeVector4<atype>& param) {
  369.     // add values
  370.     x *= param.x;
  371.     y *= param.y;
  372.     z *= param.z;
  373.     h *= param.h;
  374.  
  375.     return *this;
  376. }
  377.  
  378. // operator functions
  379. template<typename atype> aeVector4<atype> aeVector4<atype>::operator%=(
  380.         const aeVector4<atype>& param) {
  381.     // add values
  382.     x %= param.x;
  383.     y %= param.y;
  384.     z %= param.z;
  385.     h %= param.h;
  386.  
  387.     return *this;
  388. }
  389.  
  390.  
  391. // operator functions
  392. template<typename atype> aeVector4<atype> aeVector4<atype>::operator/=(
  393.         const aeVector4<atype>& param) {
  394.     // add values
  395.     x /= param.x;
  396.     y /= param.y;
  397.     z /= param.z;
  398.     h /= param.h;
  399.  
  400.     return *this;
  401. }
  402. // operator functions
  403. template<typename atype> aeVector4<atype> aeVector4<atype>::operator+(
  404.         const atype& param) {
  405.     // create a temp
  406.     aeVector4<atype> temp;
  407.  
  408.     // add values
  409.     temp.x = x + param;
  410.     temp.y = y + param;
  411.     temp.z = z + param;
  412.     temp.h = h + param;
  413.  
  414.     return temp;
  415. }
  416.  
  417. // operator functions
  418. template<typename atype> aeVector4<atype> aeVector4<atype>::operator-(
  419.         const atype& param) {
  420.     // create a temp
  421.     aeVector4<atype> temp;
  422.  
  423.     // add values
  424.     temp.x = x - param;
  425.     temp.y = y - param;
  426.     temp.z = z - param;
  427.     temp.h = h - param;
  428.  
  429.     return temp;
  430. }
  431.  
  432. // operator functions
  433. template<typename atype> aeVector4<atype> aeVector4<atype>::operator*(
  434.         const atype& param) {
  435.     // create a temp
  436.     aeVector4<atype> temp;
  437.  
  438.     // add values
  439.     temp.x = x * param;
  440.     temp.y = y * param;
  441.     temp.z = z * param;
  442.     temp.h = h * param;
  443.  
  444.  
  445.     return temp;
  446. }
  447.  
  448. // operator functions
  449. template<typename atype> aeVector4<atype> aeVector4<atype>::operator/(
  450.         const atype& param) {
  451.     // create a temp
  452.     aeVector4<atype> temp;
  453.  
  454.     // add values
  455.     temp.x = x / param;
  456.     temp.y = y / param;
  457.     temp.z = z / param;
  458.     temp.h = h / param;
  459.  
  460.     return temp;
  461. }
  462.  
  463. // operator functions
  464. template<typename atype> aeVector4<atype> aeVector4<atype>::operator%(
  465.         const atype& param) {
  466.     // create a temp
  467.     aeVector4<atype> temp;
  468.  
  469.     // add values
  470.     temp.x = x % param;
  471.     temp.y = y % param;
  472.     temp.z = z % param;
  473.     temp.h = h % param;
  474.  
  475.     return temp;
  476. }
  477.  
  478.  
  479. // bitwise AND
  480. template<typename atype> aeVector4<atype> aeVector4<atype>::operator&(
  481.         const atype& param) {
  482.     // create a temp
  483.     aeVector4<atype> temp;
  484.  
  485.     // add values
  486.     temp.x = x & param;
  487.     temp.y = y & param;
  488.     temp.z = z & param;
  489.     temp.h = h & param;
  490.  
  491.     return temp;
  492. }
  493.  
  494. //bitwise OR
  495. template<typename atype> aeVector4<atype> aeVector4<atype>::operator|(
  496.         const atype& param) {
  497.     // create a temp
  498.     aeVector4<atype> temp;
  499.  
  500.     // add values
  501.     temp.x = x | param;
  502.     temp.y = y | param;
  503.     temp.z = z | param;
  504.     temp.h = h | param;
  505.  
  506.     return temp;
  507. }
  508.  
  509. //bitwise XOR
  510. template<typename atype> aeVector4<atype> aeVector4<atype>::operator^(
  511.         const atype& param) {
  512.     // create a temp
  513.     aeVector4<atype> temp;
  514.  
  515.     // add values
  516.     temp.x = x ^ param;
  517.     temp.y = y ^ param;
  518.     temp.z = z ^ param;
  519.     temp.h = h ^ param;
  520.  
  521.     return temp;
  522. }
  523.  
  524. //bitwise left
  525. template<typename atype> aeVector4<atype> aeVector4<atype>::operator<<(
  526.         const atype& param) {
  527.     // create a temp
  528.     aeVector4<atype> temp;
  529.  
  530.     // add values
  531.     temp.x = x << param;
  532.     temp.y = y << param;
  533.     temp.z = z << param;
  534.     temp.h = h << param;
  535.  
  536.     return temp;
  537. }
  538.  
  539. // bitwise right
  540. template<typename atype> aeVector4<atype> aeVector4<atype>::operator>>(
  541.         const atype& param) {
  542.     // create a temp
  543.     aeVector4<atype> temp;
  544.  
  545.     // add values
  546.     temp.x = x >> param;
  547.     temp.y = y >> param;
  548.     temp.z = z >> param;
  549.     temp.h = h >> param;
  550.  
  551.     return temp;
  552. }
  553.  
  554. //bitwise AND=
  555. template<typename atype> aeVector4<atype> aeVector4<atype>::operator&=(
  556.         const atype& param) {
  557.     // create a temp
  558.     aeVector4<atype> temp;
  559.  
  560.     // add values
  561.     x &= param;
  562.     y &= param;
  563.     z &= param;
  564.     h &= param;
  565.  
  566.     return *this;
  567. }
  568.  
  569. // bitwise OR =
  570. template<typename atype> aeVector4<atype> aeVector4<atype>::operator|=(
  571.         const atype& param) {
  572.     // create a temp
  573.     aeVector4<atype> temp;
  574.  
  575.     // add values
  576.     x |= param;
  577.     y |= param;
  578.     z |= param;
  579.     h |= param;
  580.  
  581.     return *this;
  582. }
  583.  
  584. // bitwise XOR =
  585. template<typename atype> aeVector4<atype> aeVector4<atype>::operator^=(
  586.         const atype& param) {
  587.     // create a temp
  588.     aeVector4<atype> temp;
  589.  
  590.     // add values
  591.     x ^= param;
  592.     y ^= param;
  593.     z ^= param;
  594.     h ^= param;
  595.  
  596.     return *this;
  597. }
  598.  
  599. // bitwise left by x =
  600. template<typename atype> aeVector4<atype> aeVector4<atype>::operator<<=(
  601.         const atype& param) {
  602.     x <<= param;
  603.     y <<= param;
  604.     z <<= param;
  605.  
  606.     return *this;
  607. }
  608.  
  609. // bitwise right by x=
  610. template<typename atype> aeVector4<atype> aeVector4<atype>::operator>>=(
  611.         const atype& param) {
  612.     x >>= param;
  613.     y >>= param;
  614.     z >>= param;
  615.     h >>= param;
  616.  
  617.     return *this;
  618. }
  619.  
  620. // operator functions
  621. template<typename atype> aeVector4<atype> aeVector4<atype>::operator+=(
  622.         const atype& param) {
  623.  
  624.     // add values
  625.     x += param;
  626.     y += param;
  627.     z += param;
  628.     h += param;
  629.  
  630.     return *this;
  631. }
  632.  
  633. // operator functions
  634. template<typename atype> aeVector4<atype> aeVector4<atype>::operator-=(
  635.         const atype& param) {
  636.     // create a temp
  637.     // add values
  638.     x -= param;
  639.     y -= param;
  640.     z -= param;
  641.  
  642.     return *this;
  643. }
  644.  
  645. // operator functions
  646. template<typename atype> aeVector4<atype> aeVector4<atype>::operator*=(
  647.         const atype& param) {
  648.     // add values
  649.     x *= param;
  650.     y *= param;
  651.     z *= param;
  652.     h *= param;
  653.  
  654.     return *this;
  655. }
  656.  
  657. // operator functions
  658. template<typename atype> aeVector4<atype> aeVector4<atype>::operator%=(
  659.         const atype& param) {
  660.     // add values
  661.     x %= param;
  662.     y %= param;
  663.     z %= param;
  664.     h %= param;
  665.  
  666.     return *this;
  667. }
  668.  
  669. // operator functions
  670. template<typename atype> aeVector4<atype> aeVector4<atype>::operator/=(
  671.         const atype& param) {
  672.     // add values
  673.     x /= param;
  674.     y /= param;
  675.     z /= param;
  676.     h /= param;
  677.  
  678.     return *this;
  679. }
  680. // operator functions
  681. template<typename atype>  aeVector4<atype> aeVector4<atype>::operator-(
  682.         aeVector4<atype> param) const {
  683.     // create a temp
  684.     aeVector4<atype> temp;
  685.  
  686.     // add values
  687.     temp.x = x - param.x;
  688.     temp.y = y - param.y;
  689.     temp.z = z - param.z;
  690.     temp.h = h - param.h;
  691.  
  692.     return temp;
  693. }
  694.  
  695.  
  696. // operator functions
  697. template<typename atype> aeVector4<atype> aeVector4<atype>::operator+(
  698.          aeVector4<atype> param) const {
  699.     // create a temp
  700.     aeVector4<atype> temp;
  701.  
  702.     // add values
  703.     temp.x = x + param;
  704.     temp.y = y + param;
  705.     temp.z = z + param;
  706.     temp.h = h + param;
  707.  
  708.     return temp;
  709. }
  710.  
  711. template<typename atype> Vector3 aeVector4<atype>::GetVector3() const
  712. {
  713.     return Vector3((float)x, float(y), float(z));
  714. }
  715.  
  716.  
  717. template<typename atype> atype aeVector4<atype>::Dot(const aeVector4<atype> param) const
  718. {
  719.     return x*param.x+y*param.y+z*param.z;
  720. }
  721.  
  722.  
  723. template<typename atype> atype aeVector4<atype>::SquaredLength() const
  724. {
  725.     return Dot(*this);
  726. }
  727.  
  728. template<typename atype> atype aeVector4<atype>::GetHeight() const
  729. {
  730.     return h;
  731. }
  732.  
  733. template<typename atype> atype aeVector4<atype>::GetLength() const
  734. {
  735.     return sqrt(SquaredLength());
  736. }
  737.  
  738. template<typename atype> aeVector4<atype> aeVector4<atype>::GetNormalized() const
  739. {
  740.   if (SquaredLength() == 0)
  741.     return *this;
  742.   return *this / GetLength();
  743. }
  744.  
  745. template<typename atype> aeVector4<atype> aeVector4<atype>::Normalize()
  746. {
  747.   if (SquaredLength() == 0)
  748.     return *this;
  749.   return *this /= GetLength();
  750. }
Advertisement
Add Comment
Please, Sign In to add comment