mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 18:41:51 +00:00
add triggers
This commit is contained in:
parent
50c714692a
commit
5769be8ec8
15 changed files with 239 additions and 64 deletions
|
|
@ -6,12 +6,14 @@
|
|||
#include "../voxels/Chunks.hpp"
|
||||
#include "../voxels/voxel.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
const float E = 0.03f;
|
||||
const float MAX_FIX = 0.1f;
|
||||
|
||||
PhysicsSolver::PhysicsSolver(glm::vec3 gravity) : gravity(gravity) {
|
||||
}
|
||||
|
||||
#include "../util/timeutil.hpp"
|
||||
void PhysicsSolver::step(
|
||||
Chunks* chunks,
|
||||
Hitbox* hitbox,
|
||||
|
|
@ -19,7 +21,8 @@ void PhysicsSolver::step(
|
|||
uint substeps,
|
||||
bool shifting,
|
||||
float gravityScale,
|
||||
bool collisions
|
||||
bool collisions,
|
||||
entityid_t entity
|
||||
) {
|
||||
float dt = delta / static_cast<float>(substeps);
|
||||
float linearDamping = hitbox->linearDamping;
|
||||
|
|
@ -78,6 +81,21 @@ void PhysicsSolver::step(
|
|||
hitbox->grounded = true;
|
||||
}
|
||||
}
|
||||
AABB aabb;
|
||||
aabb.a = hitbox->position - hitbox->halfsize;
|
||||
aabb.b = hitbox->position + hitbox->halfsize;
|
||||
for (size_t i = 0; i < triggers.size(); i++) {
|
||||
auto& trigger = triggers[i];
|
||||
if (trigger->entity == entity) {
|
||||
continue;
|
||||
}
|
||||
if (aabb.intersect(trigger->calculated)) {
|
||||
if (trigger->prevEntered.find(entity) == trigger->prevEntered.end()) {
|
||||
trigger->enterCallback(trigger->entity, i, entity);
|
||||
}
|
||||
trigger->nextEntered.insert(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PhysicsSolver::colisionCalc(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue