fix du probleme de spawn d'objets
fix: + les objets ne s'envolent plus vers le haut quand un nouvel objet est spawn
This commit is contained in:
parent
d51619f437
commit
4a77df6102
@ -636,9 +636,9 @@ bool ApplicationClass::Frame(InputClass* Input)
|
||||
static int lastMouseX = 0, lastMouseY = 0;
|
||||
|
||||
static float rotation = 360.0f;
|
||||
static float x = 0.f;
|
||||
static float y = 3.f;
|
||||
static float z = 0.f;
|
||||
static float x = 0.0f;
|
||||
static float y = 3.0f;
|
||||
static float z = 0.0f;
|
||||
|
||||
// Update the system stats.
|
||||
m_Timer->Frame();
|
||||
@ -736,7 +736,7 @@ bool ApplicationClass::Frame(InputClass* Input)
|
||||
keyUp = Input->IsUpArrowPressed();
|
||||
keyDown = Input->IsDownArrowPressed();
|
||||
|
||||
for (auto object : m_object)
|
||||
for (auto& object : m_object)
|
||||
{
|
||||
if (object != nullptr) // Check if the object is not null
|
||||
{
|
||||
@ -778,8 +778,7 @@ bool ApplicationClass::Frame(InputClass* Input)
|
||||
position = position + velocity * frameTime;
|
||||
object->SetPosition(position);
|
||||
|
||||
m_Physics->ApplyGravity(object, frameTime);
|
||||
m_Physics->ApplyDrag(object, 1.0f, frameTime);
|
||||
m_Physics->ApplyGravity(object, 1.0f, frameTime);
|
||||
|
||||
// Check if the object has fallen below a certain position
|
||||
if (XMVectorGetY(object->GetPosition()) < -30.0f)
|
||||
|
@ -3,14 +3,14 @@ Pos=60,60
|
||||
Size=400,400
|
||||
|
||||
[Window][Khaotic Engine]
|
||||
Pos=593,31
|
||||
Pos=29,636
|
||||
Size=694,210
|
||||
|
||||
[Window][Objects]
|
||||
Pos=81,40
|
||||
Pos=34,270
|
||||
Size=492,353
|
||||
|
||||
[Window][Terrain]
|
||||
Pos=1120,255
|
||||
Pos=755,731
|
||||
Size=418,94
|
||||
|
||||
|
@ -28,7 +28,7 @@ void Physics::SetGravity(XMVECTOR gravity)
|
||||
}
|
||||
|
||||
// Apply gravity to an object
|
||||
void Physics::ApplyGravity(Object* object, float frameTime)
|
||||
void Physics::ApplyGravity(Object* object, float dragValue, float frameTime)
|
||||
{
|
||||
if (object == nullptr) // Verify if the object is not null
|
||||
{
|
||||
@ -41,30 +41,13 @@ void Physics::ApplyGravity(Object* object, float frameTime)
|
||||
// Add the gravity acceleration to the object's current acceleration
|
||||
object->SetAcceleration(object->GetAcceleration() + gravityAcceleration);
|
||||
|
||||
// Get the object velocity
|
||||
XMVECTOR velocity = object->GetVelocity();
|
||||
|
||||
// Update the velocity with the object's acceleration
|
||||
velocity += object->GetAcceleration() * 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;
|
||||
}
|
||||
|
||||
// Calculate the acceleration caused by drag
|
||||
XMVECTOR dragAcceleration = -object->GetVelocity() * dragValue / object->GetMass();
|
||||
|
||||
// Add the drag acceleration to the object's current acceleration
|
||||
object->SetAcceleration(object->GetAcceleration() + dragAcceleration);
|
||||
|
||||
// Get the velocity of the object
|
||||
// Get the object velocity
|
||||
XMVECTOR velocity = object->GetVelocity();
|
||||
|
||||
// Update the velocity with the object's acceleration
|
||||
|
@ -12,8 +12,7 @@ public:
|
||||
|
||||
XMVECTOR GetGravity() const; // Get the gravity value
|
||||
void SetGravity(XMVECTOR gravity); // Define the gravity value
|
||||
void ApplyGravity(Object*, float); // Apply gravity to an object
|
||||
void ApplyDrag(Object*, float, float);
|
||||
void ApplyGravity(Object*, float, float); // Apply gravity to an object
|
||||
void ApplyForce(Object*, XMVECTOR);
|
||||
|
||||
private:
|
||||
|
Loading…
x
Reference in New Issue
Block a user