indexing description: "[ An example scene representing a nice OpenGl Scene with some fog, light and nice cubes ]" date: "$Date$" revision: "$Revision$" class CUBE inherit EM_3D_COMPONENT -- redefine -- prepare_drawing -- end EM_SHARED_BITMAP_FACTORY EM_TIME_SINGLETON EMGL_BASIC_RENDERER EMGL_TEXGEN SINGLE_MATH export {NONE} all end create make feature {NONE} -- Initialisation make is -- Initialise default values. do make_3d_component create source_pos.make_xyz (0,0,0) create destination_pos.make_xyz (0,0,0) create direction.make_xyz (1,0,0) init_shapes emgl_line_width (2.0) -- init fog emgl_enable (em_gl_fog) emgl_fogi (em_gl_fog_mode, em_gl_exp2) emgl_fogf (Em_gl_fog_density, 0.35) emgl_fogf (em_gl_fog_start, 2.0) emgl_fogf (em_gl_fog_end, 6.0) emgl_hint (Em_gl_fog_hint, Em_gl_nicest) -- init lightning emgl_enable (em_gl_light0) emgl_enable (em_gl_lighting) emgl_enable (em_gl_blend) emgl_blend_func (em_gl_src_alpha, em_gl_one) -- init textures emgl_enable (em_gl_texture_2d) emgl_enable (em_gl_color_material) -- init environment mapping emgl_enable (em_gl_texture_gen_s) emgl_enable (em_gl_texture_gen_t) emgl_tex_geni (em_gl_s, em_gl_texture_gen_mode, em_gl_sphere_map) emgl_tex_geni (em_gl_t, em_gl_texture_gen_mode, em_gl_sphere_map) emgl_hint (em_gl_perspective_correction_hint, em_gl_nicest) emgl_shade_model (em_gl_smooth) -- init depth buffer emgl_shade_model (em_gl_depth_test) emgl_depth_func (em_gl_lequal) -- set perspective set_field_of_view (60) set_min_view_distance (0.1) set_max_view_distance (100.0) end feature -- Initialization init_shapes is -- Init drawing list local pos_x, pos_y, pos_z: INTEGER do -- create display list display_list := emgl_gen_lists (1) emgl_new_list (display_list, em_gl_compile) -- put cubes into the list from pos_x := 0 until pos_x = max_cube loop from pos_y := 0 until pos_y = max_cube loop from pos_z := 0 until pos_z = max_cube loop emgl_push_matrix emgl_translatef (pos_x, pos_y, pos_z) emgl_translatef (-4.5, -4.5, -4.5) render_cube emgl_pop_matrix pos_z := pos_z + 1 end pos_y := pos_y + 1 end pos_x := pos_x + 1 end emgl_end_list end feature -- Drawing -- prepare_drawing is -- Prepare for drawing `Current'. -- do -- if width > 0 and height > 0 then -- Reset depth buffer -- emgl_clear (Em_gl_depth_buffer_bit) -- Opengl settings -- emgl_enable (Em_gl_depth_test) -- Enable antialiasing -- emgl_enable (Em_gl_line_smooth) -- emgl_hint (Em_gl_line_smooth, Em_gl_nicest) -- Setup the projection matrix -- emgl_matrix_mode (Em_gl_projection) -- emgl_load_identity -- emglu_perspective (field_of_view, width/height, min_view_distance, max_view_distance) -- Setup the model view matrix -- emgl_matrix_mode (Em_gl_modelview) -- emgl_load_identity -- end -- end draw is -- Draw Scene do last_redraw_time := actual_redraw_time actual_redraw_time := time.ticks / 2000 emgl_rotatef (actual_redraw_time * 7.0, 1, 0, 0) emgl_rotatef (actual_redraw_time * 8.0, 0, 1, 0) emgl_rotatef (actual_redraw_time * 9.0, 0, 0, 1) -- gl_translatef (0, 0, (actual_redraw_time - 0.5) * 3.0) emgl_translatef (vx,vy,0) emgl_color4f (0.0, 0.5, 1.0, 0.4) gl_bind_texture_external (em_gl_texture_2d, 0) emgl_call_list (display_list) emgl_color4f (0.0, 0.8, 0.8, 0.1); emgl_polygon_mode (em_gl_front_and_back, em_gl_line) emgl_call_list (display_list) emgl_polygon_mode (em_gl_front_and_back, em_gl_fill) end feature {NONE} -- Implementation vx, vy: DOUBLE render_cube is -- Render a single cube with normals do emgl_begin (em_gl_quads) emgl_normal3f (1.0, 0.0, 0.0) emgl_tex_coord2f (0.0, 0.0); emgl_vertex3f ( 0.25, -0.25, -0.25) emgl_tex_coord2f (1.0, 0.0); emgl_vertex3f ( 0.25, 0.25, -0.25) emgl_tex_coord2f (1.0, 1.0); emgl_vertex3f ( 0.25, 0.25, 0.25) emgl_tex_coord2f (0.0, 1.0); emgl_vertex3f ( 0.25, -0.25, 0.25) emgl_normal3f (-1.0, 0.0, 0.0) emgl_tex_coord2f (0.0, 1.0); emgl_vertex3f (-0.25, -0.25, 0.25) emgl_tex_coord2f (0.0, 0.0); emgl_vertex3f (-0.25, -0.25, -0.25) emgl_tex_coord2f (1.0, 0.0); emgl_vertex3f (-0.25, 0.25, -0.25) emgl_tex_coord2f (1.0, 1.0); emgl_vertex3f (-0.25, 0.25, 0.25) emgl_normal3f (0.0, 0.0, -1.0) emgl_tex_coord2f (0.0, 1.0); emgl_vertex3f (-0.25, 0.25, -0.25) emgl_tex_coord2f (1.0, 1.0); emgl_vertex3f ( 0.25, 0.25, -0.25) emgl_tex_coord2f (1.0, 0.0); emgl_vertex3f ( 0.25, -0.25, -0.25) emgl_tex_coord2f (0.0, 0.0); emgl_vertex3f (-0.25, -0.25, -0.25) emgl_normal3f (0.0, 0.0, 1.0) emgl_tex_coord2f (0.0, 0.0); emgl_vertex3f (-0.25, -0.25, 0.25) emgl_tex_coord2f (0.0, 1.0); emgl_vertex3f (-0.25, 0.25, 0.25) emgl_tex_coord2f (1.0, 1.0); emgl_vertex3f ( 0.25, 0.25, 0.25) emgl_tex_coord2f (1.0, 0.0); emgl_vertex3f ( 0.25, -0.25, 0.25) emgl_normal3f (0.0, 1.0, 0.0) emgl_tex_coord2f (0.0, 1.0); emgl_vertex3f ( 0.25, 0.25, -0.25) emgl_tex_coord2f (1.0, 1.0); emgl_vertex3f ( 0.25, 0.25, 0.25) emgl_tex_coord2f (1.0, 0.0); emgl_vertex3f (-0.25, 0.25, 0.25) emgl_tex_coord2f (0.0, 0.0); emgl_vertex3f (-0.25, 0.25, -0.25) emgl_normal3f (0.0, -1.0, 0.0) emgl_tex_coord2f (1.0, 1.0); emgl_vertex3f ( 0.25, -0.25, 0.25) emgl_tex_coord2f (1.0, 0.0); emgl_vertex3f (-0.25, -0.25, 0.25) emgl_tex_coord2f (0.0, 0.0); emgl_vertex3f (-0.25, -0.25, -0.25) emgl_tex_coord2f (0.0, 1.0); emgl_vertex3f ( 0.25, -0.25, -0.25) emgl_end end display_list: INTEGER -- Identifier for display list max_cube: INTEGER is 10 -- maximal number of cubes to be drawn last_redraw_time, actual_redraw_time: DOUBLE -- tariable for time step: DOUBLE -- for camera position source_pos, destination_pos: GL_VECTOR_3D [DOUBLE] -- source and destionation position direction: GL_VECTOR_3D [DOUBLE] -- direction the camera is looking end