cs381/as6/components/PhysicsComponent.hpp

49 lines
1.5 KiB
C++

#pragma once
#include "Component.hpp"
/**
* Integrates velocity into transform each frame with a speed cap.
*/
struct PhysicsComponent : public Component {
float vx = 0.0f;
float vy = 0.0f;
float speedCap = 400.0f;
/**
* Clamps the provided velocity vector to this component's speed cap.
*/
void ClampVelocity(float &vxRef, float &vyRef) const;
void ClampVelocity(double &vxRef, double &vyRef) const;
/**
* Integrates a position by velocity over dt.
*/
static void IntegratePosition(float &xRef, float &yRef, float vxValue, float vyValue, float dt);
static void IntegratePosition(double &xRef, double &yRef, double vxValue, double vyValue,
double dt);
/**
* Returns true when the given X position is inside a null zone.
*/
bool IsInsideNullZone(double xPos) const;
/**
* Computes velocity delta from well gravity for a position.
* Returns false when gravity should not apply.
*/
bool ComputeWellDeltaVelocity(double px, double py, double dt, double &dvx, double &dvy,
bool ignoreWellActive = false) const;
/**
* Performs one projected simulation step using well/null-zone rules,
* velocity clamp, and position integration.
*/
void SimulateStep(double &xRef, double &yRef, double &vxRef, double &vyRef, double dt,
bool ignoreWellActive = false) const;
void Setup() override;
void Update(float dt) override;
void Cleanup() override;
};