From 468600c1b421e3f978bb45e76e0bad5ab26513d3 Mon Sep 17 00:00:00 2001 From: Cyberarm Date: Fri, 23 Mar 2018 15:59:55 -0500 Subject: [PATCH] Camera almost done, maybe. --- lib/objects/camera.rb | 10 +++++++--- lib/objects/player.rb | 2 ++ lib/window.rb | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/objects/camera.rb b/lib/objects/camera.rb index 3e89b69..9796690 100644 --- a/lib/objects/camera.rb +++ b/lib/objects/camera.rb @@ -15,7 +15,7 @@ class IMICFPS @view_distance = distance @game_object = nil - @distance = 2 + @distance = 5 self.mouse_x, self.mouse_y = Gosu.screen_width/2, Gosu.screen_height/2 @true_mouse = Point.new(Gosu.screen_width/2, Gosu.screen_height/2) @@ -49,10 +49,11 @@ class IMICFPS z_offset = horizontal_distance_from_object * Math.cos(@game_object.y_rotation.degrees_to_radians) # p @game_object.x, @game_object.z;exit @x = @game_object.x - x_offset - @y = @game_object.y - 2 + @y = @game_object.y + 2 @z = @game_object.z - z_offset @yaw = 180 - @game_object.y_rotation + @pitch = 20.0 end def draw @@ -64,7 +65,7 @@ class IMICFPS glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST) glRotatef(@pitch,1,0,0) glRotatef(@yaw,0,1,0) - glTranslatef(-@x, @y, -@z) + glTranslatef(-@x, -@y, -@z) glMatrixMode(GL_MODELVIEW) # The modelview matrix is where object information is stored. glLoadIdentity @@ -74,6 +75,9 @@ class IMICFPS position_camera if @game_object if @true_mouse_checked > 2 + @yaw-=Float(@true_mouse.x-self.mouse_x)/(@mouse_sensitivity*@field_of_view)*70 unless @game_object + @game_object.y_rotation+=Float(@true_mouse.x-self.mouse_x)/(@mouse_sensitivity*@field_of_view)*70 if @game_object + @yaw-=Float(@true_mouse.x-self.mouse_x)/(@mouse_sensitivity*@field_of_view)*70 unless @game_object @pitch-=Float(@true_mouse.y-self.mouse_y)/(@mouse_sensitivity*@field_of_view)*70 unless @game_object @yaw %= 360.0 diff --git a/lib/objects/player.rb b/lib/objects/player.rb index 92f86fb..5bc1e4e 100644 --- a/lib/objects/player.rb +++ b/lib/objects/player.rb @@ -36,6 +36,7 @@ class IMICFPS _width = (@name_image.width/@devisor)/2 _x = @x _y = normalize_bounding_box(model.bounding_box).max_y+0.05 + glPushMatrix glDisable(GL_LIGHTING) glEnable(GL_COLOR_MATERIAL) glEnable(GL_TEXTURE_2D) @@ -71,6 +72,7 @@ class IMICFPS # glDisable(GL_BLEND) glDisable(GL_TEXTURE_2D) glEnable(GL_LIGHTING) + glPopMatrix end def draw diff --git a/lib/window.rb b/lib/window.rb index 50cbe70..fa8eada 100644 --- a/lib/window.rb +++ b/lib/window.rb @@ -39,7 +39,7 @@ class IMICFPS @text = "Hello There" Light.new(x: 3, y: -6, z: 6) - Light.new(x: 0, y: -100, z: 0, diffuse: Color.new(1.0, 0.5, 0.1)) + Light.new(x: 0, y: 100, z: 0, diffuse: Color.new(1.0, 0.5, 0.1)) end def draw