Initial Commit

This commit is contained in:
2017-12-28 22:14:20 -06:00
commit 66e68581f5
11 changed files with 163342 additions and 0 deletions

6
Gemfile Normal file
View File

@@ -0,0 +1,6 @@
source "https://rubygems.org"
gem "opengl"
gem "glu"
gem "glut"
gem "gosu"
gem "wavefront" # Gem for opening blender or blender exported object with texturing

21
Gemfile.lock Normal file
View File

@@ -0,0 +1,21 @@
GEM
remote: https://rubygems.org/
specs:
glu (8.3.0)
glut (8.3.0)
gosu (0.13.1)
opengl (0.10.0)
wavefront (0.1.2)
PLATFORMS
ruby
DEPENDENCIES
glu
glut
gosu
opengl
wavefront
BUNDLED WITH
1.16.1

BIN
blends/cube.blend Normal file

Binary file not shown.

BIN
blends/cube.blend1 Normal file

Binary file not shown.

10
i-mic-fps.rb Normal file
View File

@@ -0,0 +1,10 @@
require "opengl"
require "glu"
require "glut"
require "gosu"
# require "wavefront"
require_relative "lib/object"
require_relative "lib/window"
IMICFPS::Window.new.show

50
lib/object.rb Normal file
View File

@@ -0,0 +1,50 @@
class IMICFPS
class Object
Vertex = Struct.new("Vertex", :x, :y, :z)
attr_accessor :vertexes, :texures, :normals, :faces
def initialize(object = "objects/cube.obj")
@level = File.open(object, 'r')
@vertexes = []
@textures = []
@normals = []
@faces = []
parse
end
def parse
@level.each_line do |line|
line = line.strip
array = line.split(' ')
case array[0]
when 'v'
vert = Vertex.new(Float(array[1]), Float(array[2]), Float(array[3]))
@vertexes << vert
when 'vt'
p array
# vert = Vertex.new(Float(array[1]), Float(array[2]), Float(array[3]))
# @textures << vert
when 'vn'
vert = Vertex.new(Float(array[1]), Float(array[2]), Float(array[3]))
@normals << vert
when 'f'
vert = []
norm = []
array[1..3].each do |f|
vert << f.split("/")[0]
norm << f.split("/")[2]
end
vert.each_with_index do |v, index|
face = [@vertexes[Integer(v)-1], @normals[Integer(norm[index])-1]]
@faces << face
end
end
end
end
end
end

126
lib/window.rb Normal file
View File

@@ -0,0 +1,126 @@
class IMICFPS
class Window < Gosu::Window
include GL
include GLU
include GLUT
def initialize(window_width = 1280, window_height = 800, fullscreen = false)
# super(window_width, window_height, fullscreen)
super(Gosu.screen_width, Gosu.screen_height, true)
$window = self
@level = Object.new("objects/cube.obj")
# @level = Object.new("objects/sponza.obj")
@camera = Object::Vertex.new(0,-1,0)
@camera_target = Object::Vertex.new(0,-1,0)
@speed = 0.05
@angle_y = 0 # |
@angle_x = 0 # _
@mouse = Object::Vertex.new(Gosu.screen_width/2,Gosu.screen_height/2,0)
self.mouse_x, self.mouse_y = Gosu.screen_width/2, Gosu.screen_height/2
@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, 0, 0, 1]
@diffuse_light = [1, 1, 1, 1]
@specular_light = [1, 1, 1, 1]
@light_postion = [1, 1, 1, 0]
# gl do
#
# end
end
def draw
gl do
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) # clear the screen and the depth buffer
glShadeModel(GL_SMOOTH)
#glMatrixMode(matrix) indicates that following [matrix] is going to get used
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, 100.0)
glMatrixMode(GL_MODELVIEW) # The modelview matrix is where object information is stored.
glLoadIdentity
# Think 3-d coordinate system (x,y,z). +- on each movies on that axis
glLightfv(GL_LIGHT0, GL_AMBIENT, @ambient_light)
glLightfv(GL_LIGHT0, GL_DIFFUSE, @diffuse_light)
glLightfv(GL_LIGHT0, GL_SPECULAR, @specular_light)
glLightfv(GL_LIGHT0, GL_POSITION, @light_postion)
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1)
glEnable(GL_LIGHTING)
glEnable(GL_LIGHT0)
glEnable(GL_DEPTH_TEST)
glEnable(GL_CULL_FACE)
glEnable(GL_COLOR_MATERIAL)
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE)
# glRotatef(@angle_y,0,1,0)
# glRotatef(@angle_x,1,0,0)
# glTranslate(@x, @y, @z)
# glPointSize(5.0)
gluLookAt(@camera.x,@camera.y,@camera.z, @angle_x,@angle_y,0, 0,1,0)
color = [@c1, @c2, @c3]
glBegin(GL_TRIANGLES) # begin drawing model
@level.faces.each do |vert|
vertex = vert[0]
normal = vert[1]
glColor3f(color[0], color[1], color[2])
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, [@c1, @c2, @c3, 1.0])
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, [@c1, @c2, @c3, 1.0])
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, [1,1,1,1])
glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, [10.0])
glNormal3f(normal.x, normal.y, normal.z)
glVertex3f(vertex.x, vertex.y, vertex.z)
end
glEnd
end
@text.split("~").each_with_index do |bit, i|
@font.draw(bit.strip, 10, @font.height*i, Float::INFINITY)
end
end
def update
@text = "Open Vendor: #{glGetString(GL_VENDOR)}~
OpenGL Renderer: #{glGetString(GL_RENDERER)} ~
OpenGL Version: #{glGetString(GL_VERSION)}~
OpenGL Shader Language Version: #{glGetString(GL_SHADING_LANGUAGE_VERSION)}~
~
Angle Y: #{@angle_y} Angle X: #{@angle_x} ~
X:#{@camera.x} Y:#{@camera.y} Z:#{@camera.z} ~
Mesh Vert Array: #{@level.faces.size} ~
Last Frame: #{Gosu.milliseconds-@last_frame_time}ms (#{Gosu.fps} fps)"
@last_frame_time = Gosu.milliseconds
# $window.caption = "Gosu OBJ Level - FPS:#{Gosu.fps}"
@angle_x-=Integer(@mouse.x-self.mouse_x)
@angle_y-=Integer(@mouse.y-self.mouse_y)
@angle_x = @angle_x.clamp(-360, 360)
@angle_y = @angle_y.clamp(-360, 360)
self.mouse_x, self.mouse_y = Gosu.screen_width/2, Gosu.screen_height/2
@light_postion = [-@camera.x, -@camera.y, -@camera.z, 1]
# @light_postion = [1.0, 0.249, 4.09, 1]
@camera.x-=@speed if $window.button_down?(Gosu::KbRight)
@camera.x+=@speed if $window.button_down?(Gosu::KbLeft)
@camera.z+=@speed if $window.button_down?(Gosu::KbUp)
@camera.z-=@speed if $window.button_down?(Gosu::KbDown)
@camera.y+=@speed if $window.button_down?(Gosu::KbLeftShift)
@camera.y-=@speed if $window.button_down?(Gosu::KbSpace)
$window.close if $window.button_down?(Gosu::KbEscape)
end
end
end

40
objects/cube.mtl Normal file
View File

@@ -0,0 +1,40 @@
# Blender MTL File: 'cube.blend'
# Material Count: 4
newmtl Material.001
Ns 96.078431
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
Ke 0.000000 0.000000 0.000000
Ni 1.000000
d 1.000000
illum 2
newmtl None
Ns 0
Ka 0.000000 0.000000 0.000000
Kd 0.8 0.8 0.8
Ks 0.8 0.8 0.8
d 1
illum 2

6138
objects/cube.obj Normal file

File diff suppressed because it is too large Load Diff

202
objects/sponza.mtl Normal file
View File

@@ -0,0 +1,202 @@
# Blender MTL File: 'None'
# Material Count: 20
newmtl sp_00_luk_mal1
Ns 96.078431
Ka 1.000000 1.000000 1.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.000000
d 1.000000
illum 2
newmtl sp_00_luk_mali
Ns 96.078431
Ka 1.000000 1.000000 1.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.000000
d 1.000000
illum 2
newmtl sp_00_pod
Ns 96.078431
Ka 1.000000 1.000000 1.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.000000
d 1.000000
illum 2
newmtl sp_00_prozor
Ns 96.078431
Ka 1.000000 1.000000 1.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.000000
d 1.000000
illum 2
newmtl sp_00_stup
Ns 96.078431
Ka 1.000000 1.000000 1.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.000000
d 1.000000
illum 2
newmtl sp_00_svod
Ns 96.078431
Ka 1.000000 1.000000 1.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.000000
d 1.000000
illum 2
newmtl sp_00_vrata_kock
Ns 96.078431
Ka 1.000000 1.000000 1.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.000000
d 1.000000
illum 2
newmtl sp_00_vrata_krug
Ns 96.078431
Ka 1.000000 1.000000 1.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.000000
d 1.000000
illum 2
newmtl sp_00_zid
Ns 96.078431
Ka 1.000000 1.000000 1.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.000000
d 1.000000
illum 2
newmtl sp_01_luk_a
Ns 96.078431
Ka 1.000000 1.000000 1.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.000000
d 1.000000
illum 2
newmtl sp_01_stub
Ns 96.078431
Ka 1.000000 1.000000 1.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.000000
d 1.000000
illum 2
newmtl sp_01_stub_baza
Ns 96.078431
Ka 1.000000 1.000000 1.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.000000
d 1.000000
illum 2
newmtl sp_01_stub_baza_
Ns 96.078431
Ka 1.000000 1.000000 1.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.000000
d 1.000000
illum 2
newmtl sp_01_stub_kut
Ns 96.078431
Ka 1.000000 1.000000 1.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.000000
d 1.000000
illum 2
newmtl sp_01_stup
Ns 96.078431
Ka 1.000000 1.000000 1.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.000000
d 1.000000
illum 2
newmtl sp_01_stup_baza
Ns 96.078431
Ka 1.000000 1.000000 1.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.000000
d 1.000000
illum 2
newmtl sp_02_reljef
Ns 96.078431
Ka 1.000000 1.000000 1.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.000000
d 1.000000
illum 2
newmtl sp_svod_kapitel
Ns 96.078431
Ka 1.000000 1.000000 1.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.000000
d 1.000000
illum 2
newmtl sp_vijenac
Ns 96.078431
Ka 1.000000 1.000000 1.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.000000
d 1.000000
illum 2
newmtl sp_zid_vani
Ns 96.078431
Ka 1.000000 1.000000 1.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.000000
d 1.000000
illum 2

156749
objects/sponza.obj Executable file

File diff suppressed because it is too large Load Diff