mirror of
https://github.com/cyberarm/i-mic-fps.git
synced 2025-12-15 07:32:35 +00:00
Added them lights, relative speed!
This commit is contained in:
56
lib/objects/light.rb
Normal file
56
lib/objects/light.rb
Normal file
@@ -0,0 +1,56 @@
|
||||
class IMICFPS
|
||||
class Light
|
||||
include OpenGL
|
||||
MAX_LIGHTS = GL_MAX_LIGHTS-1
|
||||
attr_accessor :x, :y, :z, :ambient, :diffuse, :specular
|
||||
def self.number_of_lights
|
||||
@number_of_lights ||= 0
|
||||
end
|
||||
|
||||
# use as Light.number_of_lights+=n
|
||||
def self.number_of_lights=(int)
|
||||
@number_of_lights = int
|
||||
end
|
||||
|
||||
def initialize(x,y,z)
|
||||
@ambient = [0.0, 0.0, 0.0, 1].pack("f*")
|
||||
@diffuse = [1, 0.5, 0, 1].pack("f*")
|
||||
@specular = [0.0, 0.0, 0.0, 1].pack("f*")
|
||||
@postion = [0, 0, 0, 0].pack("f*")
|
||||
@light_id = available_light
|
||||
end
|
||||
|
||||
def available_light
|
||||
raise "Using to many lights, #{Light.number_of_lights}/#{MAX_LIGHTS}" if Light.number_of_lights > MAX_LIGHTS
|
||||
Light.number_of_lights+=1
|
||||
puts "OpenGL::GL_LIGHT#{Light.number_of_lights}"
|
||||
@light_id = Object.const_get "OpenGL::GL_LIGHT#{Light.number_of_lights}"
|
||||
end
|
||||
|
||||
def ambient=(array)
|
||||
@ambient = array.pack("f*")
|
||||
end
|
||||
|
||||
def diffuse=(array)
|
||||
@diffuse = array.pack("f*")
|
||||
end
|
||||
|
||||
def specular=(array)
|
||||
@specular = array.pack("f*")
|
||||
end
|
||||
|
||||
def postion=(array)
|
||||
@postion = array.pack("f*")
|
||||
end
|
||||
|
||||
def draw
|
||||
glLightfv(@light_id, GL_AMBIENT, @ambient)
|
||||
glLightfv(@light_id, GL_DIFFUSE, @diffuse)
|
||||
glLightfv(@light_id, GL_SPECULAR, @specular)
|
||||
glLightfv(@light_id, GL_POSITION, @postion)
|
||||
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1)
|
||||
glEnable(GL_LIGHTING)
|
||||
glEnable(@light_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -11,6 +11,7 @@ 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")
|
||||
@@ -117,7 +118,7 @@ class IMICFPS
|
||||
@camera_light.postion = @light_postion
|
||||
# @light_postion = [0.0, 10, 0, 0]
|
||||
|
||||
relative_speed = @speed#*delta_time
|
||||
relative_speed = @speed*(delta_time/60.0)
|
||||
|
||||
if button_down?(Gosu::KbUp) || button_down?(Gosu::KbW)
|
||||
@camera.z+=Math.cos(@angle_x * Math::PI / 180)*relative_speed
|
||||
@@ -149,5 +150,11 @@ class IMICFPS
|
||||
@draw_skydome = !@draw_skydome
|
||||
end
|
||||
end
|
||||
|
||||
def delta_time
|
||||
t = Gosu.milliseconds-@delta_time
|
||||
@delta_time = Gosu.milliseconds
|
||||
return t
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user