mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-11-20 17:39:46 +00:00
move to namespace
This commit is contained in:
parent
67ed7ac582
commit
8798b34423
8 changed files with 63 additions and 45 deletions
|
|
@ -24,8 +24,8 @@ static glm::vec3 calc_nearby_reach(
|
|||
|
||||
glm::vec3 reach(
|
||||
0.5f,
|
||||
hitbox.stepHeight * 2.0f + E * 8.0f + ext.y * 0.5f +
|
||||
maxSolidHalfY + 0.5f + MAX_FIX * 2.0f,
|
||||
hitbox.stepHeight * 2.0f + physics::E * 8.0f + ext.y * 0.5f +
|
||||
maxSolidHalfY + 0.5f + physics::MAX_FIX * 2.0f,
|
||||
0.5f
|
||||
);
|
||||
reach += ext + budget;
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ void PhysicsSolver::step(
|
|||
float dt = delta / static_cast<float>(substeps);
|
||||
broadPhase.build(delta);
|
||||
for (auto hitbox : hitboxes) {
|
||||
schedule_substep(*hitbox, gravity, 0, substeps, dt);
|
||||
physics::schedule_substep(*hitbox, gravity, 0, substeps, dt);
|
||||
}
|
||||
|
||||
for (uint i = 0; i < substeps; i++) {
|
||||
|
|
@ -44,12 +44,14 @@ void PhysicsSolver::step(
|
|||
dt * static_cast<float>(i + 1 - hitbox->doneSubsteps);
|
||||
while (hitbox->doneSubsteps <= i) {
|
||||
uint left = i + 1 - hitbox->doneSubsteps;
|
||||
uint skip = calc_substep_stride(*hitbox, gravity, dt, left) - 1;
|
||||
uint skip =
|
||||
physics::calc_substep_stride(*hitbox, gravity, dt, left) -
|
||||
1;
|
||||
if (skip > 0) {
|
||||
integrate(*hitbox, gravity, dt, skip);
|
||||
physics::integrate(*hitbox, gravity, dt, skip);
|
||||
hitbox->doneSubsteps += skip;
|
||||
}
|
||||
calc_substep(
|
||||
physics::calc_substep(
|
||||
*hitbox,
|
||||
{this->chunks,
|
||||
broadPhase.getNearbySolids(j),
|
||||
|
|
@ -61,7 +63,7 @@ void PhysicsSolver::step(
|
|||
|
||||
broadPhase.update(j, dt * static_cast<float>(substeps - i));
|
||||
}
|
||||
schedule_substep(*hitbox, gravity, i + 1, substeps, dt);
|
||||
physics::schedule_substep(*hitbox, gravity, i + 1, substeps, dt);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -84,7 +86,7 @@ void PhysicsSolver::step(
|
|||
hitbox->groundVelocity *= 1.0f - delta;
|
||||
}
|
||||
|
||||
update_sensors(*hitbox, sensors);
|
||||
physics::update_sensors(*hitbox, sensors);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@
|
|||
#define GLM_ENABLE_EXPERIMENTAL
|
||||
#include <glm/gtx/norm.hpp>
|
||||
|
||||
using namespace physics;
|
||||
|
||||
static glm::vec3 calc_collsion_velocity_result(
|
||||
const Hitbox& a, const Hitbox& b
|
||||
) {
|
||||
|
|
@ -316,7 +318,7 @@ static void calc_collisions(
|
|||
}
|
||||
}
|
||||
|
||||
void calc_substep(Hitbox& hitbox, const CollisionContext& ctx) {
|
||||
void physics::calc_substep(Hitbox& hitbox, const CollisionContext& ctx) {
|
||||
const auto& chunks = ctx.chunks;
|
||||
const auto& solids = ctx.solids;
|
||||
const auto& gravity = ctx.gravity;
|
||||
|
|
|
|||
|
|
@ -9,15 +9,17 @@
|
|||
|
||||
class GlobalChunks;
|
||||
|
||||
inline constexpr float E = 0.03f;
|
||||
inline constexpr float MAX_FIX = 0.1f;
|
||||
namespace physics {
|
||||
inline constexpr float E = 0.03f;
|
||||
inline constexpr float MAX_FIX = 0.1f;
|
||||
|
||||
struct CollisionContext {
|
||||
const GlobalChunks& chunks;
|
||||
const std::vector<Hitbox*>& solids;
|
||||
glm::vec3 gravity;
|
||||
float dt;
|
||||
uint wakeSubstep;
|
||||
};
|
||||
struct CollisionContext {
|
||||
const GlobalChunks& chunks;
|
||||
const std::vector<Hitbox*>& solids;
|
||||
glm::vec3 gravity;
|
||||
float dt;
|
||||
uint wakeSubstep;
|
||||
};
|
||||
|
||||
void calc_substep(Hitbox& hitbox, const CollisionContext& ctx);
|
||||
void calc_substep(Hitbox& hitbox, const CollisionContext& ctx);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
inline constexpr float MAX_SUBSTEP_MOVE = 0.03f;
|
||||
inline constexpr float MAX_SUBSTEP_SINK = 0.015f;
|
||||
|
||||
uint calc_substep_stride(
|
||||
uint physics::calc_substep_stride(
|
||||
const Hitbox& hitbox, const glm::vec3& gravity, float dt, uint left
|
||||
) {
|
||||
if (hitbox.crouching) {
|
||||
|
|
@ -28,7 +28,7 @@ uint calc_substep_stride(
|
|||
return glm::max(1u, static_cast<uint>(stride));
|
||||
}
|
||||
|
||||
void schedule_substep(
|
||||
void physics::schedule_substep(
|
||||
Hitbox& hitbox, const glm::vec3& gravity, uint done, uint substeps, float dt
|
||||
) {
|
||||
hitbox.doneSubsteps = done;
|
||||
|
|
|
|||
|
|
@ -7,27 +7,35 @@
|
|||
#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);
|
||||
namespace physics {
|
||||
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
|
||||
);
|
||||
}
|
||||
|
||||
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
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
#include "sensors.hpp"
|
||||
|
||||
void update_sensors(Hitbox& hitbox, const std::vector<Sensor*>& sensors) {
|
||||
void physics::update_sensors(
|
||||
Hitbox& hitbox, const std::vector<Sensor*>& sensors
|
||||
) {
|
||||
auto aabb = hitbox.getAABB();
|
||||
|
||||
for (size_t i = 0; i < sensors.size(); i++) {
|
||||
|
|
|
|||
|
|
@ -4,4 +4,6 @@
|
|||
|
||||
#include <vector>
|
||||
|
||||
void update_sensors(Hitbox& hitbox, const std::vector<Sensor*>& sensors);
|
||||
namespace physics {
|
||||
void update_sensors(Hitbox& hitbox, const std::vector<Sensor*>& sensors);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue