From f77a6105195a65b7dce492b216b5a64f3c4e6f78 Mon Sep 17 00:00:00 2001 From: viktorljung Date: Tue, 8 Mar 2016 13:26:01 +0100 Subject: [PATCH] Dash now looking good --- .../Engine/Input/FirstPersonInputController.h | 114 +++++++++--------- resources/Schema/Entities/Player.xml | 8 +- src/Engine/Rendering/AnimationSystem.cpp | 2 + src/Engine/Rendering/AutoBlendQueue.cpp | 11 +- src/Game/Systems/PlayerMovementSystem.cpp | 48 +++----- 5 files changed, 88 insertions(+), 95 deletions(-) diff --git a/include/Engine/Input/FirstPersonInputController.h b/include/Engine/Input/FirstPersonInputController.h index d9b0d3e8..75726fd3 100644 --- a/include/Engine/Input/FirstPersonInputController.h +++ b/include/Engine/Input/FirstPersonInputController.h @@ -110,7 +110,6 @@ bool FirstPersonInputController::OnCommand(const Events::InputComm if (e.Command == "Pitch") { float val = glm::radians(e.Value); m_Rotation.x += -val; - //m_Rotation.x = glm::clamp(m_Rotation.x, -glm::half_pi(), glm::half_pi()); } if (e.Command == "Yaw") { @@ -123,14 +122,14 @@ bool FirstPersonInputController::OnCommand(const Events::InputComm float val = glm::clamp(e.Value, -1.f, 1.f); m_Movement.z = -val; + //Animation if (m_PlayerEntity.Valid()) { EntityWrapper playerModel = m_PlayerEntity.FirstChildByName("PlayerModel"); if (playerModel.Valid()) { - if (val > 0) { + if (val > 0) { // Walk/Run Events::AutoAnimationBlend aeb; aeb.Duration = 0.1; - - if(m_Crouching) { + if (m_Crouching) { aeb.NodeName = "Walk"; } else { aeb.NodeName = "Run"; @@ -139,7 +138,7 @@ bool FirstPersonInputController::OnCommand(const Events::InputComm aeb.Start = true; aeb.SingleLevelBlend = true; m_EventBroker->Publish(aeb); - } else if (val < 0) { + } else if (val < 0) { // Walk/run Backwards Events::AutoAnimationBlend aeb; aeb.Duration = 0.1; if (m_Crouching) { @@ -152,8 +151,6 @@ bool FirstPersonInputController::OnCommand(const Events::InputComm aeb.SingleLevelBlend = true; aeb.Reverse = true; m_EventBroker->Publish(aeb); - } else { - } } } @@ -162,10 +159,11 @@ bool FirstPersonInputController::OnCommand(const Events::InputComm float val = glm::clamp(e.Value, -1.f, 1.f); m_Movement.x = val; + + //Animation if (m_PlayerEntity.Valid()) { EntityWrapper playerModel = m_PlayerEntity.FirstChildByName("PlayerModel"); - - if (playerModel.Valid()) { + if (playerModel.Valid()) { //Right Strafe if (val > 0) { Events::AutoAnimationBlend aeb; aeb.Duration = 0.1; @@ -174,7 +172,7 @@ bool FirstPersonInputController::OnCommand(const Events::InputComm aeb.SingleLevelBlend = true; aeb.Start = true; m_EventBroker->Publish(aeb); - } else if (val < 0) { + } else if (val < 0) { //LeftStrafe Events::AutoAnimationBlend aeb; aeb.Duration = 0.1; aeb.NodeName = "Left"; @@ -182,63 +180,59 @@ bool FirstPersonInputController::OnCommand(const Events::InputComm aeb.SingleLevelBlend = true; aeb.Start = true; m_EventBroker->Publish(aeb); - } else { - - } } } - - } - - - if (glm::length2(m_Movement) < 0.1f) { - if (m_PlayerEntity.Valid()) { - EntityWrapper playerModel = m_PlayerEntity.FirstChildByName("PlayerModel"); - - if (playerModel.Valid()) { - Events::AutoAnimationBlend aeb; - aeb.Duration = 0.2; - aeb.NodeName = "Idle"; - aeb.RootNode = playerModel; - m_EventBroker->Publish(aeb); - } - } - } else { - if (m_PlayerEntity.Valid()) { - EntityWrapper playerModel = m_PlayerEntity.FirstChildByName("PlayerModel"); - - if (playerModel.Valid()) { - Events::AutoAnimationBlend aeb; - aeb.Duration = 0.2; - aeb.NodeName = "MovementBlend"; - aeb.RootNode = playerModel; - m_EventBroker->Publish(aeb); - } - } } } - - if (glm::length2(m_Movement) > 0) { - m_Movement = glm::normalize(m_Movement); - - if (m_PlayerEntity.Valid()) { - EntityWrapper playerModel = m_PlayerEntity.FirstChildByName("PlayerModel"); - - if (playerModel.Valid()) { - glm::vec2 direction = glm::normalize(glm::vec2(m_Movement.x, m_Movement.z)); - - double weight = glm::abs(glm::dot(glm::vec2(1, 0), direction)); - LOG_INFO("Weight %f", weight); - Events::SetBlendWeight sbw; - sbw.NodeName = "MovementBlend"; - sbw.Weight = weight; - sbw.RootNode = playerModel; - m_EventBroker->Publish(sbw); - } + //Animation + if (glm::length2(m_Movement) < 0.1f) { + //Blend to Idle + if (m_PlayerEntity.Valid()) { + EntityWrapper playerModel = m_PlayerEntity.FirstChildByName("PlayerModel"); + if (playerModel.Valid()) { + Events::AutoAnimationBlend aeb; + aeb.Duration = 0.2; + aeb.NodeName = "Idle"; + aeb.RootNode = playerModel; + m_EventBroker->Publish(aeb); } } + } else { + + //Blend to movement + if (m_PlayerEntity.Valid()) { + EntityWrapper playerModel = m_PlayerEntity.FirstChildByName("PlayerModel"); + if (playerModel.Valid()) { + Events::AutoAnimationBlend aeb; + aeb.Duration = 0.2; + aeb.NodeName = "MovementBlend"; + aeb.RootNode = playerModel; + m_EventBroker->Publish(aeb); + } + } + } + + + if (glm::length2(m_Movement) > 0) { + m_Movement = glm::normalize(m_Movement); + + //Animation + // movement direction blend + if (m_PlayerEntity.Valid()) { + EntityWrapper playerModel = m_PlayerEntity.FirstChildByName("PlayerModel"); + if (playerModel.Valid()) { + glm::vec2 direction = glm::normalize(glm::vec2(m_Movement.x, m_Movement.z)); + double weight = glm::abs(glm::dot(glm::vec2(1, 0), direction)); + Events::SetBlendWeight sbw; + sbw.NodeName = "MovementBlend"; + sbw.Weight = weight; + sbw.RootNode = playerModel; + m_EventBroker->Publish(sbw); + } + } + } @@ -274,6 +268,8 @@ bool FirstPersonInputController::OnCommand(const Events::InputComm if (e.Command == "Crouch") { m_Crouching = e.Value > 0; + + //Animation if (m_PlayerEntity.Valid()) { EntityWrapper playerModel = m_PlayerEntity.FirstChildByName("PlayerModel"); if (playerModel.Valid()) { diff --git a/resources/Schema/Entities/Player.xml b/resources/Schema/Entities/Player.xml index 16b7ccd1..d51b8cc5 100644 --- a/resources/Schema/Entities/Player.xml +++ b/resources/Schema/Entities/Player.xml @@ -986,7 +986,7 @@ DashForwardF - 3 + 1.7999999523162842 false @@ -998,7 +998,7 @@ DashBackwardF - 3 + 1.7999999523162842 false @@ -1022,7 +1022,7 @@ DashLeftF - 3 + 1.7999999523162842 false @@ -1034,7 +1034,7 @@ DashRightF - 3 + 1.7999999523162842 false diff --git a/src/Engine/Rendering/AnimationSystem.cpp b/src/Engine/Rendering/AnimationSystem.cpp index be00a0f4..f6c91d46 100644 --- a/src/Engine/Rendering/AnimationSystem.cpp +++ b/src/Engine/Rendering/AnimationSystem.cpp @@ -127,6 +127,7 @@ void AnimationSystem::UpdateAnimations(double dt) void AnimationSystem::UpdateWeights(double dt) { for (auto it = m_AutoBlendQueues.begin(); it != m_AutoBlendQueues.end(); ) { + it->second.PrintQueue(); if(it->second.HasActiveBlendJob()) { AutoBlendQueue::AutoBlendJob& blendJob = it->second.GetActiveBlendJob(); @@ -151,6 +152,7 @@ void AnimationSystem::UpdateWeights(double dt) } } } + LOG_INFO(""); } bool AnimationSystem::OnAutoAnimationBlend(Events::AutoAnimationBlend& e) diff --git a/src/Engine/Rendering/AutoBlendQueue.cpp b/src/Engine/Rendering/AutoBlendQueue.cpp index 1c6907e8..f4a854ec 100644 --- a/src/Engine/Rendering/AutoBlendQueue.cpp +++ b/src/Engine/Rendering/AutoBlendQueue.cpp @@ -38,11 +38,14 @@ void AutoBlendQueue::Insert(AutoBlendJob autoBlendJob) double animationSpeed = (double)autoBlendJob.AnimationEntity["Animation"]["Speed"]; double animationTime = (double)autoBlendJob.AnimationEntity["Animation"]["Time"]; - - if ((bool)autoBlendJob.AnimationEntity["Animation"]["Reverse"]) { - AnimationDuration = (animation->Duration * animationSpeed) - (animation->Duration - animationTime); + if (animationSpeed != 0) { + if ((bool)autoBlendJob.AnimationEntity["Animation"]["Reverse"]) { + AnimationDuration = (animation->Duration / animationSpeed) - (animation->Duration - animationTime); + } else { + AnimationDuration = (animation->Duration / animationSpeed) - animationTime; + } } else { - AnimationDuration = (animation->Duration * animationSpeed) - animationTime; + return; } blendNode.StartTime += AnimationDuration; diff --git a/src/Game/Systems/PlayerMovementSystem.cpp b/src/Game/Systems/PlayerMovementSystem.cpp index dbf3d889..dad84932 100644 --- a/src/Game/Systems/PlayerMovementSystem.cpp +++ b/src/Game/Systems/PlayerMovementSystem.cpp @@ -358,7 +358,7 @@ bool PlayerMovementSystem::OnDashAbility(Events::DashAbility & e) if (controller->Movement().x > 0) { { Events::AutoAnimationBlend aeb; - aeb.Duration = 0.3; + aeb.Duration = 0.1; aeb.NodeName = "DashRight"; aeb.RootNode = playerModel; aeb.Restart = true; @@ -367,19 +367,19 @@ bool PlayerMovementSystem::OnDashAbility(Events::DashAbility & e) } { Events::AutoAnimationBlend aeb; - aeb.Duration = 0.3; + aeb.Duration = 0.2; aeb.NodeName = "StandCrouchBlend"; aeb.RootNode = playerModel; - aeb.Delay = -0.3; + aeb.Delay = 0.2; aeb.Start = true; aeb.Restart = false; - aeb.AnimationEntity = playerModel.FirstChildByName("DashForward"); + aeb.AnimationEntity = playerModel.FirstChildByName("DashRight"); m_EventBroker->Publish(aeb); } } else { { Events::AutoAnimationBlend aeb; - aeb.Duration = 0.3; + aeb.Duration = 0.1; aeb.NodeName = "DashLeft"; aeb.RootNode = playerModel; aeb.Restart = true; @@ -388,13 +388,13 @@ bool PlayerMovementSystem::OnDashAbility(Events::DashAbility & e) } { Events::AutoAnimationBlend aeb; - aeb.Duration = 0.3; + aeb.Duration = 0.2; aeb.NodeName = "StandCrouchBlend"; aeb.RootNode = playerModel; - aeb.Delay = -0.3; + aeb.Delay = 0.2; aeb.Start = true; aeb.Restart = false; - aeb.AnimationEntity = playerModel.FirstChildByName("DashForward"); + aeb.AnimationEntity = playerModel.FirstChildByName("DashLeft"); m_EventBroker->Publish(aeb); } } @@ -402,7 +402,7 @@ bool PlayerMovementSystem::OnDashAbility(Events::DashAbility & e) if (controller->Movement().z < 0) { { Events::AutoAnimationBlend aeb; - aeb.Duration = 0.3; + aeb.Duration = 0.1; aeb.NodeName = "DashForward"; aeb.RootNode = playerModel; aeb.Restart = true; @@ -411,10 +411,10 @@ bool PlayerMovementSystem::OnDashAbility(Events::DashAbility & e) } { Events::AutoAnimationBlend aeb; - aeb.Duration = 0.3; + aeb.Duration = 0.2; aeb.NodeName = "StandCrouchBlend"; aeb.RootNode = playerModel; - aeb.Delay = -0.3; + aeb.Delay = 0.2; aeb.Start = true; aeb.Restart = false; aeb.AnimationEntity = playerModel.FirstChildByName("DashForward"); @@ -423,7 +423,7 @@ bool PlayerMovementSystem::OnDashAbility(Events::DashAbility & e) } else { { Events::AutoAnimationBlend aeb; - aeb.Duration = 0.3; + aeb.Duration = 0.1; aeb.NodeName = "DashBackward"; aeb.RootNode = playerModel; aeb.Restart = true; @@ -432,29 +432,30 @@ bool PlayerMovementSystem::OnDashAbility(Events::DashAbility & e) } { Events::AutoAnimationBlend aeb; - aeb.Duration = 0.3; + aeb.Duration = 0.2; aeb.NodeName = "StandCrouchBlend"; aeb.RootNode = playerModel; - aeb.Delay = -0.3; + aeb.Delay = 0.2; aeb.Start = true; aeb.Restart = false; - aeb.AnimationEntity = playerModel.FirstChildByName("DashForward"); + aeb.AnimationEntity = playerModel.FirstChildByName("DashBackward"); m_EventBroker->Publish(aeb); } } } - /* EntityWrapper dashEffectModel; - dashEffectModel = playerModel.Clone(dashEffect); + EntityWrapper dashEffectModel; + dashEffectModel = playerModel.Clone(); player["Transform"].Copy(dashEffectModel["Transform"]); - dashEffectModel.AttachComponent("ExplosionEffect"); + /* dashEffectModel.AttachComponent("ExplosionEffect"); dashEffectModel["ExplosionEffect"]["EndColor"] = (glm::vec4)playerModel["Model"]["Color"]; ((glm::vec4&)dashEffectModel["ExplosionEffect"]["EndColor"]).w = 0.f; (double&)dashEffectModel["ExplosionEffect"]["ExplosionDuration"] = dashEffect["Lifetime"]["Lifetime"]; (glm::vec3&)dashEffectModel["ExplosionEffect"]["ExplosionOrigin"] = glm::vec3(0, 1, 0) + (0.2f * controller->Movement()); +*/ @@ -462,18 +463,9 @@ bool PlayerMovementSystem::OnDashAbility(Events::DashAbility & e) for (auto animationEntity : animationChildren) { (bool&)animationEntity["Animation"]["Play"] = false; - }*/ + } } } } - - - - - - - - - return true; }