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

@@ -46,6 +46,14 @@ class IMICFPS
end end
def position_camera def position_camera
if defined?(@game_object.first_person_view)
if @game_object.first_person_view
@distance = 0
else
@distance = 5
end
end
x_offset = horizontal_distance_from_object * Math.sin(@game_object.y_rotation.degrees_to_radians) x_offset = horizontal_distance_from_object * Math.sin(@game_object.y_rotation.degrees_to_radians)
z_offset = horizontal_distance_from_object * Math.cos(@game_object.y_rotation.degrees_to_radians) z_offset = horizontal_distance_from_object * Math.cos(@game_object.y_rotation.degrees_to_radians)
# p @game_object.x, @game_object.z;exit # p @game_object.x, @game_object.z;exit

View File

@@ -2,7 +2,7 @@ class IMICFPS
class Player < GameObject class Player < GameObject
attr_accessor :speed attr_accessor :speed
attr_reader :name, :bound_model attr_reader :name, :bound_model, :first_person_view
def setup def setup
bind_model(ModelLoader.new(type: :obj, file_path: "objects/biped.obj", game_object: self)) bind_model(ModelLoader.new(type: :obj, file_path: "objects/biped.obj", game_object: self))
@@ -76,8 +76,10 @@ class IMICFPS
end end
def draw def draw
draw_nameplate if !@first_person_view
super draw_nameplate
super
end
end end
def update def update

View File

@@ -3,5 +3,11 @@ class IMICFPS
def setup def setup
bind_model(ModelLoader.new(type: :obj, file_path: "objects/skydome.obj", game_object: self)) bind_model(ModelLoader.new(type: :obj, file_path: "objects/skydome.obj", game_object: self))
end end
def draw
glDisable(GL_LIGHTING)
super
glEnable(GL_LIGHTING)
end
end end
end end

View File

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

View File

@@ -19,7 +19,7 @@ class IMICFPS
@delta_time = Gosu.milliseconds @delta_time = Gosu.milliseconds
@number_of_faces = 0 @number_of_faces = 0
@draw_skydome = true @draw_skydome = true
@skydome = Skydome.new(scale: 0.02, backface_culling: false, auto_manage: false) @skydome = Skydome.new(scale: 0.08, backface_culling: false, auto_manage: false)
Tree.new(x: 1, y: 0, z: -5) Tree.new(x: 1, y: 0, z: -5)
Tree.new(x: 5, y: 0, z: 5) Tree.new(x: 5, y: 0, z: 5)
Tree.new(x: -5, y: 0, z: 1) Tree.new(x: -5, y: 0, z: 1)
@@ -27,7 +27,7 @@ class IMICFPS
# Model.new(type: :obj, file_path: "objects/tree.obj", z: -5) # 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/tree.obj", x: -2, z: -6)
# Model.new(type: :obj, file_path: "objects/sponza.obj", scale: 1, y: -0.2) # Model.new(type: :obj, file_path: "objects/sponza.obj", scale: 1, y: -0.2)
@terrain = Terrain.new(size: 20, height: 0) @terrain = Terrain.new(size: 40, height: 0)
@player = Player.new(x: 1, y: 0, z: -1) @player = Player.new(x: 1, y: 0, z: -1)
@camera = Camera.new(x: 0, y: -2, z: 1) @camera = Camera.new(x: 0, y: -2, z: 1)
@@ -58,14 +58,15 @@ class IMICFPS
LightManager.lights.each do |light| LightManager.lights.each do |light|
light.draw light.draw
end end
@camera.draw @camera.draw
@skydome.draw if @skydome.renderable @skydome.draw if @skydome.renderable
glEnable(GL_DEPTH_TEST) glEnable(GL_DEPTH_TEST)
@terrain.draw if @terrain
ObjectManager.objects.each do |object| ObjectManager.objects.each do |object|
object.draw if object.visible && object.renderable object.draw if object.visible && object.renderable
end end
@terrain.draw if @terrain
end end
# Draw crosshair # Draw crosshair

View File

@@ -10,4 +10,4 @@ Ke 0.000000 0.000000 0.000000
Ni 1.000000 Ni 1.000000
d 1.000000 d 1.000000
illum 2 illum 2
map_Kd objects/skydome.png map_Kd objects/skydome_next.png