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

Commit

Permalink
Adds camera controls, still not the way it should work
Browse files Browse the repository at this point in the history
  • Loading branch information
dorsath committed Feb 5, 2012
1 parent ed08f04 commit 43bbb96
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
6 changes: 5 additions & 1 deletion lib/rotator.rb
Expand Up @@ -51,12 +51,16 @@ def pitch!(r)
end

def translate(x, y, z)
self.matrix += M[
M[
[ 0, 0, 0, 0],
[ 0, 0, 0, 0],
[ 0, 0, 0, 0],
[ x, y, z, 0]
]
end

def translate!(x, y, z)
self.matrix += translate(x, y, z)
end

end
35 changes: 30 additions & 5 deletions playground
Expand Up @@ -20,8 +20,20 @@ class SpaceWars < Controller
$camera.zoom_out
end

on "h" do
$camera.roll(-0.01)
end

on "j" do
$camera.pitch( 0.01)
end

on "k" do
# camera.offset_x += 0.01
$camera.pitch(-0.01)
end

on "l" do
$camera.roll( 0.01)
end

on "q" do
Expand All @@ -33,7 +45,7 @@ class SpaceWars < Controller
end

def on_tick
spaceship.animate
#spaceship.animate
end

end
Expand Down Expand Up @@ -79,18 +91,31 @@ end

class Camera

def initialize zoom = 0
@zoom = zoom
end

# XXX this is wrong
def zoom_in
rotator.translate(0, 0, 0.01)
@zoom += 0.01
end

# XXX this is wrong
def zoom_out
rotator.translate(0, 0, -0.01)
@zoom -= 0.01
end

def roll(r)
rotator.roll!(r)
end

def pitch(r)
rotator.pitch!(r)
end

def rotation
rotator.matrix.inverse
rotator.matrix + rotator.translate(0, 0, @zoom)
end

private
Expand All @@ -112,7 +137,7 @@ end
space_wars = SpaceWars.new
window = Window.new(space_wars)

$camera = Camera.new
$camera = Camera.new -2

window.views << CameraView.new($camera)
window.views << Fuselage.new(space_wars.spaceship)
Expand Down

0 comments on commit 43bbb96

Please sign in to comment.