indexing description: "In this tutorial we will cover the use of object selection" date: "$Date$" revision: "$Revision$" class SELECTION_SCENE inherit EM3D_TRACKBALL_SCENE rename make_scene as make redefine initialize_scene, handle_key_up_event, handle_mouse_motion_event, handle_mouse_button_down_event, handle_mouse_button_up_event, draw end create make feature -- Init initialize_scene is -- Build your scene graph local actor: EM3D_ACTOR main_light: EM3D_LIGHT do precursor -- In order to have some basic shading we need to add a light to the scene main_light := scene_manager.light.create_new_point ( "main light" ) -- To achieve a headlight effect we can attach the light to the camera node active_camera_node.attach_object ( main_light ) scene_manager.model_factory.load_model ( "data/monkey.x" ) actor := scene_manager.model_factory.new_model ( "data/monkey.x", scene_manager.world ) actor.selection_event.subscribe ( agent handle_selection( actor, ?, ? )) emgl_clear_color (0.1, 0.1,0.3,1) end feature -- events handle_selection( actor: EM3D_ACTOR; zn, zf: DOUBLE ) is -- An object has been selected do actor.translate ( [0.0,0.1,0.0] ) end handle_key_up_event( a_keyboard_event: EM_KEYBOARD_EVENT ) is -- Change the model when we press a key do if a_keyboard_event.key=a_keyboard_event.sdlk_escape then set_next_scene ( create {MAIN_SCENE}.make ) start_next_scene end end sx,sy: INTEGER ex,ey: INTEGER handle_mouse_motion_event (a_mouse_motion_event: EM_MOUSEMOTION_EVENT) is do Precursor {EM3D_TRACKBALL_SCENE}(a_mouse_motion_event) if a_mouse_motion_event.button_state_right then ex := a_mouse_motion_event.x ey := a_mouse_motion_event.y end end handle_mouse_button_down_event (a_mouse_button_event: EM_MOUSEBUTTON_EVENT) is do Precursor {EM3D_TRACKBALL_SCENE}(a_mouse_button_event) if a_mouse_button_event.is_right_button then sx := a_mouse_button_event.x sy := a_mouse_button_event.y ex := sx ey := sy in_selection := true end end handle_mouse_button_up_event (a_mouse_button_event: EM_MOUSEBUTTON_EVENT) is do Precursor {EM3D_TRACKBALL_SCENE}(a_mouse_button_event) if a_mouse_button_event.is_right_button then in_selection := false select_area( sx, sy, a_mouse_button_event.x, a_mouse_button_event.y ) end end feature --draw selection_renderer: EM3D_SELECTION_RENDERER is once create result.make ( 0x10000 ) end in_selection: BOOLEAN select_point( a_x, a_y: INTEGER ) is --select a small area around x,y do if active_camera/=void then active_camera.set_opengl end selection_renderer.begin_picking_select ( [a_x, a_y] , [2, 2] ) draw selection_renderer.end_select end select_area( a_x1, a_y1, a_x2, a_y2 : INTEGER ) is --select a rectangular area do if active_camera/=void then active_camera.set_opengl end selection_renderer.begin_area_select ( [a_x1, a_y1] , [a_x2, a_y2] ) draw selection_renderer.end_select end draw is -- We want to draw a nice selection box local viewport: EM_VECTOR4I do Precursor if in_selection then -- Set up 2D viewport := emgl_get_viewport emgl_matrix_mode( em_gl_projection) emgl_disable ( em_gl_lighting ) emgl_disable ( em_gl_cull_face ) emgl_push_matrix emgl_load_identity emgl_ortho ( viewport.x, viewport.z, viewport.w, viewport.y, -1, 1) emgl_matrix_mode( em_gl_modelview) emgl_push_matrix emgl_load_identity emgl_push_attrib( em_gl_enable_bit ) -- Draw the area -- Enable blending emgl_enable ( em_gl_blend ) emgl_blend_func ( em_gl_src_alpha, em_gl_one_minus_src_alpha) emgl_color4d ( 0, 0, 1, 0.25) emgl_begin( em_gl_quads ) emgl_vertex2d( sx, sy ) emgl_vertex2d( sx, ey ) emgl_vertex2d( ex, ey ) emgl_vertex2d( ex, sy ) emgl_end emgl_pop_attrib -- Reset 3D emgl_enable ( em_gl_cull_face ) emgl_matrix_mode( em_gl_projection) emgl_pop_matrix emgl_matrix_mode( em_gl_modelview) emgl_pop_matrix end end end