feat: object id et objects collisions
feat: + Ajout d'un id pour chaque objet cree + Ajout de collision entre les objets
This commit is contained in:
parent
50d206649b
commit
9dd129b7bc
@ -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);
|
||||
}
|
||||
|
@ -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<Object*> m_cubes;
|
||||
std::vector<Object*> 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<Object*> m_object;
|
||||
int m_ObjectId = 0;
|
||||
|
||||
// ----------------------------------- //
|
||||
// ------------- LIGHTS -------------- //
|
||||
|
@ -7,7 +7,7 @@ Pos=-1,652
|
||||
Size=694,210
|
||||
|
||||
[Window][Objects]
|
||||
Pos=6,299
|
||||
Pos=7,299
|
||||
Size=492,353
|
||||
|
||||
[Window][Terrain]
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user