Compare commits

..

3 Commits

Author SHA1 Message Date
Jace 1992b6cde1 WIP Defender tracers 2016-03-10 21:15:27 +01:00
Jace c82be79bb8 Functionally working defender weapon 2016-03-10 19:26:14 +01:00
Jace 35a8d45fa4 Fixed skinned models not being able to be shielded 2016-03-10 19:20:21 +01:00
27 changed files with 498 additions and 405 deletions
+1 -1
Submodule assets updated: 33455a9d10...298641b1af
-12
View File
@@ -84,18 +84,6 @@ bool AABBvsTriangles(const AABB& box,
const std::vector<unsigned int>& modelIndices,
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.
bool AABBVsAABB(const AABB& a, const AABB& b);
//Return true if the boxes are intersecting.
@@ -19,7 +19,6 @@ public:
virtual const glm::vec3 Rotation() const { return m_Rotation; }
virtual bool Jumping() const { return m_Jumping; }
virtual bool Crouching() const { return m_Crouching; }
virtual bool CrouchingLastFrame() const { return m_CrouchingLastFrame; }
virtual bool DoubleJumping() const { return m_DoubleJumping; }
virtual void SetDoubleJumping(bool isDoubleJumping) {
m_DoubleJumping = isDoubleJumping;
@@ -45,7 +44,6 @@ protected:
bool m_Jumping = false;
bool m_DoubleJumping = false;
bool m_Crouching = false;
bool m_CrouchingLastFrame = false;
//assault dash membervariables - needed to calculate the doubletap- and dashlogic
double m_AssaultDashDoubleTapDeltaTime = 0.0;
//i will let m_AssaultDashDoubleTapSensitivityTimer stay hardcoded, its not really a gamevariable (more an inputvariable),
@@ -84,7 +82,6 @@ void FirstPersonInputController<EventContext>::Reset()
{
m_Rotation = glm::vec3(0.f, 0.f, 0.f);
m_Jumping = false;
m_CrouchingLastFrame = m_Crouching;
}
template <typename EventContext>
@@ -30,7 +30,6 @@ private:
bool CapturePointSystem::OnTriggerLeave(const Events::TriggerLeave& e);
EventRelay<CapturePointSystem, Events::Captured> m_ECaptured;
bool CapturePointSystem::OnCaptured(const Events::Captured& e);
void ChangeCapturePointModelsVisibility(EntityWrapper &capturePointModels, bool isOwner);
bool m_WinnerWasFound = false;
//need to track these variables for the captureSystem to work as per design!
@@ -3,7 +3,6 @@
#include "Core/System.h"
#include "Input/EInputCommand.h"
#include "Network/EPlayerDisconnected.h"
class SpectatorCameraSystem : public ImpureSystem
{
@@ -18,8 +17,6 @@ private:
EventRelay<SpectatorCameraSystem, Events::InputCommand> m_EInputCommand;
bool OnInputCommand(const Events::InputCommand& e);
EventRelay<SpectatorCameraSystem, Events::PlayerDisconnected> m_EDisconnect;
bool OnDisconnect(const Events::PlayerDisconnected& e);
};
#endif
@@ -27,9 +27,12 @@ private:
std::random_device m_RandomDevice;
std::mt19937 m_RandomEngine;
// Weapon functions
void fireShell(ComponentWrapper cWeapon, WeaponInfo& wi);
void dealDamage(ComponentWrapper cWeapon, WeaponInfo& wi, glm::vec3 direction, double damage);
void dealDamage(ComponentWrapper cWeapon, WeaponInfo& wi, const std::vector<glm::vec2>& pattern);
void spawnTracers(ComponentWrapper cWeapon, WeaponInfo& wi, std::vector<glm::vec2> pattern);
bool canFire(ComponentWrapper cWeapon, WeaponInfo& wi);
// Utility
+1 -3
View File
@@ -29,6 +29,4 @@ K=TakeDamage,1500
F2=PerformanceTimingResetAllTimers
F3=PerformanceTimingCreateExcelData
Comma=SwapToClassPick
Period=SwapToTeamPick
Enter=PickClass,1
F5=DisconnectFromServer
Period=SwapToTeamPick
@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<DefenderWeapon xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="DefenderWeapon.xsd">
<Slot><Primary/></Slot>
<MagazineAmmo>8</MagazineAmmo>
<MagazineAmmo>9999</MagazineAmmo>
<MagazineSize>8</MagazineSize>
<Ammo>64</Ammo>
<MaxAmmo>64</MaxAmmo>
<BaseDamage>90</BaseDamage>
<SpreadAngle>0.174533</SpreadAngle> <!-- 0.174533 = 10 degrees -->
<SpreadAngle>10</SpreadAngle>
<MaxTravelAngle>0.174533</MaxTravelAngle> <!-- 0.174533 = 10 degrees -->
<NumPellets>10</NumPellets>
<NumPellets>9</NumPellets>
<RPM>120</RPM>
<ViewPunch>0.03</ViewPunch>
<ViewReturnSpeed>0.2</ViewReturnSpeed>
@@ -36,7 +36,7 @@
<xs:annotation><xs:documentation>Damage dealt if all shotgun pellets hit</xs:documentation></xs:annotation>
</xs:element>
<xs:element name="SpreadAngle" type="t:float" minOccurs="0">
<xs:annotation><xs:documentation>Spread angle in radians</xs:documentation></xs:annotation>
<xs:annotation><xs:documentation>The spread angle radius.</xs:documentation></xs:annotation>
</xs:element>
<xs:element name="MaxTravelAngle" type="t:float" minOccurs="0">
<xs:annotation><xs:documentation>Maximum vertical aim travel angle in radians</xs:documentation></xs:annotation>
+94
View File
@@ -0,0 +1,94 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Entity xmlns:c="components" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Types/Entity.xsd">
<Components>
<c:Transform/>
</Components>
<Children>
<Entity name="RayBlue">
<Components>
<c:Transform>
<Orientation X="0" Y="0.174532995" Z="0"/>
<Scale X="0" Y="1" Z="100"/>
</c:Transform>
</Components>
<Children>
<Entity>
<Components>
<c:Sprite>
<Model>Models/Core/UnitQuad.mesh</Model>
<GlowMap></GlowMap>
<DiffuseTexture>Textures/Effects/Ray.png</DiffuseTexture>
<Color A="0.419607848" B="3.92156863" G="0.270588249" R="0"/>
</c:Sprite>
<c:Transform>
<Position X="0" Y="0" Z="-0.5"/>
<Orientation X="0" Y="-1.57099998" Z="0"/>
<Scale X="1" Y="0.0260000005" Z="0"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:Sprite>
<Model>Models/Core/UnitQuad.mesh</Model>
<GlowMap></GlowMap>
<DiffuseTexture>Textures/Effects/Ray.png</DiffuseTexture>
<Color A="0.419607848" B="3.92156863" G="0.270588249" R="0"/>
</c:Sprite>
<c:Transform>
<Position X="0" Y="0" Z="-0.5"/>
<Orientation X="0" Y="4.71218538" Z="3.14199996"/>
<Scale X="1" Y="0.0260000005" Z="0"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
<Entity name="RayBlue">
<Components>
<c:Transform>
<Scale X="0" Y="1" Z="100"/>
</c:Transform>
</Components>
<Children>
<Entity>
<Components>
<c:Sprite>
<Model>Models/Core/UnitQuad.mesh</Model>
<GlowMap></GlowMap>
<DiffuseTexture>Textures/Effects/Ray.png</DiffuseTexture>
<Color A="0.419607848" B="3.92156863" G="0.270588249" R="0"/>
</c:Sprite>
<c:Transform>
<Position X="0" Y="0" Z="-0.5"/>
<Orientation X="0" Y="-1.57099998" Z="0"/>
<Scale X="1" Y="0.0260000005" Z="0"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:Sprite>
<Model>Models/Core/UnitQuad.mesh</Model>
<GlowMap></GlowMap>
<DiffuseTexture>Textures/Effects/Ray.png</DiffuseTexture>
<Color A="0.419607848" B="3.92156863" G="0.270588249" R="0"/>
</c:Sprite>
<c:Transform>
<Position X="0" Y="0" Z="-0.5"/>
<Orientation X="0" Y="4.71218538" Z="3.14199996"/>
<Scale X="1" Y="0.0260000005" Z="0"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
</Children>
</Entity>
+79 -23
View File
@@ -1,39 +1,95 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Entity name="Shield" xmlns:c="components" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Types/Entity.xsd">
<Entity xmlns:c="components" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Types/Entity.xsd">
<Components>
<c:Blend>
<Pose1>Deploy</Pose1>
<Pose2>Idle</Pose2>
<Weight>0</Weight>
</c:Blend>
<c:Model>
<Resource>Models/Characters/Defender/DefenderShield.mesh</Resource>
</c:Model>
<c:Transform/>
<c:Transform>
<Position X="1.70262027" Y="0.261695802" Z="-3.26634645"/>
</c:Transform>
</Components>
<Children>
<Entity name="Deploy">
<Entity name="Back">
<Components>
<c:Animation>
<AnimationName>ActivateDeactiveShieldF</AnimationName>
<Time>1</Time>
<Speed>1</Speed>
</c:Animation>
<c:Blend>
<Pose1>Deploy</Pose1>
<Pose2>Idle</Pose2>
<Weight>0</Weight>
</c:Blend>
<c:Shielded/>
<c:Model>
<Resource>Models/Characters/Defender/DefenderShieldBack.mesh</Resource>
<Color A="0.219607845" B="3.92156863" G="1" R="1"/>
<Shadow>false</Shadow>
<Transparent>true</Transparent>
<NormalMap>false</NormalMap>
<DiffuseTexture>false</DiffuseTexture>
<SpecularMap>false</SpecularMap>
<GlowMap>false</GlowMap>
</c:Model>
<c:Transform/>
</Components>
<Children/>
<Children>
<Entity name="Deploy">
<Components>
<c:Animation>
<AnimationName>ActivateDeactiveShieldF</AnimationName>
<Play>true</Play>
</c:Animation>
<c:Transform/>
</Components>
<Children/>
</Entity>
<Entity name="Idle">
<Components>
<c:Animation>
<AnimationName>ShieldFrontF</AnimationName>
</c:Animation>
<c:Transform/>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
<Entity name="Idle">
<Entity name="Front">
<Components>
<c:Animation>
<AnimationName>ShieldFrontF</AnimationName>
<Speed>1</Speed>
</c:Animation>
<c:Blend>
<Pose1>Deploy</Pose1>
<Pose2>Idle</Pose2>
<Weight>0</Weight>
</c:Blend>
<c:Model>
<Resource>Models/Characters/Defender/DefenderShieldFront.mesh</Resource>
<Color A="0.219607845" B="3.92156863" G="1" R="1"/>
<Shadow>false</Shadow>
<Transparent>true</Transparent>
<NormalMap>false</NormalMap>
<DiffuseTexture>false</DiffuseTexture>
<SpecularMap>false</SpecularMap>
<GlowMap>false</GlowMap>
</c:Model>
<c:Transform/>
</Components>
<Children/>
<Children>
<Entity name="Deploy">
<Components>
<c:Animation>
<AnimationName>ActivateDeactiveShieldF</AnimationName>
<Play>true</Play>
</c:Animation>
<c:Transform/>
</Components>
<Children/>
</Entity>
<Entity name="Idle">
<Components>
<c:Animation>
<AnimationName>ShieldFrontF</AnimationName>
</c:Animation>
<c:Transform/>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
</Children>
+27
View File
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Entity xmlns:c="components" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Types/Entity.xsd">
<Components>
<c:Lifetime>
<Lifetime>10</Lifetime>
</c:Lifetime>
<c:ExplosionEffect>
<Velocity X="2" Y="2.30000019" Z="0"/>
<ExplosionDuration>1</ExplosionDuration>
<Randomness>true</Randomness>
<ExponentialAccelaration>true</ExponentialAccelaration>
</c:ExplosionEffect>
<c:Model>
<Resource>Models/Core/UnitSphere.mesh</Resource>
<Color A="1" B="1" G="1" R="3.92156863"/>
<Shadow>false</Shadow>
<Transparent>true</Transparent>
</c:Model>
<c:Transform>
<Scale X="0.0500000007" Y="0.0500000007" Z="0.0500000007"/>
</c:Transform>
</Components>
<Children/>
</Entity>
+96 -4
View File
@@ -103,7 +103,7 @@
<Color A="1" B="1" G="0.254901975" R="0"/>
</c:Model>
<c:Transform>
<Position X="-0.600000024" Y="0" Z="0"/>
<Position X="0.800000012" Y="0" Z="0"/>
</c:Transform>
</Components>
<Children/>
@@ -116,7 +116,7 @@
<Color A="1" B="1" G="0.254901975" R="0"/>
</c:Model>
<c:Transform>
<Position X="0.800000012" Y="0" Z="0"/>
<Position X="-0.600000024" Y="0" Z="0.549540162"/>
</c:Transform>
</Components>
<Children/>
@@ -157,14 +157,106 @@
<Resource>Models/Weapons/Blue/DefenderWeaponBlue.mesh</Resource>
</c:Model>
<c:Transform>
<Position X="0.00681143999" Y="-0.204994932" Z="-0.209244296"/>
<Orientation X="-0.581807375" Y="0.562133908" Z="-0.0719003305"/>
<Orientation X="0" Y="-0" Z="0"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
<Entity>
<Components>
<c:Transform>
<Position X="0.870232701" Y="0.640069604" Z="4.07769537"/>
<Orientation X="0" Y="4.71238565" Z="0"/>
</c:Transform>
</Components>
<Children>
<Entity name="RayBlue">
<Components>
<c:Transform>
<Orientation X="0" Y="0.174532995" Z="0"/>
<Scale X="0" Y="1" Z="100"/>
</c:Transform>
</Components>
<Children>
<Entity>
<Components>
<c:Sprite>
<Model>Models/Core/UnitQuad.mesh</Model>
<GlowMap></GlowMap>
<DiffuseTexture>Textures/Effects/Ray.png</DiffuseTexture>
<Color A="0.419607848" B="3.92156863" G="0.270588249" R="0"/>
</c:Sprite>
<c:Transform>
<Position X="0" Y="0" Z="-0.5"/>
<Orientation X="0" Y="-1.57099998" Z="0"/>
<Scale X="1" Y="0.0260000005" Z="0"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:Sprite>
<Model>Models/Core/UnitQuad.mesh</Model>
<GlowMap></GlowMap>
<DiffuseTexture>Textures/Effects/Ray.png</DiffuseTexture>
<Color A="0.419607848" B="3.92156863" G="0.270588249" R="0"/>
</c:Sprite>
<c:Transform>
<Position X="0" Y="0" Z="-0.5"/>
<Orientation X="0" Y="4.71218538" Z="3.14199996"/>
<Scale X="1" Y="0.0260000005" Z="0"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
<Entity name="RayBlue">
<Components>
<c:Transform>
<Scale X="0" Y="1" Z="100"/>
</c:Transform>
</Components>
<Children>
<Entity>
<Components>
<c:Sprite>
<Model>Models/Core/UnitQuad.mesh</Model>
<GlowMap></GlowMap>
<DiffuseTexture>Textures/Effects/Ray.png</DiffuseTexture>
<Color A="0.419607848" B="3.92156863" G="0.270588249" R="0"/>
</c:Sprite>
<c:Transform>
<Position X="0" Y="0" Z="-0.5"/>
<Orientation X="0" Y="-1.57099998" Z="0"/>
<Scale X="1" Y="0.0260000005" Z="0"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:Sprite>
<Model>Models/Core/UnitQuad.mesh</Model>
<GlowMap></GlowMap>
<DiffuseTexture>Textures/Effects/Ray.png</DiffuseTexture>
<Color A="0.419607848" B="3.92156863" G="0.270588249" R="0"/>
</c:Sprite>
<c:Transform>
<Position X="0" Y="0" Z="-0.5"/>
<Orientation X="0" Y="4.71218538" Z="3.14199996"/>
<Scale X="1" Y="0.0260000005" Z="0"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
</Children>
</Entity>
</Children>
</Entity>
+1 -1
View File
@@ -3,7 +3,7 @@
<Components>
<c:Lifetime>
<Lifetime>0.10000000149011612</Lifetime>
<Lifetime>10</Lifetime>
</c:Lifetime>
<c:Transform>
<Scale X="0" Y="1" Z="1"/>
@@ -13,7 +13,6 @@
<c:Model>
<Resource>models/core/unitcube.mesh</Resource>
<Color A="1" B="0.980392158" G="1" R="1"/>
<Shadow>false</Shadow>
</c:Model>
<c:Transform>
<Position X="-0.100000001" Y="0" Z="0"/>
@@ -29,7 +28,6 @@
<c:Model>
<Resource>models/core/unitcube.mesh</Resource>
<Color A="1" B="0" G="0" R="1"/>
<Shadow>false</Shadow>
</c:Model>
<c:Transform>
<Position X="-14.500001" Y="1.50000012" Z="16.9222012"/>
@@ -54,7 +52,6 @@
<c:Model>
<Resource>models/core/unitcube.mesh</Resource>
<Color A="1" B="1" G="0" R="0"/>
<Shadow>false</Shadow>
</c:Model>
<c:Transform>
<Position X="-14.500001" Y="1.50000012" Z="-17.6888409"/>
@@ -70,7 +67,6 @@
<c:Model>
<Resource>models/core/unitcube.mesh</Resource>
<Color A="1" B="0" G="0" R="1"/>
<Shadow>false</Shadow>
</c:Model>
<c:Transform>
<Position X="12.1000004" Y="1.50000012" Z="16.9222012"/>
@@ -86,7 +82,6 @@
<c:Model>
<Resource>models/core/unitcube.mesh</Resource>
<Color A="1" B="1" G="0" R="0"/>
<Shadow>false</Shadow>
</c:Model>
<c:Transform>
<Position X="12.1228638" Y="1.50000012" Z="-17.9642811"/>
@@ -104,7 +99,7 @@
</c:Team>
<c:PlayerSpawn/>
<c:Spawner>
<EntityFile>Schema/Entities/PlayerRed.xml</EntityFile>
<EntityFile>Schema/Entities/Player.xml</EntityFile>
</c:Spawner>
<c:Transform/>
</Components>
@@ -203,7 +198,6 @@
<c:Model>
<Resource>models/core/unitcube.mesh</Resource>
<Color A="1" B="39.2156868" G="0" R="3.13725495"/>
<Shadow>false</Shadow>
</c:Model>
<c:Transform>
<Scale X="-70" Y="-70" Z="-70"/>
@@ -216,7 +210,7 @@
<c:Transform/>
</Components>
<Children>
<Entity name="CapP">
<Entity name="-">
<Components>
<c:AABB/>
<c:CapturePoint>
@@ -231,11 +225,6 @@
</Team>
</c:Team>
<c:Trigger/>
<c:Model>
<Resource></Resource>
<Color A="0.300000012" B="0" G="0" R="1"/>
<Visible>false</Visible>
</c:Model>
<c:Transform>
<Position X="0" Y="0" Z="-4.10000038"/>
</c:Transform>
@@ -250,24 +239,7 @@
<Scale X="2.70000005" Y="3.4000001" Z="4.60000038"/>
</c:Transform>
</Components>
<Children>
<Entity>
<Components>
<c:Model>
<Resource></Resource>
</c:Model>
<c:Transform/>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:PointLight/>
<c:Transform/>
</Components>
<Children/>
</Entity>
</Children>
<Children/>
</Entity>
<Entity name="Blue">
<Components>
@@ -278,25 +250,7 @@
<Scale X="3.4000001" Y="4.70000029" Z="0.700000048"/>
</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>
</Children>
</Entity>
</Children>
<Children/>
</Entity>
<Entity name="Spectator">
<Components>
@@ -307,43 +261,7 @@
<Scale X="1" Y="5.70000029" Z="1"/>
</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>
<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>
<Children/>
</Entity>
</Children>
</Entity>
@@ -354,11 +272,11 @@
<c:Transform/>
</Components>
<Children>
<Entity name="CapP">
<Entity name="-">
<Components>
<c:AABB/>
<c:CapturePoint>
<CaptureTimer>12</CaptureTimer>
<CaptureTimer>-15</CaptureTimer>
<HomePointForTeam>
<Blue/>
</HomePointForTeam>
@@ -384,38 +302,7 @@
<Scale X="4.4000001" Y="2" Z="3.70000029"/>
</c:Transform>
</Components>
<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>
<Children/>
</Entity>
<Entity name="Blue">
<Components>
+14 -50
View File
@@ -360,14 +360,7 @@ constexpr bool FaceIsGround(float faceNormalY)
//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) });
enum class BoxTriRes
{
Front,
Behind,
Intersect
};
BoxTriRes AABBvsTriangle(const AABB& box,
bool AABBvsTriangle(const AABB& box,
const std::array<glm::vec3, 3>& triPos,
const glm::vec3& originalBoxVelocity,
float verticalStepHeight,
@@ -381,7 +374,7 @@ BoxTriRes AABBvsTriangle(const AABB& box,
//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]);
if (!vectorHasLength(triNormal) || (glm::dot(triNormal, originalBoxVelocity) > 0)) {
return BoxTriRes::Behind;
return false;
}
triNormal = glm::normalize(triNormal);
@@ -416,9 +409,6 @@ BoxTriRes AABBvsTriangle(const AABB& box,
const glm::vec3& min = box.MinCorner();
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 (std::pair<int, int> dim : dimensionPairs) {
//2D Triangle.
@@ -436,7 +426,7 @@ BoxTriRes AABBvsTriangle(const AABB& box,
bool pushedFromTriangleLine;
//if projections don't overlap, return false.
if (!rectangleVsTriangle(boxMin, boxMax, t2D, resolutionVector, resolutionDist, pushedFromTriangleLine)) {
return noIntersection;
return false;
} else if (resolveCollision) {
//Overwrite the smallest resolution if this is smaller.
if (resolutionDist < resolveShortest.DistanceSq) {
@@ -472,15 +462,14 @@ BoxTriRes AABBvsTriangle(const AABB& box,
float t = glm::dot(triNormal, triPos[0] - origin) / glm::dot(triNormal, diagonal);
//If intersection point between plane and diagonal is within the box.
if (glm::abs(t) > 1) {
return noIntersection;
return false;
}
if (!resolveCollision) {
return BoxTriRes::Intersect;
return true;
}
glm::vec3 cornerResolution = (1+t) * diagonal;
cornerResolution = glm::dot(cornerResolution, triNormal) * triNormal;
//Overwrite the smallest resolution if cornerResolution is smaller.
float lenSq = glm::length2(cornerResolution);
if (lenSq < resolveShortest.DistanceSq) {
@@ -509,7 +498,7 @@ BoxTriRes AABBvsTriangle(const AABB& box,
case ResolveDimZ:
//If we get here, the resolution is along one coordinate axis.
//set velocity to 0 in y if it is along y-axis.
return BoxTriRes::Intersect;
return true;
case Line:
projNorm = glm::normalize(outResolution);
break;
@@ -544,10 +533,10 @@ BoxTriRes AABBvsTriangle(const AABB& box,
boxVelocity = boxVelocity - glm::dot(boxVelocity, projNorm) * projNorm;
}
}
return BoxTriRes::Intersect;
return true;
}
Output AABBvsTriangles(const AABB& box,
bool AABBvsTriangles(const AABB& box,
const RawModel::Vertex* modelVertices,
const std::vector<unsigned int>& modelIndices,
const glm::mat4& modelMatrix,
@@ -557,8 +546,8 @@ Output AABBvsTriangles(const AABB& box,
glm::vec3& outResolutionVector,
bool resolveCollision)
{
bool intersect = false;
Output out = Output::OutContained;
bool hit = false;
bool everHitTheGround = false;
AABB newBox = box;
outResolutionVector = glm::vec3(0.f);
@@ -571,27 +560,20 @@ Output AABBvsTriangles(const AABB& box,
};
glm::vec3 outVec;
bool collideWithGround = isOnGround;
switch (AABBvsTriangle(newBox, triVertices, originalBoxVelocity, verticalStepHeight, collideWithGround, boxVelocity, outVec, resolveCollision)) {
case Collision::BoxTriRes::Front:
out = Output::OutSeparated;
break;
case Collision::BoxTriRes::Intersect:
intersect = true;
if (AABBvsTriangle(newBox, triVertices, originalBoxVelocity, verticalStepHeight, collideWithGround, boxVelocity, outVec, resolveCollision)) {
hit = true;
outResolutionVector += outVec;
newBox = AABB::FromOriginSize(newBox.Origin() + outVec, newBox.Size());
if (collideWithGround) {
everHitTheGround = isOnGround = true;
}
break;
default:
break;
}
}
if (!everHitTheGround) {
isOnGround = false;
}
return intersect ? Output::OutIntersecting : out;
return hit;
}
bool AABBvsTriangles(const AABB& box,
@@ -611,31 +593,13 @@ bool AABBvsTriangles(const AABB& box,
verticalStepHeight,
isOnGround,
outResolutionVector,
true) == Output::OutIntersecting;
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) == 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;
bool g;
+3 -10
View File
@@ -37,10 +37,6 @@ void CollisionSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& c
bool hit;
float dist;
if (boxB.Entity.HasComponent("Model")) {
if (!((bool)boxB.Entity["Model"]["Visible"])) {
// Don't collide against invisible models.
continue;
}
RawModel* model;
std::string res = (std::string)boxB.Entity["Model"]["Resource"];
try {
@@ -81,11 +77,7 @@ void CollisionSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& c
}
if (boxB.Entity.HasComponent("Model") && Collision::AABBVsAABB(boxA, boxB)) {
// 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;
}
//Here we know boxB is a entity with Collideable, AABB, and Model.
RawModel* model;
try {
model = ResourceManager::Load<RawModel, true>(boxB.Entity["Model"]["Resource"]);
@@ -96,11 +88,12 @@ void CollisionSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& c
glm::mat4 modelMatrix = Transform::ModelMatrix(boxB.Entity);
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"];
float verticalStepHeight = (float)(double)cPhysics["VerticalStepHeight"];
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.
(glm::vec3&)cTransform["Position"] += resolutionVector;
(glm::vec3&)cTransform["Position"] += notMovingxz ? prevPosIt->second - boxA.Origin() : resolutionVector;
boxA = *Collision::EntityAbsoluteAABB(entity);
cPhysics["Velocity"] = inOutVelocity;
if (isOnGround) {
+10 -31
View File
@@ -10,16 +10,6 @@ void TriggerSystem::UpdateComponent(EntityWrapper& triggerEntity, ComponentWrapp
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_Octree->ObjectsInSameRegion(*triggerBox, m_OctreeOut);
@@ -32,17 +22,7 @@ void TriggerSystem::UpdateComponent(EntityWrapper& triggerEntity, ComponentWrapp
if (colliderFitsInTrigger) {
completelyInsideBox = AABB::FromOriginSize((*triggerBox).Origin(), (*triggerBox).Size() - 2.0f * colliderBox.Size());
}
// 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) {
if (colliderFitsInTrigger && Collision::AABBVsAABB(completelyInsideBox, colliderBox)) {
// Entity is completely inside the trigger.
// If it was only touching before, it is erased.
m_EntitiesTouchingTrigger[triggerEntity].erase(colliderEntity);
@@ -52,8 +32,7 @@ void TriggerSystem::UpdateComponent(EntityWrapper& triggerEntity, ComponentWrapp
completeSet.insert(colliderEntity);
publish<Events::TriggerEnter>(colliderEntity, triggerEntity);
}
continue;
} else if (out != Collision::Output::OutSeparated) {
} else {
// Entity is only touching the trigger.
auto& touchSet = m_EntitiesTouchingTrigger[triggerEntity];
auto& completeSet = m_EntitiesCompletelyInTrigger[triggerEntity];
@@ -68,17 +47,17 @@ void TriggerSystem::UpdateComponent(EntityWrapper& triggerEntity, ComponentWrapp
touchSet.insert(colliderEntity);
}
// 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;
}
// 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);
}
}
+13 -1
View File
@@ -27,7 +27,7 @@ void EntityWrapper::AttachComponent(const char* componentName)
EntityWrapper EntityWrapper::Parent()
{
if (this->World == nullptr || this->ID == EntityID_Invalid) {
if (!Valid()) {
return EntityWrapper::Invalid;
} else {
return EntityWrapper(this->World, this->World->GetParent(this->ID));
@@ -36,6 +36,10 @@ EntityWrapper EntityWrapper::Parent()
EntityWrapper EntityWrapper::FirstParentByName(const std::string& parentEntityName)
{
if (!Valid()) {
return EntityWrapper::Invalid;
}
EntityWrapper entity = *this;
while (entity.Parent().Valid()) {
entity = entity.Parent();
@@ -48,6 +52,10 @@ EntityWrapper EntityWrapper::FirstParentByName(const std::string& parentEntityNa
EntityWrapper EntityWrapper::FirstChildByName(const std::string& name)
{
if (!Valid()) {
return EntityWrapper::Invalid;
}
return firstChildByNameRecursive(name, this->ID);
}
@@ -78,6 +86,10 @@ EntityWrapper EntityWrapper::FirstLevelChildByName(const std::string& name)
EntityWrapper EntityWrapper::FirstParentWithComponent(const std::string& componentType)
{
if (!Valid()) {
return EntityWrapper::Invalid;
}
EntityWrapper entity = *this;
while (entity.Parent().Valid()) {
entity = entity.Parent();
-1
View File
@@ -47,7 +47,6 @@ EditorSystem::EditorSystem(SystemParams params, IRenderer* renderer, RenderFrame
Enable();
} else {
Disable();
m_EventBroker->Publish(Events::UnlockMouse());
}
}
+1 -6
View File
@@ -1,5 +1,4 @@
#include "Network/Client.h"
#include "Network/EPlayerDisconnected.h"
using namespace boost::asio::ip;
Client::Client(World* world, EventBroker* eventBroker)
@@ -225,7 +224,7 @@ void Client::parseServerlist(Packet& packet)
void Client::parseKick()
{
LOG_WARNING("You have been kicked from the server.");
disconnect();
m_IsConnected = false;
}
void Client::parseSpawnEvents()
@@ -465,10 +464,6 @@ void Client::disconnect()
Packet packet(MessageType::Disconnect, m_SendPacketID);
m_Reliable.Send(packet);
m_Reliable.Disconnect();
Events::PlayerDisconnected e;
e.Entity = m_LocalPlayer.ID;
e.PlayerID = -1;
m_EventBroker->Publish(e);
createMainMenu();
}
+1 -1
View File
@@ -1232,7 +1232,7 @@ void DrawFinalPass::DrawToDepthStencilBuffer(std::list<std::shared_ptr<RenderJob
} else {
frameBones = modelJob->Skeleton->GetTPose();
}
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
} else {
if (lastShader != m_FillDepthStencilBufferProgram->GetHandle()) {
@@ -10,8 +10,6 @@ DrawFinalPassState::DrawFinalPassState(GLuint frameBuffer)
Enable(GL_DEPTH_TEST);
DepthMask(GL_TRUE);
Enable(GL_CULL_FACE);
Enable(GL_ALPHA_TEST);
AlphaFunc(GL_GEQUAL, 0.05f);
// Enable(GL_STENCIL_TEST);
// StencilFunc(GL_NOTEQUAL, 1, 0xFF);
// StencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
+4 -17
View File
@@ -108,10 +108,10 @@ void CapturePointSystem::UpdateComponent(EntityWrapper& capturePointEntity, Comp
//change what model is displaying (change all in case 2 capturepoints has been captured on the same frame)
for (int i = 0; i < m_NumberOfCapturePoints; i++) {
auto owner = (int)m_CapturePointNumberToEntityMap[i]["Team"]["Team"];
if (m_CapturePointNumberToEntityMap[i].FirstChildByName("Red").Valid()) {
ChangeCapturePointModelsVisibility(m_CapturePointNumberToEntityMap[i].FirstChildByName("Red"), owner == redTeam);
ChangeCapturePointModelsVisibility(m_CapturePointNumberToEntityMap[i].FirstChildByName("Blue"), owner == blueTeam);
ChangeCapturePointModelsVisibility(m_CapturePointNumberToEntityMap[i].FirstChildByName("Spectator"), owner == spectatorTeam);
if (m_CapturePointNumberToEntityMap[i].FirstChildByName("Red").ID != EntityID_Invalid) {
(bool&)m_CapturePointNumberToEntityMap[i].FirstChildByName("Red")["Model"]["Visible"] = owner == redTeam ? true : false;
(bool&)m_CapturePointNumberToEntityMap[i].FirstChildByName("Blue")["Model"]["Visible"] = owner == blueTeam ? true : false;
(bool&)m_CapturePointNumberToEntityMap[i].FirstChildByName("Spectator")["Model"]["Visible"] = owner == spectatorTeam ? true : false;
}
}
//save the next cap points and publish the captured event
@@ -232,19 +232,6 @@ void CapturePointSystem::UpdateComponent(EntityWrapper& capturePointEntity, Comp
}
void CapturePointSystem::ChangeCapturePointModelsVisibility(EntityWrapper &capturePointModels, bool isOwner) {
(bool&)capturePointModels["Model"]["Visible"] = isOwner;
for (auto& capModel : capturePointModels.ChildrenWithComponent("Transform"))
{
if (capModel.HasComponent("Model")) {
(bool&)capModel["Model"]["Visible"] = isOwner;
}
if (capModel.HasComponent("PointLight")) {
(bool&)capModel["PointLight"]["Visible"] = isOwner;
}
}
}
bool CapturePointSystem::OnTriggerTouch(const Events::TriggerTouch& e)
{
//personEntered = e.Entity, thingEntered = e.Trigger
@@ -264,11 +264,6 @@ void PlayerMovementSystem::updateMovementControllers(double dt)
size = glm::vec3(1.f, 1.f, 1.f);
} else {
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;
}
}
}
+1 -15
View File
@@ -8,7 +8,6 @@ SpectatorCameraSystem::SpectatorCameraSystem(SystemParams params)
, m_PickedTeam(-1)
{
EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &SpectatorCameraSystem::OnInputCommand);
EVENT_SUBSCRIBE_MEMBER(m_EDisconnect, &SpectatorCameraSystem::OnDisconnect);
}
void SpectatorCameraSystem::Update(double dt)
@@ -88,17 +87,4 @@ bool SpectatorCameraSystem::OnInputCommand(const Events::InputCommand& e)
}
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;
}
}
@@ -190,60 +190,50 @@ void DefenderWeaponBehaviour::fireShell(ComponentWrapper cWeapon, WeaponInfo& wi
magAmmo -= 1;
}
int numPellets = cWeapon["NumPellets"];
float spreadAngle = cWeapon["SpreadAngle"];
std::uniform_real_distribution<float> randomSpreadAngle(-spreadAngle, spreadAngle);
// Calculate pellet angles
// HACK: Random for now?
// TODO: Make distribution even for each quadrant
std::vector<glm::vec2> pelletAngles;
for (int i = 0; i < numPellets; i++) {
pelletAngles.push_back(glm::vec2(randomSpreadAngle(m_RandomEngine), randomSpreadAngle(m_RandomEngine)));
// We can't really do any valuable calculations without a valid camera
if (!m_CurrentCamera.Valid()) {
return;
}
double pelletDamage = (double)cWeapon["BaseDamage"] / numPellets;
int numPellets = cWeapon["NumPellets"];
// Create a spread pattern
std::vector<glm::vec2> pattern;
// The first pellet is always centered
pattern.push_back(glm::vec2(0, 0));
// Any additional pellets form circles around the middle
int numOuterPellets = numPellets - 1;
float angleIncrement = glm::two_pi<float>() / numOuterPellets;
for (int i = 0; i < numOuterPellets; ++i) {
float angle = angleIncrement * i;
glm::vec2 pellet = glm::vec2(glm::cos(angle), glm::sin(angle));
pattern.push_back(pellet);
}
// Deal damage (clientside)
dealDamage(cWeapon, wi, pattern);
// Spawn tracers
spawnTracers(cWeapon, wi, pattern);
// View punch
if (IsClient) {
EntityWrapper camera = wi.Player.FirstChildByName("Camera");
if (camera.Valid()) {
glm::vec3& cameraOrientation = camera["Transform"]["Orientation"];
float viewPunch = cWeapon["ViewPunch"];
float maxTravelAngle = cWeapon["MaxTravelAngle"];
float& currentTravel = cWeapon["CurrentTravel"];
if (currentTravel < maxTravelAngle) {
float change = viewPunch;
if (currentTravel + change > maxTravelAngle) {
change = maxTravelAngle - currentTravel;
}
cameraOrientation.x += change;
currentTravel += change;
}
}
}
// Tracers
EntityWrapper weaponModelEntity;
if (wi.Player == LocalPlayer) {
weaponModelEntity = wi.FirstPersonEntity;
} else {
weaponModelEntity = wi.ThirdPersonEntity;
}
if (weaponModelEntity.Valid()) {
EntityWrapper spawner = weaponModelEntity.FirstChildByName("WeaponMuzzle");
for (auto& angles : pelletAngles) {
glm::vec3 direction = Transform::AbsoluteOrientation(spawner) * glm::quat(glm::vec3(angles, 0.f)) * glm::vec3(0, 0, -1);
float distance = traceRayDistance(Transform::AbsolutePosition(spawner), direction);
EntityWrapper ray = SpawnerSystem::Spawn(spawner);
((glm::vec3&)ray["Transform"]["Scale"]).z = (distance / 100.f);
glm::vec3& orientation = ray["Transform"]["Orientation"];
orientation.x += angles.x;
orientation.y += angles.y;
glm::vec3 trajectory = direction * distance;
dealDamage(cWeapon, wi, direction, pelletDamage);
}
}
//if (IsClient) {
// EntityWrapper camera = wi.Player.FirstChildByName("Camera");
// if (camera.Valid()) {
// glm::vec3& cameraOrientation = camera["Transform"]["Orientation"];
// float viewPunch = cWeapon["ViewPunch"];
// float maxTravelAngle = cWeapon["MaxTravelAngle"];
// float& currentTravel = cWeapon["CurrentTravel"];
// if (currentTravel < maxTravelAngle) {
// float change = viewPunch;
// if (currentTravel + change > maxTravelAngle) {
// change = maxTravelAngle - currentTravel;
// }
// cameraOrientation.x += change;
// currentTravel += change;
// }
// }
//}
// Play animation
playAnimationAndReturn(wi.FirstPersonEntity, "FinalBlend", "Fire");
@@ -255,7 +245,35 @@ void DefenderWeaponBehaviour::fireShell(ComponentWrapper cWeapon, WeaponInfo& wi
m_EventBroker->Publish(e);
}
void DefenderWeaponBehaviour::dealDamage(ComponentWrapper cWeapon, WeaponInfo& wi, glm::vec3 direction, double damage)
void DefenderWeaponBehaviour::spawnTracers(ComponentWrapper cWeapon, WeaponInfo& wi, std::vector<glm::vec2> pattern)
{
EntityWrapper muzzle = getRelevantWeaponEntity(wi).FirstChildByName("WeaponMuzzle");
if (!muzzle.Valid()) {
return;
}
float spreadAngle = glm::radians((float)cWeapon["SpreadAngle"]);
for (auto& pellet : pattern) {
glm::quat pelletRotation = glm::quat(Transform::AbsoluteOrientationEuler(wi.Player.FirstChildByName("Camera"))) * glm::quat(glm::vec3(pellet.y, pellet.x, 0) * spreadAngle);
glm::vec3 origin = Transform::AbsolutePosition(wi.Player.FirstChildByName("Camera"));
glm::vec3 direction = pelletRotation * glm::vec3(0, 0, -1);
float distance = traceRayDistance(origin, direction);
EntityWrapper ray = SpawnerSystem::Spawn(muzzle);
if (ray.Valid()) {
ComponentWrapper cTransform = ray["Transform"];
glm::vec3& position = cTransform["Position"];
glm::vec3& orientation = cTransform["Orientation"];
glm::vec3& scale = cTransform["Scale"];
position = Transform::AbsolutePosition(wi.Player.FirstChildByName("Camera"));
orientation = glm::eulerAngles(pelletRotation);
scale.z = distance;
}
}
}
void DefenderWeaponBehaviour::dealDamage(ComponentWrapper cWeapon, WeaponInfo& wi, const std::vector<glm::vec2>& pattern)
{
// Only deal damage client side
if (!IsClient) {
@@ -271,47 +289,76 @@ void DefenderWeaponBehaviour::dealDamage(ComponentWrapper cWeapon, WeaponInfo& w
if (!wi.Player.Valid()) {
return;
}
glm::vec3 maxRange = direction * 2.f;
EntityWrapper camera = wi.Player.FirstChildByName("Camera");
glm::vec3 cameraPosition = Transform::AbsolutePosition(camera);
if (!camera.Valid()) {
return;
}
Rectangle screenResolution = m_Renderer->GetViewportSize();
glm::vec2 centerScreen = glm::vec2(screenResolution.Width / 2, screenResolution.Height / 2);
glm::vec2 screenCoords = cameraFromEntity(m_CurrentCamera).WorldToScreen(cameraPosition + maxRange, m_Renderer->GetViewportSize());
PickData pickData = m_Renderer->Pick(centerScreen + screenCoords);
EntityWrapper victim(m_World, pickData.Entity);
if (!victim.Valid()) {
return;
// Convert the spread angle to screen coordinates, taking FOV into account
Rectangle res = m_Renderer->GetViewportSize();
float spreadAngle = glm::radians((float)cWeapon["SpreadAngle"]);
float nearClip = (double)m_CurrentCamera["Camera"]["NearClip"];
float farClip = (double)m_CurrentCamera["Camera"]["FarClip"];
float yFOV = glm::radians((double)m_CurrentCamera["Camera"]["FOV"]);
//float yRefFOV = glm::radians(59.f);
//float yRef = glm::tan(yRefFOV) * nearClip;
//float yRatio = yRef / (glm::tan(yFOV) * nearClip);
//float yMax = (yRatio / 2.f) * spreadAngle * (res.Height / 2.f);
float yRefFOV = glm::radians(59.f);
float yRef = glm::tan(yRefFOV) * nearClip;
float yRatio = yRef / (glm::tan(yFOV) * nearClip);
float yMax = yRatio * (glm::tan(spreadAngle) * farClip);
LOG_DEBUG("Ratio: %f", yRatio);
LOG_DEBUG("fatClip: %f", farClip);
LOG_DEBUG("yMax: %f", yMax);
double pelletDamage = (double)cWeapon["BaseDamage"] / pattern.size();
// Pick!
std::unordered_map<EntityWrapper, double> damageSum;
glm::vec2 screenCenter(res.Width / 2.f, res.Height / 2.f);
for (auto& pellet : pattern) {
glm::vec2 pickCoord = screenCenter + (pellet * glm::vec2(yMax, yMax));
PickData pick = m_Renderer->Pick(pickCoord);
EntityWrapper victim(m_World, pick.Entity);
if (!victim.Valid()) {
continue;
}
// Temp hit decal
EntityWrapper hit = ResourceManager::Load<EntityFile>("Schema/Entities/HitTest.xml")->MergeInto(m_World);
hit["Transform"]["Position"] = pick.Position;
// Don't let us shoot ourselves in the foot somehow
if (victim == LocalPlayer) {
continue;
}
// Only care about players being hit
if (!victim.HasComponent("Player")) {
victim = victim.FirstParentWithComponent("Player");
if (!victim.Valid()) {
continue;
}
}
// Check for friendly fire
if ((ComponentInfo::EnumType)victim["Team"]["Team"] == (ComponentInfo::EnumType)wi.Player["Team"]["Team"]) {
// TODO: Ammo sharing
continue;
}
damageSum[victim] += pelletDamage;
((glm::vec3&)hit["Model"]["Color"]).b = 1.f;
}
// Don't let us shoot ourselves in the foot somehow
if (victim == LocalPlayer) {
return;
// Deal damage!
for (auto& kv : damageSum) {
// Deal damage!
Events::PlayerDamage ePlayerDamage;
ePlayerDamage.Inflictor = wi.Player;
ePlayerDamage.Victim = kv.first;
ePlayerDamage.Damage = kv.second;
m_EventBroker->Publish(ePlayerDamage);
LOG_DEBUG("Dealt %f damage to #%i", kv.second, kv.first.ID);
}
// Only care about players being hit
if (!victim.HasComponent("Player")) {
victim = victim.FirstParentWithComponent("Player");
}
if (!victim.Valid()) {
return;
}
// Check for friendly fire
if ((ComponentInfo::EnumType)victim["Team"]["Team"] == (ComponentInfo::EnumType)wi.Player["Team"]["Team"]) {
return;
}
// Deal damage!
Events::PlayerDamage ePlayerDamage;
ePlayerDamage.Inflictor = wi.Player;
ePlayerDamage.Victim = victim;
ePlayerDamage.Damage = damage;
m_EventBroker->Publish(ePlayerDamage);
LOG_DEBUG("Damage: %f", damage);
}
bool DefenderWeaponBehaviour::canFire(ComponentWrapper cWeapon, WeaponInfo& wi)