mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-10-02 19:03:43 +00:00
Volumes on the server touched far more than in the client: - An enemy's body in the physics world was a sphere the size of its aggro radius, so trigger and damage volumes caught enemies from far away (Cavalry Hill enemies taking damage on spawn). It is now the enemy's own radius and collision group from its physics component. - Trigger volumes ignored their collision group and caught everything. dpEntity now filters with the client's collision filter (PeCollisionFilter, 1.10.64 0x00fb6940, group table from 0x00fcf9a0): POI walls ignore enemies, threat clearing walls ignore players, and so on. The aggro sensor keeps seeing only players. - Rotated boxes were tested as the axis aligned box around them, which for a turned wall covers a big square (the AG survival boundary). Sphere and point tests now use the box's own axes. Proximity monitors take an optional collision group like live's SetProximityRadius; the AM shield generators use live's (10 finds enemies, 1 finds players). Fixes #1127 Refs #1971 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
108 lines
3.3 KiB
C++
108 lines
3.3 KiB
C++
#include "dpCollisionChecks.h"
|
|
#include "dpEntity.h"
|
|
#include "dpShapeBase.h"
|
|
#include "dpShapeSphere.h"
|
|
#include "dpShapeBox.h"
|
|
|
|
#include <iostream>
|
|
#include <algorithm>
|
|
|
|
using namespace dpCollisionChecks;
|
|
|
|
bool dpCollisionChecks::AreColliding(dpEntity* a, dpEntity* b) {
|
|
auto shapeA = a->GetShape();
|
|
auto shapeB = b->GetShape();
|
|
|
|
//Sphere to sphere collision
|
|
if (shapeA->GetShapeType() == dpShapeType::Sphere && shapeB->GetShapeType() == dpShapeType::Sphere) {
|
|
return CheckSpheres(a, b);
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
bool dpCollisionChecks::CheckSpheres(dpEntity* a, dpEntity* b) {
|
|
if (!a || !b) return false;
|
|
|
|
auto posA = a->GetPosition();
|
|
auto distance = Vector3::DistanceSquared(posA, b->GetPosition());
|
|
|
|
auto sphereA = static_cast<dpShapeSphere*>(a->GetShape());
|
|
auto sphereB = static_cast<dpShapeSphere*>(b->GetShape());
|
|
const auto radius = sphereA->GetRadius() + sphereB->GetRadius();
|
|
|
|
if (distance <= radius * radius)
|
|
return true;
|
|
|
|
return false;
|
|
}
|
|
|
|
bool dpCollisionChecks::CheckBoxes(dpEntity* a, dpEntity* b) {
|
|
if (!a || !b) return false;
|
|
|
|
auto boxA = static_cast<dpShapeBox*>(a->GetShape());
|
|
auto boxB = static_cast<dpShapeBox*>(b->GetShape());
|
|
|
|
const auto& posA = a->GetPosition();
|
|
const auto& posB = b->GetPosition();
|
|
|
|
for (const auto& vert : boxA->GetVertices()) {
|
|
if (boxB->IsVertInBox(vert))
|
|
return true;
|
|
}
|
|
|
|
/*//Check if we're overlapping on X/Z:
|
|
if ((boxA->GetMaxWidth() >= boxB->GetMinWidth()) && //If our max width is greater than starting X of b
|
|
(boxA->GetMinWidth() <= boxB->GetMaxWidth()) && //If our start x is less than b's max width
|
|
(boxA->GetMaxDepth() >= boxB->GetMinDepth()) &&
|
|
(boxA->GetMinDepth() <= boxB->GetMaxDepth())) {
|
|
|
|
//Check if we're in the right height
|
|
if (boxA->GetTop() <= boxB->GetTop() && boxA->GetTop() >= boxB->GetBottom() || //If our top Y is within their minY/maxY bounds
|
|
boxA->GetBottom() <= boxB->GetTop() && boxA->GetBottom() >= boxB->GetBottom()) //Or our bottom Y
|
|
return true; //We definitely are colliding.
|
|
}*/
|
|
|
|
/*//Check if we're overlapping on X/Z:
|
|
if ((boxA->GetMaxWidth() >= posB.x) && //If our max width is greater than starting X of b
|
|
(posA.x <= boxB->GetMaxWidth()) && //If our start x is less than b's max width
|
|
(boxA->GetMaxDepth() >= posB.z) &&
|
|
(posA.z <= boxB->GetMaxDepth())) {
|
|
|
|
//Check if we're in the right height
|
|
if (boxA->GetTop() <= boxB->GetTop() && boxA->GetTop() >= posB.y || //If our top Y is within their minY/maxY bounds
|
|
posA.y <= boxB->GetTop() && posA.y >= posB.y) //Or our bottom Y
|
|
return true; //We definitely are colliding.
|
|
}*/
|
|
|
|
return false;
|
|
}
|
|
|
|
bool dpCollisionChecks::CheckSphereBox(dpEntity* a, dpEntity* b) {
|
|
if (!a || !b) return false;
|
|
|
|
NiPoint3 boxPos;
|
|
dpShapeBox* box;
|
|
|
|
NiPoint3 spherePos;
|
|
dpShapeSphere* sphere;
|
|
|
|
//Figure out which is the box and which is the sphere
|
|
if (a->GetShape()->GetShapeType() == dpShapeType::Box) {
|
|
box = static_cast<dpShapeBox*>(a->GetShape());
|
|
sphere = static_cast<dpShapeSphere*>(b->GetShape());
|
|
boxPos = a->GetPosition();
|
|
spherePos = b->GetPosition();
|
|
} else {
|
|
box = static_cast<dpShapeBox*>(b->GetShape());
|
|
sphere = static_cast<dpShapeSphere*>(a->GetShape());
|
|
boxPos = b->GetPosition();
|
|
spherePos = a->GetPosition();
|
|
}
|
|
|
|
const float distanceSquared = box->SquaredDistanceTo(spherePos);
|
|
const float radius = sphere->GetRadius();
|
|
|
|
return distanceSquared < radius* radius;
|
|
}
|