From 1992b6cde1a5e562f32dbda0d1b5615aaff4bb4b Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Thu, 10 Mar 2016 21:15:27 +0100 Subject: [PATCH] WIP Defender tracers --- assets | 2 +- .../Systems/Weapon/DefenderWeaponBehaviour.h | 1 + .../Schema/Components/DefenderWeapon.xml | 2 +- resources/Schema/Entities/10Degrees.xml | 94 ++++++++++++++++ resources/Schema/Entities/HitTest.xml | 2 +- resources/Schema/Entities/MovementTest.xml | 100 +++++++++++++++++- resources/Schema/Entities/RayBlue.xml | 2 +- src/Engine/Core/EntityWrapper.cpp | 14 ++- .../Weapon/DefenderWeaponBehaviour.cpp | 99 ++++++++++------- 9 files changed, 266 insertions(+), 50 deletions(-) create mode 100644 resources/Schema/Entities/10Degrees.xml diff --git a/assets b/assets index 85d96f6f..298641b1 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit 85d96f6f3d2269e46962492f9713ec67c54e8ece +Subproject commit 298641b1afe313ebde00d77a0c4d75e6c6a0533d diff --git a/include/Game/Systems/Weapon/DefenderWeaponBehaviour.h b/include/Game/Systems/Weapon/DefenderWeaponBehaviour.h index e8e73e8f..a32d65f1 100644 --- a/include/Game/Systems/Weapon/DefenderWeaponBehaviour.h +++ b/include/Game/Systems/Weapon/DefenderWeaponBehaviour.h @@ -32,6 +32,7 @@ private: // Weapon functions void fireShell(ComponentWrapper cWeapon, WeaponInfo& wi); void dealDamage(ComponentWrapper cWeapon, WeaponInfo& wi, const std::vector& pattern); + void spawnTracers(ComponentWrapper cWeapon, WeaponInfo& wi, std::vector pattern); bool canFire(ComponentWrapper cWeapon, WeaponInfo& wi); // Utility diff --git a/resources/Schema/Components/DefenderWeapon.xml b/resources/Schema/Components/DefenderWeapon.xml index 6f7e5a84..9c3861cd 100755 --- a/resources/Schema/Components/DefenderWeapon.xml +++ b/resources/Schema/Components/DefenderWeapon.xml @@ -1,7 +1,7 @@ - 8 + 9999 8 64 64 diff --git a/resources/Schema/Entities/10Degrees.xml b/resources/Schema/Entities/10Degrees.xml new file mode 100644 index 00000000..0039ca82 --- /dev/null +++ b/resources/Schema/Entities/10Degrees.xml @@ -0,0 +1,94 @@ + + + + + + + + + + + + + + + + + + + + Models/Core/UnitQuad.mesh + + Textures/Effects/Ray.png + + + + + + + + + + + + + + Models/Core/UnitQuad.mesh + + Textures/Effects/Ray.png + + + + + + + + + + + + + + + + + + + + + + + Models/Core/UnitQuad.mesh + + Textures/Effects/Ray.png + + + + + + + + + + + + + + Models/Core/UnitQuad.mesh + + Textures/Effects/Ray.png + + + + + + + + + + + + + + + diff --git a/resources/Schema/Entities/HitTest.xml b/resources/Schema/Entities/HitTest.xml index bea1c6c9..4649072b 100644 --- a/resources/Schema/Entities/HitTest.xml +++ b/resources/Schema/Entities/HitTest.xml @@ -3,7 +3,7 @@ - 1 + 10 diff --git a/resources/Schema/Entities/MovementTest.xml b/resources/Schema/Entities/MovementTest.xml index 8a99df55..604aaca4 100644 --- a/resources/Schema/Entities/MovementTest.xml +++ b/resources/Schema/Entities/MovementTest.xml @@ -103,7 +103,7 @@ - + @@ -116,7 +116,7 @@ - + @@ -157,14 +157,106 @@ Models/Weapons/Blue/DefenderWeaponBlue.mesh - - + + + + + + + + + + + + + + + + + + + + + Models/Core/UnitQuad.mesh + + Textures/Effects/Ray.png + + + + + + + + + + + + + + Models/Core/UnitQuad.mesh + + Textures/Effects/Ray.png + + + + + + + + + + + + + + + + + + + + + + + Models/Core/UnitQuad.mesh + + Textures/Effects/Ray.png + + + + + + + + + + + + + + Models/Core/UnitQuad.mesh + + Textures/Effects/Ray.png + + + + + + + + + + + + + + diff --git a/resources/Schema/Entities/RayBlue.xml b/resources/Schema/Entities/RayBlue.xml index 83adbe51..64ff3619 100644 --- a/resources/Schema/Entities/RayBlue.xml +++ b/resources/Schema/Entities/RayBlue.xml @@ -3,7 +3,7 @@ - 0.10000000149011612 + 10 diff --git a/src/Engine/Core/EntityWrapper.cpp b/src/Engine/Core/EntityWrapper.cpp index a85127ad..83a31fa7 100644 --- a/src/Engine/Core/EntityWrapper.cpp +++ b/src/Engine/Core/EntityWrapper.cpp @@ -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(); diff --git a/src/Game/Systems/Weapon/DefenderWeaponBehaviour.cpp b/src/Game/Systems/Weapon/DefenderWeaponBehaviour.cpp index 81873dc9..ca12ec91 100644 --- a/src/Game/Systems/Weapon/DefenderWeaponBehaviour.cpp +++ b/src/Game/Systems/Weapon/DefenderWeaponBehaviour.cpp @@ -213,46 +213,27 @@ void DefenderWeaponBehaviour::fireShell(ComponentWrapper cWeapon, WeaponInfo& wi // Deal damage (clientside) dealDamage(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; - } - } - } + // Spawn tracers + spawnTracers(cWeapon, wi, pattern); - // 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); - } - }*/ + // 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; + // } + // } + //} // Play animation playAnimationAndReturn(wi.FirstPersonEntity, "FinalBlend", "Fire"); @@ -264,6 +245,34 @@ void DefenderWeaponBehaviour::fireShell(ComponentWrapper cWeapon, WeaponInfo& wi m_EventBroker->Publish(e); } +void DefenderWeaponBehaviour::spawnTracers(ComponentWrapper cWeapon, WeaponInfo& wi, std::vector 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& pattern) { // Only deal damage client side @@ -284,13 +293,21 @@ void DefenderWeaponBehaviour::dealDamage(ComponentWrapper cWeapon, WeaponInfo& w // 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 = glm::radians((double)m_CurrentCamera["Camera"]["NearClip"]); + 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 / 2.f) * spreadAngle * (res.Height / 2.f); + 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!