Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2021
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.83 KB | None | 0 0
  1. #include "pch.h"
  2. #include "Main_Types.h"
  3. #include "Graphic_Library.h"
  4. #include "Graphic_Library.cpp"
  5.  
  6. struct Vector2 {
  7. public:
  8.     float x;
  9. public:
  10.     float y;
  11. #pragma region Operators   
  12.  
  13. public:
  14.     void operator+=(const Vector2 value) {
  15.         x += value.x;
  16.         y += value.y;
  17.     }
  18. public:
  19.     void operator-=(const Vector2 value) {
  20.         x -= value.x;
  21.         y -= value.y;
  22.     }
  23. public:
  24.     void operator*=(const Vector2 value) {
  25.         x *= value.x;
  26.         y *= value.y;
  27.     }
  28. public:
  29.     void operator/=(const Vector2 value) {
  30.         x /= value.x;
  31.         y /= value.y;
  32.     }
  33.  
  34. public:
  35.     Vector2 operator+(const Vector2 value) const {
  36.         return Vector2(x + value.x, y + value.y);
  37.     }
  38. public:
  39.     Vector2 operator-(const Vector2 value) const {
  40.         return Vector2(x - value.x, y - value.y);
  41.     }
  42. public:
  43.     Vector2 operator*(const Vector2 value) const {
  44.         return Vector2(x * value.x, y * value.y);
  45.     }
  46. public:
  47.     Vector2 operator/(const Vector2 value) const {
  48.         return Vector2(x / value.x, y / value.y);
  49.     }
  50.  
  51. #pragma endregion
  52.  
  53. public:
  54.     __declspec(dllexport) void Invert() {
  55.         x = -y;
  56.         y = -y;
  57.     }
  58. public:
  59.     __declspec(dllexport) float Magnitude() {
  60.  
  61.         return sqrtf(x * x + y * y);
  62.     }
  63. public:
  64.     __declspec(dllexport) float SquareMagnitude() {
  65.         return  abs(x * x + y * y);
  66.     }
  67. public:
  68.     __declspec(dllexport) void Normalize() {
  69.         float magnitude = Magnitude();
  70.         if (magnitude > 0)
  71.         {
  72.             x = x / magnitude;
  73.             y = y / magnitude;
  74.         }
  75.     }
  76.     /*
  77. public:
  78.     __declspec(dllexport) Vector2 ComponentProduct(const Vector2 vector) {
  79.         return Vector2(x * vector.x,y * vector.y);
  80.     }
  81. public:
  82.     __declspec(dllexport) void ComponentProductUpdate(const Vector2 vector) {
  83.         x *= vector.x;
  84.         y *= vector.y;
  85.     }
  86. public:
  87.     __declspec(dllexport) float ScalarProduct(const Vector2 vector) {
  88.         return x * vector.x + y * vector.y;
  89.     }
  90. public:
  91.     __declspec(dllexport) Vector2 VectorProduct(const Vector2 vector) {
  92.         return 0;
  93.     }
  94. public:
  95.     __declspec(dllexport) float DotProduct(const Vector2 vector) {
  96.         return (x * vector.x) + (y * vector.y);
  97.     }
  98. public:
  99.     __declspec(dllexport) float CrossProduct() {
  100.         return 0;
  101.     }
  102.     */
  103.  
  104.     Vector2(float x = 0, float y = 0) {
  105.         this->x = x;
  106.         this->y = y;
  107.     }
  108. };
  109.  
  110. class GameObject {
  111.     //------------------------------Graphical Library Variables-----------------------------//
  112. public:    COORD PositionObject;
  113. public:    Mesh MeshObject;
  114. public:    DWORD Color;
  115. public:    string Tag;
  116.       //------------------------------Graphical Library Variables-----------------------------//
  117.  
  118.       //------------------------------Physical Library Variables-----------------------------//
  119. public:   vector<Vector2> trianglesCollision;
  120. public:   Vector2 gravityVector;
  121. public:   float Mass;
  122. public:   float Friction;
  123. public:   float Buoyancy;
  124. public:   float SpringAbility;
  125.       //------------------------------Physical Library Variables-----------------------------//
  126.  
  127.       //------------------------------Other Variables-----------------------------//
  128. public: SpriteObject* SpritePart;
  129. public: PhysicalObject* PhysicalPart;
  130.       //------------------------------Other Variable-----------------------------//
  131.  
  132.       void AddGraphics(
  133.           Vector2 positionObject,
  134.           Mesh meshObject,
  135.           DWORD color = 15,
  136.           string tag = "null"
  137.       ) {
  138.           //Initialization graphical part
  139.           SpritePart->Pos = positionObject;
  140.           SpritePart->mesh = meshObject;
  141.           SpritePart->Tag = tag;
  142.           SpritePart->Color = color;
  143.       }
  144.  
  145.       void AddPhisics(
  146.           vector<Vector2> trianglesCollision,
  147.           Vector2 gravityVector = Vector2(0, -1),
  148.           float mass = 0,
  149.           float friction = 1,
  150.           float buoyancy = 1,
  151.           float springAbility = 0) {
  152.           //Initialization physical part
  153.           PhysicalPart->TrianglesCollision = trianglesCollision;
  154.           PhysicalPart->Buoyancy = buoyancy;
  155.           PhysicalPart->Friction = friction;
  156.           PhysicalPart->Mass = mass;
  157.           PhysicalPart->SpringAbility = springAbility;
  158.       }
  159. };
  160.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement