Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2012-12-30 23:17:44 +0000
committerStijn Buys <ingar@osirion.org>2012-12-30 23:17:44 +0000
commit140ea71836bca67705a8643c11b5ce9efdabcc07 (patch)
tree84cb9873df7a0c1d6e275abdf7faaa0b4f3e9f98 /src/game/base
parent5773da9e78a61daf5bd2a3ee0504683e56af72f5 (diff)
Added support for weapons mouse aiming.
Diffstat (limited to 'src/game/base')
-rw-r--r--src/game/base/ship.cc46
1 files changed, 33 insertions, 13 deletions
diff --git a/src/game/base/ship.cc b/src/game/base/ship.cc
index ea793af..219cb0c 100644
--- a/src/game/base/ship.cc
+++ b/src/game/base/ship.cc
@@ -917,22 +917,42 @@ void Ship::frame(const unsigned long elapsed)
const Weapon *weapon = static_cast<const Weapon *>(slot->item()->info());
if ((weapon->subtype() == Weapon::Cannon) && (weapon->projectile_interval() > 0) && (slot->last_fired() + weapon->projectile_interval() <= core::server()->timestamp())) {
- // spawn a new projectile
- core::EntityProjectile *projectile = new core::EntityProjectile(this);
+ // aim
+ const float projectile_radius = 0.01f; // FIXME this should be defined somewhere
+
+ math::Axis projectile_axis(axis() * slot->axis());
+ math::Vector3f projectile_location(location() + (axis() * slot->location() * modelscale) + projectile_axis.forward() * projectile_radius);
+ math::Vector3f projectile_direction(target_aim - projectile_location);
+ projectile_direction.normalize();
+ float cosa = math::dotproduct(projectile_direction, projectile_axis.forward());
+
+ // fire a projectile if the angle between the aim direction and the slot's forward direction is small enough
+ // TODO configurable aim cone
+ if (cosa > 0.5f) {
+ // aim
+ math::Vector3f normal(math::crossproduct(projectile_direction, projectile_axis.forward()));
+ if (normal.length() > MIN_DELTA) {
+ float sina = sqrt(1 - cosa * cosa);
+
+ normal.normalize();
+ projectile_axis.rotate(normal, cosa, sina);
+ }
- projectile->set_damage(weapon->damage());
- projectile->set_lifespan(weapon->projectile_lifespan());
- projectile->set_projectile_modelname(weapon->projectile_modelname());
- projectile->set_projectile_soundname(weapon->projectile_soundname());
-
- projectile->set_axis(axis() * slot->axis());
- projectile->set_location(location() + (axis() * slot->location() * modelscale) + projectile->axis().forward() * projectile->radius());
- projectile->set_speed(weapon->projectile_speed());
+ // spawn a new projectile
+ core::EntityProjectile *projectile = new core::EntityProjectile(this);
- projectile->reset();
-
- slot->set_last_fired(core::server()->timestamp());
+ projectile->set_damage(weapon->damage());
+ projectile->set_lifespan(weapon->projectile_lifespan());
+ projectile->set_projectile_modelname(weapon->projectile_modelname());
+ projectile->set_projectile_soundname(weapon->projectile_soundname());
+
+ projectile->set_axis(projectile_axis);
+ projectile->set_location(projectile_location);
+ projectile->set_speed(weapon->projectile_speed());
+ projectile->reset();
+ slot->set_last_fired(core::server()->timestamp());
+ }
}
}
}