Third person animations and shoot effects base work

This commit is contained in:
2016-02-11 00:08:50 +01:00
parent 6396925b68
commit 9d9c6bdf1e
13 changed files with 228 additions and 118 deletions
+1 -1
Submodule assets updated: 45cbc3abae...172b3ad527
+1 -1
View File
@@ -46,7 +46,7 @@ public:
private: private:
std::string m_NetworkAddress; std::string m_NetworkAddress;
int m_NetworkPort; int m_NetworkPort = 0;
ConfigFile* m_Config = nullptr; ConfigFile* m_Config = nullptr;
EventBroker* m_EventBroker; EventBroker* m_EventBroker;
+62 -50
View File
@@ -15,6 +15,7 @@
#include "Core/EntityFileParser.h" #include "Core/EntityFileParser.h"
#include "Core/Octree.h" #include "Core/Octree.h"
#include "Collision/EntityAABB.h" #include "Collision/EntityAABB.h"
#include "Systems/SpawnerSystem.h"
class WeaponBehaviour; class WeaponBehaviour;
@@ -150,69 +151,80 @@ private:
void spawnTracer() void spawnTracer()
{ {
ComponentWrapper cTeam = m_Entity["Team"]; EntityWrapper spawner;
ComponentInfo::EnumType team = cTeam["Team"]; if (m_Entity == LocalPlayer) {
spawner = m_Entity.FirstChildByName("WeaponMuzzle");
} else {
spawner = m_Entity.FirstChildByName("ThirdPersonWeaponMuzzle");
}
// Select the right color of effect if (!spawner.Valid()) {
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; return;
} }
// Create the entity Events::SpawnerSpawn e;
EntityFileParser parser(rayFile); e.Spawner = spawner;
EntityID rayID = parser.MergeEntities(m_World); m_EventBroker->Publish(e);
EntityWrapper ray(m_World, rayID);
// Figure out where to put it //ComponentWrapper cTeam = m_Entity["Team"];
EntityWrapper attachment; //ComponentInfo::EnumType team = cTeam["Team"];
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); //// Select the right color of effect
glm::vec3 _scale; //EntityFile* rayFile = nullptr;
glm::vec3 translation; //if (team == cTeam["Team"].Enum("Red")) {
glm::quat _orientation; // rayFile = m_RayRed;
glm::vec3 _skew; //}
glm::vec4 _perspective; //if (team == cTeam["Team"].Enum("Blue")) {
glm::decompose(transformation, _scale, _orientation, translation, _skew, _perspective); // rayFile = m_RayBlue;
//}
//if (rayFile == nullptr) {
// return;
//}
// Matrix to euler angles //// Create the entity
glm::vec3 euler; //EntityFileParser parser(rayFile);
euler.y = glm::asin(-transformation[0][2]); //EntityID rayID = parser.MergeEntities(m_World);
if (cos(euler.y) != 0) { //EntityWrapper ray(m_World, rayID);
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? //// 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::vec3&)ray["Transform"]["Position"] = translation; //glm::mat4 transformation = Transform::AbsoluteTransformation(attachment);
(glm::vec3&)ray["Transform"]["Orientation"] = euler; //glm::vec3 _scale;
glm::vec3& scale = ray["Transform"]["Scale"]; //glm::vec3 translation;
scale.z = traceRayDistance(translation, glm::quat(euler) * glm::vec3(0.f, 0.f, -1.f)); //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) float traceRayDistance(glm::vec3 origin, glm::vec3 direction)
{ {
OctSpace::Output result; // TODO: Cast a ray and size tracer appropriately
if (m_CollisionOctree->RayCollides(Ray(origin, direction), result)) { return 100.f;
return result.CollideDistance;
} else {
return 0.f;
}
} }
}; };
+1 -3
View File
@@ -52,6 +52,7 @@
</Entity> </Entity>
<Entity name="DirectionalLight"> <Entity name="DirectionalLight">
<Components> <Components>
<c:SceneLight/>
<c:DirectionalLight/> <c:DirectionalLight/>
<c:Model> <c:Model>
<Resource>sModels/Widgets/Lights/DirectionalLightWidget.mesh</Resource> <Resource>sModels/Widgets/Lights/DirectionalLightWidget.mesh</Resource>
@@ -65,9 +66,6 @@
</Entity> </Entity>
<Entity name="ObstacleCourse"> <Entity name="ObstacleCourse">
<Components> <Components>
<c:AABB>
<Size X="50" Y="50" Z="50"/>
</c:AABB>
<c:Collidable/> <c:Collidable/>
<c:Model> <c:Model>
<Resource>Models/Test/ObstacleCourse.mesh</Resource> <Resource>Models/Test/ObstacleCourse.mesh</Resource>
+77 -28
View File
@@ -10,9 +10,7 @@
<RPM>600</RPM> <RPM>600</RPM>
</c:AssaultWeapon> </c:AssaultWeapon>
<c:Collidable/> <c:Collidable/>
<c:DashAbility> <c:DashAbility/>
<CoolDownMaxTimer>2</CoolDownMaxTimer>
</c:DashAbility>
<c:Health/> <c:Health/>
<c:Physics> <c:Physics>
<Velocity X="2.30999646e-23" Y="0" Z="1.05272533e-23"/> <Velocity X="2.30999646e-23" Y="0" Z="1.05272533e-23"/>
@@ -22,12 +20,10 @@
</c:Player> </c:Player>
<c:Team> <c:Team>
<Team> <Team>
<Red/> <Blue/>
</Team> </Team>
</c:Team> </c:Team>
<c:Transform> <c:Transform/>
<Position X="1.28011036e-21" Y="0.0264999866" Z="1.82592022"/>
</c:Transform>
</Components> </Components>
<Children> <Children>
@@ -35,7 +31,7 @@
<Components> <Components>
<c:Camera/> <c:Camera/>
<c:Transform> <c:Transform>
<Position X="0" Y="1.37700009" Z="0"/> <Position X="0" Y="1.27700007" Z="0"/>
</c:Transform> </c:Transform>
</Components> </Components>
<Children> <Children>
@@ -105,26 +101,48 @@
</Components> </Components>
<Children/> <Children/>
</Entity> </Entity>
<Entity name="Weapon"> </Children>
</Entity>
<Entity name="Hands">
<Components>
<c:Animation>
<AnimationName1>Idle</AnimationName1>
<Time1>0.24743387388836702</Time1>
<Speed1>1</Speed1>
</c:Animation>
<c:Model>
<Resource>Models/Characters/Assault/FirstPerson.mesh</Resource>
<Transparent>true</Transparent>
</c:Model>
<c:Transform/>
</Components>
<Children>
<Entity name="WeaponModel">
<Components> <Components>
<c:BoneAttachment>
<BoneName>R_Arm_Weapon_Joint</BoneName>
</c:BoneAttachment>
<c:Model> <c:Model>
<Resource>Models/Weapons/Red/AssaultWeaponRed.mesh</Resource> <Resource>Models/Weapons/Blue/AssaultWeaponBlue.mesh</Resource>
<Transparent>true</Transparent>
</c:Model> </c:Model>
<c:Transform> <c:Transform>
<Position X="0.180000007" Y="-0.183000013" Z="0"/> <Position X="0.120747976" Y="-0.229536116" Z="-0.151475713"/>
<Orientation X="0" Y="3.08300018" Z="0"/> <Orientation X="0.0104047507" Y="-0.00268173264" Z="0.0428441092"/>
</c:Transform> </c:Transform>
</Components> </Components>
<Children/> <Children>
</Entity> <Entity name="WeaponMuzzle">
<Entity name="WeaponMuzzle"> <Components>
<Components> <c:Spawner>
<c:Transform> <EntityFile>Schema/Entities/RayBlue.xml</EntityFile>
<Position X="0.215000004" Y="-0.153000012" Z="-0.923000038"/> </c:Spawner>
</c:Transform> <c:Transform>
</Components> <Position X="0" Y="0.0480000004" Z="-0.807000041"/>
<Children/> </c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity> </Entity>
</Children> </Children>
</Entity> </Entity>
@@ -147,18 +165,49 @@
<Entity name="PlayerModel"> <Entity name="PlayerModel">
<Components> <Components>
<c:Animation> <c:Animation>
<Name>Hold Pos</Name> <AnimationName1>Idle</AnimationName1>
<Time>0.86415395295813102</Time> <Speed1>1</Speed1>
<Speed>1</Speed>
</c:Animation> </c:Animation>
<c:AnimationOffset>
<AnimationName>AimRifle</AnimationName>
<Time>0.5</Time>
</c:AnimationOffset>
<c:HiddenForLocalPlayer/> <c:HiddenForLocalPlayer/>
<c:Model> <c:Model>
<Resource>Models/Characters/Assault/AssaultAnimated.mesh</Resource> <Resource>Models/Characters/Assault/AssaultAnimations.mesh</Resource>
<Color A="1" B="0" G="0" R="1"/> <Color A="1" B="1" G="0.309803933" R="0"/>
</c:Model> </c:Model>
<c:Transform/> <c:Transform/>
</Components> </Components>
<Children/> <Children>
<Entity name="ThirdPersonWeaponModel">
<Components>
<c:BoneAttachment>
<BoneName>R_Arm_Weapon_Joint</BoneName>
</c:BoneAttachment>
<c:Model>
<Resource>Models/Weapons/Blue/AssaultWeaponBlue.mesh</Resource>
</c:Model>
<c:Transform>
<Position X="0.156722724" Y="1.03299165" Z="-0.216208369"/>
<Orientation X="-0.062651813" Y="-0.0297243949" Z="0.120719783"/>
</c:Transform>
</Components>
<Children>
<Entity name="ThirdPersonWeaponMuzzle">
<Components>
<c:Spawner>
<EntityFile>Schema/Entities/RayBlue.xml</EntityFile>
</c:Spawner>
<c:Transform>
<Position X="0.00644115033" Y="0.096679531" Z="-0.436609417"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
</Children>
</Entity> </Entity>
<Entity name="AABBStanding"> <Entity name="AABBStanding">
<Components> <Components>
+3 -3
View File
@@ -6,12 +6,12 @@
<Lifetime>0.25</Lifetime> <Lifetime>0.25</Lifetime>
</c:Lifetime> </c:Lifetime>
<c:Model> <c:Model>
<Resource>Models/Weapons/CylinderBullet.mesh</Resource> <Resource>Models/Effects/CylinderShot.mesh</Resource>
<Color A="0.156862751" B="39.2156868" G="7.84313726" R="0"/> <Color A="0.149019614" B="39.2156868" G="39.2156868" R="0"/>
<Transparent>true</Transparent> <Transparent>true</Transparent>
</c:Model> </c:Model>
<c:Transform> <c:Transform>
<Scale X="0.0109999999" Y="0.0289999992" Z="100"/> <Scale X="0.0690000057" Y="0.0690000057" Z="100"/>
</c:Transform> </c:Transform>
</Components> </Components>
+2 -2
View File
@@ -66,8 +66,8 @@ void RenderSystem::fillModels(RenderScene::Queues &Jobs)
} }
// Hide things parented to local player if they have the HiddenFromLocalPlayer component // Hide things parented to local player if they have the HiddenFromLocalPlayer component
if (entity.HasComponent("HiddenForLocalPlayer") && (entity == m_LocalPlayer || entity.IsChildOf(m_LocalPlayer))) { if ((entity.HasComponent("HiddenForLocalPlayer") || entity.FirstParentWithComponent("HiddenForLocalPlayer").Valid()) && (entity == m_LocalPlayer || entity.IsChildOf(m_LocalPlayer))) {
continue; //continue;
} }
Model* model; Model* model;
-6
View File
@@ -104,7 +104,6 @@ void Skeleton::AccumulateBoneTransforms(bool noRootMotion, std::vector<Animation
if (progress > 1.0f || progress < 0.0f) { if (progress > 1.0f || progress < 0.0f) {
LOG_INFO("Progress: %f", progress);
progress = glm::clamp(progress, 0.0f, 1.0f); progress = glm::clamp(progress, 0.0f, 1.0f);
} }
Animation::Keyframe::BoneProperty currentBoneProperty = currentFrame.BoneProperties; Animation::Keyframe::BoneProperty currentBoneProperty = currentFrame.BoneProperties;
@@ -181,7 +180,6 @@ void Skeleton::AccumulateBoneTransforms(bool noRootMotion, std::vector<Animation
} }
if (offset != glm::mat4(1)) { if (offset != glm::mat4(1)) {
boneMatrix = parentMatrix * ((glm::translate(finalPosInterp) * glm::toMat4(finalRotInterp) * glm::scale(finalScaleInterp)) + offset); boneMatrix = parentMatrix * ((glm::translate(finalPosInterp) * glm::toMat4(finalRotInterp) * glm::scale(finalScaleInterp)) + offset);
} else { } else {
@@ -233,9 +231,7 @@ void Skeleton::AccumulateBoneTransforms(bool noRootMotion, std::vector<Animation
} }
if (progress > 1.0f || progress < 0.0f) { if (progress > 1.0f || progress < 0.0f) {
LOG_INFO("Progress: %f", progress);
progress = glm::clamp(progress, 0.0f, 1.0f); progress = glm::clamp(progress, 0.0f, 1.0f);
} }
Animation::Keyframe::BoneProperty currentBoneProperty = currentFrame.BoneProperties; 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) { if (progress > 1.0f || progress < 0.0f) {
LOG_INFO("Progress: %f", progress);
progress = glm::clamp(progress, 0.0f, 1.0f); progress = glm::clamp(progress, 0.0f, 1.0f);
} }
Animation::Keyframe::BoneProperty currentBoneProperty = currentFrame.BoneProperties; Animation::Keyframe::BoneProperty currentBoneProperty = currentFrame.BoneProperties;
+1 -4
View File
@@ -227,11 +227,8 @@ int Game::parseArgs(int argc, char* argv[])
exit(1); exit(1);
} }
if (vm.count("connect")) {
m_IsClient = true;
}
// HACK: Right now, client and server are mutually exclusive // HACK: Right now, client and server are mutually exclusive
m_IsClient = true;
if (m_IsServer) { if (m_IsServer) {
m_IsClient = false; m_IsClient = false;
} }
@@ -26,6 +26,8 @@ bool MultiplayerSnapshotFilter::FilterComponent(EntityWrapper entity, SharedComp
bool MultiplayerSnapshotFilter::OnPlayerSpawned(Events::PlayerSpawned ePlayerSpawned) bool MultiplayerSnapshotFilter::OnPlayerSpawned(Events::PlayerSpawned ePlayerSpawned)
{ {
m_LocalPlayer = ePlayerSpawned.Player; if (ePlayerSpawned.PlayerID == -1) {
m_LocalPlayer = ePlayerSpawned.Player;
}
return true; return true;
} }
+67 -9
View File
@@ -29,12 +29,20 @@ void PlayerMovementSystem::updateMovementControllers(double dt)
continue; continue;
} }
// Aim pitch
EntityWrapper cameraEntity = player.FirstChildByName("Camera"); EntityWrapper cameraEntity = player.FirstChildByName("Camera");
if (cameraEntity.Valid()) { if (cameraEntity.Valid()) {
glm::vec3& cameraOrientation = cameraEntity["Transform"]["Orientation"]; glm::vec3& cameraOrientation = cameraEntity["Transform"]["Orientation"];
cameraOrientation.x += controller->Rotation().x; cameraOrientation.x += controller->Rotation().x;
// Limit camera pitch so we don't break our necks // Limit camera pitch so we don't break our necks
cameraOrientation.x = glm::clamp(cameraOrientation.x, -glm::half_pi<float>(), glm::half_pi<float>()); cameraOrientation.x = glm::clamp(cameraOrientation.x, -glm::half_pi<float>(), glm::half_pi<float>());
// 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<float>()) / glm::pi<float>();
cAnimationOffset["Time"] = time;
}
} }
ComponentWrapper& cTransform = player["Transform"]; ComponentWrapper& cTransform = player["Transform"];
@@ -124,24 +132,74 @@ void PlayerMovementSystem::updateMovementControllers(double dt)
EntityWrapper playerModel = player.FirstChildByName("PlayerModel"); EntityWrapper playerModel = player.FirstChildByName("PlayerModel");
if (playerModel.Valid()) { if (playerModel.Valid()) {
ComponentWrapper cAnimation = playerModel["Animation"]; 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); float movementLength = glm::length(groundVelocity);
//TODO: add assault dash animation here //TODO: add assault dash animation here
if (glm::length(controller->Movement()) > 0.f) { if (glm::length(controller->Movement()) > 0.f) {
if (controller->Crouching()) { double forwardMovement = controller->Movement().z;
cAnimation["AnimationName1"] = "Crouch Walk"; double strafeMovement = controller->Movement().x;
(double&)cAnimation["Speed1"] = 1.f * -glm::sign(controller->Movement().z);
if (controller->Crouching() && animationName1 != "CrouchWalk") {
animationName1 = "CrouchWalk";
animationSpeed1 = 1.0 * -glm::sign(controller->Movement().z);
} else { } else {
cAnimation["AnimationName1"] = "Run"; if (glm::abs(forwardMovement) > 0) {
(double&)cAnimation["Speed1"] = 2.f * -glm::sign(controller->Movement().z); 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 { } else {
if (controller->Crouching()) { if (controller->Crouching()) {
cAnimation["AnimationName1"] = "Crouch"; animationName1 = "Crouch";
(double&)cAnimation["Speed"] = 1.f; animationName2 = "";
animationSpeed1 = 1.0;
animationSpeed2 = 0.0;
animationWeight1 = 1.0;
animationWeight2 = 0.0;
} else { } else {
cAnimation["AnimationName1"] = "Hold Pos"; animationName1 = "Idle";
(double&)cAnimation["Speed1"] = 1.f; animationName2 = "";
animationSpeed1 = 1.f;
animationSpeed2 = 0.0;
animationWeight1 = 1.0;
animationWeight2 = 0.0;
//cAnimation["AnimationName2"] = "Idle";
} }
} }
} }
+1 -1
View File
@@ -91,7 +91,7 @@ bool PlayerSpawnSystem::OnPlayerSpawned(Events::PlayerSpawned& e)
if (cameraEntity.Valid()) { if (cameraEntity.Valid()) {
Events::SetCamera e; Events::SetCamera e;
e.CameraEntity = cameraEntity; e.CameraEntity = cameraEntity;
m_EventBroker->Publish(e); //m_EventBroker->Publish(e);
} }
// HACK: Set the player model color to team color // HACK: Set the player model color to team color
+8 -8
View File
@@ -20,14 +20,14 @@ void WeaponSystem::Update(double dt)
void WeaponSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& cPlayer, double dt) void WeaponSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& cPlayer, double dt)
{ {
// Update potential weapon behaviour for player // Update potential weapon behaviour for player
//auto it = m_ActiveWeapons.find(entity); auto it = m_ActiveWeapons.find(entity);
//if (it != m_ActiveWeapons.end()) { if (it != m_ActiveWeapons.end()) {
// //if (it->first.Valid()) { if (it->first.Valid()) {
// it->second->Update(dt); it->second->Update(dt);
// //} else { } else {
// // m_ActiveWeapons.erase(it); m_ActiveWeapons.erase(it);
// //} }
//} }
} }
bool WeaponSystem::OnInputCommand(Events::InputCommand& e) bool WeaponSystem::OnInputCommand(Events::InputCommand& e)