feat: improve fps controller / add fog and ambient light to the scene
This commit is contained in:
@@ -58,6 +58,9 @@ public:
|
||||
[[nodiscard]] bool AllowsSleep() const { return m_AllowSleep; }
|
||||
void SetAllowSleep(bool allowSleep) { m_AllowSleep = allowSleep; NotifyPhysicsChanged(); }
|
||||
|
||||
[[nodiscard]] bool FreezesRotation() const { return m_FreezeRotation; }
|
||||
void SetFreezeRotation(bool freezeRotation) { m_FreezeRotation = freezeRotation; NotifyPhysicsChanged(); }
|
||||
|
||||
[[nodiscard]] PhysicsWorld* GetPhysicsWorld() const { return m_World; }
|
||||
|
||||
private:
|
||||
@@ -72,4 +75,5 @@ private:
|
||||
|
||||
bool m_UseGravity{true};
|
||||
bool m_AllowSleep{true};
|
||||
bool m_FreezeRotation{false};
|
||||
};
|
||||
|
||||
@@ -20,7 +20,7 @@ public:
|
||||
void init(GfxDevice& gfxDevice, RenderResources& resources, VkFormat drawImageFormat, VkFormat depthImageFormat);
|
||||
void cleanup(VkDevice device);
|
||||
|
||||
void draw(VkCommandBuffer cmd, RenderResources& resources, const Camera& camera);
|
||||
void draw(VkCommandBuffer cmd, RenderResources& resources, const Camera& camera, float rotation);
|
||||
|
||||
void setSkyboxImage(const ImageID skyboxId);
|
||||
|
||||
@@ -30,8 +30,6 @@ private:
|
||||
std::unique_ptr<Pipeline> pipeline;
|
||||
ImageID skyboxTextureId{NULL_IMAGE_ID};
|
||||
|
||||
glm::mat4 skyboxRotation{1.f};
|
||||
|
||||
struct SkyboxPushConstants {
|
||||
glm::mat4 invViewProj;
|
||||
glm::vec4 skyboxRot[3];
|
||||
|
||||
@@ -34,6 +34,7 @@ public:
|
||||
float ambientIntensity;
|
||||
glm::vec3 fogColor;
|
||||
float fogDensity;
|
||||
float skyboxRotation{0.0f}; // radians around the world up axis
|
||||
};
|
||||
|
||||
explicit GameRenderer();
|
||||
|
||||
@@ -53,7 +53,8 @@ public:
|
||||
bool Raycast(const glm::vec3& origin,
|
||||
const glm::vec3& direction,
|
||||
float maxDistance,
|
||||
PhysicsRaycastHit& hit) const override;
|
||||
PhysicsRaycastHit& hit,
|
||||
PhysicsBodyHandle ignoreBody = {}) const override;
|
||||
|
||||
std::vector<TriggerEvent> ConsumeTriggerEvents() override;
|
||||
|
||||
|
||||
@@ -115,6 +115,7 @@ struct PhysicsBodyDesc {
|
||||
float mass{1.0f};
|
||||
bool useGravity{true};
|
||||
bool allowSleep{true};
|
||||
bool freezeRotation{false};
|
||||
};
|
||||
|
||||
struct TriggerEvent {
|
||||
|
||||
@@ -46,10 +46,12 @@ public:
|
||||
virtual void AddForce(PhysicsBodyHandle body, const glm::vec3& force) = 0;
|
||||
virtual void AddImpulse(PhysicsBodyHandle body, const glm::vec3& impulse) = 0;
|
||||
|
||||
// Triggers are never hit. ignoreBody is skipped too, e.g. so a character can cast from inside its own collider
|
||||
virtual bool Raycast(const glm::vec3& origin,
|
||||
const glm::vec3& direction,
|
||||
float maxDistance,
|
||||
PhysicsRaycastHit& hit) const = 0;
|
||||
PhysicsRaycastHit& hit,
|
||||
PhysicsBodyHandle ignoreBody = {}) const = 0;
|
||||
|
||||
// Trigger events accumulated during the last Step().
|
||||
virtual std::vector<TriggerEvent> ConsumeTriggerEvents() { return {}; }
|
||||
|
||||
@@ -46,7 +46,8 @@ public:
|
||||
bool Raycast(const glm::vec3& origin,
|
||||
const glm::vec3& direction,
|
||||
float maxDistance,
|
||||
PhysicsRaycastHit& hit) const override;
|
||||
PhysicsRaycastHit& hit,
|
||||
PhysicsBodyHandle ignoreBody = {}) const override;
|
||||
|
||||
void SyncKinematicBodiesToPhysics();
|
||||
void SyncDynamicBodiesToTransforms();
|
||||
|
||||
@@ -14,6 +14,18 @@
|
||||
|
||||
class CameraComponent;
|
||||
class GameObject;
|
||||
|
||||
|
||||
struct SceneEnvironment {
|
||||
glm::vec3 ambientColor{0.1f};
|
||||
float ambientIntensity{0.5f};
|
||||
|
||||
glm::vec3 fogColor{0.5f};
|
||||
float fogDensity{0.0f};
|
||||
|
||||
float skyboxRotationSpeed{0.01f};
|
||||
float skyboxRotation{0.0f};
|
||||
};
|
||||
class SceneSerializer;
|
||||
class PhysicsWorld;
|
||||
|
||||
@@ -107,6 +119,9 @@ public:
|
||||
|
||||
PhysicsSceneBridge& GetPhysics() { return m_Physics; }
|
||||
|
||||
[[nodiscard]] SceneEnvironment& GetEnvironment() { return m_Environment; }
|
||||
[[nodiscard]] const SceneEnvironment& GetEnvironment() const { return m_Environment; }
|
||||
|
||||
[[nodiscard]] CameraComponent* GetCurrentCamera() const;
|
||||
[[nodiscard]] std::vector<CameraComponent*> GetCameras() const;
|
||||
void SetCurrentCamera(const CameraComponent* camera);
|
||||
@@ -134,6 +149,10 @@ private:
|
||||
|
||||
ObjectId m_CurrentCameraId{InvalidObjectId};
|
||||
|
||||
SceneEnvironment m_Environment{};
|
||||
|
||||
void DrawSettingsImGui();
|
||||
|
||||
std::function<void()> m_registerBindings;
|
||||
std::function<void()> m_unregisterBindings;
|
||||
bool m_bindingsUnloaded{false};
|
||||
|
||||
@@ -14,6 +14,10 @@ public:
|
||||
[[nodiscard]] double FixedDeltaTime() const;
|
||||
[[nodiscard]] double DeltaTime() const;
|
||||
|
||||
// How far the current frame is between the last two fixed steps (0..1), used to interpolate physics objects
|
||||
[[nodiscard]] float FixedAlpha() const { return m_FixedAlpha; }
|
||||
void SetFixedAlpha(float alpha) { m_FixedAlpha = alpha; }
|
||||
|
||||
[[nodiscard]] std::chrono::nanoseconds SleepDuration() const;
|
||||
|
||||
void Update();
|
||||
@@ -25,6 +29,7 @@ private:
|
||||
static constexpr double m_FixedDeltaTime{1.0 / 60.0};
|
||||
static constexpr double FPS{60};
|
||||
double m_DeltaTime{};
|
||||
float m_FixedAlpha{1.0f};
|
||||
std::chrono::high_resolution_clock::time_point m_PrevTime;
|
||||
};
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ namespace ImGuiUtils {
|
||||
const std::vector<std::shared_ptr<GameObject>>& pendingAdditions,
|
||||
ObjectId& selectedObjectId,
|
||||
const std::function<GameObject*()>& createGameObject,
|
||||
const std::function<void()>& drawSceneSettings,
|
||||
bool* open = nullptr);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user