class Disp3D::GLView
GLView
class hold primary object for 3D displaying like camera, scene_graph. User never use this class Use QtWidgetGL
class (in Qt Application) Use GLUTWindow
class (in GLUT Window)
Attributes
bk_color[RW]
camera[R]
camera_scene_graph[R]
light[R]
manipulator[R]
picker[R]
world_scene_graph[R]
Public Class Methods
new(width, height)
click to toggle source
# File lib/gl_view.rb, line 19 def initialize(width, height) GL.FrontFace(GL::GL_CW) GL.Enable(GL::GL_AUTO_NORMAL) GL.Enable(GL::GL_NORMALIZE) GL.Enable(GL::GL_DEPTH_TEST) GL.DepthFunc(GL::GL_LESS) GL.Enable(GL::BLEND) GL.BlendFunc(GL::GL_SRC_ALPHA, GL::GL_ONE_MINUS_SRC_ALPHA) @light = Light.new() @camera = Camera.new() @world_scene_graph = SceneGraph.new() @camera_scene_graph = SceneGraph.new() @picker = Picker.new(self) @bk_color = [0.28,0.23,0.55,1] @manipulator = Manipulator.new(@camera, @picker) @compass = Compass.new(@camera) @mouse_move_proc = nil @mouse_press_proc = nil @mouse_release_proc = nil end
Public Instance Methods
capture()
click to toggle source
# File lib/gl_view.rb, line 52 def capture dmy,dmy, w, h = @camera.viewport gl_display GL.ReadBuffer(GL::FRONT) GL.PixelStorei(GL::UNPACK_ALIGNMENT,1) data = GL.ReadPixels(0,0,w,h,GL::RGB, GL::UNSIGNED_BYTE) data_ary = data.unpack("C*") data_index = -1 max_color_intensity = Magick::QuantumRange.to_f pixels = Array.new(w*h).collect do | elem | r = data_ary[data_index+=1] g = data_ary[data_index+=1] b = data_ary[data_index+=1] elem = Magick::Pixel.new( r/255.0*max_color_intensity, g/255.0*max_color_intensity, b/255.0*max_color_intensity) end image = Magick::Image.new(w, h).store_pixels(0,0,w,h,pixels) return image.flip end
centering()
click to toggle source
# File lib/gl_view.rb, line 78 def centering @manipulator.centering(@world_scene_graph) end
fit()
click to toggle source
# File lib/gl_view.rb, line 74 def fit @manipulator.fit(@world_scene_graph) end
gl_display()
click to toggle source
# File lib/gl_view.rb, line 94 def gl_display() GL.DrawBuffer( GL::BACK ) GL.ClearColor(@bk_color[0],@bk_color[1],@bk_color[2],@bk_color[3]) GL.Clear(GL::GL_COLOR_BUFFER_BIT | GL::GL_DEPTH_BUFFER_BIT) return if(@camera.nil? or @light.nil?) GL.Enable(GL::GL_DEPTH_TEST) @camera.set_projection_for_world_scene gl_display_world_scene_graph() GL.Disable(GL::GL_DEPTH_TEST) @camera.set_projection_for_camera_scene gl_display_camera_scene_graph() @compass.gl_display(self) end
gl_display_camera_scene_graph()
click to toggle source
# File lib/gl_view.rb, line 124 def gl_display_camera_scene_graph() return if(@camera_scene_graph.nil?) GL.MatrixMode(GL::GL_MODELVIEW) GL.PushMatrix() GL.LoadIdentity() GLU.LookAt(0, 0, 1, 0, 0, 0, 0, 1, 0) @camera_scene_graph.gl_display(self) GL.PopMatrix() end
gl_display_world_scene_graph()
click to toggle source
users do not need to user them
¶ ↑
# File lib/gl_view.rb, line 112 def gl_display_world_scene_graph() return if(@world_scene_graph.nil?) GL.MatrixMode(GL::GL_MODELVIEW) GL.PushMatrix() GL.LoadIdentity() @camera.apply_position() @camera.apply_attitude() @light.gl_display() @world_scene_graph.gl_display(self) GL.PopMatrix() end
mouse_move(&block)
click to toggle source
# File lib/gl_view.rb, line 82 def mouse_move(&block) @mouse_move_proc = block end
mouse_move_process(x,y)
click to toggle source
# File lib/gl_view.rb, line 151 def mouse_move_process(x,y) @mouse_move_proc.call(self, x,y) if( @mouse_move_proc != nil) picking_in_progress = @picker.motion(x, y) if(picking_in_progress) return false end return @manipulator.motion(x, y) end
mouse_press(&block)
click to toggle source
# File lib/gl_view.rb, line 86 def mouse_press(&block) @mouse_press_proc = block end
mouse_press_process(button, x, y)
click to toggle source
# File lib/gl_view.rb, line 139 def mouse_press_process(button, x, y) @mouse_press_proc.call(self, button, x, y) if( @mouse_press_proc != nil) @manipulator.mouse(button, GLUT::GLUT_DOWN, x, y) @picker.mouse(button, GLUT::GLUT_DOWN, x, y) end
mouse_release(&block)
click to toggle source
# File lib/gl_view.rb, line 90 def mouse_release(&block) @mouse_release_proc = block end
mouse_release_process(button, x, y)
click to toggle source
# File lib/gl_view.rb, line 145 def mouse_release_process(button, x, y) @mouse_release_proc.call(self, button, x, y) if( @mouse_release_proc != nil) @manipulator.mouse(button, GLUT::GLUT_UP, x, y) @picker.mouse(button, GLUT::GLUT_UP, x, y) end
reshape(w,h)
click to toggle source
# File lib/gl_view.rb, line 134 def reshape(w,h) @camera.reshape(w,h) @compass.update end
sync_to(target_view)
click to toggle source
# File lib/gl_view.rb, line 48 def sync_to target_view @world_scene_graph = target_view.world_scene_graph end