diff --git a/enginecustom/applicationclass.cpp b/enginecustom/applicationclass.cpp index d619213..a840de2 100644 --- a/enginecustom/applicationclass.cpp +++ b/enginecustom/applicationclass.cpp @@ -716,7 +716,7 @@ bool ApplicationClass::Frame(InputClass* Input) } // Update the rotation variable each frame. - rotation -= 0.0174532925f * speed; + rotation -= 0.0174532925f * m_speed; if (rotation < 0.0f) { rotation += 360.0f; @@ -760,6 +760,20 @@ bool ApplicationClass::Frame(InputClass* Input) } } + for (auto& object2 : m_object) + { + if (object->GetId() != object2->GetId() && object2 != nullptr) + { + if (m_Physics->IsColliding(object, object2)) + { + // Stop movement in any direction + object->SetVelocity(XMVectorZero()); + object->SetAcceleration(XMVectorZero()); + } + } + + } + // Apply forces float forceX = 0, forceY = 0, forceZ = 0, forceW = 0; @@ -1328,9 +1342,11 @@ void ApplicationClass::AddKobject(WCHAR* filepath) Object* newObject = new Object(); newObject->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), modelFilename, textureFilename, textureFilename2, textureFilename3); newObject->SetMass(1.0f); - newObject->SetTranslateMatrix(XMMatrixTranslation(0.0f, 50.0f, 0.0f)); newObject->SetName(filename); + newObject->SetId(m_ObjectId); + + m_ObjectId++; m_object.push_back(newObject); } diff --git a/enginecustom/applicationclass.h b/enginecustom/applicationclass.h index 87550cc..3f6836a 100644 --- a/enginecustom/applicationclass.h +++ b/enginecustom/applicationclass.h @@ -64,8 +64,8 @@ public: int GetScreenWidth() const; int GetScreenHeight() const; - float GetSpeed() const { return speed; }; - void SetSpeed(float speed) { this->speed = speed; }; + float GetSpeed() const { return m_speed; }; + void SetSpeed(float speed) { this->m_speed = speed; }; void AddCube(); void DeleteKobject(int index); @@ -116,8 +116,9 @@ private : Object* m_SelectedObject; std::vector m_cubes; std::vector m_terrainChunk; - float speed = 0.1f; // speed for the demo spinning object + float m_speed = 0.1f; // speed for the demo spinning object std::vector m_object; + int m_ObjectId = 0; // ----------------------------------- // // ------------- LIGHTS -------------- // diff --git a/enginecustom/imgui.ini b/enginecustom/imgui.ini index b2e9417..6c66b0c 100644 --- a/enginecustom/imgui.ini +++ b/enginecustom/imgui.ini @@ -7,7 +7,7 @@ Pos=-1,652 Size=694,210 [Window][Objects] -Pos=6,299 +Pos=7,299 Size=492,353 [Window][Terrain] diff --git a/enginecustom/object.cpp b/enginecustom/object.cpp index 3d19f39..ea0f053 100644 --- a/enginecustom/object.cpp +++ b/enginecustom/object.cpp @@ -12,6 +12,7 @@ Object::Object() : ModelClass() m_acceleration = XMVectorZero(); m_mass = NULL; m_isGrounded = false; + m_id = NULL; } Object::~Object() @@ -213,3 +214,13 @@ bool Object::GetGrounded() const return m_isGrounded; } +int Object::SetId(int id) +{ + return m_id = id; +} + +int Object::GetId() const +{ + return m_id; +} + diff --git a/enginecustom/object.h b/enginecustom/object.h index e488087..db82b29 100644 --- a/enginecustom/object.h +++ b/enginecustom/object.h @@ -47,11 +47,14 @@ public: std::string GetName(); void SetName(std::string name); + int SetId(int id); + int GetId() const; public : bool m_demoSpinning = false; XMVECTOR m_previousPosition; XMVECTOR m_velocity; + int m_id; private: XMMATRIX m_scaleMatrix;