mirror of
https://github.com/cyberarm/i-mic-fps.git
synced 2025-12-15 15:42:35 +00:00
Broken mouse input, texture mapping issue persists.
This commit is contained in:
@@ -18,6 +18,8 @@ end
|
||||
|
||||
BoundingBox = Struct.new(:min_x, :min_y, :min_z, :max_x, :max_y, :max_z)
|
||||
|
||||
$debug = true if ARGV.join.include?("--debug")
|
||||
|
||||
require_relative "lib/objects/light"
|
||||
require_relative "lib/wavefront/parser"
|
||||
require_relative "lib/wavefront/model"
|
||||
@@ -25,6 +27,6 @@ require_relative "lib/wavefront/object"
|
||||
require_relative "lib/wavefront/material"
|
||||
require_relative "lib/window"
|
||||
|
||||
MODEL_METER_SCALE = 0.0009 # Objects exported from blender using the millimeter object scale will be close to 1 GL unit
|
||||
MODEL_METER_SCALE = 0.001 # Objects exported from blender using the millimeter object scale will be close to 1 GL unit
|
||||
|
||||
IMICFPS::Window.new.show
|
||||
|
||||
@@ -15,19 +15,21 @@ class IMICFPS
|
||||
|
||||
def set_texture(texture_path)
|
||||
puts "#{name} texture #{texture_path}"
|
||||
@texture = Gosu::Image.new(texture_path)
|
||||
@texture = Gosu::Image.new(texture_path, retro: true)
|
||||
array_of_pixels = @texture.to_blob
|
||||
if @texture.gl_tex_info
|
||||
@texture_id = @texture.gl_tex_info.tex_name
|
||||
else
|
||||
puts "Allocating..."
|
||||
tex_names_buf = ' ' * 8
|
||||
glGenTextures(1, tex_names_buf)
|
||||
@texture_id = tex_names_buf.unpack('L2').first
|
||||
end
|
||||
glBindTexture(GL_TEXTURE_2D, @texture_id)
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, @texture.width, @texture.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, array_of_pixels) unless @texture.gl_tex_info
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, @texture.width, @texture.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, array_of_pixels)
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR)
|
||||
glGenerateMipmap(GL_TEXTURE_2D)
|
||||
end
|
||||
|
||||
def texture_id
|
||||
|
||||
@@ -25,7 +25,7 @@ class IMICFPS
|
||||
@faces = []
|
||||
@smoothing= 0
|
||||
|
||||
@bounding_box = BoundingBox.new(0.0,0.0,0.0, 0.0,0.0,0.0)
|
||||
@bounding_box = BoundingBox.new(nil,nil,nil, nil,nil,nil)
|
||||
@debug_color = Color.new(rand(0.0..1.0), rand(0.0..1.0), rand(0.0..1.0))
|
||||
start_time = Time.now
|
||||
parse
|
||||
@@ -35,7 +35,7 @@ class IMICFPS
|
||||
face_count = 0
|
||||
@objects.each {|o| face_count+=o.faces.size}
|
||||
@objects.each_with_index do |o, i|
|
||||
puts "OBJECT FACES: Name: #{o.name} #{o.faces.size}, array size divided by 3: #{o.faces.size.to_f/3.0}"
|
||||
puts "Model::Object Name: #{o.name} Faces: #{o.faces.size}, array size divided by 3: #{o.faces.size.to_f/3.0}"
|
||||
end
|
||||
$window.number_of_faces+=face_count
|
||||
@model_has_texture = false
|
||||
@@ -97,9 +97,9 @@ class IMICFPS
|
||||
end
|
||||
glDisable(GL_CULL_FACE) if back_face_culling
|
||||
glDisable(GL_COLOR_MATERIAL)
|
||||
render_bounding_box(o.bounding_box) if ARGV.join("--debug")
|
||||
render_bounding_box(o.bounding_box, o.debug_color) if $debug
|
||||
end
|
||||
render_bounding_box(@bounding_box) if ARGV.join("--debug")
|
||||
render_bounding_box(@bounding_box) if $debug
|
||||
glPopMatrix
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
class IMICFPS
|
||||
class Wavefront
|
||||
class Object
|
||||
attr_reader :name, :vertices, :textures, :normals, :bounding_box
|
||||
attr_reader :name, :vertices, :textures, :normals, :bounding_box, :debug_color
|
||||
attr_accessor :faces
|
||||
|
||||
def initialize(name)
|
||||
@@ -11,6 +11,7 @@ class IMICFPS
|
||||
@normals = []
|
||||
@faces = []
|
||||
@bounding_box = BoundingBox.new(nil,nil,nil, nil,nil,nil)
|
||||
@debug_color = Parser::Color.new(1.0,0.0,0.0)
|
||||
|
||||
# Faces array packs everything:
|
||||
# vertex = index[0]
|
||||
@@ -21,6 +22,8 @@ class IMICFPS
|
||||
|
||||
def flattened_vertices
|
||||
unless @vertices_list
|
||||
@debug_color = @faces.first[3].diffuse
|
||||
|
||||
list = []
|
||||
@faces.each do |face|
|
||||
[face[0]].each do |v|
|
||||
|
||||
@@ -141,9 +141,9 @@ class IMICFPS
|
||||
def add_texture_coordinate(array)
|
||||
texture = nil
|
||||
if array.size == 4
|
||||
texture = Vertex.new(Float(array[1]), Float(array[2]), Float(array[3]))
|
||||
texture = Vertex.new(Float(array[1]), 1-Float(array[2]), Float(array[3]))
|
||||
elsif array.size == 3
|
||||
texture = Vertex.new(Float(array[1]), Float(array[2]), 0.0)
|
||||
texture = Vertex.new(Float(array[1]), 1-Float(array[2]), 0.0)
|
||||
else
|
||||
raise
|
||||
end
|
||||
|
||||
118
lib/window.rb
118
lib/window.rb
@@ -11,29 +11,28 @@ class IMICFPS
|
||||
super(window_width, window_height, fullscreen)
|
||||
# super(Gosu.screen_width, Gosu.screen_height, true)
|
||||
$window = self
|
||||
|
||||
@delta_time = Gosu.milliseconds
|
||||
@number_of_faces = 0
|
||||
@draw_skydome = true
|
||||
@skydome = Wavefront::Model.new("objects/skydome.obj")
|
||||
@model = Wavefront::Model.new("objects/biped.obj")
|
||||
# @scene = Wavefront::Model.new("objects/cube.obj")
|
||||
@tree = Wavefront::Model.new("objects/tree.obj")
|
||||
@mega_model = Wavefront::Model.new("objects/sponza.obj")
|
||||
# @skydome = Wavefront::Model.new("objects/skydome.obj")
|
||||
@cube = Wavefront::Model.new("objects/cube.obj")
|
||||
# @model = Wavefront::Model.new("objects/biped.obj")
|
||||
# @tree = Wavefront::Model.new("objects/tree.obj")
|
||||
# @mega_model = Wavefront::Model.new("objects/sponza.obj")
|
||||
|
||||
@camera = Wavefront::Model::Vertex.new(0,-1,0)
|
||||
@camera_target = Wavefront::Model::Vertex.new(0,-1,0)
|
||||
@speed = 0.05
|
||||
@angle_y = 0.0 # |
|
||||
@angle_x = 0.0 # _
|
||||
@mouse = Point.new(Gosu.screen_width/2, Gosu.screen_height/2)
|
||||
@old_speed = @speed
|
||||
@vertical_angle = 0.0 # |
|
||||
@horizontal_angle = 0.0 # _
|
||||
self.mouse_x, self.mouse_y = Gosu.screen_width/2, Gosu.screen_height/2
|
||||
@mouse = Point.new(Gosu.screen_width/2, Gosu.screen_height/2)
|
||||
@mouse_sesitivity = 5.0
|
||||
|
||||
@font = Gosu::Font.new(18, name: "DejaVu Sans")
|
||||
@text = "Hello There"
|
||||
@last_frame_time = 0
|
||||
@tick = 0
|
||||
@c1, @c2, @c3 = rand(0.0..1.0), rand(0.0..1.0), rand(0.0..1.0)
|
||||
|
||||
@ambient_light = [0.5, 0.5, 0.5, 1]
|
||||
@diffuse_light = [1, 0.5, 0, 1]
|
||||
@@ -65,7 +64,8 @@ class IMICFPS
|
||||
glMatrixMode(GL_PROJECTION) # The projection matrix is responsible for adding perspective to our scene.
|
||||
glLoadIdentity # Resets current modelview matrix
|
||||
# Calculates aspect ratio of the window. Gets perspective view. 45 is degree viewing angle, (0.1, 100) are ranges how deep can we draw into the screen
|
||||
gluPerspective(90.0, width / height, 0.1, 1000.0)
|
||||
gluPerspective(70.0, width / height, 0.1, 1000.0)
|
||||
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
|
||||
|
||||
glMatrixMode(GL_MODELVIEW) # The modelview matrix is where object information is stored.
|
||||
glLoadIdentity
|
||||
@@ -73,18 +73,17 @@ class IMICFPS
|
||||
@camera_light.draw
|
||||
glEnable(GL_DEPTH_TEST)
|
||||
|
||||
glRotatef(@angle_y,1,0,0)
|
||||
glRotatef(@angle_x,0,1,0)
|
||||
glRotatef(@vertical_angle,1,0,0)
|
||||
glRotatef(@horizontal_angle,0,1,0)
|
||||
glTranslatef(@camera.x, @camera.y, @camera.z)
|
||||
# gluLookAt(@camera.x,@camera.y,@camera.z, @angle_x,@angle_y,0, 0,1,0)
|
||||
# gluLookAt(@camera.x,@camera.y,@camera.z, @horizontal_angle,@vertical_angle,0, 0,1,0)
|
||||
|
||||
color = [@c1, @c2, @c3]
|
||||
@skydome.draw(0,0,0, 1, false) if @draw_skydome
|
||||
# @scene.draw(0,0,0, 1)
|
||||
@model.draw(1, 0, 0)
|
||||
@tree.draw(5, 0, 0)
|
||||
@tree.draw(5, 0, 3)
|
||||
@tree.draw(3, 0, 10)
|
||||
# @skydome.draw(0,0,0, 0.005, false) if @draw_skydome
|
||||
@cube.draw(0,1,0)
|
||||
# @model.draw(1, 0, 0)
|
||||
# @tree.draw(5, 0, 0)
|
||||
# @tree.draw(5, 0, 3)
|
||||
# @tree.draw(3, 0, 10)
|
||||
# @mega_model.draw(0,0,0, 1)
|
||||
end
|
||||
|
||||
@@ -99,62 +98,85 @@ class IMICFPS
|
||||
OpenGL Version: #{glGetString(GL_VERSION)}~
|
||||
OpenGL Shader Language Version: #{glGetString(GL_SHADING_LANGUAGE_VERSION)}~
|
||||
~
|
||||
Angle Y: #{@angle_y.round(2)} Angle X: #{@angle_x.round(2)} ~
|
||||
Vertical Angle: #{@vertical_angle.round(2)} Horizontal Angle: #{@horizontal_angle.round(2)} ~
|
||||
X:#{@camera.x.round(2)} Y:#{@camera.y.round(2)} Z:#{@camera.z.round(2)} ~
|
||||
Faces: #{@number_of_faces} ~
|
||||
Last Frame: #{Gosu.milliseconds-@last_frame_time}ms (#{Gosu.fps} fps)~
|
||||
Last Frame: #{delta_time}ms (#{Gosu.fps} fps)~
|
||||
~
|
||||
Draw Skydome: #{@draw_skydome}"
|
||||
Draw Skydome: #{@draw_skydome}~
|
||||
Debug mode: <c=992200>#{$debug}</b>~"
|
||||
@last_frame_time = Gosu.milliseconds
|
||||
|
||||
# $window.caption = "Gosu OBJ object - FPS:#{Gosu.fps}"
|
||||
@angle_x-=Float(@mouse.x-self.mouse_x)/@mouse_sesitivity
|
||||
@angle_y-=Float(@mouse.y-self.mouse_y)/@mouse_sesitivity
|
||||
@angle_x %= 360.0
|
||||
@angle_y = @angle_y.clamp(-90.0, 90.0)
|
||||
self.mouse_x, self.mouse_y = Gosu.screen_width/2, Gosu.screen_height/2
|
||||
puts "#{@mouse}"
|
||||
@horizontal_angle-=Float(@mouse.x-self.mouse_x)/@mouse_sesitivity
|
||||
@vertical_angle-=Float(@mouse.y-self.mouse_y)/@mouse_sesitivity
|
||||
@horizontal_angle %= 360.0
|
||||
@vertical_angle = @vertical_angle.clamp(-90.0, 90.0)
|
||||
|
||||
@light_postion = [@camera.x, @camera.y, @camera.z, 0]
|
||||
# @camera_light.position = @light_position
|
||||
# @light_postion = [0.0, 10, 0, 0]
|
||||
self.mouse_x, self.mouse_y = Gosu.screen_width/2.0, Gosu.screen_height/2.0
|
||||
# @mouse.x, @mouse.y = self.mouse_x, self.mouse_y
|
||||
puts "#{@mouse.x}-#{self.mouse_x}" if @mouse.x != self.mouse_x
|
||||
puts "#{@mouse.y}-#{self.mouse_y}" if @mouse.y != self.mouse_y
|
||||
|
||||
relative_speed = @speed*(delta_time/60.0)
|
||||
relative_speed = @speed
|
||||
if button_down?(Gosu::KbLeftControl)
|
||||
relative_speed = (@speed*10.0)*(delta_time/60.0)
|
||||
else
|
||||
relative_speed = @speed*(delta_time/60.0)
|
||||
end
|
||||
|
||||
if button_down?(Gosu::KbUp) || button_down?(Gosu::KbW)
|
||||
@camera.z+=Math.cos(@angle_x * Math::PI / 180)*relative_speed
|
||||
@camera.x-=Math.sin(@angle_x * Math::PI / 180)*relative_speed
|
||||
@camera.z+=Math.cos(@horizontal_angle * Math::PI / 180)*relative_speed
|
||||
@camera.x-=Math.sin(@horizontal_angle * Math::PI / 180)*relative_speed
|
||||
end
|
||||
if button_down?(Gosu::KbDown) || button_down?(Gosu::KbS)
|
||||
@camera.z-=Math.cos(@angle_x * Math::PI / 180)*relative_speed
|
||||
@camera.x+=Math.sin(@angle_x * Math::PI / 180)*relative_speed
|
||||
@camera.z-=Math.cos(@horizontal_angle * Math::PI / 180)*relative_speed
|
||||
@camera.x+=Math.sin(@horizontal_angle * Math::PI / 180)*relative_speed
|
||||
end
|
||||
if button_down?(Gosu::KbLeft) || button_down?(Gosu::KbA)
|
||||
@camera.z+=Math.sin(@angle_x * Math::PI / 180)*relative_speed
|
||||
@camera.x+=Math.cos(@angle_x * Math::PI / 180)*relative_speed
|
||||
if button_down?(Gosu::KbA)
|
||||
@camera.z+=Math.sin(@horizontal_angle * Math::PI / 180)*relative_speed
|
||||
@camera.x+=Math.cos(@horizontal_angle * Math::PI / 180)*relative_speed
|
||||
end
|
||||
if button_down?(Gosu::KbRight) || button_down?(Gosu::KbD)
|
||||
@camera.z-=Math.sin(@angle_x * Math::PI / 180)*relative_speed
|
||||
@camera.x-=Math.cos(@angle_x * Math::PI / 180)*relative_speed
|
||||
if button_down?(Gosu::KbD)
|
||||
@camera.z-=Math.sin(@horizontal_angle * Math::PI / 180)*relative_speed
|
||||
@camera.x-=Math.cos(@horizontal_angle * Math::PI / 180)*relative_speed
|
||||
end
|
||||
|
||||
@camera.y+=relative_speed if $window.button_down?(Gosu::KbLeftShift)
|
||||
if button_down?(Gosu::KbLeft)
|
||||
@horizontal_angle-=relative_speed*100
|
||||
end
|
||||
if button_down?(Gosu::KbRight)
|
||||
@horizontal_angle+=relative_speed*100
|
||||
end
|
||||
|
||||
@camera.y+=relative_speed if $window.button_down?(Gosu::KbC) || $window.button_down?(Gosu::KbLeftShift)
|
||||
@camera.y-=relative_speed if $window.button_down?(Gosu::KbSpace)
|
||||
|
||||
$window.close if $window.button_down?(Gosu::KbEscape)
|
||||
@number_of_faces = 0
|
||||
@delta_time = Gosu.milliseconds
|
||||
end
|
||||
|
||||
def button_up(id)
|
||||
case id
|
||||
when Gosu::KbZ
|
||||
@draw_skydome = !@draw_skydome
|
||||
when Gosu::KbBacktick
|
||||
$debug = !$debug
|
||||
end
|
||||
end
|
||||
|
||||
def needs_cursor?
|
||||
true
|
||||
end
|
||||
|
||||
def lose_focus
|
||||
puts 'Bye'
|
||||
end
|
||||
|
||||
def delta_time
|
||||
t = Gosu.milliseconds-@delta_time
|
||||
@delta_time = Gosu.milliseconds
|
||||
return t
|
||||
Gosu.milliseconds-@delta_time
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,42 +1,13 @@
|
||||
# Blender MTL File: 'cube.blend'
|
||||
# Material Count: 4
|
||||
|
||||
newmtl Material
|
||||
Ns 96.078431
|
||||
Ka 1.000000 1.000000 1.000000
|
||||
Kd 0.000000 0.800000 0.000071
|
||||
Ks 0.500000 0.500000 0.500000
|
||||
Ke 0.000000 0.000000 0.000000
|
||||
Ni 1.000000
|
||||
d 1.000000
|
||||
illum 2
|
||||
# Blender MTL File: 'None'
|
||||
# Material Count: 1
|
||||
|
||||
newmtl Material.001
|
||||
Ns 96.078431
|
||||
Ns 94.117647
|
||||
Ka 1.000000 1.000000 1.000000
|
||||
Kd 0.640000 0.007390 0.000000
|
||||
Ks 0.500000 0.500000 0.500000
|
||||
Ke 0.000000 0.000000 0.000000
|
||||
Ni 1.000000
|
||||
d 1.000000
|
||||
illum 2
|
||||
|
||||
newmtl Material.002
|
||||
Ns 96.078431
|
||||
Ka 1.000000 1.000000 1.000000
|
||||
Kd 0.069712 0.069712 0.069712
|
||||
Ks 0.500000 0.500000 0.500000
|
||||
Ke 0.000000 0.000000 0.000000
|
||||
Ni 1.000000
|
||||
d 1.000000
|
||||
illum 2
|
||||
|
||||
newmtl Material.003
|
||||
Ns 96.078431
|
||||
Ka 1.000000 1.000000 1.000000
|
||||
Kd 0.166102 0.640000 0.127010
|
||||
Ks 0.500000 0.500000 0.500000
|
||||
Kd 0.800000 0.800000 0.800000
|
||||
Ks 0.000000 0.000000 0.000000
|
||||
Ke 0.000000 0.000000 0.000000
|
||||
Ni 1.000000
|
||||
d 1.000000
|
||||
illum 2
|
||||
map_Kd objects/skydome.png
|
||||
|
||||
6177
objects/cube.obj
6177
objects/cube.obj
File diff suppressed because it is too large
Load Diff
@@ -1,13 +1,13 @@
|
||||
# Blender MTL File: 'skydome.blend'
|
||||
# Blender MTL File: 'None'
|
||||
# Material Count: 1
|
||||
|
||||
newmtl Material.001
|
||||
Ns 96.078431
|
||||
Ns 94.117647
|
||||
Ka 0.000000 0.000000 0.000000
|
||||
Kd 0.129836 0.406902 0.640000
|
||||
Ks 0.000000 0.000000 0.000000
|
||||
Ke 0.000000 0.000000 0.000000
|
||||
Ni 1.000000
|
||||
d 1.000000
|
||||
illum 1
|
||||
illum 2
|
||||
map_Kd objects/skydome.png
|
||||
|
||||
3248
objects/skydome.obj
3248
objects/skydome.obj
File diff suppressed because it is too large
Load Diff
Binary file not shown.
|
Before Width: | Height: | Size: 392 KiB After Width: | Height: | Size: 379 KiB |
Reference in New Issue
Block a user