feat: ajout de la trainee (drag)
j'espere que c'est bien comme ça que ça marche
This commit is contained in:
parent
b37f253c5c
commit
ebccd2cf68
@ -728,18 +728,25 @@ bool ApplicationClass::Frame(InputClass* Input)
|
||||
//// Update the z position variable each frame.
|
||||
//z -= 0.0174532925f * 0.2f;
|
||||
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
// Obtenez la position actuelle de l'objet
|
||||
XMVECTOR currentPosition = object->GetPosition();
|
||||
// Définissez la nouvelle position y tout en conservant les positions x et z actuelles
|
||||
object->SetPosition(XMVectorSetY(currentPosition, 20.0f));
|
||||
XMVECTOR currentPosition = object->GetPosition(); // Obtain the current position of the object
|
||||
object->SetPosition(XMVectorSetY(currentPosition, 20.0f)); // Define the new position of the object
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -160,6 +160,7 @@ private :
|
||||
|
||||
Physics* m_Physics;
|
||||
float m_gravity;
|
||||
XMVECTOR m_previousPosition;
|
||||
};
|
||||
|
||||
#endif
|
@ -382,8 +382,12 @@
|
||||
<None Include="translate.ps">
|
||||
<Filter>shader</Filter>
|
||||
</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>
|
||||
<Text Include="font01.txt">
|
||||
|
@ -3,14 +3,14 @@ Pos=60,60
|
||||
Size=400,400
|
||||
|
||||
[Window][Khaotic Engine]
|
||||
Pos=819,137
|
||||
Pos=587,47
|
||||
Size=694,210
|
||||
|
||||
[Window][Objects]
|
||||
Pos=222,19
|
||||
Pos=91,47
|
||||
Size=492,353
|
||||
|
||||
[Window][Terrain]
|
||||
Pos=890,19
|
||||
Pos=1120,255
|
||||
Size=418,94
|
||||
|
||||
|
@ -7,6 +7,8 @@ Object::Object() : ModelClass()
|
||||
m_translateMatrix = XMMatrixIdentity();
|
||||
m_srMatrix = XMMatrixIdentity();
|
||||
m_worldMatrix = XMMatrixIdentity();
|
||||
m_previousPosition = XMVectorZero();
|
||||
m_velocity = XMVectorZero();
|
||||
}
|
||||
|
||||
Object::~Object()
|
||||
@ -161,4 +163,14 @@ std::string Object::GetName()
|
||||
void Object::SetName(std::string name)
|
||||
{
|
||||
m_name = name;
|
||||
}
|
||||
|
||||
void Object::SetVelocity(XMVECTOR velocity)
|
||||
{
|
||||
m_velocity = velocity;
|
||||
}
|
||||
|
||||
XMVECTOR Object::GetVelocity()
|
||||
{
|
||||
return m_velocity;
|
||||
}
|
@ -27,6 +27,9 @@ public:
|
||||
XMVECTOR GetRotation();
|
||||
XMVECTOR GetScale();
|
||||
|
||||
void SetVelocity(XMVECTOR);
|
||||
XMVECTOR GetVelocity();
|
||||
|
||||
void UpdateWorldMatrix();
|
||||
void UpdateSRMatrix();
|
||||
void UpdateScaleMatrix();
|
||||
@ -40,6 +43,8 @@ public:
|
||||
|
||||
public :
|
||||
bool m_demoSpinning = false;
|
||||
XMVECTOR m_previousPosition;
|
||||
XMVECTOR m_velocity;
|
||||
|
||||
private:
|
||||
XMMATRIX m_scaleMatrix;
|
||||
|
@ -35,8 +35,29 @@ void Physics::ApplyGravity(Object* object, float frameTime)
|
||||
return;
|
||||
}
|
||||
|
||||
// Update the object position
|
||||
XMVECTOR position = object->GetPosition();
|
||||
position = XMVectorSetY(position, XMVectorGetY(position) + m_gravity * frameTime); // Update the Y position
|
||||
object->SetPosition(position);
|
||||
// Get the object velocity
|
||||
XMVECTOR velocity = object->GetVelocity();
|
||||
|
||||
// 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);
|
||||
}
|
@ -13,6 +13,8 @@ public:
|
||||
float GetGravity(); // Get the gravity value
|
||||
void SetGravity(float gravity); // Define the gravity value
|
||||
void ApplyGravity(Object*, float); // Apply gravity to an object
|
||||
void ApplyDrag(Object*, float, float);
|
||||
|
||||
|
||||
private:
|
||||
float m_gravity;
|
||||
|
Loading…
x
Reference in New Issue
Block a user