Fixed nameplate oddly cutting off terrain, got a grid for terrain, first/third person toggle.

This commit is contained in:
2018-03-31 21:22:11 -05:00
parent 162e23d0b4
commit 05a77a0f11
6 changed files with 54 additions and 37 deletions

View File

@@ -1,8 +1,9 @@
class IMICFPS
class Terrain
TILE_SIZE = 0.5
include OpenGL
def initialize(size:, height: nil, width: nil, length: nil, heightmap: nil)
@size = 3#size
@size = size
@heightmap = heightmap
@map = []
@@ -17,49 +18,45 @@ class IMICFPS
end
def generate
# x
row = []
@width.times do |x|
@length.times do |z|
# TRIANGLE STRIP (BROKEN)
# @map << Vertex.new((x+1)-@width.to_f/2, 0, z-@legth.to_f/2)
# @map << Vertex.new(x-@width.to_f/2, 0, (z+1)-@length.to_f/2)
# WORKING TRIANGLES
@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)-@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
@map << Vertex.new(x-@width.to_f/2, @height, (z+1)-@length.to_f/2)
@map << Vertex.new((x+1)-@width.to_f/2, @height, z-@length.to_f/2)
@map << Vertex.new((x+1)-@width.to_f/2, @height, (z+1)-@length.to_f/2)
end
# @map << row
end
@map.size do |i|
@map.size.times do |i|
@vertices << @map[i].x
@vertices << @map[i].y
@vertices << @map[i].z
@vertices << 1.0
normal = Vertex.new(0,1,0)
@normals << normal.x
@normals << normal.y
@normals << normal.z
color = Vertex.new(0,rand(0.2..1.0),0)
color = Color.new(0,rand(0.2..1.0),0)
@colors << color.red
@colors << color.green
@colors << color.blue
end
@vertices = @vertices.pack("f*")
@normals = @normals.pack("f*")
@colors = @colors.pack("f*")
@vertices_packed = @vertices.pack("f*")
@normals_packed = @normals.pack("f*")
@colors_packed = @colors.pack("f*")
end
def draw
# new_draw
old_draw
new_draw
# old_draw
end
def old_draw
@@ -83,29 +80,32 @@ class IMICFPS
end
def new_draw
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
glEnable(GL_NORMALIZE)
glPushMatrix
glEnable(GL_COLOR_MATERIAL)
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE)
glShadeModel(GL_SMOOTH)
glShadeModel(GL_FLAT)
glEnableClientState(GL_VERTEX_ARRAY)
glEnableClientState(GL_NORMAL_ARRAY)
glEnableClientState(GL_COLOR_ARRAY)
glVertexPointer(4, GL_FLOAT, 0, @vertices)
glNormalPointer(GL_FLOAT, 0, @normals)
glColorPointer(3, GL_FLOAT, 0, @colors)
glVertexPointer(3, GL_FLOAT, 0, @vertices_packed)
glNormalPointer(GL_FLOAT, 0, @normals_packed)
glColorPointer(3, GL_FLOAT, 0, @colors_packed)
glDrawArrays(GL_TRIANGLE_STRIP, 0, @map.size/4)
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
# glDrawArrays(GL_TRIANGLE_STRIP, 0, @vertices.size/3)
glDrawArrays(GL_TRIANGLES, 0, @vertices.size/3)
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
# glDrawArrays(GL_TRIANGLE_STRIP, 0, @vertices.size/3)
glDrawArrays(GL_TRIANGLES, 0, @vertices.size/3)
glDisableClientState(GL_VERTEX_ARRAY)
glDisableClientState(GL_NORMAL_ARRAY)
glDisableClientState(GL_COLOR_ARRAY)
glPopMatrix
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
end
end
end