Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 33.83 KB | None | 0 0
  1. //Vector2 .h
  2.  
  3. class Vector2
  4. {
  5. public:
  6.     //Data
  7.     union
  8.     {
  9.         struct { float x, y; };
  10.         float data[2];
  11.     };
  12.  
  13.     Vector2(); //Default constructor
  14.     Vector2(float a_x, float a_y);
  15.     ~Vector2();
  16.  
  17.     float& operator [] (int index); //Subscript operator
  18.     operator float* (); //Casts the vector to an array of floats
  19.     operator const float* (); //Casts the vector to a const array of floats
  20.  
  21.     //Magnitude
  22.     float Magnitude() const { return sqrt(x*x + y * y); } //Returns the magnitude of the vector (Pythagoras)
  23.     float MagnitudeSqr() const { return (x*x + y * y); } //Returns the squared magnitude of the vector (Pythagoras)
  24.  
  25.     float Distance(const Vector2& other) const; //Returns the distance between two points
  26.     void Normalize(); //Make vector unit length
  27.  
  28.     //Dot
  29.     float Dot(const Vector2& other) const; //Returns the dot product
  30.     float AngleBetween(const Vector2& other) const; //Normalizes both vectors and returns the dot product
  31.  
  32.     Vector2 GetPerpendicularRH() const { return { -y, x }; }
  33.     Vector2 GetPerpendicularLH() const { return { y, -x }; }
  34.  
  35.     //Equality
  36.     bool operator == (const Vector2& other); //Checks for exact equality
  37.     bool operator != (const Vector2& other); //Checks for exact inequality
  38.     bool Equal(const Vector2& other, float tolerance = 0.005f); //Checks for equality within the tolerance difference
  39.     bool NotEqual(const Vector2& other, float tolerance = 0.005f); //Checks for inequality within the tolerance difference
  40.  
  41.     Vector2 Inverse(); //Flips the vector
  42.  
  43.     //Addition
  44.     Vector2 operator + (const Vector2& other) const;
  45.     Vector2 operator += (const Vector2& other);
  46.     //Subtraction
  47.     Vector2 operator - (const Vector2& other) const;
  48.     Vector2 operator -= (const Vector2& other);
  49.     //Multiplication
  50.     Vector2 operator * (float scalar) const;
  51.     Vector2 operator *= (float scalar);
  52.     //float * Vector2
  53.     friend Vector2 operator * (float scalar, const Vector2& v);
  54.     friend Vector2 operator *= (float scalar, const Vector2& v);
  55.     //Division
  56.     Vector2 operator / (float scalar) const;
  57.     Vector2 operator /= (float scalar);
  58.     //Assignment
  59.     Vector2 operator = (const Vector2& other);
  60. };
  61.  
  62.  
  63.  
  64. //Vector2 .cpp
  65.  
  66. //Constructors
  67. Vector2::Vector2() //Default
  68. {
  69.     x = 0; y = 0;
  70. }
  71. Vector2::Vector2(float a_x, float a_y)
  72. {
  73.     x = a_x;
  74.     y = a_y;
  75. }
  76. Vector2::~Vector2()
  77. {
  78. }
  79.  
  80. float & Vector2::operator[](int index) { return data[index]; }
  81. Vector2::operator float*() { return data; }
  82. Vector2::operator const float*() { return data; }
  83.  
  84. float Vector2::Distance(const Vector2 & other) const
  85. {
  86.     float diffX = x - other.x;
  87.     float diffY = y - other.y;
  88.     return sqrt(diffX*diffX + diffY * diffY); //Use Pythagoras theorum to find the distance between the two vectors
  89. }
  90.  
  91. void Vector2::Normalize()
  92. {
  93.     float mag = Magnitude();
  94.     x /= mag;
  95.     y /= mag;
  96. }
  97.  
  98. float Vector2::Dot(const Vector2 & other) const
  99. {
  100.     return x * other.x + y * other.y;
  101. }
  102.  
  103. float Vector2::AngleBetween(const Vector2& other) const
  104. {
  105.     //Normalize the vectors first
  106.     Vector2 a; a.Normalize();
  107.     Vector2 b; b.Normalize();
  108.  
  109.     return acos(a.Dot(b));
  110. }
  111.  
  112. //Equality
  113. bool Vector2::operator==(const Vector2& other)
  114. {
  115.     //Check if all elements are the same
  116.     if (x == other.x && y == other.y) return true;
  117.     return false;
  118. }
  119. bool Vector2::operator!=(const Vector2 & other)
  120. {
  121.     //If all parts are the same, the vectors are equal
  122.     if (x == other.x && y == other.y) return false;
  123.     return true;
  124. }
  125. bool Vector2::Equal(const Vector2 & other, float tolerance)
  126. {
  127.     //Checks if the absolute value of the difference between this element and the other element is more than the tolerance
  128.     //If it is, then the vectors are not equal
  129.     if (fabs(x - other.x) > tolerance) return false;
  130.     if (fabs(y - other.y) > tolerance) return false;
  131.     return true;
  132. }
  133. bool Vector2::NotEqual(const Vector2 & other, float tolerance)
  134. {
  135.     //Checks if the absolute value of the difference between all the elements and all the other elements is less than the tolerance
  136.     //If they are all less than the tolerance, the vectors are equal
  137.     if (fabs(x - other.x) < tolerance && fabs(y - other.y) < tolerance) return false;
  138.     return true;
  139. }
  140.  
  141. //Inverse
  142. Vector2 Vector2::Inverse()
  143. {
  144.     x *= -1; y *= -1;
  145.     return *this;
  146. }
  147.  
  148. //Addition
  149. Vector2 Vector2::operator+(const Vector2 & other) const
  150. {
  151.     return { x + other.x, y + other.y };
  152. }
  153. Vector2 Vector2::operator+=(const Vector2 & other)
  154. {
  155.     x += other.x; y += other.y;
  156.     return *this;
  157. }
  158. //Subtraction
  159. Vector2 Vector2::operator-(const Vector2 & other) const
  160. {
  161.     return { x - other.x, y - other.y };
  162. }
  163. Vector2 Vector2::operator-=(const Vector2 & other)
  164. {
  165.     x -= other.x; y -= other.y;
  166.     return *this;
  167. }
  168. //Multiplication
  169. Vector2 Vector2::operator*(float scalar) const
  170. {
  171.     return { x * scalar, y * scalar };
  172. }
  173. Vector2 Vector2::operator*=(float scalar)
  174. {
  175.     x *= scalar; y *= scalar;
  176.     return *this;
  177. }
  178. //float * Vector2
  179. Vector2 operator*(float scalar, const Vector2 & v)
  180. {
  181.     return { v.x * scalar, v.y * scalar };
  182. }
  183. Vector2 operator*=(float scalar, const Vector2 & v)
  184. {
  185.     Vector2 vec = v;
  186.     vec.x *= scalar; vec.y *= scalar;
  187.     return vec;
  188. }
  189. //Division
  190. Vector2 Vector2::operator/(float scalar) const
  191. {
  192.     return { x / scalar, y / scalar };
  193. }
  194. Vector2 Vector2::operator/=(float scalar)
  195. {
  196.     x /= scalar; y /= scalar;
  197.     return *this;
  198. }
  199. //Assignment
  200. Vector2 Vector2::operator=(const Vector2 & other)
  201. {
  202.     x = other.x; y = other.y;
  203.     return *this;
  204. }
  205.  
  206.  
  207. //Vector3 .h
  208.  
  209. class Vector3
  210. {
  211. public:
  212.     //Data
  213.     union
  214.     {
  215.         struct
  216.         {
  217.             float x, y;
  218.             union { float z, w; }; //Vector3 can be used as a homogeneous Vector2
  219.         };
  220.         struct { float r, g, b; };
  221.         float data[3];
  222.     };
  223.  
  224.     Vector3(); //Default constructor
  225.     Vector3(float a_x, float a_y, float a_z);
  226.     ~Vector3();
  227.  
  228.     float& operator [] (int index) { return data[index]; } //Subscript operator
  229.     operator float* () { return data; } //Casts the vector to an array of floats
  230.     operator const float* () { return data; } //Casts the vector to a const array of floats
  231.  
  232.     //Magnitude
  233.     float Magnitude() const { return sqrt(x*x + y * y + z * z); } //Returns the magnitude of the vector (Pythagoras)
  234.     float MagnitudeSqr() const { return (x*x + y * y + z * z); } //Returns the squared magnitude of the vector (Pythagoras)
  235.  
  236.     float Distance(const Vector3& other) const; //Returns the distance between two points
  237.     void Normalize(); //Makes the vector unit length
  238.  
  239.     //Dot
  240.     float Dot(const Vector3& other) const; //Returns the dot product
  241.     float AngleBetween(const Vector3& other) const; //Normalizes both vectors and returns the dot product
  242.     //Cross
  243.     Vector3 Cross(const Vector3& other) const; //Returns the cross product
  244.  
  245.     //Equality
  246.     bool operator == (const Vector3& other); //Checks for exact equality
  247.     bool operator != (const Vector3& other); //Checks for exact inequality
  248.     bool Equal(const Vector3& other, float tolerance = 0.005f); //Checks for equality within the tolerance difference
  249.     bool NotEqual(const Vector3& other, float tolerance = 0.005f); //Checks for inequality within the tolerance difference
  250.  
  251.     Vector3 Inverse(); //Flips the vector
  252.  
  253.     //Addition
  254.     Vector3 operator + (const Vector3& other) const;
  255.     Vector3 operator += (const Vector3& other);
  256.     //Subtraction
  257.     Vector3 operator - (const Vector3& other) const;
  258.     Vector3 operator -= (const Vector3& other);
  259.     //Multiplication
  260.     Vector3 operator * (float scalar) const;
  261.     Vector3 operator *= (float scalar);
  262.     //float * Vector3
  263.     friend Vector3 operator * (float scalar, const Vector3& v);
  264.     friend Vector3 operator *= (float scalar, const Vector3& v);
  265.     //Division
  266.     Vector3 operator / (float scalar) const;
  267.     Vector3 operator /= (float scalar);
  268.     //Assignment
  269.     Vector3 operator = (const Vector3& other);
  270. };
  271.  
  272.  
  273.  
  274. //Vector3 .cpp
  275.  
  276. Vector3::Vector3() //Default
  277. {
  278.     x = 0; y = 0; z = 0;
  279. }
  280.  
  281. Vector3::Vector3(float a_x, float a_y, float a_z)
  282. {
  283.     x = a_x;
  284.     y = a_y;
  285.     z = a_z;
  286. }
  287. Vector3::~Vector3()
  288. {
  289. }
  290.  
  291. float Vector3::Distance(const Vector3 & other) const
  292. {
  293.     float diffX = x - other.x;
  294.     float diffY = y - other.y;
  295.     float diffZ = z - other.z;
  296.     return sqrt(diffX*diffX + diffY * diffY + diffZ * diffZ); //Use Pythagoras theorum to find the distance between the two vectors
  297. }
  298.  
  299. void Vector3::Normalize()
  300. {
  301.     float mag = Magnitude();
  302.     x /= mag;
  303.     y /= mag;
  304.     z /= mag;
  305. }
  306.  
  307. float Vector3::Dot(const Vector3 & other) const
  308. {
  309.     return x * other.x + y * other.y + z * other.z;
  310. }
  311.  
  312. float Vector3::AngleBetween(const Vector3 & other) const
  313. {
  314.     //Normalize the vectors first
  315.     Vector3 a; a.Normalize();
  316.     Vector3 b; b.Normalize();
  317.  
  318.     return acos(a.Dot(b));
  319. }
  320.  
  321. Vector3 Vector3::Cross(const Vector3 & other) const
  322. {
  323.     return { y * other.z - z * other.y,
  324.                 z * other.x - x * other.z,
  325.                 x * other.y - y * other.x };
  326. }
  327.  
  328. //Equality
  329. bool Vector3::operator==(const Vector3 & other)
  330. {
  331.     //If any of these are false, the vectors are not equal
  332.     if (x != other.x) return false;
  333.     if (y != other.y) return false;
  334.     if (z != other.z) return false;
  335.     return true;
  336. }
  337. bool Vector3::operator!=(const Vector3 & other)
  338. {
  339.     //If all parts are the same, the vectors are equal
  340.     if (x == other.x && y == other.y && z == other.z) return false;
  341.     return true;
  342. }
  343. bool Vector3::Equal(const Vector3 & other, float tolerance)
  344. {
  345.     //Checks if the absolute value of the difference between this element and the other element is more than the tolerance
  346.     //If it is, then the vectors are not equal
  347.     if (fabs(x - other.x) > tolerance) return false;
  348.     if (fabs(y - other.y) > tolerance) return false;
  349.     if (fabs(z - other.z) > tolerance) return false;
  350.     return true;
  351. }
  352. bool Vector3::NotEqual(const Vector3 & other, float tolerance)
  353. {
  354.     //Checks if the absolute value of the difference between all the elements and all the other elements is less than the tolerance
  355.     //If they are all less than the tolerance, the vectors are equal
  356.     if (fabs(x - other.x) < tolerance && fabs(y - other.y) < tolerance && fabs(z - other.z) < tolerance) return false;
  357.     return true;
  358. }
  359.  
  360. //Inverse
  361. Vector3 Vector3::Inverse()
  362. {
  363.     x *= -1; y *= -1; z *= -1;
  364.     return *this;
  365. }
  366.  
  367. //Addition
  368. Vector3 Vector3::operator+(const Vector3 & other) const
  369. {
  370.     return { x + other.x, y + other.y, z + other.z };
  371. }
  372. Vector3 Vector3::operator+=(const Vector3 & other)
  373. {
  374.     x += other.x; y += other.y; z += other.z;
  375.     return *this;
  376. }
  377. //Subtraction
  378. Vector3 Vector3::operator-(const Vector3 & other) const
  379. {
  380.     return { x - other.x, y - other.y, z - other.z };
  381. }
  382. Vector3 Vector3::operator-=(const Vector3 & other)
  383. {
  384.     x -= other.x; y -= other.y; z -= other.z;
  385.     return *this;
  386. }
  387. //Multiplication
  388. Vector3 Vector3::operator*(float scalar) const
  389. {
  390.     return { x * scalar, y * scalar, z * scalar };
  391. }
  392. Vector3 Vector3::operator*=(float scalar)
  393. {
  394.     x *= scalar; y *= scalar; z *= scalar;
  395.     return *this;
  396. }
  397. //float * Vector3
  398. Vector3 operator*(float scalar, const Vector3 & v)
  399. {
  400.     return { v.x * scalar, v.y * scalar, v.z * scalar };
  401. }
  402. Vector3 operator*=(float scalar, const Vector3 & v)
  403. {
  404.     Vector3 vec = v;
  405.     vec.x *= scalar; vec.y *= scalar; vec.z *= scalar;
  406.     return vec;
  407. }
  408. //Division
  409. Vector3 Vector3::operator/(float scalar) const
  410. {
  411.     return { x / scalar, y / scalar, z / scalar };
  412. }
  413. Vector3 Vector3::operator/=(float scalar)
  414. {
  415.     x /= scalar; y /= scalar; z /= scalar;
  416.     return *this;
  417. }
  418. //Assignment
  419. Vector3 Vector3::operator=(const Vector3 & other)
  420. {
  421.     x = other.x; y = other.y; z = other.z;
  422.     return *this;
  423. }
  424.  
  425.  
  426. //Vector4 .h
  427.  
  428. class Vector4
  429. {
  430. public:
  431.     //Data
  432.     union
  433.     {
  434.         struct { float x, y, z, w; };
  435.         float data[4];
  436.     };
  437.  
  438.     Vector4(); //Default constructor
  439.     Vector4(float a_x, float a_y, float a_z, float a_w);
  440.     ~Vector4();
  441.  
  442.     float& operator [] (int index) { return data[index]; } //Subscript operator
  443.     operator float* () { return data; } //Casts the vector to an array of floats
  444.     operator const float* () { return data; } //Casts the vector to a const array of floats
  445.  
  446.     //Magnitude
  447.     float Magnitude() const { return sqrt(x*x + y * y + z * z + w * w); } //Returns the magnitude of the vector (Pythagoras)
  448.     float MagnitudeSqr() const { return (x*x + y * y + z * z + w * w); } //Returns the squared magnitude of the vector (Pythagoras)
  449.  
  450.     float Distance(const Vector4& other) const; //Returns the distance between two points
  451.     void Normalize(); //Makes the vector unit length
  452.  
  453.     //Dot
  454.     float Dot(const Vector4& other) const; //Returns the dot product
  455.     float AngleBetween(const Vector4& other) const; //Normalizes both vectors and returns the dot product
  456.     //Cross
  457.     Vector4 Cross(const Vector4& other) const; //Returns the cross product
  458.  
  459.     //Equality
  460.     bool operator == (const Vector4& other); //Checks for exact equality
  461.     bool operator != (const Vector4& other); //Checks for exact inequality
  462.     bool Equal(const Vector4& other, float tolerance = 0.005f); //Checks for equality within the tolerance difference
  463.     bool NotEqual(const Vector4& other, float tolerance = 0.005f); //Checks for inequality within the tolerance difference
  464.  
  465.     Vector4 Inverse(); //Flips the vector
  466.  
  467.     //Addition
  468.     Vector4 operator + (const Vector4& other) const;
  469.     Vector4 operator += (const Vector4& other);
  470.     //Subtraction
  471.     Vector4 operator - (const Vector4& other) const;
  472.     Vector4 operator -= (const Vector4& other);
  473.     //Multiplication
  474.     Vector4 operator * (float scalar) const;
  475.     Vector4 operator *= (float scalar);
  476.     //float * Vector4
  477.     friend Vector4 operator * (float scalar, const Vector4& v);
  478.     friend Vector4 operator *= (float scalar, const Vector4& v);
  479.     //Division
  480.     Vector4 operator / (float scalar) const;
  481.     Vector4 operator /= (float scalar);
  482.     //Assignment
  483.     Vector4 operator = (const Vector4& other);
  484. };
  485.  
  486.  
  487. //Vector4 .cpp
  488.  
  489. Vector4::Vector4() //Default
  490. {
  491.     x = 0; y = 0; z = 0; w = 0;
  492. }
  493. Vector4::Vector4(float a_x, float a_y, float a_z, float a_w)
  494. {
  495.     x = a_x;
  496.     y = a_y;
  497.     z = a_z;
  498.     w = a_w;
  499. }
  500. Vector4::~Vector4()
  501. {
  502. }
  503.  
  504. float Vector4::Distance(const Vector4 & other) const
  505. {
  506.     float diffX = x - other.x;
  507.     float diffY = y - other.y;
  508.     float diffZ = z - other.z;
  509.     float diffT = w - other.w;
  510.     return sqrt(diffX*diffX + diffY * diffY + diffZ * diffZ + diffT * diffT); //Use Pythagoras theorum to find the distance between the two vectors
  511. }
  512.  
  513. void Vector4::Normalize()
  514. {
  515.     float mag = Magnitude();
  516.     x /= mag;
  517.     y /= mag;
  518.     z /= mag;
  519.     w /= mag;
  520. }
  521.  
  522. float Vector4::Dot(const Vector4 & other) const
  523. {
  524.     return x * other.x + y * other.y + z * other.z + w * other.w;
  525. }
  526.  
  527. float Vector4::AngleBetween(const Vector4 & other) const
  528. {
  529.     //Normalize the vectors first
  530.     Vector4 a; a.Normalize();
  531.     Vector4 b; b.Normalize();
  532.  
  533.     return acos(a.Dot(b));
  534. }
  535.  
  536. Vector4 Vector4::Cross(const Vector4 & other) const
  537. {
  538.     return { y * other.z - z * other.y,
  539.                 z * other.x - x * other.z,
  540.                 x * other.y - y * other.x,
  541.                 0 };
  542. }
  543.  
  544. //Equality
  545. bool Vector4::operator==(const Vector4 & other)
  546. {
  547.     //If any of these are false, the vectors are not equal
  548.     if (x != other.x) return false;
  549.     if (y != other.y) return false;
  550.     if (z != other.z) return false;
  551.     if (w != other.w) return false;
  552.     return true;
  553. }
  554. bool Vector4::operator!=(const Vector4 & other)
  555. {
  556.     //If all parts are the same, the vectors are equal
  557.     if (x == other.x && y == other.y && z == other.z && w == other.w) return false;
  558.     return true;
  559. }
  560. bool Vector4::Equal(const Vector4 & other, float tolerance)
  561. {
  562.     //Checks if the absolute value of the difference between this element and the other element is more than the tolerance
  563.     //If it is, then the vectors are not equal
  564.     if (fabs(x - other.x) > tolerance) return false;
  565.     if (fabs(y - other.y) > tolerance) return false;
  566.     if (fabs(z - other.z) > tolerance) return false;
  567.     if (fabs(w - other.w) > tolerance) return false;
  568.     return true;
  569. }
  570. bool Vector4::NotEqual(const Vector4 & other, float tolerance)
  571. {
  572.     //Checks if the absolute value of the difference between all the elements and all the other elements is less than the tolerance
  573.     //If they are all less than the tolerance, the vectors are equal
  574.     if (fabs(x - other.x) < tolerance && fabs(y - other.y) < tolerance && fabs(z - other.z) < tolerance && fabs(w - other.w) < tolerance) return false;
  575.     return true;
  576. }
  577.  
  578. //Inverse
  579. Vector4 Vector4::Inverse()
  580. {
  581.     x *= -1; y *= -1; z *= -1; w *= -1;
  582.     return *this;
  583. }
  584.  
  585. //Addition
  586. Vector4 Vector4::operator+(const Vector4 & other) const
  587. {
  588.     return { x + other.x, y + other.y, z + other.z, w + other.w };
  589. }
  590. Vector4 Vector4::operator+=(const Vector4 & other)
  591. {
  592.     x += other.x; y += other.y; z += other.z; w += other.w;
  593.     return *this;
  594. }
  595. //Subtraction
  596. Vector4 Vector4::operator-(const Vector4 & other) const
  597. {
  598.     return { x - other.x, y - other.y, z - other.z, w - other.w };
  599. }
  600. Vector4 Vector4::operator-=(const Vector4 & other)
  601. {
  602.     x -= other.x; y -= other.y; z -= other.z; w -= other.w;
  603.     return *this;
  604. }
  605. //Multiplication
  606. Vector4 Vector4::operator*(float scalar) const
  607. {
  608.     return { x * scalar, y * scalar, z * scalar, w * scalar };
  609. }
  610. Vector4 Vector4::operator*=(float scalar)
  611. {
  612.     x *= scalar; y *= scalar; z *= scalar; w *= scalar;
  613.     return *this;
  614. }
  615. //float * Vector4
  616. Vector4 operator*(float scalar, const Vector4 & v)
  617. {
  618.     return { v.x * scalar, v.y * scalar, v.z * scalar, v.w * scalar };
  619. }
  620. Vector4 operator*=(float scalar, const Vector4 & v)
  621. {
  622.     Vector4 vec = v;
  623.     vec.x *= scalar; vec.y *= scalar; vec.z *= scalar; vec.w *= scalar;
  624.     return vec;
  625. }
  626. //Division
  627. Vector4 Vector4::operator/(float scalar) const
  628. {
  629.     return { x / scalar, y / scalar, z / scalar, w / scalar };
  630. }
  631. Vector4 Vector4::operator/=(float scalar)
  632. {
  633.     x /= scalar; y /= scalar; z /= scalar; w /= scalar;
  634.     return *this;
  635. }
  636. //Assignment
  637. Vector4 Vector4::operator=(const Vector4 & other)
  638. {
  639.     x = other.x; y = other.y; z = other.z; w = other.w;
  640.     return *this;
  641. }
  642.  
  643.  
  644. //Matrix2 .h
  645.  
  646. class Matrix2
  647. {
  648. public:
  649.     //Data
  650.     union
  651.     {
  652.         struct
  653.         {
  654.             Vector2 xAxis;
  655.             Vector2 yAxis;
  656.         };
  657.         Vector2 axis[2];
  658.         float data[2][2];
  659.     };
  660.  
  661.     static const Matrix2 identity; //Identity matrix
  662.  
  663.     Matrix2(); //Default constructor
  664.     Matrix2(float x1, float y1, float x2, float y2);
  665.     ~Matrix2();
  666.  
  667.     Vector2& operator [] (int index) { return axis[index]; } //Subscript operator
  668.     const Vector2& operator [] (int index) const { return axis[index]; } //Read-only subscript operator
  669.     operator float* () { return *data; } //Casts the matrix to an array of floats
  670.     operator const float* () { return *data; } //Casts the matrix to a const array of floats
  671.  
  672.     Matrix2 Transpose() const; //Switch between Row-major and Column-major
  673.  
  674.     //Scale
  675.     void SetScaled(float x, float y); //Scale the matrix
  676.     void SetScaled(const Vector2& v); //Scale the matrix
  677.     void Scale(float x, float y); //Scale an existing matrix
  678.     void Scale(const Vector2& v); //Scale an existing matrix
  679.  
  680.     //Multiply by a Matrix
  681.     Matrix2 operator * (const Matrix2& other) const;
  682.     Matrix2 operator *= (const Matrix2& other);
  683.     //Multiply by a Vector
  684.     Vector2 operator * (const Vector2& other) const;
  685.     Vector2& operator *= (const Vector2& other);
  686.     //Assignment
  687.     Matrix2 operator =(const Matrix2& other);
  688. };
  689.  
  690. //Matrix2 .cpp
  691.  
  692. //Identity Matrix
  693. const Matrix2 Matrix2::identity = Matrix2(1, 0,
  694.     0, 1);
  695.  
  696. //Constructors
  697. Matrix2::Matrix2()
  698. {
  699.     for (int r = 0; r < 2; r++)
  700.         for (int c = 0; c < 2; c++)
  701.             data[c][r] = 0;
  702. }
  703. Matrix2::Matrix2(float x1, float y1, float x2, float y2)
  704. {
  705.     xAxis = { x1, y1 };
  706.     yAxis = { x2, y2 };
  707. }
  708. Matrix2::~Matrix2()
  709. {
  710. }
  711.  
  712. Matrix2 Matrix2::Transpose() const
  713. {
  714.     Matrix2 result;
  715.  
  716.     for (int r = 0; r < 2; r++)
  717.         for (int c = 0; c < 2; c++)
  718.             result.data[r][c] = data[c][r];
  719.  
  720.     return result;
  721. }
  722.  
  723. //Scaling
  724. void Matrix2::SetScaled(float x, float y)
  725. {
  726.     xAxis = { x, 0 };
  727.     yAxis = { 0, y };
  728. }
  729. void Matrix2::SetScaled(const Vector2 & v)
  730. {
  731.     xAxis = { v.x, 0 };
  732.     yAxis = { 0, v.y };
  733. }
  734. void Matrix2::Scale(float x, float y)
  735. {
  736.     Matrix2 m;
  737.     m.SetScaled(x, y);
  738.  
  739.     *this *= m;
  740. }
  741. void Matrix2::Scale(const Vector2 & v)
  742. {
  743.     Matrix2 m;
  744.     m.SetScaled(v.x, v.y);
  745.  
  746.     *this *= m;
  747. }
  748.  
  749. //Multiplication
  750. Matrix2 Matrix2::operator*(const Matrix2& other) const
  751. {
  752.     Matrix2 result;
  753.  
  754.     for (int r = 0; r < 2; r++)
  755.         for (int c = 0; c < 2; c++)
  756.             result.data[c][r] = data[0][r] * other.data[c][0] +
  757.             data[1][r] * other.data[c][1];
  758.     return result;
  759. }
  760. Matrix2 Matrix2::operator*=(const Matrix2 & other)
  761. {
  762.     Matrix2 result;
  763.  
  764.     for (int r = 0; r < 2; r++)
  765.         for (int c = 0; c < 2; c++)
  766.             result.data[c][r] = data[0][r] * other.data[c][0] +
  767.             data[1][r] * other.data[c][1];
  768.     *this = result;
  769.     return *this;
  770. }
  771. Vector2 Matrix2::operator*(const Vector2& other) const
  772. {
  773.     Vector2 result;
  774.     Vector2 v = other;
  775.  
  776.     for (int r = 0; r < 2; r++)
  777.         result[r] = data[0][r] * v[0] +
  778.         data[1][r] * v[1];
  779.     return result;
  780. }
  781. Vector2& Matrix2::operator*=(const Vector2 & other)
  782. {
  783.     Vector2 result;
  784.     Vector2 v = other;
  785.  
  786.     for (int r = 0; r < 2; r++)
  787.         result[r] = data[0][r] * v[0] +
  788.         data[1][r] * v[1];
  789.     return result;
  790. }
  791. //Assignment
  792. Matrix2 Matrix2::operator=(const Matrix2 & other)
  793. {
  794.     for (int r = 0; r < 2; r++)
  795.         for (int c = 0; c < 2; c++)
  796.             data[c][r] = other.data[c][r];
  797.     return *this;
  798. }
  799.  
  800. //Matrix3 .h
  801.  
  802. class Matrix3
  803. {
  804. public:
  805.     //Data
  806.     union
  807.     {
  808.         struct
  809.         {
  810.             Vector3 xAxis;
  811.             Vector3 yAxis;
  812.             union //Matrix3 can be used as a homogeneous Matrix2
  813.             {
  814.                 Vector3 zAxis;
  815.                 Vector3 translation;
  816.             };
  817.         };
  818.         Vector3 axis[3];
  819.         float data[3][3];
  820.     };
  821.  
  822.     static const Matrix3 identity; //Identity matrix
  823.  
  824.     Matrix3(); //Default constructor
  825.     Matrix3(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3);
  826.     ~Matrix3();
  827.  
  828.     Vector3& operator [] (int index) { return axis[index]; } //Subscript operator
  829.     const Vector3& operator [] (int index) const { return axis[index]; } //Read-only subscript operator
  830.     operator float* () { return *data; } //Casts the matrix to an array of floats
  831.     operator const float* () { return *data; } //Casts the matrix to a const array of floats
  832.  
  833.     Matrix3 Transpose() const; //Switch between Row-major and Column-major
  834.  
  835.     //Scale
  836.     void SetScaled(float x, float y, float z); //Scale the matrix
  837.     void SetScaled(const Vector3& v); //Scale the matrix
  838.     void Scale(float x, float y, float z); //Scale an existing matrix
  839.     void Scale(const Vector3& v); //Scale an existing matrix
  840.     //Rotate
  841.     void SetEuler(float pitch, float yaw, float roll); //Rotate around all axis
  842.     void SetRotateX(float radians); //Rotate matrix around the X axis
  843.     void SetRotateY(float radians); //Rotate matrix around the Y axis
  844.     void SetRotateZ(float radians); //Rotate matrix around the Z axis
  845.     void RotateX(float radians); //Rotate an existing matrix around the X axis
  846.     void RotateY(float radians); //Rotate an existing matrix around the Y axis
  847.     void RotateZ(float radians); //Rotate an existing matrix around the Z axis
  848.     //Translate (For homogeneous Matrices)
  849.     void Translate(float x, float y); //Translate the matrix
  850.     void Translate(const Vector3& other); //Translate the matrix
  851.  
  852.     //Multiply by a Matrix
  853.     Matrix3 operator * (const Matrix3& other) const;
  854.     Matrix3 operator *= (const Matrix3& other);
  855.     //Multiply by a Vector
  856.     Vector3 operator * (const Vector3& other) const;
  857.     Vector3& operator *= (const Vector3& other);
  858.     //Assignment
  859.     Matrix3 operator =(const Matrix3& other);
  860. };
  861.  
  862. //Matrix3 .cpp
  863.  
  864. //Identity Matrix
  865. const Matrix3 Matrix3::identity = Matrix3(1, 0, 0,
  866.     0, 1, 0,
  867.     0, 0, 1);
  868.  
  869. //Constructors
  870. Matrix3::Matrix3()
  871. {
  872.     for (int r = 0; r < 3; r++)
  873.         for (int c = 0; c < 3; c++)
  874.             data[c][r] = 0;
  875. }
  876. Matrix3::Matrix3(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3)
  877. {
  878.     xAxis = { x1, y1, z1 };
  879.     yAxis = { x2, y2, z2 };
  880.     zAxis = { x3, y3, z3 };
  881. }
  882. Matrix3::~Matrix3()
  883. {
  884. }
  885.  
  886. Matrix3 Matrix3::Transpose() const
  887. {
  888.     Matrix3 result;
  889.  
  890.     for (int r = 0; r < 3; r++)
  891.         for (int c = 0; c < 3; c++)
  892.             result.data[r][c] = data[c][r];
  893.  
  894.     return result;
  895. }
  896.  
  897. //Scaling
  898. void Matrix3::SetScaled(float x, float y, float z)
  899. {
  900.     xAxis = { x, 0, 0 };
  901.     yAxis = { 0, y, 0 };
  902.     zAxis = { 0, 0, z };
  903. }
  904. void Matrix3::SetScaled(const Vector3 & v)
  905. {
  906.     xAxis = { v.x, 0, 0 };
  907.     yAxis = { 0, v.y, 0 };
  908.     zAxis = { 0, 0, v.z };
  909. }
  910. void Matrix3::Scale(float x, float y, float z)
  911. {
  912.     Matrix3 m;
  913.     m.SetScaled(x, y, z);
  914.  
  915.     *this = *this * m;
  916. }
  917. void Matrix3::Scale(const Vector3 & v)
  918. {
  919.     Matrix3 m;
  920.     m.SetScaled(v.x, v.y, v.z);
  921.  
  922.     *this = *this * m;
  923. }
  924. //Rotation
  925. void Matrix3::SetEuler(float pitch, float yaw, float roll)
  926. {
  927.     Matrix3 x, y, z;
  928.     x.SetRotateX(pitch);
  929.     y.SetRotateX(yaw);
  930.     z.SetRotateX(roll);
  931.  
  932.     //Combine rotations in order Z, Y, X
  933.     *this = z * y * x;
  934. }
  935. void Matrix3::SetRotateX(float radians)
  936. {
  937.     xAxis = { 1, 0, 0 }; //leave X axis unchanged
  938.     yAxis = { 0, cosf(radians), sinf(radians) };
  939.     zAxis = { 0, -sinf(radians), cosf(radians) };
  940. }
  941. void Matrix3::SetRotateY(float radians)
  942. {
  943.     xAxis = { cosf(radians), 0, -sinf(radians) };
  944.     yAxis = { 0, 1, 0 }; //leave Y axis unchanged
  945.     zAxis = { sinf(radians), 0, cosf(radians) };
  946. }
  947. void Matrix3::SetRotateZ(float radians)
  948. {
  949.     xAxis = { cosf(radians), sinf(radians), 0 };
  950.     yAxis = { -sinf(radians), cosf(radians), 0 };
  951.     zAxis = { 0, 0, 1 }; //leave Z axis unchanged
  952. }
  953. void Matrix3::RotateX(float radians)
  954. {
  955.     Matrix3 m;
  956.     m.SetRotateX(radians);
  957.     *this *= m;
  958. }
  959. void Matrix3::RotateY(float radians)
  960. {
  961.     Matrix3 m;
  962.     m.SetRotateY(radians);
  963.     *this *= m;
  964. }
  965. void Matrix3::RotateZ(float radians)
  966. {
  967.     Matrix3 m;
  968.     m.SetRotateZ(radians);
  969.     *this *= m;
  970. }
  971. //Translation
  972. void Matrix3::Translate(float x, float y)
  973. {
  974.     translation += Vector3(x, y, 0);
  975. }
  976. void Matrix3::Translate(const Vector3 & other)
  977. {
  978.     translation += other;
  979. }
  980.  
  981. //Multiplication
  982. Matrix3 Matrix3::operator*(const Matrix3 & other) const
  983. {
  984.     Matrix3 result;
  985.  
  986.     for (int r = 0; r < 3; r++)
  987.         for (int c = 0; c < 3; c++)
  988.             result.data[c][r] = data[0][r] * other.data[c][0] +
  989.             data[1][r] * other.data[c][1] +
  990.             data[2][r] * other.data[c][2];
  991.     return result;
  992. }
  993. Matrix3 Matrix3::operator*=(const Matrix3 & other)
  994. {
  995.     Matrix3 result;
  996.  
  997.     for (int r = 0; r < 3; r++)
  998.         for (int c = 0; c < 3; c++)
  999.             result.data[c][r] = data[0][r] * other.data[c][0] +
  1000.             data[1][r] * other.data[c][1] +
  1001.             data[2][r] * other.data[c][2];
  1002.  
  1003.     *this = result;
  1004.     return *this;
  1005. }
  1006. Vector3 Matrix3::operator*(const Vector3 & other) const
  1007. {
  1008.     Vector3 result;
  1009.     Vector3 v = other;
  1010.  
  1011.     for (int r = 0; r < 3; r++)
  1012.         result[r] = data[0][r] * v[0] +
  1013.         data[1][r] * v[1] +
  1014.         data[2][r] * v[2];
  1015.     return result;
  1016. }
  1017. Vector3& Matrix3::operator*=(const Vector3 & other)
  1018. {
  1019.     Vector3 result;
  1020.     Vector3 v = other;
  1021.  
  1022.     for (int r = 0; r < 3; r++)
  1023.         result[r] = data[0][r] * v[0] +
  1024.         data[1][r] * v[1] +
  1025.         data[2][r] * v[2];
  1026.     return result;
  1027. }
  1028. //Assignment
  1029. Matrix3 Matrix3::operator=(const Matrix3 & other)
  1030. {
  1031.     for (int r = 0; r < 3; r++)
  1032.         for (int c = 0; c < 3; c++)
  1033.             data[c][r] = other.data[c][r];
  1034.     return *this;
  1035. }
  1036.  
  1037. //Matrix4 .h
  1038.  
  1039.  
  1040. class Matrix4
  1041. {
  1042. public:
  1043.     //Data
  1044.     union
  1045.     {
  1046.         struct
  1047.         {
  1048.             Vector4 xAxis;
  1049.             Vector4 yAxis;
  1050.             Vector4 zAxis;
  1051.             Vector4 translation;
  1052.         };
  1053.         Vector4 axis[4];
  1054.         float data[4][4];
  1055.     };
  1056.  
  1057.     static const Matrix4 identity; //Identity matrix
  1058.  
  1059.     Matrix4(); //Default constructor
  1060.     Matrix4(float x1, float y1, float z1, float t1, float x2, float y2, float z2, float t2, float x3, float y3, float z3, float t3, float x4, float y4, float z4, float t4);
  1061.     ~Matrix4();
  1062.  
  1063.     Vector4& operator [] (int index) { return axis[index]; } //Subscript operator
  1064.     const Vector4& operator [] (int index) const { return axis[index]; } //Read-only subscript operator
  1065.     operator float* () { return *data; } //Casts the matrix to an array of floats
  1066.     operator const float* () { return *data; } //Casts the matrix to a const array of floats
  1067.  
  1068.     Matrix4 Transpose() const; //Switch between Row-major and Column-major
  1069.  
  1070.     //Scale
  1071.     void SetScaled(float x, float y, float z); //Scale the matrix
  1072.     void SetScaled(const Vector4& v); //Scale the matrix
  1073.     void Scale(float x, float y, float z); //Scale an existing matrix
  1074.     void Scale(const Vector4& v); //Scale an existing matrix
  1075.     //Rotate
  1076.     void SetEuler(float pitch, float yaw, float roll); //Rotate around all axis
  1077.     void SetRotateX(float radians); //Rotate matrix around the X axis
  1078.     void SetRotateY(float radians); //Rotate matrix around the Y axis
  1079.     void SetRotateZ(float radians); //Rotate matrix around the Z axis
  1080.     void RotateX(float radians); //Rotate an existing matrix around the X axis
  1081.     void RotateY(float radians); //Rotate an existing matrix around the Y axis
  1082.     void RotateZ(float radians); //Rotate an existing matrix around the Z axis
  1083.     //Translate
  1084.     void Translate(float x, float y, float z); //Translate the matrix
  1085.     void Translate(const Vector4& other); //Translate the matrix
  1086.  
  1087.     //Multiply by a Matrix
  1088.     Matrix4 operator * (const Matrix4& other) const;
  1089.     Matrix4 operator *= (const Matrix4& other);
  1090.     //Multiply by a Vector
  1091.     Vector4 operator * (const Vector4& other) const;
  1092.     Vector4& operator *= (const Vector4& other);
  1093.     //Assignment
  1094.     Matrix4 operator =(const Matrix4& other);
  1095. };
  1096.  
  1097. //Matrix4 .cpp
  1098.  
  1099. //Identity Matrix
  1100. const Matrix4 Matrix4::identity = Matrix4(1, 0, 0, 0,
  1101.     0, 1, 0, 0,
  1102.     0, 0, 1, 0,
  1103.     0, 0, 0, 1);
  1104.  
  1105. //Constructors
  1106. Matrix4::Matrix4()
  1107. {
  1108.     for (int r = 0; r < 4; r++)
  1109.         for (int c = 0; c < 4; c++)
  1110.             data[c][r] = 0;
  1111. }
  1112. Matrix4::Matrix4(float x1, float y1, float z1, float t1, float x2, float y2, float z2, float t2, float x3, float y3, float z3, float t3, float x4, float y4, float z4, float t4)
  1113. {
  1114.     xAxis = { x1, y1, z1, t1 };
  1115.     yAxis = { x2, y2, z2, t2 };
  1116.     zAxis = { x3, y3, z3, t3 };
  1117.     translation = { x4, y4, z4, t4 };
  1118. }
  1119. Matrix4::~Matrix4()
  1120. {
  1121. }
  1122.  
  1123. Matrix4 Matrix4::Transpose() const
  1124. {
  1125.     Matrix4 result;
  1126.  
  1127.     for (int r = 0; r < 4; r++)
  1128.         for (int c = 0; c < 4; c++)
  1129.             result.data[r][c] = data[c][r];
  1130.  
  1131.     return result;
  1132. }
  1133.  
  1134. //Scaling
  1135. void Matrix4::SetScaled(float x, float y, float z)
  1136. {
  1137.     xAxis = { x, 0, 0, 0 };
  1138.     yAxis = { 0, y, 0, 0 };
  1139.     zAxis = { 0, 0, z, 0 };
  1140.     translation = { 0, 0, 0, 1 };
  1141. }
  1142. void Matrix4::SetScaled(const Vector4 & v)
  1143. {
  1144.     xAxis = { v.x, 0, 0, 0 };
  1145.     yAxis = { 0, v.y, 0, 0 };
  1146.     zAxis = { 0, 0, v.z, 0 };
  1147.     translation = { 0, 0, 0, 1 };
  1148. }
  1149. void Matrix4::Scale(float x, float y, float z)
  1150. {
  1151.     Matrix4 m;
  1152.     m.SetScaled(x, y, z);
  1153.  
  1154.     *this *= m;
  1155. }
  1156. void Matrix4::Scale(const Vector4 & v)
  1157. {
  1158.     Matrix4 m;
  1159.     m.SetScaled(v.x, v.y, v.z);
  1160.  
  1161.     *this *= m;
  1162. }
  1163. //Rotation
  1164. void Matrix4::SetEuler(float pitch, float yaw, float roll)
  1165. {
  1166.     Matrix4 x, y, z;
  1167.     x.SetRotateX(pitch);
  1168.     y.SetRotateX(yaw);
  1169.     z.SetRotateX(roll);
  1170.  
  1171.     //Combine rotations in order Z, Y, X
  1172.     *this = z * y * x;
  1173. }
  1174. void Matrix4::SetRotateX(float radians)
  1175. {
  1176.     xAxis = { 1, 0, 0, 0 }; //leave X axis unchanged
  1177.     yAxis = { 0, cosf(radians), sinf(radians), 0 };
  1178.     zAxis = { 0, -sinf(radians), cosf(radians), 0 };
  1179.     translation = { 0, 0, 0, 1 };
  1180. }
  1181. void Matrix4::SetRotateY(float radians)
  1182. {
  1183.     xAxis = { cosf(radians), 0, -sinf(radians), 0 };
  1184.     yAxis = { 0, 1, 0, 0 }; //leave Y axis unchanged
  1185.     zAxis = { sinf(radians), 0, cosf(radians), 0 };
  1186.     translation = { 0, 0, 0, 1 };
  1187. }
  1188. void Matrix4::SetRotateZ(float radians)
  1189. {
  1190.     xAxis = { cosf(radians), sinf(radians), 0, 0 };
  1191.     yAxis = { -sinf(radians), cosf(radians), 0, 0 };
  1192.     zAxis = { 0, 0, 1, 0 }; //leave Z axis unchanged
  1193.     translation = { 0, 0, 0, 1 };
  1194. }
  1195. void Matrix4::RotateX(float radians)
  1196. {
  1197.     Matrix4 m;
  1198.     m.SetRotateX(radians);
  1199.     *this *= m;
  1200. }
  1201. void Matrix4::RotateY(float radians)
  1202. {
  1203.     Matrix4 m;
  1204.     m.SetRotateY(radians);
  1205.     *this *= m;
  1206. }
  1207. void Matrix4::RotateZ(float radians)
  1208. {
  1209.     Matrix4 m;
  1210.     m.SetRotateZ(radians);
  1211.     *this *= m;
  1212. }
  1213. //Translation
  1214. void Matrix4::Translate(float x, float y, float z)
  1215. {
  1216.     translation += Vector4(x, y, z, 0);
  1217. }
  1218. void Matrix4::Translate(const Vector4 & other)
  1219. {
  1220.     translation += other;
  1221. }
  1222.  
  1223. //Multiplication
  1224. Matrix4 Matrix4::operator*(const Matrix4 & other) const
  1225. {
  1226.     Matrix4 result;
  1227.  
  1228.     for (int r = 0; r < 4; r++)
  1229.         for (int c = 0; c < 4; c++)
  1230.             result.data[c][r] = data[0][r] * other.data[c][0] +
  1231.             data[1][r] * other.data[c][1] +
  1232.             data[2][r] * other.data[c][2] +
  1233.             data[3][r] * other.data[c][3];
  1234.     return result;
  1235. }
  1236. Matrix4 Matrix4::operator*=(const Matrix4 & other)
  1237. {
  1238.     Matrix4 result;
  1239.     for (int r = 0; r < 4; r++)
  1240.         for (int c = 0; c < 4; c++)
  1241.             result.data[c][r] = data[0][r] * other.data[c][0] +
  1242.             data[1][r] * other.data[c][1] +
  1243.             data[2][r] * other.data[c][2] +
  1244.             data[3][r] * other.data[c][3];
  1245.     *this = result;
  1246.     return *this;
  1247. }
  1248. Vector4 Matrix4::operator*(const Vector4 & other) const
  1249. {
  1250.     Vector4 result;
  1251.     Vector4 v = other;
  1252.  
  1253.     for (int r = 0; r < 4; r++)
  1254.         result[r] = data[0][r] * v[0] +
  1255.         data[1][r] * v[1] +
  1256.         data[2][r] * v[2] +
  1257.         data[3][r] * v[3];
  1258.     return result;
  1259. }
  1260. Vector4& Matrix4::operator*=(const Vector4 & other)
  1261. {
  1262.     Vector4 result;
  1263.     Vector4 v = other;
  1264.  
  1265.     for (int r = 0; r < 4; r++)
  1266.         result[r] = data[0][r] * v[0] +
  1267.         data[1][r] * v[1] +
  1268.         data[2][r] * v[2] +
  1269.         data[3][r] * v[3];
  1270.     return result;
  1271. }
  1272. //Assignment
  1273. Matrix4 Matrix4::operator=(const Matrix4 & other)
  1274. {
  1275.     for (int r = 0; r < 4; r++)
  1276.         for (int c = 0; c < 4; c++)
  1277.             data[c][r] = other.data[c][r];
  1278.     return *this;
  1279. }
  1280.  
  1281. //Binary .h
  1282.  
  1283. class Binary
  1284. {
  1285. public:
  1286.     static void DecimalToBinary(char* binaryString, int len, int value); //Convert a decimal number to a binary number
  1287.     static int BinaryToDecimal(const char* binaryString); //Convert a binary number to a decimal number
  1288.  
  1289.     static void SetBit(char& bitfield, char bit, char value); //Set a bit in a bitfield
  1290.     static char CheckBit(char& bitfield, char bit); //Check if a bit is set in a bitfield
  1291. };
  1292.  
  1293. //Binary .cpp
  1294.  
  1295. void Binary::DecimalToBinary(char * binaryString, int len, int value)
  1296. {
  1297.     int i = 0;
  1298.     while (value > 0)
  1299.     {
  1300.         if (i > len) //If i is larger than the length of the array, i is out of bounds
  1301.             break;
  1302.  
  1303.         binaryString[i] = value % 2 + '0'; //Stores the remainder (either 1 or 0)
  1304.         value /= 2; //Reduces value to half its size
  1305.         i++;
  1306.     }
  1307. }
  1308.  
  1309. int Binary::BinaryToDecimal(const char * binaryString)
  1310. {
  1311.     int decimalValue = 0, length = 0, indexCounter = 0;
  1312.  
  1313.     //Get length of string
  1314.     int i = 0;
  1315.     while (binaryString[i] == '0' || binaryString[i] == '1')
  1316.     {
  1317.         length++;
  1318.         i++;
  1319.     }
  1320.  
  1321.     for (int i = 0; i < length; i++)
  1322.     {
  1323.         //0 in binary is just 0, so it only needs to add on the 1s
  1324.         if (binaryString[i] == '1')
  1325.             decimalValue += pow(2, indexCounter);
  1326.         indexCounter++;
  1327.     }
  1328.     return decimalValue;
  1329. }
  1330.  
  1331. void Binary::SetBit(char & bitfield, char bit, char value)
  1332. {
  1333.     bitfield |= (bit << value);
  1334. }
  1335. char Binary::CheckBit(char & bitfield, char bit)
  1336. {
  1337.     return bitfield & bit;
  1338. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement