mirror of
https://github.com/cyberarm/i-mic-fps.git
synced 2025-12-16 08:02:36 +00:00
Camera can bind to model
This commit is contained in:
@@ -5,6 +5,7 @@ class IMICFPS
|
||||
include GLU
|
||||
|
||||
attr_accessor :x,:y,:z, :field_of_view, :vertical_angle, :horizontal_angle, :mouse_sensitivity
|
||||
attr_reader :bound_model
|
||||
def initialize(x: 0, y: 0, z: 0, fov: 70.0)
|
||||
@x,@y,@z = x,y,z
|
||||
@vertical_angle = 0.0
|
||||
@@ -17,6 +18,16 @@ class IMICFPS
|
||||
@true_mouse = Point.new(Gosu.screen_width/2, Gosu.screen_height/2)
|
||||
@true_mouse_checked = 0
|
||||
@mouse_sensitivity = 20.0
|
||||
|
||||
@bound_model = nil
|
||||
end
|
||||
|
||||
def bind_model(model)
|
||||
@bound_model = model
|
||||
end
|
||||
|
||||
def unbind
|
||||
@bound_model = nil
|
||||
end
|
||||
|
||||
def draw
|
||||
@@ -86,6 +97,17 @@ class IMICFPS
|
||||
|
||||
@y+=relative_speed if button_down?(Gosu::KbC) || button_down?(Gosu::KbLeftShift)
|
||||
@y-=relative_speed if button_down?(Gosu::KbSpace)
|
||||
|
||||
if @bound_model
|
||||
distance = 2.0
|
||||
x_offset = distance * Math.cos(@bound_model.y_rotation)
|
||||
z_offset = distance * Math.sin(@bound_model.y_rotation)
|
||||
@bound_model.x = @x*-1+x_offset
|
||||
@bound_model.y = @y*-1-2
|
||||
@bound_model.z = @z*-1-z_offset
|
||||
|
||||
@bound_model.y_rotation = (@horizontal_angle*-1)+180
|
||||
end
|
||||
end
|
||||
|
||||
def button_up(id)
|
||||
|
||||
@@ -31,7 +31,7 @@ class IMICFPS
|
||||
unless load_model_from_cache
|
||||
case type
|
||||
when :obj
|
||||
@model = Wavefront::Model.new(@file_path)
|
||||
@model = Wavefront::Model.new(file_path: @file_path, x: x, y: y, z: z, scale: scale)
|
||||
else
|
||||
raise "Unsupported model type, supported models are: #{Model.supported_models.join(', ')}"
|
||||
end
|
||||
@@ -59,9 +59,7 @@ class IMICFPS
|
||||
render_bounding_box(@model.bounding_box) if $debug
|
||||
@model.objects.each {|o| render_bounding_box(o.bounding_box, o.debug_color)} if $debug
|
||||
|
||||
glTranslatef(x,y,z)
|
||||
glScalef(scale, scale, scale)
|
||||
|
||||
glTranslatef(@x, @y, @z)
|
||||
glRotatef(@x_rotation,1.0, 0, 0)
|
||||
glRotatef(@y_rotation,0, 1.0, 0)
|
||||
glRotatef(@z_rotation,0, 0, 1.0)
|
||||
@@ -78,8 +76,10 @@ class IMICFPS
|
||||
ObjectManager.objects.each do |a|
|
||||
ObjectManager.objects.each do |b|
|
||||
next if a == b
|
||||
next if b.name == "skydome"
|
||||
if a.intersect(a.model.bounding_box, b.model.bounding_box)
|
||||
if a.name == "tree"
|
||||
puts "#{b.name} is touching me"
|
||||
a.y_rotation+=0.01
|
||||
end
|
||||
end
|
||||
@@ -112,9 +112,9 @@ class IMICFPS
|
||||
if (a.min_x <= b.max_x && a.max_x >= b.min_x) &&
|
||||
(a.min_y <= b.max_y && a.max_y >= b.min_y) &&
|
||||
(a.min_z <= b.max_z && a.max_z >= b.min_z)
|
||||
true
|
||||
return true
|
||||
else
|
||||
false
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user