add triggers
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user