indexing description: "A EiffelMedia Vizualize axample" date: "$Date$" revision: "$Revision$" class BOX_SCENE inherit EM_ALIGNMENT_CONSTANTS EM_SHARED_VIZ_OPTIONS EM3D_ORTHO_SCENE redefine draw3d, handle_key_down_event end DOUBLE_MATH export {NONE} all end create make feature {NONE} -- Access orthographic_projection: BOOLEAN -- Use orthographic projection? scale: DOUBLE -- Scale factor angles: EM_VECTOR2D -- Angles by which exhibit will be rotated exhibits: ARRAY [EXHIBIT_BOX] is -- All exhibits once Result := << create {EXHIBIT_HELP_BOX}.make, create {EXHIBIT_TEXT_BOX}.make, create {EXHIBIT_VHD_BOX}.make, create {EXHIBIT_TABLE_BOX}.make, create {EXHIBIT_DECORATOR_BOX}.make, create {EXHIBIT_CANDY_BOX}.make, create {EXHIBIT_DIAGRAMS_BOX}.make, create {EXHIBIT_FIN_BOX}.make >> end exhibit_index: INTEGER -- Index of current exhibit shown exhibit: EXHIBIT_BOX is -- Current exhibit shown do Result := exhibits @ exhibit_index end feature {NONE} -- Initialization make -- create the scene do make_scene -- Set OpenGL near and far plane. Remember that the default OpenGL -- coordinate system has its z-axis towards the viewer. Thus the -- near plane is behind the viewer here for orthographic projections, while -- the far plane is in front. ortho_z_near := -1000 ortho_z_far := 1000 scale := 1.0 exhibit_index := exhibits.lower end feature {NONE} -- Keyboard handling handle_key_down_event (an_event: EM_KEYBOARD_EVENT) is -- Handle keyboard events local old_index: like exhibit_index do old_index := exhibit_index if an_event.key = an_event.sdlk_space then -- Advance one page exhibit_index := exhibit_index + 1 elseif an_event.key = an_event.sdlk_backspace then -- Go back one page exhibit_index := exhibit_index - 1 elseif an_event.key = an_event.sdlk_h then -- Go to help page exhibit_index := exhibits.lower elseif an_event.key = an_event.sdlk_escape then -- Quit example quit elseif an_event.key = an_event.sdlk_left then -- Rotate around y-axis angles.add ([0, 10]) elseif an_event.key = an_event.sdlk_right then -- Ditto, but other direction angles.add ([0, -10]) elseif an_event.key = an_event.sdlk_up then -- Rotate around x-axis angles.add ([10, 0]) elseif an_event.key = an_event.sdlk_down then -- Ditto, but other direction angles.add ([-10, 0]) elseif an_event.key = an_event.sdlk_pageup then scale := scale * 1.1 elseif an_event.key = an_event.sdlk_pagedown then scale := scale / 1.1 elseif an_event.key = an_event.sdlk_a then -- Animate current exhibit start_animating (exhibit) elseif an_event.key = an_event.sdlk_s then -- Stop animating current exhibit stop_animating (exhibit) elseif an_event.key = an_event.sdlk_d then -- Toggle debugging hints Viz_options.set_debug_gfx (not Viz_options.debug_gfx) elseif an_event.key = an_event.sdlk_q then -- Toggle antialiasing Viz_options.set_use_antialiasing (not Viz_options.use_antialiasing) elseif an_event.key = an_event.sdlk_o then -- Toggle orthographic projection orthographic_projection := not orthographic_projection elseif an_event.key = an_event.sdlk_p then -- Toggle point snapping Viz_options.set_use_point_snapping (not Viz_options.use_point_snapping) end -- Make sure index is valid if exhibit_index > exhibits.upper then -- exhibit_index := exhibits.lower exhibit_index := exhibits.upper end if exhibit_index < exhibits.lower then -- exhibit_index := exhibits.upper exhibit_index := exhibits.lower end -- Stop animating if not visible anymore if old_index /= exhibit_index then stop_animating (exhibits.item (old_index)) end end feature {NONE} -- Rendering draw3d is -- Don't draw anything 3d do end draw2d (w, h: DOUBLE) -- Do the drawing local frame: EM_VIZ_BOX_FRAME [EXHIBIT_BOX] cframe: EM_VIZ_COORDINATE_FRAME do -- Update if neccessary if Viz_options.needs_update then exhibit.deep_expire Viz_options.update end create frame.make_for_opengl_2d (exhibit) -- Set up orthographic projection if neccessary if orthographic_projection then create cframe.make_unit cframe.set_z_axis ([0.4, -0.4, 0.7]) frame.concatenate (cframe) end -- Translate to center of viewport frame.translated (w*0.5, h*0.5, 0.0) -- Rotate frame.rotated (angles.y, 0, 1, 0) frame.rotated (angles.x, 1, 0, 0) frame.scaled (scale, scale, scale) -- Draw exhibit at center of viewport frame.translated (-0.5*exhibit.width, -0.5*exhibit.height, 0.0) frame.draw end end