diff --git a/lib/objects/terrain.rb b/lib/objects/terrain.rb index ce0724b..2b8bcb2 100644 --- a/lib/objects/terrain.rb +++ b/lib/objects/terrain.rb @@ -2,7 +2,7 @@ class IMICFPS class Terrain include OpenGL def initialize(size:, height: nil, width: nil, length: nil, heightmap: nil) - @size = size + @size = 3#size @heightmap = heightmap @map = [] @@ -18,20 +18,23 @@ class IMICFPS def generate # x - row = [] - @width.times do |x| - @length.times do |z| - @map << Vertex.new(x-@width.to_f/2, @height, z-@length.to_f/2) - @map << Vertex.new(x+1-@width.to_f/2, @height, z-@length.to_f/2) - # @map << Vertex.new(x+1, height, z) - # @map << Vertex.new(x+1, height, z-1) - # - # @map << Vertex.new(x, height, z) - # @map << Vertex.new(x+1, height, z) - # @map << Vertex.new(x+1, height, z-1) - # height +=0.5 + row = [] + @width.times do |x| + @length.times do |z| + @map << Vertex.new(x-@width.to_f/2, @height, z-@length.to_f/2) + @map << Vertex.new(x+1-@width.to_f/2, @height, z-@length.to_f/2) + @map << Vertex.new(x-@width.to_f/2, @height, z+1-@length.to_f/2) + + # @map << Vertex.new(x+1, height, z) + # @map << Vertex.new(x+1, height, z-1) + # + # @map << Vertex.new(x, height, z) + # @map << Vertex.new(x+1, height, z) + # @map << Vertex.new(x+1, height, z-1) + # height +=0.5 end + # @map << row end @@ -55,22 +58,22 @@ class IMICFPS end def draw - new_draw + # new_draw old_draw end def old_draw glEnable(GL_COLOR_MATERIAL) - glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) + # glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) glPointSize(5) # glBegin(GL_LINES) # glBegin(GL_POINTS) - glBegin(GL_TRIANGLE_STRIP) + glBegin(GL_TRIANGLES) @map.each_with_index do |vertex, index| glNormal3f(0,1,0) glColor3f(0.0, 0.5, 0) if index.even? - glColor3f(0.5, 0, 0) if index.odd? + glColor3f(0, 1.0, 0) if index.odd? glVertex3f(vertex.x, vertex.y, vertex.z) end glEnd diff --git a/lib/window.rb b/lib/window.rb index fa8eada..ae17e77 100644 --- a/lib/window.rb +++ b/lib/window.rb @@ -21,13 +21,15 @@ class IMICFPS @draw_skydome = true @skydome = Skydome.new(scale: 0.02, backface_culling: false, auto_manage: false) Tree.new(x: 1, y: 0, z: -5) + Tree.new(x: 5, y: 0, z: 5) + Tree.new(x: -5, y: 0, z: 1) p ObjectManager.objects.map {|o| o.name} # Model.new(type: :obj, file_path: "objects/tree.obj", z: -5) # Model.new(type: :obj, file_path: "objects/tree.obj", x: -2, z: -6) # Model.new(type: :obj, file_path: "objects/sponza.obj", scale: 1, y: -0.2) @terrain = Terrain.new(size: 20, height: 0) - @player = Player.new(x: 1, y: 0, z: -10) + @player = Player.new(x: 1, y: 0, z: -1) @camera = Camera.new(x: 0, y: -2, z: 1) @camera.attach_to(@player)