Cannot respawn inside other players, unless all are blocked.

This commit is contained in:
William Moberg
2016-02-17 14:54:59 +01:00
parent 969e7cb0d5
commit 23bb1a6405
5 changed files with 143 additions and 24 deletions
+49 -4
View File
@@ -366,7 +366,8 @@ bool AABBvsTriangle(const AABB& box,
float verticalStepHeight,
bool& isOnGround,
glm::vec3& boxVelocity,
glm::vec3& outResolution)
glm::vec3& outResolution,
bool resolveCollision)
{
//Check so we don't have a zero area triangle when calculating the normal.
//Also, don't check a triangle facing away from the player.
@@ -426,7 +427,7 @@ bool AABBvsTriangle(const AABB& box,
//if projections don't overlap, return false.
if (!rectangleVsTriangle(boxMin, boxMax, t2D, resolutionVector, resolutionDist, pushedFromTriangleLine)) {
return false;
} else {
} else if (resolveCollision) {
//Overwrite the smallest resolution if this is smaller.
if (resolutionDist < resolveShortest.DistanceSq) {
resolveShortest.Vector = glm::vec3(0.f);
@@ -463,6 +464,11 @@ bool AABBvsTriangle(const AABB& box,
if (glm::abs(t) > 1) {
return false;
}
if (!resolveCollision) {
return true;
}
glm::vec3 cornerResolution = (1+t) * diagonal;
//Overwrite the smallest resolution if cornerResolution is smaller.
float lenSq = glm::length2(cornerResolution);
@@ -537,7 +543,8 @@ bool AABBvsTriangles(const AABB& box,
glm::vec3& boxVelocity,
float verticalStepHeight,
bool& isOnGround,
glm::vec3& outResolutionVector)
glm::vec3& outResolutionVector,
bool resolveCollision)
{
bool hit = false;
@@ -553,7 +560,7 @@ bool AABBvsTriangles(const AABB& box,
};
glm::vec3 outVec;
bool collideWithGround = isOnGround;
if (AABBvsTriangle(newBox, triVertices, originalBoxVelocity, verticalStepHeight, collideWithGround, boxVelocity, outVec)) {
if (AABBvsTriangle(newBox, triVertices, originalBoxVelocity, verticalStepHeight, collideWithGround, boxVelocity, outVec, resolveCollision)) {
hit = true;
outResolutionVector += outVec;
newBox = AABB::FromOriginSize(newBox.Origin() + outVec, newBox.Size());
@@ -569,6 +576,44 @@ bool AABBvsTriangles(const AABB& box,
return hit;
}
bool AABBvsTriangles(const AABB& box,
const RawModel::Vertex* modelVertices,
const std::vector<unsigned int>& modelIndices,
const glm::mat4& modelMatrix,
glm::vec3& boxVelocity,
float verticalStepHeight,
bool& isOnGround,
glm::vec3& outResolutionVector)
{
return AABBvsTriangles(box,
modelVertices,
modelIndices,
modelMatrix,
boxVelocity,
verticalStepHeight,
isOnGround,
outResolutionVector,
true);
}
bool AABBvsTriangles(const AABB& box,
const RawModel::Vertex* modelVertices,
const std::vector<unsigned int>& modelIndices,
const glm::mat4& modelMatrix)
{
glm::vec3 vel, outres;
bool g;
return AABBvsTriangles(box,
modelVertices,
modelIndices,
modelMatrix,
vel,
0.f,
g,
outres,
false);
}
boost::optional<EntityAABB> EntityAbsoluteAABB(EntityWrapper& entity, bool takeModelBox)
{
AABB modelSpaceBox;