Skip to content

Commit

Permalink
Making camera angle variable
Browse files Browse the repository at this point in the history
  • Loading branch information
TomK32 committed Dec 11, 2010
1 parent c5f186f commit 5f6e710
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 16 deletions.
2 changes: 2 additions & 0 deletions Movable.rb
Expand Up @@ -21,7 +21,9 @@ def turns_sum
def turn(val)
self.turns.unshift(val)
self.last_turn = self.turns_sum.abs > 1 ? val : 0
old_orientation = self.orientation
self.orientation = (self.orientation + self.turns_sum) % 360
return self.orientation - old_orientation
end

def speedUp(val)
Expand Down
24 changes: 12 additions & 12 deletions Player.rb
Expand Up @@ -25,8 +25,8 @@ def initialize
self.score = 0
self.score_history = {}

self.view_width = 55
self.view_angle = [270 - view_width / 2, 270 + view_width / 2]
self.view_width = 70
self.view_angle = [90 + view_width / 2, 90 - view_width / 2]
end

def redraw(tick)
Expand All @@ -45,25 +45,24 @@ def draw_camera

glBegin(GL_LINE_STRIP)
glColor3f(0,0,0)
puts [radians(view_angle[0]), radians(view_angle[1])].inspect
c_x = Math.cos(radians(view_angle[0])) / 5.0
c_y = Math.cos(radians(view_angle[1])) / 5.0
puts [c_x, c_y].inspect
c_x = Math.cos(radians(self.orientation - view_angle[0] + 180)) / 3.0
c_y = Math.sin(radians(self.orientation - view_angle[0] + 180)) / 3.0
glVertex2f(c_x, c_y)
glColor3f(1,1,1)
glVertex2f(-0.03, 0)
glColor3f(0,0,0)
glVertex2f(-c_x, c_y)
c_x = Math.cos(radians(self.orientation - view_angle[1] + 180)) / 3.0
c_y = Math.sin(radians(self.orientation - view_angle[1] + 180)) / 3.0
glVertex2f(c_x, c_y)
glEnd
glPopMatrix
glFlush
end

def turn_with_camera(direction)
orientation_before = self.orientation
self.turn_without_camera(direction)
self.view_angle[0] += orientation_before - self.orientation
self.view_angle[1] += orientation_before - self.orientation
difference = self.turn_without_camera(direction)
self.view_angle[0] = (self.view_angle[0] + difference) % 360
self.view_angle[1] = (self.view_angle[1] + difference) % 360
end
alias_method :turn_without_camera, :turn
alias_method :turn, :turn_with_camera
Expand All @@ -85,7 +84,7 @@ def keyDown(key)

# count planes in view
def make_picture(planes)
score_history.map{|k, history| score_history[k] = history[0..10] }
score_history.map{|k, history| score_history[k] = history[0..20] }

# TODO set planes that are not in view to []
objects_in_view(planes).each do |hit|
Expand All @@ -94,6 +93,7 @@ def make_picture(planes)
self.score += score_history[hit.object_id].inject {|sum, i| sum + i}
end
score_history.map{|k, history| history.unshift(0); }
puts score
end


Expand Down
2 changes: 1 addition & 1 deletion README
Expand Up @@ -3,5 +3,5 @@ The Flying Camera

It's 1929 and Howard Houghes is making his movie about the Great War: Hell's Angels.
You are assigned to one of the planes equipped with a camera and your mission
is to film the planes around you as they simulate their dog-fights.
is to film the planes around you as they simulate their dogfights.
Capture as many scenes as you can and always keep a watch for the Red Baron!
4 changes: 4 additions & 0 deletions The Flying Camera.xcodeproj/project.pbxproj
Expand Up @@ -46,6 +46,7 @@
0E2BDBC112B267D400D634EE /* Team.rb in Resources */ = {isa = PBXBuildFile; fileRef = 0E2BDBC012B267D400D634EE /* Team.rb */; };
0E2BDC1012B26E8B00D634EE /* GLUT.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0E2BDC0F12B26E8B00D634EE /* GLUT.framework */; };
0EB704E312B39CC2006FF01B /* Visibility.rb in Resources */ = {isa = PBXBuildFile; fileRef = 0EB704E212B39CC2006FF01B /* Visibility.rb */; };
0EB706C812B3B10C006FF01B /* README in Resources */ = {isa = PBXBuildFile; fileRef = 0EB706C712B3B10C006FF01B /* README */; };
0ED8FB4212B24A0700296022 /* Movable.rb in Resources */ = {isa = PBXBuildFile; fileRef = 0ED8FB4112B24A0700296022 /* Movable.rb */; };
0ED8FB9612B24C6100296022 /* Plane.rb in Resources */ = {isa = PBXBuildFile; fileRef = 0ED8FB9512B24C6100296022 /* Plane.rb */; };
0ED8FBAD12B24FAF00296022 /* Enemy.rb in Resources */ = {isa = PBXBuildFile; fileRef = 0ED8FBAC12B24FAF00296022 /* Enemy.rb */; };
Expand Down Expand Up @@ -81,6 +82,7 @@
0E2BDBC012B267D400D634EE /* Team.rb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.ruby; path = Team.rb; sourceTree = "<group>"; };
0E2BDC0F12B26E8B00D634EE /* GLUT.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = GLUT.framework; path = System/Library/Frameworks/GLUT.framework; sourceTree = SDKROOT; };
0EB704E212B39CC2006FF01B /* Visibility.rb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.ruby; path = Visibility.rb; sourceTree = "<group>"; };
0EB706C712B3B10C006FF01B /* README */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = README; sourceTree = "<group>"; };
0ED8FB4112B24A0700296022 /* Movable.rb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.ruby; path = Movable.rb; sourceTree = "<group>"; };
0ED8FB9512B24C6100296022 /* Plane.rb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.ruby; path = Plane.rb; sourceTree = "<group>"; };
0ED8FBAC12B24FAF00296022 /* Enemy.rb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.ruby; path = Enemy.rb; sourceTree = "<group>"; };
Expand Down Expand Up @@ -128,6 +130,7 @@
0EF05CB612B14A4A009C18E8 /* GameLoop.rb */,
0EF05D5F12B1703A009C18E8 /* GameWindowController.rb */,
0EF05CB112B14956009C18E8 /* GameView.rb */,
0EB706C712B3B10C006FF01B /* README */,
);
name = Classes;
sourceTree = "<group>";
Expand Down Expand Up @@ -304,6 +307,7 @@
0ED8FBAD12B24FAF00296022 /* Enemy.rb in Resources */,
0E2BDBC112B267D400D634EE /* Team.rb in Resources */,
0EB704E312B39CC2006FF01B /* Visibility.rb in Resources */,
0EB706C812B3B10C006FF01B /* README in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
7 changes: 4 additions & 3 deletions Visibility.rb
Expand Up @@ -15,14 +15,15 @@ def objects_in_view(objects)
if view_angle.nil? || view_angle.empty? || view_angle.size != 2
raise 'Missing view angle for %s' % self
end
objects.collect do |object|
return objects.collect do |object|
# nur im Rückschritt liegt die Zukunft
a = self.x - object.x
b = self.y - object.y

gamma = Math.atan2(b,a)

gamma = (gamma / Math::PI * 180) + 180
puts view_angle.inspect
gamma = ((gamma / Math::PI * 180) + 180) % 360

n = view_angle[0]
m = view_angle[1]
if m < n && gamma > m && gamma < n
Expand Down

0 comments on commit 5f6e710

Please sign in to comment.