WIP Defender tracers

This commit is contained in:
2016-03-10 21:15:27 +01:00
parent c82be79bb8
commit 1992b6cde1
9 changed files with 266 additions and 50 deletions
+1 -1
Submodule assets updated: 85d96f6f3d...298641b1af
@@ -32,6 +32,7 @@ private:
// Weapon functions
void fireShell(ComponentWrapper cWeapon, WeaponInfo& wi);
void dealDamage(ComponentWrapper cWeapon, WeaponInfo& wi, const std::vector<glm::vec2>& pattern);
void spawnTracers(ComponentWrapper cWeapon, WeaponInfo& wi, std::vector<glm::vec2> pattern);
bool canFire(ComponentWrapper cWeapon, WeaponInfo& wi);
// Utility
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<DefenderWeapon xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="DefenderWeapon.xsd">
<Slot><Primary/></Slot>
<MagazineAmmo>8</MagazineAmmo>
<MagazineAmmo>9999</MagazineAmmo>
<MagazineSize>8</MagazineSize>
<Ammo>64</Ammo>
<MaxAmmo>64</MaxAmmo>
+94
View File
@@ -0,0 +1,94 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Entity xmlns:c="components" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Types/Entity.xsd">
<Components>
<c:Transform/>
</Components>
<Children>
<Entity name="RayBlue">
<Components>
<c:Transform>
<Orientation X="0" Y="0.174532995" Z="0"/>
<Scale X="0" Y="1" Z="100"/>
</c:Transform>
</Components>
<Children>
<Entity>
<Components>
<c:Sprite>
<Model>Models/Core/UnitQuad.mesh</Model>
<GlowMap></GlowMap>
<DiffuseTexture>Textures/Effects/Ray.png</DiffuseTexture>
<Color A="0.419607848" B="3.92156863" G="0.270588249" R="0"/>
</c:Sprite>
<c:Transform>
<Position X="0" Y="0" Z="-0.5"/>
<Orientation X="0" Y="-1.57099998" Z="0"/>
<Scale X="1" Y="0.0260000005" Z="0"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:Sprite>
<Model>Models/Core/UnitQuad.mesh</Model>
<GlowMap></GlowMap>
<DiffuseTexture>Textures/Effects/Ray.png</DiffuseTexture>
<Color A="0.419607848" B="3.92156863" G="0.270588249" R="0"/>
</c:Sprite>
<c:Transform>
<Position X="0" Y="0" Z="-0.5"/>
<Orientation X="0" Y="4.71218538" Z="3.14199996"/>
<Scale X="1" Y="0.0260000005" Z="0"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
<Entity name="RayBlue">
<Components>
<c:Transform>
<Scale X="0" Y="1" Z="100"/>
</c:Transform>
</Components>
<Children>
<Entity>
<Components>
<c:Sprite>
<Model>Models/Core/UnitQuad.mesh</Model>
<GlowMap></GlowMap>
<DiffuseTexture>Textures/Effects/Ray.png</DiffuseTexture>
<Color A="0.419607848" B="3.92156863" G="0.270588249" R="0"/>
</c:Sprite>
<c:Transform>
<Position X="0" Y="0" Z="-0.5"/>
<Orientation X="0" Y="-1.57099998" Z="0"/>
<Scale X="1" Y="0.0260000005" Z="0"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:Sprite>
<Model>Models/Core/UnitQuad.mesh</Model>
<GlowMap></GlowMap>
<DiffuseTexture>Textures/Effects/Ray.png</DiffuseTexture>
<Color A="0.419607848" B="3.92156863" G="0.270588249" R="0"/>
</c:Sprite>
<c:Transform>
<Position X="0" Y="0" Z="-0.5"/>
<Orientation X="0" Y="4.71218538" Z="3.14199996"/>
<Scale X="1" Y="0.0260000005" Z="0"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
</Children>
</Entity>
+1 -1
View File
@@ -3,7 +3,7 @@
<Components>
<c:Lifetime>
<Lifetime>1</Lifetime>
<Lifetime>10</Lifetime>
</c:Lifetime>
<c:ExplosionEffect>
<Velocity X="2" Y="2.30000019" Z="0"/>
+96 -4
View File
@@ -103,7 +103,7 @@
<Color A="1" B="1" G="0.254901975" R="0"/>
</c:Model>
<c:Transform>
<Position X="-0.600000024" Y="0" Z="0"/>
<Position X="0.800000012" Y="0" Z="0"/>
</c:Transform>
</Components>
<Children/>
@@ -116,7 +116,7 @@
<Color A="1" B="1" G="0.254901975" R="0"/>
</c:Model>
<c:Transform>
<Position X="0.800000012" Y="0" Z="0"/>
<Position X="-0.600000024" Y="0" Z="0.549540162"/>
</c:Transform>
</Components>
<Children/>
@@ -157,14 +157,106 @@
<Resource>Models/Weapons/Blue/DefenderWeaponBlue.mesh</Resource>
</c:Model>
<c:Transform>
<Position X="0.00681143999" Y="-0.204994932" Z="-0.209244296"/>
<Orientation X="-0.581807375" Y="0.562133908" Z="-0.0719003305"/>
<Orientation X="0" Y="-0" Z="0"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
<Entity>
<Components>
<c:Transform>
<Position X="0.870232701" Y="0.640069604" Z="4.07769537"/>
<Orientation X="0" Y="4.71238565" Z="0"/>
</c:Transform>
</Components>
<Children>
<Entity name="RayBlue">
<Components>
<c:Transform>
<Orientation X="0" Y="0.174532995" Z="0"/>
<Scale X="0" Y="1" Z="100"/>
</c:Transform>
</Components>
<Children>
<Entity>
<Components>
<c:Sprite>
<Model>Models/Core/UnitQuad.mesh</Model>
<GlowMap></GlowMap>
<DiffuseTexture>Textures/Effects/Ray.png</DiffuseTexture>
<Color A="0.419607848" B="3.92156863" G="0.270588249" R="0"/>
</c:Sprite>
<c:Transform>
<Position X="0" Y="0" Z="-0.5"/>
<Orientation X="0" Y="-1.57099998" Z="0"/>
<Scale X="1" Y="0.0260000005" Z="0"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:Sprite>
<Model>Models/Core/UnitQuad.mesh</Model>
<GlowMap></GlowMap>
<DiffuseTexture>Textures/Effects/Ray.png</DiffuseTexture>
<Color A="0.419607848" B="3.92156863" G="0.270588249" R="0"/>
</c:Sprite>
<c:Transform>
<Position X="0" Y="0" Z="-0.5"/>
<Orientation X="0" Y="4.71218538" Z="3.14199996"/>
<Scale X="1" Y="0.0260000005" Z="0"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
<Entity name="RayBlue">
<Components>
<c:Transform>
<Scale X="0" Y="1" Z="100"/>
</c:Transform>
</Components>
<Children>
<Entity>
<Components>
<c:Sprite>
<Model>Models/Core/UnitQuad.mesh</Model>
<GlowMap></GlowMap>
<DiffuseTexture>Textures/Effects/Ray.png</DiffuseTexture>
<Color A="0.419607848" B="3.92156863" G="0.270588249" R="0"/>
</c:Sprite>
<c:Transform>
<Position X="0" Y="0" Z="-0.5"/>
<Orientation X="0" Y="-1.57099998" Z="0"/>
<Scale X="1" Y="0.0260000005" Z="0"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:Sprite>
<Model>Models/Core/UnitQuad.mesh</Model>
<GlowMap></GlowMap>
<DiffuseTexture>Textures/Effects/Ray.png</DiffuseTexture>
<Color A="0.419607848" B="3.92156863" G="0.270588249" R="0"/>
</c:Sprite>
<c:Transform>
<Position X="0" Y="0" Z="-0.5"/>
<Orientation X="0" Y="4.71218538" Z="3.14199996"/>
<Scale X="1" Y="0.0260000005" Z="0"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
</Children>
</Entity>
</Children>
</Entity>
+1 -1
View File
@@ -3,7 +3,7 @@
<Components>
<c:Lifetime>
<Lifetime>0.10000000149011612</Lifetime>
<Lifetime>10</Lifetime>
</c:Lifetime>
<c:Transform>
<Scale X="0" Y="1" Z="1"/>
+13 -1
View File
@@ -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();
@@ -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<glm::vec2> 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<glm::vec2>& 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!