Compare commits

..

11 Commits

Author SHA1 Message Date
verysecrethero 0aedeb61b4 CapturePointSystem now sets all children visible/not visible for each red/blue/spectator 2016-03-11 14:15:46 +01:00
verysecrethero 0869afd529 Merge pull request #193 from teamfisk/BoxModelCollision
Removed collision jittering effects
2016-03-11 10:48:25 +01:00
Adam Byléhn 56a13d03fc Merge pull request #197 from teamfisk/SpectatorCamera
Properly unlocked mouse
2016-03-11 10:43:29 +01:00
Adam Byléhn dad18a200f Merge pull request #202 from teamfisk/Trigger
Triggersystem updated for the capturepoints
2016-03-11 10:38:20 +01:00
William Moberg d6e3a47182 Merge branch 'master' into Trigger 2016-03-10 16:14:17 +01:00
William Moberg 038a706e28 Don't collide against disabled (invisible) models. Triggers uses model vs. box instead of only box vs. box. 2016-03-10 16:05:30 +01:00
William Moberg bdcb33d992 Mouse always unlocked on game start and on disconnecting (i.e when menu shows). 2016-03-10 12:46:06 +01:00
William Moberg 8a8c375d3a Merge remote-tracking branch 'origin/master' into BoxModelCollision 2016-03-10 09:57:33 +01:00
William Moberg 8936b3d6c3 Probably fixed all the jittering, won't need the jitter guard anymore. 2016-03-09 19:45:26 +01:00
William Moberg 8a3564ad49 Merge remote-tracking branch 'origin/master' into BoxModelCollision 2016-03-09 18:03:39 +01:00
William Moberg 9581e9ac84 Don't set the player to previous position when uncrouching. 2016-03-09 17:51:26 +01:00
19 changed files with 284 additions and 83 deletions
+1 -1
Submodule assets updated: 007b54bd67...33455a9d10
+12
View File
@@ -84,6 +84,18 @@ bool AABBvsTriangles(const AABB& box,
const std::vector<unsigned int>& modelIndices, const std::vector<unsigned int>& modelIndices,
const glm::mat4& modelMatrix); const glm::mat4& modelMatrix);
enum Output
{
OutContained,
OutSeparated,
OutIntersecting
};
//Detects intersection and containment.
Output AABBvsTrianglesWContainment(const AABB& box,
const RawModel::Vertex* modelVertices,
const std::vector<unsigned int>& modelIndices,
const glm::mat4& modelMatrix);
//Return true if the boxes are intersecting. //Return true if the boxes are intersecting.
bool AABBVsAABB(const AABB& a, const AABB& b); bool AABBVsAABB(const AABB& a, const AABB& b);
//Return true if the boxes are intersecting. //Return true if the boxes are intersecting.
@@ -19,6 +19,7 @@ public:
virtual const glm::vec3 Rotation() const { return m_Rotation; } virtual const glm::vec3 Rotation() const { return m_Rotation; }
virtual bool Jumping() const { return m_Jumping; } virtual bool Jumping() const { return m_Jumping; }
virtual bool Crouching() const { return m_Crouching; } virtual bool Crouching() const { return m_Crouching; }
virtual bool CrouchingLastFrame() const { return m_CrouchingLastFrame; }
virtual bool DoubleJumping() const { return m_DoubleJumping; } virtual bool DoubleJumping() const { return m_DoubleJumping; }
virtual void SetDoubleJumping(bool isDoubleJumping) { virtual void SetDoubleJumping(bool isDoubleJumping) {
m_DoubleJumping = isDoubleJumping; m_DoubleJumping = isDoubleJumping;
@@ -44,6 +45,7 @@ protected:
bool m_Jumping = false; bool m_Jumping = false;
bool m_DoubleJumping = false; bool m_DoubleJumping = false;
bool m_Crouching = false; bool m_Crouching = false;
bool m_CrouchingLastFrame = false;
//assault dash membervariables - needed to calculate the doubletap- and dashlogic //assault dash membervariables - needed to calculate the doubletap- and dashlogic
double m_AssaultDashDoubleTapDeltaTime = 0.0; double m_AssaultDashDoubleTapDeltaTime = 0.0;
//i will let m_AssaultDashDoubleTapSensitivityTimer stay hardcoded, its not really a gamevariable (more an inputvariable), //i will let m_AssaultDashDoubleTapSensitivityTimer stay hardcoded, its not really a gamevariable (more an inputvariable),
@@ -82,6 +84,7 @@ void FirstPersonInputController<EventContext>::Reset()
{ {
m_Rotation = glm::vec3(0.f, 0.f, 0.f); m_Rotation = glm::vec3(0.f, 0.f, 0.f);
m_Jumping = false; m_Jumping = false;
m_CrouchingLastFrame = m_Crouching;
} }
template <typename EventContext> template <typename EventContext>
+1 -2
View File
@@ -13,7 +13,6 @@
#include "Texture.h" #include "Texture.h"
#include "ShadowPass.h" #include "ShadowPass.h"
#include "BlurHUD.h" #include "BlurHUD.h"
#include "TextPass.h"
class DrawFinalPass class DrawFinalPass
{ {
@@ -23,7 +22,7 @@ public:
void InitializeTextures(); void InitializeTextures();
void InitializeFrameBuffers(); void InitializeFrameBuffers();
void InitializeShaderPrograms(); void InitializeShaderPrograms();
void Draw(RenderScene& scene, BlurHUD* blurHUDPass, TextPass* textPass); void Draw(RenderScene& scene, BlurHUD* blurHUDPass);
void ClearBuffer(); void ClearBuffer();
void OnWindowResize(); void OnWindowResize();
@@ -3,6 +3,7 @@
#include "Core/System.h" #include "Core/System.h"
#include "Input/EInputCommand.h" #include "Input/EInputCommand.h"
#include "Network/EPlayerDisconnected.h"
class SpectatorCameraSystem : public ImpureSystem class SpectatorCameraSystem : public ImpureSystem
{ {
@@ -17,6 +18,8 @@ private:
EventRelay<SpectatorCameraSystem, Events::InputCommand> m_EInputCommand; EventRelay<SpectatorCameraSystem, Events::InputCommand> m_EInputCommand;
bool OnInputCommand(const Events::InputCommand& e); bool OnInputCommand(const Events::InputCommand& e);
EventRelay<SpectatorCameraSystem, Events::PlayerDisconnected> m_EDisconnect;
bool OnDisconnect(const Events::PlayerDisconnected& e);
}; };
#endif #endif
+3 -1
View File
@@ -29,4 +29,6 @@ K=TakeDamage,1500
F2=PerformanceTimingResetAllTimers F2=PerformanceTimingResetAllTimers
F3=PerformanceTimingCreateExcelData F3=PerformanceTimingCreateExcelData
Comma=SwapToClassPick Comma=SwapToClassPick
Period=SwapToTeamPick Period=SwapToTeamPick
Enter=PickClass,1
F5=DisconnectFromServer
@@ -13,6 +13,7 @@
<c:Model> <c:Model>
<Resource>models/core/unitcube.mesh</Resource> <Resource>models/core/unitcube.mesh</Resource>
<Color A="1" B="0.980392158" G="1" R="1"/> <Color A="1" B="0.980392158" G="1" R="1"/>
<Shadow>false</Shadow>
</c:Model> </c:Model>
<c:Transform> <c:Transform>
<Position X="-0.100000001" Y="0" Z="0"/> <Position X="-0.100000001" Y="0" Z="0"/>
@@ -28,6 +29,7 @@
<c:Model> <c:Model>
<Resource>models/core/unitcube.mesh</Resource> <Resource>models/core/unitcube.mesh</Resource>
<Color A="1" B="0" G="0" R="1"/> <Color A="1" B="0" G="0" R="1"/>
<Shadow>false</Shadow>
</c:Model> </c:Model>
<c:Transform> <c:Transform>
<Position X="-14.500001" Y="1.50000012" Z="16.9222012"/> <Position X="-14.500001" Y="1.50000012" Z="16.9222012"/>
@@ -52,6 +54,7 @@
<c:Model> <c:Model>
<Resource>models/core/unitcube.mesh</Resource> <Resource>models/core/unitcube.mesh</Resource>
<Color A="1" B="1" G="0" R="0"/> <Color A="1" B="1" G="0" R="0"/>
<Shadow>false</Shadow>
</c:Model> </c:Model>
<c:Transform> <c:Transform>
<Position X="-14.500001" Y="1.50000012" Z="-17.6888409"/> <Position X="-14.500001" Y="1.50000012" Z="-17.6888409"/>
@@ -67,6 +70,7 @@
<c:Model> <c:Model>
<Resource>models/core/unitcube.mesh</Resource> <Resource>models/core/unitcube.mesh</Resource>
<Color A="1" B="0" G="0" R="1"/> <Color A="1" B="0" G="0" R="1"/>
<Shadow>false</Shadow>
</c:Model> </c:Model>
<c:Transform> <c:Transform>
<Position X="12.1000004" Y="1.50000012" Z="16.9222012"/> <Position X="12.1000004" Y="1.50000012" Z="16.9222012"/>
@@ -82,6 +86,7 @@
<c:Model> <c:Model>
<Resource>models/core/unitcube.mesh</Resource> <Resource>models/core/unitcube.mesh</Resource>
<Color A="1" B="1" G="0" R="0"/> <Color A="1" B="1" G="0" R="0"/>
<Shadow>false</Shadow>
</c:Model> </c:Model>
<c:Transform> <c:Transform>
<Position X="12.1228638" Y="1.50000012" Z="-17.9642811"/> <Position X="12.1228638" Y="1.50000012" Z="-17.9642811"/>
@@ -198,6 +203,7 @@
<c:Model> <c:Model>
<Resource>models/core/unitcube.mesh</Resource> <Resource>models/core/unitcube.mesh</Resource>
<Color A="1" B="39.2156868" G="0" R="3.13725495"/> <Color A="1" B="39.2156868" G="0" R="3.13725495"/>
<Shadow>false</Shadow>
</c:Model> </c:Model>
<c:Transform> <c:Transform>
<Scale X="-70" Y="-70" Z="-70"/> <Scale X="-70" Y="-70" Z="-70"/>
@@ -210,7 +216,7 @@
<c:Transform/> <c:Transform/>
</Components> </Components>
<Children> <Children>
<Entity name="-"> <Entity name="CapP">
<Components> <Components>
<c:AABB/> <c:AABB/>
<c:CapturePoint> <c:CapturePoint>
@@ -254,6 +260,13 @@
</Components> </Components>
<Children/> <Children/>
</Entity> </Entity>
<Entity>
<Components>
<c:PointLight/>
<c:Transform/>
</Components>
<Children/>
</Entity>
</Children> </Children>
</Entity> </Entity>
<Entity name="Blue"> <Entity name="Blue">
@@ -265,7 +278,25 @@
<Scale X="3.4000001" Y="4.70000029" Z="0.700000048"/> <Scale X="3.4000001" Y="4.70000029" Z="0.700000048"/>
</c:Transform> </c:Transform>
</Components> </Components>
<Children/> <Children>
<Entity>
<Components>
<c:Model>
<Resource></Resource>
</c:Model>
<c:Transform/>
</Components>
<Children>
<Entity>
<Components>
<c:PointLight/>
<c:Transform/>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
</Children>
</Entity> </Entity>
<Entity name="Spectator"> <Entity name="Spectator">
<Components> <Components>
@@ -276,7 +307,43 @@
<Scale X="1" Y="5.70000029" Z="1"/> <Scale X="1" Y="5.70000029" Z="1"/>
</c:Transform> </c:Transform>
</Components> </Components>
<Children/> <Children>
<Entity>
<Components>
<c:PointLight/>
<c:Transform/>
</Components>
<Children>
<Entity>
<Components>
<c:Model>
<Resource></Resource>
</c:Model>
<c:Transform/>
</Components>
<Children>
<Entity>
<Components>
<c:PointLight/>
<c:Transform/>
</Components>
<Children>
<Entity>
<Components>
<c:Model>
<Resource></Resource>
</c:Model>
<c:Transform/>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
</Children>
</Entity>
</Children>
</Entity>
</Children>
</Entity> </Entity>
</Children> </Children>
</Entity> </Entity>
@@ -287,11 +354,11 @@
<c:Transform/> <c:Transform/>
</Components> </Components>
<Children> <Children>
<Entity name="-"> <Entity name="CapP">
<Components> <Components>
<c:AABB/> <c:AABB/>
<c:CapturePoint> <c:CapturePoint>
<CaptureTimer>-15</CaptureTimer> <CaptureTimer>12</CaptureTimer>
<HomePointForTeam> <HomePointForTeam>
<Blue/> <Blue/>
</HomePointForTeam> </HomePointForTeam>
@@ -317,7 +384,38 @@
<Scale X="4.4000001" Y="2" Z="3.70000029"/> <Scale X="4.4000001" Y="2" Z="3.70000029"/>
</c:Transform> </c:Transform>
</Components> </Components>
<Children/> <Children>
<Entity>
<Components>
<c:Model>
<Resource></Resource>
</c:Model>
<c:Transform/>
</Components>
<Children>
<Entity>
<Components>
<c:Transform/>
</Components>
<Children>
<Entity>
<Components>
<c:Transform/>
</Components>
<Children>
<Entity>
<Components>
<c:Transform/>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
</Children>
</Entity>
</Children>
</Entity>
</Children>
</Entity> </Entity>
<Entity name="Blue"> <Entity name="Blue">
<Components> <Components>
+50 -14
View File
@@ -360,7 +360,14 @@ constexpr bool FaceIsGround(float faceNormalY)
//An array containing 3 int pairs { 0, 2 }, { 0, 1 }, { 1, 2 } //An array containing 3 int pairs { 0, 2 }, { 0, 1 }, { 1, 2 }
constexpr std::array<std::pair<int, int>, 3> dimensionPairs({ std::pair<int, int>(0, 2), std::pair<int, int>(0, 1), std::pair<int, int>(1, 2) }); constexpr std::array<std::pair<int, int>, 3> dimensionPairs({ std::pair<int, int>(0, 2), std::pair<int, int>(0, 1), std::pair<int, int>(1, 2) });
bool AABBvsTriangle(const AABB& box, enum class BoxTriRes
{
Front,
Behind,
Intersect
};
BoxTriRes AABBvsTriangle(const AABB& box,
const std::array<glm::vec3, 3>& triPos, const std::array<glm::vec3, 3>& triPos,
const glm::vec3& originalBoxVelocity, const glm::vec3& originalBoxVelocity,
float verticalStepHeight, float verticalStepHeight,
@@ -374,7 +381,7 @@ bool AABBvsTriangle(const AABB& box,
//Less checks, and we should be able to walk out from models if we are trapped inside. //Less checks, and we should be able to walk out from models if we are trapped inside.
glm::vec3 triNormal = glm::cross(triPos[1] - triPos[0], triPos[2] - triPos[0]); glm::vec3 triNormal = glm::cross(triPos[1] - triPos[0], triPos[2] - triPos[0]);
if (!vectorHasLength(triNormal) || (glm::dot(triNormal, originalBoxVelocity) > 0)) { if (!vectorHasLength(triNormal) || (glm::dot(triNormal, originalBoxVelocity) > 0)) {
return false; return BoxTriRes::Behind;
} }
triNormal = glm::normalize(triNormal); triNormal = glm::normalize(triNormal);
@@ -409,6 +416,9 @@ bool AABBvsTriangle(const AABB& box,
const glm::vec3& min = box.MinCorner(); const glm::vec3& min = box.MinCorner();
const glm::vec3& max = box.MaxCorner(); const glm::vec3& max = box.MaxCorner();
// If there is no intersection, whether the box center is in front of or behind the triangle.
BoxTriRes noIntersection = glm::dot(triNormal, origin - triPos[0]) > 0 ? BoxTriRes::Front : BoxTriRes::Behind;
//For each projection in xy-, xz-, and yx-planes. //For each projection in xy-, xz-, and yx-planes.
for (std::pair<int, int> dim : dimensionPairs) { for (std::pair<int, int> dim : dimensionPairs) {
//2D Triangle. //2D Triangle.
@@ -426,7 +436,7 @@ bool AABBvsTriangle(const AABB& box,
bool pushedFromTriangleLine; bool pushedFromTriangleLine;
//if projections don't overlap, return false. //if projections don't overlap, return false.
if (!rectangleVsTriangle(boxMin, boxMax, t2D, resolutionVector, resolutionDist, pushedFromTriangleLine)) { if (!rectangleVsTriangle(boxMin, boxMax, t2D, resolutionVector, resolutionDist, pushedFromTriangleLine)) {
return false; return noIntersection;
} else if (resolveCollision) { } else if (resolveCollision) {
//Overwrite the smallest resolution if this is smaller. //Overwrite the smallest resolution if this is smaller.
if (resolutionDist < resolveShortest.DistanceSq) { if (resolutionDist < resolveShortest.DistanceSq) {
@@ -462,14 +472,15 @@ bool AABBvsTriangle(const AABB& box,
float t = glm::dot(triNormal, triPos[0] - origin) / glm::dot(triNormal, diagonal); float t = glm::dot(triNormal, triPos[0] - origin) / glm::dot(triNormal, diagonal);
//If intersection point between plane and diagonal is within the box. //If intersection point between plane and diagonal is within the box.
if (glm::abs(t) > 1) { if (glm::abs(t) > 1) {
return false; return noIntersection;
} }
if (!resolveCollision) { if (!resolveCollision) {
return true; return BoxTriRes::Intersect;
} }
glm::vec3 cornerResolution = (1+t) * diagonal; glm::vec3 cornerResolution = (1+t) * diagonal;
cornerResolution = glm::dot(cornerResolution, triNormal) * triNormal;
//Overwrite the smallest resolution if cornerResolution is smaller. //Overwrite the smallest resolution if cornerResolution is smaller.
float lenSq = glm::length2(cornerResolution); float lenSq = glm::length2(cornerResolution);
if (lenSq < resolveShortest.DistanceSq) { if (lenSq < resolveShortest.DistanceSq) {
@@ -498,7 +509,7 @@ bool AABBvsTriangle(const AABB& box,
case ResolveDimZ: case ResolveDimZ:
//If we get here, the resolution is along one coordinate axis. //If we get here, the resolution is along one coordinate axis.
//set velocity to 0 in y if it is along y-axis. //set velocity to 0 in y if it is along y-axis.
return true; return BoxTriRes::Intersect;
case Line: case Line:
projNorm = glm::normalize(outResolution); projNorm = glm::normalize(outResolution);
break; break;
@@ -533,10 +544,10 @@ bool AABBvsTriangle(const AABB& box,
boxVelocity = boxVelocity - glm::dot(boxVelocity, projNorm) * projNorm; boxVelocity = boxVelocity - glm::dot(boxVelocity, projNorm) * projNorm;
} }
} }
return true; return BoxTriRes::Intersect;
} }
bool AABBvsTriangles(const AABB& box, Output AABBvsTriangles(const AABB& box,
const RawModel::Vertex* modelVertices, const RawModel::Vertex* modelVertices,
const std::vector<unsigned int>& modelIndices, const std::vector<unsigned int>& modelIndices,
const glm::mat4& modelMatrix, const glm::mat4& modelMatrix,
@@ -546,8 +557,8 @@ bool AABBvsTriangles(const AABB& box,
glm::vec3& outResolutionVector, glm::vec3& outResolutionVector,
bool resolveCollision) bool resolveCollision)
{ {
bool hit = false; bool intersect = false;
Output out = Output::OutContained;
bool everHitTheGround = false; bool everHitTheGround = false;
AABB newBox = box; AABB newBox = box;
outResolutionVector = glm::vec3(0.f); outResolutionVector = glm::vec3(0.f);
@@ -560,20 +571,27 @@ bool AABBvsTriangles(const AABB& box,
}; };
glm::vec3 outVec; glm::vec3 outVec;
bool collideWithGround = isOnGround; bool collideWithGround = isOnGround;
if (AABBvsTriangle(newBox, triVertices, originalBoxVelocity, verticalStepHeight, collideWithGround, boxVelocity, outVec, resolveCollision)) { switch (AABBvsTriangle(newBox, triVertices, originalBoxVelocity, verticalStepHeight, collideWithGround, boxVelocity, outVec, resolveCollision)) {
hit = true; case Collision::BoxTriRes::Front:
out = Output::OutSeparated;
break;
case Collision::BoxTriRes::Intersect:
intersect = true;
outResolutionVector += outVec; outResolutionVector += outVec;
newBox = AABB::FromOriginSize(newBox.Origin() + outVec, newBox.Size()); newBox = AABB::FromOriginSize(newBox.Origin() + outVec, newBox.Size());
if (collideWithGround) { if (collideWithGround) {
everHitTheGround = isOnGround = true; everHitTheGround = isOnGround = true;
} }
break;
default:
break;
} }
} }
if (!everHitTheGround) { if (!everHitTheGround) {
isOnGround = false; isOnGround = false;
} }
return hit; return intersect ? Output::OutIntersecting : out;
} }
bool AABBvsTriangles(const AABB& box, bool AABBvsTriangles(const AABB& box,
@@ -593,13 +611,31 @@ bool AABBvsTriangles(const AABB& box,
verticalStepHeight, verticalStepHeight,
isOnGround, isOnGround,
outResolutionVector, outResolutionVector,
true); true) == Output::OutIntersecting;
} }
bool AABBvsTriangles(const AABB& box, bool AABBvsTriangles(const AABB& box,
const RawModel::Vertex* modelVertices, const RawModel::Vertex* modelVertices,
const std::vector<unsigned int>& modelIndices, const std::vector<unsigned int>& modelIndices,
const glm::mat4& modelMatrix) const glm::mat4& modelMatrix)
{
glm::vec3 vel, outres;
bool g;
return AABBvsTriangles(box,
modelVertices,
modelIndices,
modelMatrix,
vel,
0.f,
g,
outres,
false) == Output::OutIntersecting;
}
Output AABBvsTrianglesWContainment(const AABB& box,
const RawModel::Vertex* modelVertices,
const std::vector<unsigned int>& modelIndices,
const glm::mat4& modelMatrix)
{ {
glm::vec3 vel, outres; glm::vec3 vel, outres;
bool g; bool g;
+10 -3
View File
@@ -37,6 +37,10 @@ void CollisionSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& c
bool hit; bool hit;
float dist; float dist;
if (boxB.Entity.HasComponent("Model")) { if (boxB.Entity.HasComponent("Model")) {
if (!((bool)boxB.Entity["Model"]["Visible"])) {
// Don't collide against invisible models.
continue;
}
RawModel* model; RawModel* model;
std::string res = (std::string)boxB.Entity["Model"]["Resource"]; std::string res = (std::string)boxB.Entity["Model"]["Resource"];
try { try {
@@ -77,7 +81,11 @@ void CollisionSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& c
} }
if (boxB.Entity.HasComponent("Model") && Collision::AABBVsAABB(boxA, boxB)) { if (boxB.Entity.HasComponent("Model") && Collision::AABBVsAABB(boxA, boxB)) {
//Here we know boxB is a entity with Collideable, AABB, and Model. // Here we know boxB is a entity with Collideable, AABB, and Model.
if (!((bool)boxB.Entity["Model"]["Visible"])) {
// Don't collide against invisible models.
continue;
}
RawModel* model; RawModel* model;
try { try {
model = ResourceManager::Load<RawModel, true>(boxB.Entity["Model"]["Resource"]); model = ResourceManager::Load<RawModel, true>(boxB.Entity["Model"]["Resource"]);
@@ -88,12 +96,11 @@ void CollisionSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& c
glm::mat4 modelMatrix = Transform::ModelMatrix(boxB.Entity); glm::mat4 modelMatrix = Transform::ModelMatrix(boxB.Entity);
glm::vec3 inOutVelocity = (glm::vec3)cPhysics["Velocity"]; glm::vec3 inOutVelocity = (glm::vec3)cPhysics["Velocity"];
bool notMovingxz = glm::all(glm::lessThan(glm::abs(glm::vec2(inOutVelocity.x, inOutVelocity.z)), glm::vec2(0.01f))) && prevPosIt != m_PrevPositions.end();
bool isOnGround = (bool)cPhysics["IsOnGround"]; bool isOnGround = (bool)cPhysics["IsOnGround"];
float verticalStepHeight = (float)(double)cPhysics["VerticalStepHeight"]; float verticalStepHeight = (float)(double)cPhysics["VerticalStepHeight"];
if (Collision::AABBvsTriangles(boxA, model->Vertices(), model->m_Indices, modelMatrix, inOutVelocity, verticalStepHeight, isOnGround, resolutionVector)) { if (Collision::AABBvsTriangles(boxA, model->Vertices(), model->m_Indices, modelMatrix, inOutVelocity, verticalStepHeight, isOnGround, resolutionVector)) {
//Move the position to previous position if it is not moving in the xz-plane, else resolve with the resolution vector. //Move the position to previous position if it is not moving in the xz-plane, else resolve with the resolution vector.
(glm::vec3&)cTransform["Position"] += notMovingxz ? prevPosIt->second - boxA.Origin() : resolutionVector; (glm::vec3&)cTransform["Position"] += resolutionVector;
boxA = *Collision::EntityAbsoluteAABB(entity); boxA = *Collision::EntityAbsoluteAABB(entity);
cPhysics["Velocity"] = inOutVelocity; cPhysics["Velocity"] = inOutVelocity;
if (isOnGround) { if (isOnGround) {
+31 -10
View File
@@ -10,6 +10,16 @@ void TriggerSystem::UpdateComponent(EntityWrapper& triggerEntity, ComponentWrapp
return; return;
} }
RawModel* triggerModel = nullptr;
glm::mat4 triggerModelMat;
if (triggerEntity.HasComponent("Model")) {
try {
triggerModel = ResourceManager::Load<RawModel, true>(triggerEntity["Model"]["Resource"]);
triggerModelMat = Transform::ModelMatrix(triggerEntity);
} catch (const std::exception&) {
}
}
m_OctreeOut.clear(); m_OctreeOut.clear();
m_Octree->ObjectsInSameRegion(*triggerBox, m_OctreeOut); m_Octree->ObjectsInSameRegion(*triggerBox, m_OctreeOut);
@@ -22,7 +32,17 @@ void TriggerSystem::UpdateComponent(EntityWrapper& triggerEntity, ComponentWrapp
if (colliderFitsInTrigger) { if (colliderFitsInTrigger) {
completelyInsideBox = AABB::FromOriginSize((*triggerBox).Origin(), (*triggerBox).Size() - 2.0f * colliderBox.Size()); completelyInsideBox = AABB::FromOriginSize((*triggerBox).Origin(), (*triggerBox).Size() - 2.0f * colliderBox.Size());
} }
if (colliderFitsInTrigger && Collision::AABBVsAABB(completelyInsideBox, colliderBox)) {
// We know the entity is inside the trigger box, but perhaps not the model yet.
Collision::Output out = triggerModel == nullptr
? Collision::Output::OutContained
: Collision::AABBvsTrianglesWContainment(
colliderBox,
triggerModel->Vertices(),
triggerModel->m_Indices,
triggerModelMat);
if (colliderFitsInTrigger && Collision::AABBVsAABB(completelyInsideBox, colliderBox) && out == Collision::Output::OutContained) {
// Entity is completely inside the trigger. // Entity is completely inside the trigger.
// If it was only touching before, it is erased. // If it was only touching before, it is erased.
m_EntitiesTouchingTrigger[triggerEntity].erase(colliderEntity); m_EntitiesTouchingTrigger[triggerEntity].erase(colliderEntity);
@@ -32,7 +52,8 @@ void TriggerSystem::UpdateComponent(EntityWrapper& triggerEntity, ComponentWrapp
completeSet.insert(colliderEntity); completeSet.insert(colliderEntity);
publish<Events::TriggerEnter>(colliderEntity, triggerEntity); publish<Events::TriggerEnter>(colliderEntity, triggerEntity);
} }
} else { continue;
} else if (out != Collision::Output::OutSeparated) {
// Entity is only touching the trigger. // Entity is only touching the trigger.
auto& touchSet = m_EntitiesTouchingTrigger[triggerEntity]; auto& touchSet = m_EntitiesTouchingTrigger[triggerEntity];
auto& completeSet = m_EntitiesCompletelyInTrigger[triggerEntity]; auto& completeSet = m_EntitiesCompletelyInTrigger[triggerEntity];
@@ -47,17 +68,17 @@ void TriggerSystem::UpdateComponent(EntityWrapper& triggerEntity, ComponentWrapp
touchSet.insert(colliderEntity); touchSet.insert(colliderEntity);
} }
// Else, it was touching the trigger last frame too and nothing is done. // Else, it was touching the trigger last frame too and nothing is done.
}
} else {
// Entity is not touching the trigger,
// Throw event if it was previously.
if (throwLeaveIfWasInTrigger(m_EntitiesTouchingTrigger[triggerEntity], colliderEntity, triggerEntity)) {
continue; continue;
} }
// This only occurs if the entity was completely inside the trigger one frame,
// then completely outside the trigger, e.g. when dying and respawning.
throwLeaveIfWasInTrigger(m_EntitiesCompletelyInTrigger[triggerEntity], colliderEntity, triggerEntity);
} }
// Only get here if entity is not touching the trigger,
// throw event if it was touching previously.
if (throwLeaveIfWasInTrigger(m_EntitiesTouchingTrigger[triggerEntity], colliderEntity, triggerEntity)) {
continue;
}
// This only occurs if the entity was completely inside the trigger one frame,
// then completely outside the trigger, e.g. when dying and respawning.
throwLeaveIfWasInTrigger(m_EntitiesCompletelyInTrigger[triggerEntity], colliderEntity, triggerEntity);
} }
} }
+1
View File
@@ -47,6 +47,7 @@ EditorSystem::EditorSystem(SystemParams params, IRenderer* renderer, RenderFrame
Enable(); Enable();
} else { } else {
Disable(); Disable();
m_EventBroker->Publish(Events::UnlockMouse());
} }
} }
+6 -1
View File
@@ -1,4 +1,5 @@
#include "Network/Client.h" #include "Network/Client.h"
#include "Network/EPlayerDisconnected.h"
using namespace boost::asio::ip; using namespace boost::asio::ip;
Client::Client(World* world, EventBroker* eventBroker) Client::Client(World* world, EventBroker* eventBroker)
@@ -224,7 +225,7 @@ void Client::parseServerlist(Packet& packet)
void Client::parseKick() void Client::parseKick()
{ {
LOG_WARNING("You have been kicked from the server."); LOG_WARNING("You have been kicked from the server.");
m_IsConnected = false; disconnect();
} }
void Client::parseSpawnEvents() void Client::parseSpawnEvents()
@@ -464,6 +465,10 @@ void Client::disconnect()
Packet packet(MessageType::Disconnect, m_SendPacketID); Packet packet(MessageType::Disconnect, m_SendPacketID);
m_Reliable.Send(packet); m_Reliable.Send(packet);
m_Reliable.Disconnect(); m_Reliable.Disconnect();
Events::PlayerDisconnected e;
e.Entity = m_LocalPlayer.ID;
e.PlayerID = -1;
m_EventBroker->Publish(e);
createMainMenu(); createMainMenu();
} }
+22 -28
View File
@@ -242,7 +242,7 @@ void DrawFinalPass::InitializeShaderPrograms()
} }
void DrawFinalPass::Draw(RenderScene& scene, BlurHUD* blurHUDPass, TextPass* textPass) void DrawFinalPass::Draw(RenderScene& scene, BlurHUD* blurHUDPass)
{ {
GLERROR("Pre"); GLERROR("Pre");
DrawFinalPassState* stateDethp = new DrawFinalPassState(m_ShieldDepthFrameBuffer.GetHandle()); DrawFinalPassState* stateDethp = new DrawFinalPassState(m_ShieldDepthFrameBuffer.GetHandle());
@@ -282,36 +282,10 @@ void DrawFinalPass::Draw(RenderScene& scene, BlurHUD* blurHUDPass, TextPass* tex
//state->StencilMask(0x00); //state->StencilMask(0x00);
DrawModelRenderQueues(scene.Jobs.OpaqueObjects, scene); DrawModelRenderQueues(scene.Jobs.OpaqueObjects, scene);
GLERROR("OpaqueObjects"); GLERROR("OpaqueObjects");
delete state;
DrawFinalPassState* stateSprite = new DrawFinalPassState(m_FinalPassFrameBuffer.GetHandle());
if (scene.ShouldBlur) {
//Combine nonblur and blur texture
stateSprite->Disable(GL_DEPTH_TEST);
stateSprite->Disable(GL_STENCIL_TEST);
m_CombinedTexture = blurHUDPass->CombineTextures(m_SceneTexture, m_FullBlurredTexture);
}
//Draw Transparen objects
//state->BlendFunc(GL_ONE, GL_ONE);
//state->StencilFunc(GL_EQUAL, 1, 0xFF);
//DrawModelRenderQueues(scene.Jobs.TransparentObjects, scene);
GLERROR("TransparentObjects");
//state->BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
stateSprite->Enable(GL_DEPTH_TEST);
//stateSprite->AlphaFunc(GL_GEQUAL, 0.05f);
//stateSprite->Enable(GL_ALPHA_TEST);
DrawSprites(scene.Jobs.SpriteJob, scene);
GLERROR("SpriteJobs");
delete stateSprite;
state = new DrawFinalPassState(m_FinalPassFrameBuffer.GetHandle());
//state->Disable(GL_STENCIL_TEST); //state->Disable(GL_STENCIL_TEST);
//Draw Transparen Shielded objects //Draw Transparen Shielded objects
state->BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); state->BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
textPass->Draw(scene, m_FinalPassFrameBuffer);
DrawModelRenderQueuesWithShieldCheck(scene.Jobs.TransparentObjects, scene); //might need changing DrawModelRenderQueuesWithShieldCheck(scene.Jobs.TransparentObjects, scene); //might need changing
GLERROR("Shielded Transparent objects"); GLERROR("Shielded Transparent objects");
@@ -322,7 +296,27 @@ void DrawFinalPass::Draw(RenderScene& scene, BlurHUD* blurHUDPass, TextPass* tex
m_FullBlurredTexture = blurHUDPass->Draw(m_SceneTexture, scene); m_FullBlurredTexture = blurHUDPass->Draw(m_SceneTexture, scene);
} }
DrawFinalPassState* stateSprite = new DrawFinalPassState(m_FinalPassFrameBuffer.GetHandle());
if(scene.ShouldBlur) {
//Combine nonblur and blur texture
stateSprite->Disable(GL_DEPTH_TEST);
stateSprite->Disable(GL_STENCIL_TEST);
m_CombinedTexture = blurHUDPass->CombineTextures(m_SceneTexture, m_FullBlurredTexture);
}
//Draw Transparen objects
//state->BlendFunc(GL_ONE, GL_ONE);
//state->StencilFunc(GL_EQUAL, 1, 0xFF);
//DrawModelRenderQueues(scene.Jobs.TransparentObjects, scene);
GLERROR("TransparentObjects");
//state->BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
stateSprite->Enable(GL_DEPTH_TEST);
//stateSprite->AlphaFunc(GL_GEQUAL, 0.05f);
//stateSprite->Enable(GL_ALPHA_TEST);
DrawSprites(scene.Jobs.SpriteJob, scene);
GLERROR("SpriteJobs");
delete stateSprite;
GLERROR("END"); GLERROR("END");
} }
+4 -5
View File
@@ -210,15 +210,14 @@ void Renderer::Draw(RenderFrame& frame)
PerformanceTimer::StartTimerAndStopPrevious("Renderer-Light Culling"); PerformanceTimer::StartTimerAndStopPrevious("Renderer-Light Culling");
m_LightCullingPass->CullLights(*scene); m_LightCullingPass->CullLights(*scene);
GLERROR("LightCulling"); GLERROR("LightCulling");
PerformanceTimer::StartTimerAndStopPrevious("Renderer-Draw Text");
//m_TextPass->Draw(*scene, *m_DrawFinalPass->FinalPassFrameBuffer());
GLERROR("Draw Text");
PerformanceTimer::StartTimerAndStopPrevious("Renderer-Draw Geometry+Light"); PerformanceTimer::StartTimerAndStopPrevious("Renderer-Draw Geometry+Light");
m_DrawFinalPass->Draw(*scene, m_BlurHUDPass, m_TextPass); m_DrawFinalPass->Draw(*scene, m_BlurHUDPass);
GLERROR("Draw Geometry+Light"); GLERROR("Draw Geometry+Light");
//m_DrawScenePass->Draw(*scene); //m_DrawScenePass->Draw(*scene);
PerformanceTimer::StartTimerAndStopPrevious("Renderer-Draw Text");
m_TextPass->Draw(*scene, *m_DrawFinalPass->FinalPassFrameBuffer());
GLERROR("Draw Text");
PerformanceTimer::StopTimer("Renderer-Draw Text"); PerformanceTimer::StopTimer("Renderer-Draw Text");
} }
+2 -2
View File
@@ -34,7 +34,7 @@ void TextPass::Update()
void TextPass::Draw(RenderScene& scene, FrameBuffer& frameBuffer) void TextPass::Draw(RenderScene& scene, FrameBuffer& frameBuffer)
{ {
GLERROR("Derp1"); GLERROR("Derp1");
//TextPassState* state = new TextPassState(frameBuffer.GetHandle()); TextPassState* state = new TextPassState(frameBuffer.GetHandle());
for (auto &job : scene.Jobs.Text) { for (auto &job : scene.Jobs.Text) {
auto textJob = std::dynamic_pointer_cast<TextJob>(job); auto textJob = std::dynamic_pointer_cast<TextJob>(job);
if (textJob) { if (textJob) {
@@ -43,7 +43,7 @@ void TextPass::Draw(RenderScene& scene, FrameBuffer& frameBuffer)
} }
} }
GLERROR("Derp2"); GLERROR("Derp2");
// delete state; delete state;
} }
void TextPass::renderText(std::string text, Font* font, TextJob::AlignmentEnum alignment, glm::vec4 color, glm::mat4 modelMatrix, glm::mat4 projectionMatrix, glm::mat4 viewMatrix) void TextPass::renderText(std::string text, Font* font, TextJob::AlignmentEnum alignment, glm::vec4 color, glm::mat4 modelMatrix, glm::mat4 projectionMatrix, glm::mat4 viewMatrix)
+4 -7
View File
@@ -4,13 +4,10 @@
TextPassState::TextPassState(GLuint frameBuffer) TextPassState::TextPassState(GLuint frameBuffer)
{ {
BindFramebuffer(frameBuffer); BindFramebuffer(frameBuffer);
Enable(GL_BLEND); glEnable(GL_BLEND);
Disable(GL_CULL_FACE); glDisable(GL_CULL_FACE);
Enable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Enable(GL_ALPHA_TEST);
AlphaFunc(GL_GEQUAL, 0.05f);
} }
TextPassState::~TextPassState() TextPassState::~TextPassState()
+7 -2
View File
@@ -234,9 +234,14 @@ void CapturePointSystem::UpdateComponent(EntityWrapper& capturePointEntity, Comp
void CapturePointSystem::ChangeCapturePointModelsVisibility(EntityWrapper &capturePointModels, bool isOwner) { void CapturePointSystem::ChangeCapturePointModelsVisibility(EntityWrapper &capturePointModels, bool isOwner) {
(bool&)capturePointModels["Model"]["Visible"] = isOwner; (bool&)capturePointModels["Model"]["Visible"] = isOwner;
for (auto& capModel : capturePointModels.ChildrenWithComponent("Model")) for (auto& capModel : capturePointModels.ChildrenWithComponent("Transform"))
{ {
(bool&)capModel["Model"]["Visible"] = isOwner; if (capModel.HasComponent("Model")) {
(bool&)capModel["Model"]["Visible"] = isOwner;
}
if (capModel.HasComponent("PointLight")) {
(bool&)capModel["PointLight"]["Visible"] = isOwner;
}
} }
} }
@@ -264,6 +264,11 @@ void PlayerMovementSystem::updateMovementControllers(double dt)
size = glm::vec3(1.f, 1.f, 1.f); size = glm::vec3(1.f, 1.f, 1.f);
} else { } else {
size = glm::vec3(1.f, 1.6f, 1.f); size = glm::vec3(1.f, 1.6f, 1.f);
if (controller->CrouchingLastFrame() && isOnGround) {
// The collision should resolve this anyway, but
// this is more reliable, since the box gets larger.
((glm::vec3&)cTransform["Position"]).y += 0.3f;
}
} }
} }
+15 -1
View File
@@ -8,6 +8,7 @@ SpectatorCameraSystem::SpectatorCameraSystem(SystemParams params)
, m_PickedTeam(-1) , m_PickedTeam(-1)
{ {
EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &SpectatorCameraSystem::OnInputCommand); EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &SpectatorCameraSystem::OnInputCommand);
EVENT_SUBSCRIBE_MEMBER(m_EDisconnect, &SpectatorCameraSystem::OnDisconnect);
} }
void SpectatorCameraSystem::Update(double dt) void SpectatorCameraSystem::Update(double dt)
@@ -87,4 +88,17 @@ bool SpectatorCameraSystem::OnInputCommand(const Events::InputCommand& e)
} }
return true; return true;
} }
bool SpectatorCameraSystem::OnDisconnect(const Events::PlayerDisconnected& e)
{
// If local player gets disconnected, they should be set to
// the spectator camera next time a map loads that has one.
if (e.Entity == LocalPlayer.ID) {
m_CamSetToTeamPick = false;
// They will also be set to menu, so unlock mouse just in case they were in game with locked mouse.
Events::UnlockMouse unlock;
m_EventBroker->Publish(unlock);
}
return true;
}