mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-11-21 01:49:44 +00:00
refactor physics solver
This commit is contained in:
parent
103f3b2b05
commit
67ed7ac582
12 changed files with 933 additions and 806 deletions
33
src/physics/scheduling.hpp
Normal file
33
src/physics/scheduling.hpp
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
#pragma once
|
||||
|
||||
#include "Hitbox.hpp"
|
||||
|
||||
#include "typedefs.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
inline void integrate(
|
||||
Hitbox& box, const glm::vec3& gravity, float dt, uint substeps
|
||||
) {
|
||||
float n = static_cast<float>(substeps);
|
||||
auto accel = gravity * box.gravityScale;
|
||||
box.position += box.velocity * (dt * n) +
|
||||
accel * (dt * dt * n * (n + 2.0f) * 0.5f);
|
||||
box.velocity += accel * (dt * n);
|
||||
}
|
||||
|
||||
inline void push_body(Hitbox& box, int axis, float value, uint wakeSubstep) {
|
||||
if (box.velocity[axis] != value) {
|
||||
box.velocity[axis] = value;
|
||||
box.nextSubstep = std::min(box.nextSubstep, wakeSubstep);
|
||||
}
|
||||
}
|
||||
|
||||
uint calc_substep_stride(
|
||||
const Hitbox& hitbox, const glm::vec3& gravity, float dt, uint left
|
||||
);
|
||||
|
||||
void schedule_substep(
|
||||
Hitbox& hitbox, const glm::vec3& gravity, uint done, uint substeps, float dt
|
||||
);
|
||||
Loading…
Add table
Add a link
Reference in a new issue