indexing description: "[ A projection helper used for transforming coordinates between the world space and the OpenGL projection. ]" date: "$Date$" revision: "$Revision$" class EM3D_PROJECTOR inherit EMGL_SETTINGS EMGL_VIEW export {NONE} all undefine default_create, is_equal, copy end EMGLU_VIEW export {NONE} all undefine default_create, is_equal, copy end EM_CONSTANTS EXCEPTIONS create make feature -- Initialization make is -- Create a new projector do create viewport.default_create create projection_matrix.default_create create modelview_matrix.default_create end feature -- Commands project (s: EM_VECTOR3D): EM_VECTOR3D is -- projects a point from the 3d space into the projection plane require input_not_void: s /= Void local status: INTEGER ox, oy, oz: DOUBLE do status := emglu_project(s.x, s.y, s.z, modelview_matrix, projection_matrix, viewport, $ox, $oy, $oz) if status = em_gl_true then oy := viewport.w - oy -- mirror at y axis Result := [ox, oy, oz] else Result := [0, 0, 0] raise("Error by projecting coordinates") end ensure output_not_void: Result /= Void end un_project (s: EM_VECTOR3D): EM_VECTOR3D is -- un-projects a point from the projection plane back into the 3d space require input_not_void: s /= Void local status: INTEGER ox, oy, oz: DOUBLE do status := emglu_un_project(s.x, s.y, s.z, modelview_matrix, projection_matrix, viewport, $ox, $oy, $oz) if status = em_gl_true then oy := viewport.w - oy -- mirror at y axis Result := [ox, oy, oz] else Result := [0, 0, 0] raise("Error by unprojecting coordinates") end ensure output_not_void: Result /= Void end feature -- Matrix setup set_matrices (a_modelview_matrix, a_projection_matrix: EM_MATRIX44) is -- Sets the local modelview / projection matrices do modelview_matrix := a_modelview_matrix projection_matrix := a_projection_matrix end set_viewport (a_viewport: EM_VECTOR4I) is -- sets the current viewport do viewport := a_viewport end load_from_opengl is -- Load current projection settings from OpenGL do viewport := emgl_get_viewport projection_matrix := emgl_get_projection_matrix modelview_matrix := emgl_get_modelview_matrix end feature {NONE} -- Implementation projection_matrix: EM_MATRIX44 modelview_matrix: EM_MATRIX44 viewport: EM_VECTOR4I end -- class EM3D_PROJECTOR