Class: Disp3D::GLView
- Inherits:
-
Object
- Object
- Disp3D::GLView
- Defined in:
- lib/gl_view.rb
Overview
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)
Direct Known Subclasses
Instance Attribute Summary collapse
-
#bk_color ⇒ Object
Returns the value of attribute bk_color.
-
#camera ⇒ Object
readonly
Returns the value of attribute camera.
-
#camera_scene_graph ⇒ Object
readonly
Returns the value of attribute camera_scene_graph.
-
#light ⇒ Object
readonly
Returns the value of attribute light.
-
#manipulator ⇒ Object
readonly
Returns the value of attribute manipulator.
-
#picker ⇒ Object
readonly
Returns the value of attribute picker.
-
#world_scene_graph ⇒ Object
readonly
Returns the value of attribute world_scene_graph.
Instance Method Summary collapse
- #capture ⇒ Object
- #centering ⇒ Object
- #fit ⇒ Object
- #gl_display ⇒ Object
- #gl_display_camera_scene_graph ⇒ Object
-
#gl_display_world_scene_graph ⇒ Object
users do not need to user them =====================================.
-
#initialize(width, height) ⇒ GLView
constructor
A new instance of GLView.
- #mouse_move(&block) ⇒ Object
- #mouse_move_process(x, y) ⇒ Object
- #mouse_press(&block) ⇒ Object
- #mouse_press_process(button, x, y) ⇒ Object
- #mouse_release(&block) ⇒ Object
- #mouse_release_process(button, x, y) ⇒ Object
- #reshape(w, h) ⇒ Object
- #sync_to(target_view) ⇒ Object
Constructor Details
#initialize(width, height) ⇒ GLView
Returns a new instance of GLView.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# 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 |
Instance Attribute Details
#bk_color ⇒ Object
Returns the value of attribute bk_color.
17 18 19 |
# File 'lib/gl_view.rb', line 17 def bk_color @bk_color end |
#camera ⇒ Object (readonly)
Returns the value of attribute camera.
12 13 14 |
# File 'lib/gl_view.rb', line 12 def camera @camera end |
#camera_scene_graph ⇒ Object (readonly)
Returns the value of attribute camera_scene_graph.
11 12 13 |
# File 'lib/gl_view.rb', line 11 def camera_scene_graph @camera_scene_graph end |
#light ⇒ Object (readonly)
Returns the value of attribute light.
14 15 16 |
# File 'lib/gl_view.rb', line 14 def light @light end |
#manipulator ⇒ Object (readonly)
Returns the value of attribute manipulator.
13 14 15 |
# File 'lib/gl_view.rb', line 13 def manipulator @manipulator end |
#picker ⇒ Object (readonly)
Returns the value of attribute picker.
15 16 17 |
# File 'lib/gl_view.rb', line 15 def picker @picker end |
#world_scene_graph ⇒ Object (readonly)
Returns the value of attribute world_scene_graph.
10 11 12 |
# File 'lib/gl_view.rb', line 10 def world_scene_graph @world_scene_graph end |
Instance Method Details
#capture ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/gl_view.rb', line 52 def capture dmy,dmy, w, h = @camera. 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 ⇒ Object
78 79 80 |
# File 'lib/gl_view.rb', line 78 def centering @manipulator.centering(@world_scene_graph) end |
#fit ⇒ Object
74 75 76 |
# File 'lib/gl_view.rb', line 74 def fit @manipulator.fit(@world_scene_graph) end |
#gl_display ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# 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 ⇒ Object
124 125 126 127 128 129 130 131 132 |
# 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 ⇒ Object
users do not need to user them
112 113 114 115 116 117 118 119 120 121 122 |
# 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) ⇒ Object
82 83 84 |
# File 'lib/gl_view.rb', line 82 def mouse_move(&block) @mouse_move_proc = block end |
#mouse_move_process(x, y) ⇒ Object
151 152 153 154 155 156 157 158 |
# 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) ⇒ Object
86 87 88 |
# File 'lib/gl_view.rb', line 86 def mouse_press(&block) @mouse_press_proc = block end |
#mouse_press_process(button, x, y) ⇒ Object
139 140 141 142 143 |
# File 'lib/gl_view.rb', line 139 def mouse_press_process(, x, y) @mouse_press_proc.call(self, , x, y) if( @mouse_press_proc != nil) @manipulator.mouse(, GLUT::GLUT_DOWN, x, y) @picker.mouse(, GLUT::GLUT_DOWN, x, y) end |
#mouse_release(&block) ⇒ Object
90 91 92 |
# File 'lib/gl_view.rb', line 90 def mouse_release(&block) @mouse_release_proc = block end |
#mouse_release_process(button, x, y) ⇒ Object
145 146 147 148 149 |
# File 'lib/gl_view.rb', line 145 def mouse_release_process(, x, y) @mouse_release_proc.call(self, , x, y) if( @mouse_release_proc != nil) @manipulator.mouse(, GLUT::GLUT_UP, x, y) @picker.mouse(, GLUT::GLUT_UP, x, y) end |
#reshape(w, h) ⇒ Object
134 135 136 137 |
# File 'lib/gl_view.rb', line 134 def reshape(w,h) @camera.reshape(w,h) @compass.update end |
#sync_to(target_view) ⇒ Object
48 49 50 |
# File 'lib/gl_view.rb', line 48 def sync_to target_view @world_scene_graph = target_view.world_scene_graph end |