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:
std::string m_NetworkAddress;
int m_NetworkPort;
int m_NetworkPort = 0;
ConfigFile* m_Config = nullptr;
EventBroker* m_EventBroker;
+63 -51
View File
@@ -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;
}
};
+1 -3
View File
@@ -52,6 +52,7 @@
</Entity>
<Entity name="DirectionalLight">
<Components>
<c:SceneLight/>
<c:DirectionalLight/>
<c:Model>
<Resource>sModels/Widgets/Lights/DirectionalLightWidget.mesh</Resource>
@@ -65,9 +66,6 @@
</Entity>
<Entity name="ObstacleCourse">
<Components>
<c:AABB>
<Size X="50" Y="50" Z="50"/>
</c:AABB>
<c:Collidable/>
<c:Model>
<Resource>Models/Test/ObstacleCourse.mesh</Resource>
+77 -28
View File
@@ -10,9 +10,7 @@
<RPM>600</RPM>
</c:AssaultWeapon>
<c:Collidable/>
<c:DashAbility>
<CoolDownMaxTimer>2</CoolDownMaxTimer>
</c:DashAbility>
<c:DashAbility/>
<c:Health/>
<c:Physics>
<Velocity X="2.30999646e-23" Y="0" Z="1.05272533e-23"/>
@@ -22,12 +20,10 @@
</c:Player>
<c:Team>
<Team>
<Red/>
<Blue/>
</Team>
</c:Team>
<c:Transform>
<Position X="1.28011036e-21" Y="0.0264999866" Z="1.82592022"/>
</c:Transform>
<c:Transform/>
</Components>
<Children>
@@ -35,7 +31,7 @@
<Components>
<c:Camera/>
<c:Transform>
<Position X="0" Y="1.37700009" Z="0"/>
<Position X="0" Y="1.27700007" Z="0"/>
</c:Transform>
</Components>
<Children>
@@ -105,26 +101,48 @@
</Components>
<Children/>
</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>
<c:BoneAttachment>
<BoneName>R_Arm_Weapon_Joint</BoneName>
</c:BoneAttachment>
<c:Model>
<Resource>Models/Weapons/Red/AssaultWeaponRed.mesh</Resource>
<Transparent>true</Transparent>
<Resource>Models/Weapons/Blue/AssaultWeaponBlue.mesh</Resource>
</c:Model>
<c:Transform>
<Position X="0.180000007" Y="-0.183000013" Z="0"/>
<Orientation X="0" Y="3.08300018" Z="0"/>
<Position X="0.120747976" Y="-0.229536116" Z="-0.151475713"/>
<Orientation X="0.0104047507" Y="-0.00268173264" Z="0.0428441092"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity name="WeaponMuzzle">
<Components>
<c:Transform>
<Position X="0.215000004" Y="-0.153000012" Z="-0.923000038"/>
</c:Transform>
</Components>
<Children/>
<Children>
<Entity name="WeaponMuzzle">
<Components>
<c:Spawner>
<EntityFile>Schema/Entities/RayBlue.xml</EntityFile>
</c:Spawner>
<c:Transform>
<Position X="0" Y="0.0480000004" Z="-0.807000041"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
</Children>
</Entity>
@@ -147,18 +165,49 @@
<Entity name="PlayerModel">
<Components>
<c:Animation>
<Name>Hold Pos</Name>
<Time>0.86415395295813102</Time>
<Speed>1</Speed>
<AnimationName1>Idle</AnimationName1>
<Speed1>1</Speed1>
</c:Animation>
<c:AnimationOffset>
<AnimationName>AimRifle</AnimationName>
<Time>0.5</Time>
</c:AnimationOffset>
<c:HiddenForLocalPlayer/>
<c:Model>
<Resource>Models/Characters/Assault/AssaultAnimated.mesh</Resource>
<Color A="1" B="0" G="0" R="1"/>
<Resource>Models/Characters/Assault/AssaultAnimations.mesh</Resource>
<Color A="1" B="1" G="0.309803933" R="0"/>
</c:Model>
<c:Transform/>
</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 name="AABBStanding">
<Components>
+3 -3
View File
@@ -6,12 +6,12 @@
<Lifetime>0.25</Lifetime>
</c:Lifetime>
<c:Model>
<Resource>Models/Weapons/CylinderBullet.mesh</Resource>
<Color A="0.156862751" B="39.2156868" G="7.84313726" R="0"/>
<Resource>Models/Effects/CylinderShot.mesh</Resource>
<Color A="0.149019614" B="39.2156868" G="39.2156868" R="0"/>
<Transparent>true</Transparent>
</c:Model>
<c:Transform>
<Scale X="0.0109999999" Y="0.0289999992" Z="100"/>
<Scale X="0.0690000057" Y="0.0690000057" Z="100"/>
</c:Transform>
</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
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;
-6
View File
@@ -104,7 +104,6 @@ void Skeleton::AccumulateBoneTransforms(bool noRootMotion, std::vector<Animation
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;
@@ -181,7 +180,6 @@ void Skeleton::AccumulateBoneTransforms(bool noRootMotion, std::vector<Animation
}
if (offset != glm::mat4(1)) {
boneMatrix = parentMatrix * ((glm::translate(finalPosInterp) * glm::toMat4(finalRotInterp) * glm::scale(finalScaleInterp)) + offset);
} else {
@@ -233,9 +231,7 @@ void Skeleton::AccumulateBoneTransforms(bool noRootMotion, std::vector<Animation
}
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;
@@ -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;
+1 -4
View File
@@ -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;
}
@@ -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;
}
+67 -9
View File
@@ -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<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"];
@@ -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";
}
}
}
+1 -1
View File
@@ -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
+8 -8
View File
@@ -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)