Skip to content
This repository has been archived by the owner on Jul 7, 2020. It is now read-only.

Commit

Permalink
Allow rotation in all directions
Browse files Browse the repository at this point in the history
  • Loading branch information
iain committed Feb 6, 2012
1 parent d000dda commit 4b20e0d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
4 changes: 4 additions & 0 deletions lib/rotator.rb
Expand Up @@ -8,6 +8,10 @@ class Rotator
attr_accessor :matrix

def initialize
reset
end

def reset
self.matrix = yaw(0) * roll(0) * pitch(0)
end

Expand Down
42 changes: 33 additions & 9 deletions playground
Expand Up @@ -5,19 +5,31 @@ require 'environment'
class SpaceWars < Controller

on "w" do
spaceship.turn_up
spaceship.pitch_left
end

on "s" do
spaceship.turn_down
spaceship.pitch_right
end

on "a" do
spaceship.turn_left
spaceship.roll_left
end

on "d" do
spaceship.turn_right
spaceship.roll_right
end

on "z" do
spaceship.yaw_left
end

on "c" do
spaceship.yaw_right
end

on "x" do
spaceship.reset_rotation
end

on "=" do
Expand Down Expand Up @@ -61,7 +73,7 @@ class SpaceWars < Controller
end

def on_tick
# spaceship.animate
spaceship.animate
end

end
Expand All @@ -85,22 +97,34 @@ class Spaceship
rotator.matrix
end

def turn_left
def roll_left
rotator.roll!(-0.1)
end

def turn_right
def roll_right
rotator.roll!(0.1)
end

def turn_up
def pitch_left
rotator.pitch!(-0.1)
end

def turn_down
def pitch_right
rotator.pitch!(0.1)
end

def yaw_left
rotator.yaw!(-0.1)
end

def yaw_right
rotator.yaw!(0.1)
end

def reset_rotation
rotator.reset
end

private

def rotator
Expand Down

0 comments on commit 4b20e0d

Please sign in to comment.