mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 18:41:51 +00:00
Fixed PhysicsSolver, added zoom, linear_damping
This commit is contained in:
parent
2aba3e91db
commit
10931372cc
8 changed files with 83 additions and 46 deletions
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
#include <iostream>
|
||||
|
||||
#define E 0.01
|
||||
#define E 0.03
|
||||
|
||||
PhysicsSolver::PhysicsSolver(vec3 gravity) : gravity(gravity) {
|
||||
}
|
||||
|
|
@ -12,6 +12,7 @@ PhysicsSolver::PhysicsSolver(vec3 gravity) : gravity(gravity) {
|
|||
void PhysicsSolver::step(Chunks* chunks, Hitbox* hitbox, float delta, unsigned substeps, bool shifting) {
|
||||
for (unsigned i = 0; i < substeps; i++){
|
||||
float dt = delta / (float)substeps;
|
||||
float linear_damping = hitbox->linear_damping;
|
||||
vec3& pos = hitbox->position;
|
||||
vec3& half = hitbox->halfsize;
|
||||
vec3& vel = hitbox->velocity;
|
||||
|
|
@ -76,6 +77,7 @@ void PhysicsSolver::step(Chunks* chunks, Hitbox* hitbox, float delta, unsigned s
|
|||
hitbox->grounded = false;
|
||||
if (vel.y < 0.0){
|
||||
for (int x = floor(pos.x-half.x+E); x <= floor(pos.x+half.x-E); x++){
|
||||
bool broken = false;
|
||||
for (int z = floor(pos.z-half.z+E); z <= floor(pos.z+half.z-E); z++){
|
||||
int y = floor(pos.y-half.y-E);
|
||||
if (chunks->isObstacle(x,y,z)){
|
||||
|
|
@ -85,9 +87,12 @@ void PhysicsSolver::step(Chunks* chunks, Hitbox* hitbox, float delta, unsigned s
|
|||
vel.x *= max(0.0, 1.0 - dt * f);
|
||||
vel.z *= max(0.0, 1.0 - dt * f);
|
||||
hitbox->grounded = true;
|
||||
broken = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (broken)
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (vel.y > 0.0){
|
||||
|
|
@ -103,6 +108,9 @@ void PhysicsSolver::step(Chunks* chunks, Hitbox* hitbox, float delta, unsigned s
|
|||
}
|
||||
}
|
||||
|
||||
vel.x *= max(0.0, 1.0 - dt * linear_damping);
|
||||
vel.z *= max(0.0, 1.0 - dt * linear_damping);
|
||||
|
||||
pos.x += vel.x * dt;
|
||||
pos.y += vel.y * dt;
|
||||
pos.z += vel.z * dt;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue