mirror of
https://github.com/cyberarm/i-mic-fps.git
synced 2025-12-15 15:42:35 +00:00
Terrain is still broken, player moves in the correct relative directions now :)
This commit is contained in:
@@ -20,28 +20,30 @@ class IMICFPS
|
||||
relative_speed = @speed*(delta_time/60.0)
|
||||
end
|
||||
|
||||
relative_y_rotation = @y_rotation*-1
|
||||
|
||||
if button_down?(Gosu::KbUp) || button_down?(Gosu::KbW)
|
||||
@z-=Math.cos(@y_rotation * Math::PI / 180)*relative_speed
|
||||
@x+=Math.sin(@y_rotation * Math::PI / 180)*relative_speed
|
||||
@z+=Math.cos(relative_y_rotation * Math::PI / 180)*relative_speed
|
||||
@x-=Math.sin(relative_y_rotation * Math::PI / 180)*relative_speed
|
||||
end
|
||||
if button_down?(Gosu::KbDown) || button_down?(Gosu::KbS)
|
||||
@z+=Math.cos(@y_rotation * Math::PI / 180)*relative_speed
|
||||
@x-=Math.sin(@y_rotation * Math::PI / 180)*relative_speed
|
||||
@z-=Math.cos(relative_y_rotation * Math::PI / 180)*relative_speed
|
||||
@x+=Math.sin(relative_y_rotation * Math::PI / 180)*relative_speed
|
||||
end
|
||||
if button_down?(Gosu::KbA)
|
||||
@z-=Math.sin(@y_rotation * Math::PI / 180)*relative_speed
|
||||
@x-=Math.cos(@y_rotation * Math::PI / 180)*relative_speed
|
||||
@z+=Math.sin(relative_y_rotation * Math::PI / 180)*relative_speed
|
||||
@x+=Math.cos(relative_y_rotation * Math::PI / 180)*relative_speed
|
||||
end
|
||||
if button_down?(Gosu::KbD)
|
||||
@z+=Math.sin(@y_rotation * Math::PI / 180)*relative_speed
|
||||
@x+=Math.cos(@y_rotation * Math::PI / 180)*relative_speed
|
||||
@z-=Math.sin(relative_y_rotation * Math::PI / 180)*relative_speed
|
||||
@x-=Math.cos(relative_y_rotation * Math::PI / 180)*relative_speed
|
||||
end
|
||||
|
||||
if button_down?(Gosu::KbLeft)
|
||||
@y_rotation-=relative_speed*100
|
||||
@y_rotation+=relative_speed*100
|
||||
end
|
||||
if button_down?(Gosu::KbRight)
|
||||
@y_rotation+=relative_speed*100
|
||||
@y_rotation-=relative_speed*100
|
||||
end
|
||||
|
||||
@y-=relative_speed if button_down?(Gosu::KbC) || button_down?(Gosu::KbLeftShift) unless @y <= 0
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
class IMICFPS
|
||||
class Terrain
|
||||
include OpenGL
|
||||
def initialize(size:, heightmap: nil)
|
||||
def initialize(size:, height: nil, width: nil, length: nil, heightmap: nil)
|
||||
@size = size
|
||||
@heightmap = heightmap
|
||||
@map = []
|
||||
|
||||
@height = height ? height : 1
|
||||
@width = width ? width : @size
|
||||
@length = length ? length : @size
|
||||
|
||||
@vertices = []
|
||||
@normals = []
|
||||
@colors = []
|
||||
@@ -14,18 +18,18 @@ class IMICFPS
|
||||
|
||||
def generate
|
||||
# x
|
||||
@size.times do |x|
|
||||
height = 0
|
||||
# row = []
|
||||
@size.times do |z|
|
||||
@map << Vertex.new(x, height, z)
|
||||
@map << Vertex.new(x, height, z-1)
|
||||
@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+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
|
||||
@@ -56,18 +60,20 @@ class IMICFPS
|
||||
end
|
||||
|
||||
def old_draw
|
||||
height = 0
|
||||
glEnable(GL_COLOR_MATERIAL)
|
||||
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
|
||||
|
||||
glBegin(GL_TRIANGLES)
|
||||
@map.each do |vertex|
|
||||
glNormal3f(0,1,0)
|
||||
glColor3f(0.0, 0.5, 0)
|
||||
glVertex3f(vertex.x, vertex.y, vertex.z)
|
||||
end
|
||||
glEnd
|
||||
glPointSize(5)
|
||||
# glBegin(GL_LINES)
|
||||
# glBegin(GL_POINTS)
|
||||
glBegin(GL_TRIANGLE_STRIP)
|
||||
@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?
|
||||
glVertex3f(vertex.x, vertex.y, vertex.z)
|
||||
end
|
||||
glEnd
|
||||
|
||||
glDisable(GL_COLOR_MATERIAL)
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
|
||||
@@ -89,7 +95,7 @@ class IMICFPS
|
||||
glNormalPointer(GL_FLOAT, 0, @normals)
|
||||
glColorPointer(3, GL_FLOAT, 0, @colors)
|
||||
|
||||
glDrawArrays(GL_TRIANGLES, 0, @map.size/4)
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, @map.size/4)
|
||||
|
||||
glDisableClientState(GL_VERTEX_ARRAY)
|
||||
glDisableClientState(GL_NORMAL_ARRAY)
|
||||
|
||||
@@ -25,7 +25,7 @@ class IMICFPS
|
||||
# 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)
|
||||
@terrain = Terrain.new(size: 20, height: 0)
|
||||
|
||||
@camera = Camera.new(x: 0, y: -2, z: 1)
|
||||
@player = Player.new(x: 1, y: 0, z: -10)
|
||||
|
||||
Reference in New Issue
Block a user