diff options
author | Stijn Buys <ingar@osirion.org> | 2008-04-27 13:08:12 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2008-04-27 13:08:12 +0000 |
commit | a4b36e6d1e20b5036d1ed7cf9f61a48dbbf77812 (patch) | |
tree | 7efd0048fd8c10b1f04d427c78e3ac8da402f059 /src/game/ship.cc | |
parent | fe95954f9d17c9dade1827fe5d4cf8cffffddbce (diff) |
3D flight
Diffstat (limited to 'src/game/ship.cc')
-rw-r--r-- | src/game/ship.cc | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/src/game/ship.cc b/src/game/ship.cc index 7c3d21d..af10525 100644 --- a/src/game/ship.cc +++ b/src/game/ship.cc @@ -37,9 +37,9 @@ void Ship::frame(float seconds) { // update thrust entity_thrust = target_thrust; - if (entity_thrust < 0) + if (entity_thrust < 0.0f) entity_thrust = 0.0f; - else if(entity_thrust > 1) + else if(entity_thrust > 1.0f) entity_thrust = 1.0f; // update direction @@ -48,9 +48,19 @@ void Ship::frame(float seconds) else if (target_direction < -1.0f) target_direction = -1.0f; - // turnspeed is rotations per second - float direction_offset = 360.0f * ship_shipmodel->turnspeed() * seconds * target_direction; - entity_direction = degrees360f(entity_direction + direction_offset); + float direction_offset = ship_shipmodel->turnspeed() * seconds * target_direction; + if (direction_offset) + entity_axis.change_direction(360.0f * direction_offset); + + // update pitch + if (target_pitch > 1.0f) + target_pitch = 1.0f; + else if (target_pitch < -1.0f) + target_pitch = -1.0f; + + float pitch_offset = ship_shipmodel->turnspeed() * seconds * target_pitch; + if (pitch_offset) + entity_axis.change_pitch(360.0f * pitch_offset); // update speed if (entity_speed < entity_thrust * ship_shipmodel->maxspeed()) { @@ -60,12 +70,10 @@ void Ship::frame(float seconds) } } else if(entity_speed > entity_thrust * ship_shipmodel->maxspeed()) { entity_speed -= ship_shipmodel->acceleration() * seconds; - if (entity_speed < 0) entity_speed = 0; + if (entity_speed < 0.0f) entity_speed = 0.0f; } - // location TODO avoid sin/cos calculations - entity_location.x += cosf(entity_direction * M_PI / 180) * entity_speed * seconds; - entity_location.y += sinf(entity_direction * M_PI / 180) * entity_speed * seconds; + entity_location += entity_axis.forward() * entity_speed * seconds; entity_dirty = true; } |