From 9d9c6bdf1ebf04b65da97f4a0c4909d49d957bae Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Thu, 11 Feb 2016 00:08:50 +0100 Subject: [PATCH] Third person animations and shoot effects base work --- assets | 2 +- include/Game/Game.h | 2 +- include/Game/Systems/WeaponSystem.h | 114 ++++++++++-------- resources/Schema/Entities/MovementTest.xml | 4 +- resources/Schema/Entities/Player.xml | 105 +++++++++++----- resources/Schema/Entities/RayBlue.xml | 6 +- src/Engine/Rendering/RenderSystem.cpp | 4 +- src/Engine/Rendering/Skeleton.cpp | 6 - src/Game/Game.cpp | 5 +- .../Network/MultiplayerSnapshotFilter.cpp | 4 +- src/Game/Systems/PlayerMovementSystem.cpp | 76 ++++++++++-- src/Game/Systems/PlayerSpawnSystem.cpp | 2 +- src/Game/Systems/WeaponSystem.cpp | 16 +-- 13 files changed, 228 insertions(+), 118 deletions(-) diff --git a/assets b/assets index 45cbc3ab..172b3ad5 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit 45cbc3abaebe5f815e2c1b58bcf884d4953a4c52 +Subproject commit 172b3ad527fc14aa6175fa72580a66a00f04e0ba diff --git a/include/Game/Game.h b/include/Game/Game.h index 42ef4d96..baf15656 100644 --- a/include/Game/Game.h +++ b/include/Game/Game.h @@ -46,7 +46,7 @@ public: private: std::string m_NetworkAddress; - int m_NetworkPort; + int m_NetworkPort = 0; ConfigFile* m_Config = nullptr; EventBroker* m_EventBroker; diff --git a/include/Game/Systems/WeaponSystem.h b/include/Game/Systems/WeaponSystem.h index 489048b8..c3daeceb 100644 --- a/include/Game/Systems/WeaponSystem.h +++ b/include/Game/Systems/WeaponSystem.h @@ -15,6 +15,7 @@ #include "Core/EntityFileParser.h" #include "Core/Octree.h" #include "Collision/EntityAABB.h" +#include "Systems/SpawnerSystem.h" class WeaponBehaviour; @@ -150,69 +151,80 @@ private: void spawnTracer() { - ComponentWrapper cTeam = m_Entity["Team"]; - ComponentInfo::EnumType team = cTeam["Team"]; + EntityWrapper spawner; + if (m_Entity == LocalPlayer) { + spawner = m_Entity.FirstChildByName("WeaponMuzzle"); + } else { + spawner = m_Entity.FirstChildByName("ThirdPersonWeaponMuzzle"); + } - // Select the right color of effect - EntityFile* rayFile = nullptr; - if (team == cTeam["Team"].Enum("Red")) { - rayFile = m_RayRed; - } - if (team == cTeam["Team"].Enum("Blue")) { - rayFile = m_RayBlue; - } - if (rayFile == nullptr) { + if (!spawner.Valid()) { return; } - // Create the entity - EntityFileParser parser(rayFile); - EntityID rayID = parser.MergeEntities(m_World); - EntityWrapper ray(m_World, rayID); + Events::SpawnerSpawn e; + e.Spawner = spawner; + m_EventBroker->Publish(e); - // Figure out where to put it - EntityWrapper attachment; - if (m_Entity == LocalPlayer || true) { - // Spawn the effect from the weapon view model for the local player - attachment = m_Entity.FirstChildByName("WeaponMuzzle"); - } - // TODO: Spawn the effect from the weapon world model once it exists + //ComponentWrapper cTeam = m_Entity["Team"]; + //ComponentInfo::EnumType team = cTeam["Team"]; - glm::mat4 transformation = Transform::AbsoluteTransformation(attachment); - glm::vec3 _scale; - glm::vec3 translation; - glm::quat _orientation; - glm::vec3 _skew; - glm::vec4 _perspective; - glm::decompose(transformation, _scale, _orientation, translation, _skew, _perspective); - - // Matrix to euler angles - glm::vec3 euler; - euler.y = glm::asin(-transformation[0][2]); - if (cos(euler.y) != 0) { - euler.x = atan2(transformation[1][2], transformation[2][2]); - euler.z = atan2(transformation[0][1], transformation[0][0]); - } else { - euler.x = atan2(-transformation[2][0], transformation[1][1]); - euler.z = 0; - } + //// Select the right color of effect + //EntityFile* rayFile = nullptr; + //if (team == cTeam["Team"].Enum("Red")) { + // rayFile = m_RayRed; + //} + //if (team == cTeam["Team"].Enum("Blue")) { + // rayFile = m_RayBlue; + //} + //if (rayFile == nullptr) { + // return; + //} - // TODO: Spread? + //// Create the entity + //EntityFileParser parser(rayFile); + //EntityID rayID = parser.MergeEntities(m_World); + //EntityWrapper ray(m_World, rayID); - (glm::vec3&)ray["Transform"]["Position"] = translation; - (glm::vec3&)ray["Transform"]["Orientation"] = euler; - glm::vec3& scale = ray["Transform"]["Scale"]; - scale.z = traceRayDistance(translation, glm::quat(euler) * glm::vec3(0.f, 0.f, -1.f)); + //// Figure out where to put it + //EntityWrapper attachment; + //if (m_Entity == LocalPlayer || true) { + // // Spawn the effect from the weapon view model for the local player + // attachment = m_Entity.FirstChildByName("WeaponMuzzle"); + //} + //// TODO: Spawn the effect from the weapon world model once it exists + + //glm::mat4 transformation = Transform::AbsoluteTransformation(attachment); + //glm::vec3 _scale; + //glm::vec3 translation; + //glm::quat _orientation; + //glm::vec3 _skew; + //glm::vec4 _perspective; + //glm::decompose(transformation, _scale, _orientation, translation, _skew, _perspective); + // + //// Matrix to euler angles + //glm::vec3 euler; + //euler.y = glm::asin(-transformation[0][2]); + //if (cos(euler.y) != 0) { + // euler.x = atan2(transformation[1][2], transformation[2][2]); + // euler.z = atan2(transformation[0][1], transformation[0][0]); + //} else { + // euler.x = atan2(-transformation[2][0], transformation[1][1]); + // euler.z = 0; + //} + + //// TODO: Spread? + + //(glm::vec3&)ray["Transform"]["Position"] = translation; + //(glm::vec3&)ray["Transform"]["Orientation"] = euler; + //glm::vec3& scale = ray["Transform"]["Scale"]; + //scale.z = traceRayDistance(translation, glm::quat(euler) * glm::vec3(0.f, 0.f, -1.f)); } float traceRayDistance(glm::vec3 origin, glm::vec3 direction) { - OctSpace::Output result; - if (m_CollisionOctree->RayCollides(Ray(origin, direction), result)) { - return result.CollideDistance; - } else { - return 0.f; - } + // TODO: Cast a ray and size tracer appropriately + return 100.f; } }; diff --git a/resources/Schema/Entities/MovementTest.xml b/resources/Schema/Entities/MovementTest.xml index b8b68ef1..16a28684 100644 --- a/resources/Schema/Entities/MovementTest.xml +++ b/resources/Schema/Entities/MovementTest.xml @@ -52,6 +52,7 @@ + sModels/Widgets/Lights/DirectionalLightWidget.mesh @@ -65,9 +66,6 @@ - - - Models/Test/ObstacleCourse.mesh diff --git a/resources/Schema/Entities/Player.xml b/resources/Schema/Entities/Player.xml index e0cafc23..423e729e 100644 --- a/resources/Schema/Entities/Player.xml +++ b/resources/Schema/Entities/Player.xml @@ -10,9 +10,7 @@ 600 - - 2 - + @@ -22,12 +20,10 @@ - + - - - + @@ -35,7 +31,7 @@ - + @@ -105,26 +101,48 @@ - + + + + + + Idle + 0.24743387388836702 + 1 + + + Models/Characters/Assault/FirstPerson.mesh + true + + + + + + + R_Arm_Weapon_Joint + - Models/Weapons/Red/AssaultWeaponRed.mesh - true + Models/Weapons/Blue/AssaultWeaponBlue.mesh - - + + - - - - - - - - - + + + + + Schema/Entities/RayBlue.xml + + + + + + + + @@ -147,18 +165,49 @@ - Hold Pos - - 1 + Idle + 1 + + AimRifle + + - Models/Characters/Assault/AssaultAnimated.mesh - + Models/Characters/Assault/AssaultAnimations.mesh + - + + + + + R_Arm_Weapon_Joint + + + Models/Weapons/Blue/AssaultWeaponBlue.mesh + + + + + + + + + + + Schema/Entities/RayBlue.xml + + + + + + + + + + diff --git a/resources/Schema/Entities/RayBlue.xml b/resources/Schema/Entities/RayBlue.xml index 8d8e6e1e..022d7769 100644 --- a/resources/Schema/Entities/RayBlue.xml +++ b/resources/Schema/Entities/RayBlue.xml @@ -6,12 +6,12 @@ 0.25 - Models/Weapons/CylinderBullet.mesh - + Models/Effects/CylinderShot.mesh + true - + diff --git a/src/Engine/Rendering/RenderSystem.cpp b/src/Engine/Rendering/RenderSystem.cpp index 8dc24e14..36baea0d 100644 --- a/src/Engine/Rendering/RenderSystem.cpp +++ b/src/Engine/Rendering/RenderSystem.cpp @@ -66,8 +66,8 @@ void RenderSystem::fillModels(RenderScene::Queues &Jobs) } // Hide things parented to local player if they have the HiddenFromLocalPlayer component - if (entity.HasComponent("HiddenForLocalPlayer") && (entity == m_LocalPlayer || entity.IsChildOf(m_LocalPlayer))) { - continue; + if ((entity.HasComponent("HiddenForLocalPlayer") || entity.FirstParentWithComponent("HiddenForLocalPlayer").Valid()) && (entity == m_LocalPlayer || entity.IsChildOf(m_LocalPlayer))) { + //continue; } Model* model; diff --git a/src/Engine/Rendering/Skeleton.cpp b/src/Engine/Rendering/Skeleton.cpp index 1aabd84c..71f351e6 100644 --- a/src/Engine/Rendering/Skeleton.cpp +++ b/src/Engine/Rendering/Skeleton.cpp @@ -104,7 +104,6 @@ void Skeleton::AccumulateBoneTransforms(bool noRootMotion, std::vector 1.0f || progress < 0.0f) { - LOG_INFO("Progress: %f", progress); progress = glm::clamp(progress, 0.0f, 1.0f); } Animation::Keyframe::BoneProperty currentBoneProperty = currentFrame.BoneProperties; @@ -181,7 +180,6 @@ void Skeleton::AccumulateBoneTransforms(bool noRootMotion, std::vector 1.0f || progress < 0.0f) { - LOG_INFO("Progress: %f", progress); progress = glm::clamp(progress, 0.0f, 1.0f); } Animation::Keyframe::BoneProperty currentBoneProperty = currentFrame.BoneProperties; @@ -353,9 +349,7 @@ glm::mat4 Skeleton::GetOffsetTransform(const Bone* bone, AnimationOffset animati } - if (progress > 1.0f || progress < 0.0f) { - LOG_INFO("Progress: %f", progress); progress = glm::clamp(progress, 0.0f, 1.0f); } Animation::Keyframe::BoneProperty currentBoneProperty = currentFrame.BoneProperties; diff --git a/src/Game/Game.cpp b/src/Game/Game.cpp index a6f12f03..6057d463 100644 --- a/src/Game/Game.cpp +++ b/src/Game/Game.cpp @@ -227,11 +227,8 @@ int Game::parseArgs(int argc, char* argv[]) exit(1); } - if (vm.count("connect")) { - m_IsClient = true; - } - // HACK: Right now, client and server are mutually exclusive + m_IsClient = true; if (m_IsServer) { m_IsClient = false; } diff --git a/src/Game/Network/MultiplayerSnapshotFilter.cpp b/src/Game/Network/MultiplayerSnapshotFilter.cpp index 709ce6b1..65d40189 100644 --- a/src/Game/Network/MultiplayerSnapshotFilter.cpp +++ b/src/Game/Network/MultiplayerSnapshotFilter.cpp @@ -26,6 +26,8 @@ bool MultiplayerSnapshotFilter::FilterComponent(EntityWrapper entity, SharedComp bool MultiplayerSnapshotFilter::OnPlayerSpawned(Events::PlayerSpawned ePlayerSpawned) { - m_LocalPlayer = ePlayerSpawned.Player; + if (ePlayerSpawned.PlayerID == -1) { + m_LocalPlayer = ePlayerSpawned.Player; + } return true; } \ No newline at end of file diff --git a/src/Game/Systems/PlayerMovementSystem.cpp b/src/Game/Systems/PlayerMovementSystem.cpp index ec834715..7c69f0ce 100644 --- a/src/Game/Systems/PlayerMovementSystem.cpp +++ b/src/Game/Systems/PlayerMovementSystem.cpp @@ -29,12 +29,20 @@ void PlayerMovementSystem::updateMovementControllers(double dt) continue; } + // Aim pitch EntityWrapper cameraEntity = player.FirstChildByName("Camera"); if (cameraEntity.Valid()) { glm::vec3& cameraOrientation = cameraEntity["Transform"]["Orientation"]; cameraOrientation.x += controller->Rotation().x; // Limit camera pitch so we don't break our necks cameraOrientation.x = glm::clamp(cameraOrientation.x, -glm::half_pi(), glm::half_pi()); + // Set third person model aim pitch + EntityWrapper playerModel = player.FirstChildByName("PlayerModel"); + if (playerModel.Valid()) { + ComponentWrapper cAnimationOffset = playerModel["AnimationOffset"]; + double time = (cameraOrientation.x + glm::half_pi()) / glm::pi(); + cAnimationOffset["Time"] = time; + } } ComponentWrapper& cTransform = player["Transform"]; @@ -124,24 +132,74 @@ void PlayerMovementSystem::updateMovementControllers(double dt) EntityWrapper playerModel = player.FirstChildByName("PlayerModel"); if (playerModel.Valid()) { ComponentWrapper cAnimation = playerModel["Animation"]; + std::string& animationName1 = cAnimation["AnimationName1"]; + std::string& animationName2 = cAnimation["AnimationName2"]; + double& animationTime1 = cAnimation["Time1"]; + double& animationTime2 = cAnimation["Time2"]; + double& animationSpeed1 = cAnimation["Speed1"]; + double& animationSpeed2 = cAnimation["Speed2"]; + double& animationWeight1 = cAnimation["Weight1"]; + double& animationWeight2 = cAnimation["Weight2"]; float movementLength = glm::length(groundVelocity); //TODO: add assault dash animation here if (glm::length(controller->Movement()) > 0.f) { - if (controller->Crouching()) { - cAnimation["AnimationName1"] = "Crouch Walk"; - (double&)cAnimation["Speed1"] = 1.f * -glm::sign(controller->Movement().z); + double forwardMovement = controller->Movement().z; + double strafeMovement = controller->Movement().x; + + if (controller->Crouching() && animationName1 != "CrouchWalk") { + animationName1 = "CrouchWalk"; + animationSpeed1 = 1.0 * -glm::sign(controller->Movement().z); } else { - cAnimation["AnimationName1"] = "Run"; - (double&)cAnimation["Speed1"] = 2.f * -glm::sign(controller->Movement().z); + if (glm::abs(forwardMovement) > 0) { + if (animationName1 != "Run") { + animationName1 = "Run"; + if (animationName2 == "StrafeLeft" || animationName2 == "StrafeRight") { + animationTime1 = animationTime2; + } else { + animationTime1 = 0.0; + } + } + animationSpeed1 = 2.f * -glm::sign(forwardMovement); + } + + if (glm::abs(strafeMovement) > 0) { + if (animationName2 != "StrafeLeft" && animationName2 != "StrafeRight") { + if (strafeMovement < 0) { + animationName2 = "StrafeLeft"; + } + if (strafeMovement > 0) { + animationName2 = "StrafeRight"; + } + if (animationName1 == "Run") { + animationTime2 = animationTime1; + } else { + animationTime2 = 0.0; + } + } + animationSpeed2 = 2.f * glm::abs(strafeMovement); + } + + double strafeWeight = glm::abs(strafeMovement) / (glm::abs(forwardMovement) + glm::abs(strafeMovement)); + animationWeight2 = strafeWeight; + animationWeight1 = 1.0 - strafeWeight; } } else { if (controller->Crouching()) { - cAnimation["AnimationName1"] = "Crouch"; - (double&)cAnimation["Speed"] = 1.f; + animationName1 = "Crouch"; + animationName2 = ""; + animationSpeed1 = 1.0; + animationSpeed2 = 0.0; + animationWeight1 = 1.0; + animationWeight2 = 0.0; } else { - cAnimation["AnimationName1"] = "Hold Pos"; - (double&)cAnimation["Speed1"] = 1.f; + animationName1 = "Idle"; + animationName2 = ""; + animationSpeed1 = 1.f; + animationSpeed2 = 0.0; + animationWeight1 = 1.0; + animationWeight2 = 0.0; + //cAnimation["AnimationName2"] = "Idle"; } } } diff --git a/src/Game/Systems/PlayerSpawnSystem.cpp b/src/Game/Systems/PlayerSpawnSystem.cpp index 507ed0f5..2afb0de1 100644 --- a/src/Game/Systems/PlayerSpawnSystem.cpp +++ b/src/Game/Systems/PlayerSpawnSystem.cpp @@ -91,7 +91,7 @@ bool PlayerSpawnSystem::OnPlayerSpawned(Events::PlayerSpawned& e) if (cameraEntity.Valid()) { Events::SetCamera e; e.CameraEntity = cameraEntity; - m_EventBroker->Publish(e); + //m_EventBroker->Publish(e); } // HACK: Set the player model color to team color diff --git a/src/Game/Systems/WeaponSystem.cpp b/src/Game/Systems/WeaponSystem.cpp index dfb84581..117176c1 100644 --- a/src/Game/Systems/WeaponSystem.cpp +++ b/src/Game/Systems/WeaponSystem.cpp @@ -20,14 +20,14 @@ void WeaponSystem::Update(double dt) void WeaponSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& cPlayer, double dt) { // Update potential weapon behaviour for player - //auto it = m_ActiveWeapons.find(entity); - //if (it != m_ActiveWeapons.end()) { - // //if (it->first.Valid()) { - // it->second->Update(dt); - // //} else { - // // m_ActiveWeapons.erase(it); - // //} - //} + auto it = m_ActiveWeapons.find(entity); + if (it != m_ActiveWeapons.end()) { + if (it->first.Valid()) { + it->second->Update(dt); + } else { + m_ActiveWeapons.erase(it); + } + } } bool WeaponSystem::OnInputCommand(Events::InputCommand& e)