feat: ajout de la trainee (drag)

j'espere que c'est bien comme ça que ça marche
This commit is contained in:
StratiX0 2024-04-09 12:30:37 +02:00
parent b37f253c5c
commit ebccd2cf68
8 changed files with 67 additions and 15 deletions

View File

@ -728,18 +728,25 @@ bool ApplicationClass::Frame(InputClass* Input)
//// Update the z position variable each frame. //// Update the z position variable each frame.
//z -= 0.0174532925f * 0.2f; //z -= 0.0174532925f * 0.2f;
for (auto object : m_object) for (auto object : m_object)
{ {
if (object != nullptr) // Vérifie que l'objet n'est pas nullptr if (object != nullptr) // Check if the object is not null
{ {
m_Physics->ApplyGravity(object, frameTime);
if (XMVectorGetY(object->GetPosition()) < -10.0f) if (XMVectorGetY(object->GetPosition()) < -10.0f)
{ {
// Obtenez la position actuelle de l'objet XMVECTOR currentPosition = object->GetPosition(); // Obtain the current position of the object
XMVECTOR currentPosition = object->GetPosition(); object->SetPosition(XMVectorSetY(currentPosition, 20.0f)); // Define the new position of the object
// Définissez la nouvelle position y tout en conservant les positions x et z actuelles
object->SetPosition(XMVectorSetY(currentPosition, 20.0f));
} }
m_Physics->ApplyGravity(object, frameTime);
m_Physics->ApplyDrag(object, 0.1f, frameTime);
// Update object position based on its velocity
XMVECTOR position = object->GetPosition();
XMVECTOR velocity = object->GetVelocity();
position = position + velocity * frameTime;
object->SetPosition(position);
object->m_previousPosition = object->GetPosition();
} }
} }

View File

@ -160,6 +160,7 @@ private :
Physics* m_Physics; Physics* m_Physics;
float m_gravity; float m_gravity;
XMVECTOR m_previousPosition;
}; };
#endif #endif

View File

@ -382,8 +382,12 @@
<None Include="translate.ps"> <None Include="translate.ps">
<Filter>shader</Filter> <Filter>shader</Filter>
</None> </None>
<None Include="reflection.vs" /> <None Include="reflection.ps">
<None Include="reflection.ps" /> <Filter>shader</Filter>
</None>
<None Include="reflection.vs">
<Filter>shader</Filter>
</None>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Text Include="font01.txt"> <Text Include="font01.txt">

View File

@ -3,14 +3,14 @@ Pos=60,60
Size=400,400 Size=400,400
[Window][Khaotic Engine] [Window][Khaotic Engine]
Pos=819,137 Pos=587,47
Size=694,210 Size=694,210
[Window][Objects] [Window][Objects]
Pos=222,19 Pos=91,47
Size=492,353 Size=492,353
[Window][Terrain] [Window][Terrain]
Pos=890,19 Pos=1120,255
Size=418,94 Size=418,94

View File

@ -7,6 +7,8 @@ Object::Object() : ModelClass()
m_translateMatrix = XMMatrixIdentity(); m_translateMatrix = XMMatrixIdentity();
m_srMatrix = XMMatrixIdentity(); m_srMatrix = XMMatrixIdentity();
m_worldMatrix = XMMatrixIdentity(); m_worldMatrix = XMMatrixIdentity();
m_previousPosition = XMVectorZero();
m_velocity = XMVectorZero();
} }
Object::~Object() Object::~Object()
@ -162,3 +164,13 @@ void Object::SetName(std::string name)
{ {
m_name = name; m_name = name;
} }
void Object::SetVelocity(XMVECTOR velocity)
{
m_velocity = velocity;
}
XMVECTOR Object::GetVelocity()
{
return m_velocity;
}

View File

@ -27,6 +27,9 @@ public:
XMVECTOR GetRotation(); XMVECTOR GetRotation();
XMVECTOR GetScale(); XMVECTOR GetScale();
void SetVelocity(XMVECTOR);
XMVECTOR GetVelocity();
void UpdateWorldMatrix(); void UpdateWorldMatrix();
void UpdateSRMatrix(); void UpdateSRMatrix();
void UpdateScaleMatrix(); void UpdateScaleMatrix();
@ -40,6 +43,8 @@ public:
public : public :
bool m_demoSpinning = false; bool m_demoSpinning = false;
XMVECTOR m_previousPosition;
XMVECTOR m_velocity;
private: private:
XMMATRIX m_scaleMatrix; XMMATRIX m_scaleMatrix;

View File

@ -35,8 +35,29 @@ void Physics::ApplyGravity(Object* object, float frameTime)
return; return;
} }
// Update the object position // Get the object velocity
XMVECTOR position = object->GetPosition(); XMVECTOR velocity = object->GetVelocity();
position = XMVectorSetY(position, XMVectorGetY(position) + m_gravity * frameTime); // Update the Y position
object->SetPosition(position); // Update the Y component of the velocity
velocity = XMVectorSetY(velocity, XMVectorGetY(velocity) + m_gravity * frameTime);
// Set the new velocity
object->SetVelocity(velocity);
}
void Physics::ApplyDrag(Object* object, float dragValue, float frameTime)
{
if (object == nullptr) // Verify if the object is not null
{
return;
}
// Get the velocity of the object
XMVECTOR velocity = object->GetVelocity();
// Calculate the new velocity
XMVECTOR newVelocity = velocity - (velocity * dragValue * frameTime);
// Update the velocity of the object
object->SetVelocity(newVelocity);
} }

View File

@ -13,6 +13,8 @@ public:
float GetGravity(); // Get the gravity value float GetGravity(); // Get the gravity value
void SetGravity(float gravity); // Define the gravity value void SetGravity(float gravity); // Define the gravity value
void ApplyGravity(Object*, float); // Apply gravity to an object void ApplyGravity(Object*, float); // Apply gravity to an object
void ApplyDrag(Object*, float, float);
private: private:
float m_gravity; float m_gravity;