indexing description: "[ Small cubes for a big special effect. This class is part of the XAE Extended Adventure Engine Project. ]" author: "Ralph Wiedemeier, ralphw@student.ethz.ch" date: "$Date$" revision: "$Revision$" class GUI_SFX_SMALL_CUBE inherit OPEN_GL_LIBRARY export {NONE} all end DOUBLE_MATH export {NONE} all undefine default_create end create {GUI_TRANSITION} make_with_pos feature -- Initialization -- make_with_pos (a_row: INTEGER; a_src_col: INTEGER; a_dst_col: INTEGER; a_src_tex: INTEGER; a_dst_tex: INTEGER) is make_with_pos (a_row: INTEGER; a_src_col: INTEGER; a_dst_col: INTEGER; a_src_tex: EM3D_TEXTURE_2D[ EMGL_FORMAT_RGBA ]; a_dst_tex: EM3D_TEXTURE_2D[ EMGL_FORMAT_RGBA ]) is -- create new cube with given source and destination positions do row := a_row src_col := a_src_col dst_col := a_dst_col -- src_texture_id := a_src_tex -- dst_texture_id := a_dst_tex src_texture := a_src_tex dst_texture := a_dst_tex generate_gl_script end feature -- Operation draw (time: DOUBLE) is -- draw cube (time from 0..1) local x, y, z: DOUBLE do x := smooth_05 (1 - time) * x_target y := y_target z := smooth_05 (time) * z_target emgl_push_matrix emgl_translated (x, y, z) -- gl_call_list (script_id) display_list.call_list emgl_pop_matrix end feature {NONE} -- Implementation generate_gl_script is -- local tex_width, tex_height: DOUBLE src_tex_u, dst_tex_u, tex_v: DOUBLE cube_width, cube_height: DOUBLE do tex_width := 1 / columns tex_height := 1 / rows src_tex_u := src_col * tex_width dst_tex_u := 1 - dst_col * tex_width tex_v := row * tex_height cube_width := width / columns cube_height := height / rows x_target := cube_width * src_col y_target := cube_height * row z_target := -cube_width * dst_col -- script_id := gl_gen_lists (1) -- gl_new_list (script_id, EM_GL_COMPILE) create display_list display_list.new_list_compile -- macro_bind_texture_antialiased_replace (src_texture_id) macro_bind_texture_antialiased_replace (src_texture) -- CHANGES em prepended emgl_begin (EM_gl_quads) -- Front Face (SOURCE) emgl_tex_coord2d (src_tex_u, tex_v) emgl_vertex3d (0, 0, 0) emgl_tex_coord2d (src_tex_u + tex_width, tex_v) emgl_vertex3d (cube_width, 0, 0) emgl_tex_coord2d (src_tex_u + tex_width, tex_v + tex_height) emgl_vertex3d (cube_width, cube_height, 0) emgl_tex_coord2d (src_tex_u, tex_v + tex_height) emgl_vertex3d (0, cube_height, 0) -- Back Face emgl_tex_coord2d (src_tex_u, tex_v) emgl_vertex3d (cube_width, 0, -cube_width) emgl_tex_coord2d (src_tex_u + tex_width, tex_v) emgl_vertex3d (0, 0, -cube_width) emgl_tex_coord2d (src_tex_u + tex_width, tex_v + tex_height) emgl_vertex3d (0, cube_height, -cube_width) emgl_tex_coord2d (src_tex_u, tex_v + tex_height) emgl_vertex3d (cube_width, cube_height, -cube_width) emgl_end src_texture.unbind -- macro_bind_texture_antialiased_replace (dst_texture_id) macro_bind_texture_antialiased_replace (dst_texture) emgl_begin (EM_gl_quads) -- Left Face emgl_tex_coord2d (dst_tex_u, tex_v) emgl_vertex3d (0, 0, 0) emgl_tex_coord2d (dst_tex_u - tex_width, tex_v) emgl_vertex3d (0, 0, -cube_width) emgl_tex_coord2d (dst_tex_u - tex_width, tex_v + tex_height) emgl_vertex3d (0, cube_height, -cube_width) emgl_tex_coord2d (dst_tex_u, tex_v + tex_height) emgl_vertex3d (0, cube_height, 0) -- Right Face (TARGET) emgl_tex_coord2d (dst_tex_u, tex_v) emgl_vertex3d (cube_width, 0, -cube_width) emgl_tex_coord2d (dst_tex_u - tex_width, tex_v) emgl_vertex3d (cube_width, 0, 0) emgl_tex_coord2d (dst_tex_u - tex_width, tex_v + tex_height) emgl_vertex3d (cube_width, cube_height, 0) emgl_tex_coord2d (dst_tex_u, tex_v + tex_height) emgl_vertex3d (cube_width, cube_height, -cube_width) emgl_end dst_texture.unbind macro_disable_texture_mapping emgl_begin (EM_gl_quads) emgl_color4d (0.1, 0.1, 0.2, 1) -- Top Face emgl_vertex3d (0, cube_height, 0) emgl_vertex3d (cube_width, cube_height, 0) emgl_vertex3d (cube_width, cube_height, -cube_width) emgl_vertex3d (0, cube_height, -cube_width) -- Bottom Face emgl_vertex3d (0, 0, 0) emgl_vertex3d (cube_width, 0, 0) emgl_vertex3d (cube_width, 0, -cube_width) emgl_vertex3d (0, 0, -cube_width) emgl_end emgl_end_list end smooth (t: DOUBLE): DOUBLE is -- Get smooth transition (0..1) do result := 3*t*t - 2*t*t*t end smooth_05 (t: DOUBLE): DOUBLE is -- Get smooth transition (0..0.5) local s: DOUBLE do s := t * 2 if s > 1 then s := 1 end result := 3*s*s - 2*s*s*s end -- script_id: INTEGER -- src_texture_id: INTEGER -- dst_texture_id: INTEGER display_list: EMGL_DISPLAY_LIST src_texture: EM3D_TEXTURE_2D[ EMGL_FORMAT_RGBA ] dst_texture: EM3D_TEXTURE_2D[ EMGL_FORMAT_RGBA ] row: INTEGER src_col: INTEGER dst_col: INTEGER x_target: DOUBLE y_target: DOUBLE z_target: DOUBLE rows: INTEGER is 5 columns: INTEGER is 10 width: INTEGER is 1024 height: INTEGER is 512 end -- class GUI_SFX_SMALL_CUBE