WIP Defender tracers
This commit is contained in:
@@ -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!
|
||||
|
||||
Reference in New Issue
Block a user