Advertisement
Guest User

Math.h

a guest
Jul 5th, 2015
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.18 KB | None | 0 0
  1. #pragma once
  2. #include "Globals.h"
  3. class Vector3D
  4. {
  5. public:
  6.     float x;
  7.     float y;
  8.     float z;
  9.     //SwapLines1
  10.     //AddRandomTrash   
  11.     //AddRandomTrash   
  12.     //AddRandomTrash   
  13.     //AddRandomTrash   
  14.     Vector3D(){};
  15.  
  16.     Vector3D(float r, float s, float t){ x = r; y = s; z = t; };
  17.  
  18.     Vector3D& Set(float r, float s, float t){ x = r; y = s; z = t; return (*this); };
  19.  
  20.     float& operator [](long k){ return ((&x)[k]); };
  21.  
  22.     const float& operator [](long k) const{ return ((&x)[k]); };
  23.  
  24.     Vector3D& operator +=(const Vector3D& v){ x += v.x; y += v.y; z += v.z; return (*this); };
  25.  
  26.     Vector3D& operator -=(const Vector3D& v){ x -= v.x; y -= v.y; z -= v.z; return (*this); };
  27.  
  28.     Vector3D& operator *=(float t){ x *= t; y *= t; z *= t; return (*this); };
  29.  
  30.     Vector3D& operator /=(float t){ float f = 1.0F / t; x *= f; y *= f; z *= f; return (*this); };
  31.  
  32.     Vector3D& operator %=(const Vector3D& v){ float r, s; r = y * v.z - z * v.y; s = z * v.x - x * v.z; z = x * v.y - y * v.x; x = r; y = s; return (*this); };
  33.  
  34.     Vector3D& operator &=(const Vector3D& v){ x *= v.x; y *= v.y; z *= v.z; return (*this); };
  35.  
  36.     Vector3D operator -(void) const{ return (Vector3D(-x, -y, -z)); };
  37.  
  38.     Vector3D operator +(const Vector3D& v) const{ return (Vector3D(x + v.x, y + v.y, z + v.z)); };
  39.  
  40.     Vector3D operator -(const Vector3D& v) const{ return (Vector3D(x - v.x, y - v.y, z - v.z)); };
  41.  
  42.     Vector3D operator *(float t) const{ return (Vector3D(x * t, y * t, z * t)); };
  43.  
  44.     Vector3D operator /(float t) const{ float f = 1.0F / t; return (Vector3D(x * f, y * f, z * f)); };
  45.  
  46.     float operator *(const Vector3D& v) const{ return (x * v.x + y * v.y + z * v.z); };
  47.  
  48.     Vector3D operator %(const Vector3D& v) const{ return (Vector3D(y * v.z - z * v.y, z * v.x - x * v.z, x * v.y - y * v.x)); };
  49.  
  50.     Vector3D operator &(const Vector3D& v) const{ return (Vector3D(x * v.x, y * v.y, z * v.z)); };
  51.  
  52.     bool operator ==(const Vector3D& v) const{ return ((x == v.x) && (y == v.y) && (z == v.z)); };
  53.  
  54.     bool operator !=(const Vector3D& v) const{ return ((x != v.x) || (y != v.y) || (z != v.z)); };
  55.  
  56.     Vector3D& Normalize(void){ return (*this /= sqrtf(x * x + y * y + z * z)); };
  57.     //SwapLines0
  58. };
  59.  
  60. inline Vector3D operator *(float t, const Vector3D& v)
  61. {
  62.     return (Vector3D(t * v.x, t * v.y, t * v.z));
  63. }
  64.  
  65. inline float Dot(const Vector3D& v1, const Vector3D& v2)
  66. {
  67.     return (v1 * v2);
  68. }
  69.  
  70. inline Vector3D Cross(const Vector3D& v1, const Vector3D& v2)
  71. {
  72.     return (v1 % v2);
  73. }
  74.  
  75. inline float Magnitude(const Vector3D& v)
  76. {
  77.     return (sqrtf(v.x * v.x + v.y * v.y + v.z * v.z));
  78. }
  79.  
  80. inline float InverseMag(const Vector3D& v)
  81. {
  82.     return (1.0F / sqrtf(v.x * v.x + v.y * v.y + v.z * v.z));
  83. }
  84.  
  85. inline float SquaredMag(const Vector3D& v)
  86. {
  87.     return (v.x * v.x + v.y * v.y + v.z * v.z);
  88. }
  89.  
  90.  
  91. class ViewMatrix
  92. {
  93. public:
  94.     float Matrix[4][4];
  95. };
  96.  
  97. class BoneMatrix
  98. {
  99. public:
  100.     float Matrix[3][4];
  101. };
  102.  
  103. class Bones
  104. {
  105. public:
  106.     bool IsOnScreen;
  107.     Vector3D PositionInGame;
  108.     Vector3D PositionOnScreen;
  109. };
  110.  
  111. float Get3dDistance(Vector3D Pos1, Vector3D Pos2);
  112. bool WorldToScreen(Vector3D PositionIn, Vector3D &PositionOut);
  113. void CalcAngle(Vector3D src, Vector3D dst, Vector3D &angles);
  114. Vector3D AngleToDirection(Vector3D angle);
  115.  
  116. extern ViewMatrix vMatrix;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement