1. package body GL.Frustums is 
  2.  
  3.    procedure Normalise (the_Planes  : in out plane_Array) is 
  4.  
  5.       use GL.Geometry; 
  6.  
  7.    begin 
  8.       for Each in the_Planes'Range loop 
  9.          Normalise (the_Planes (Each)); 
  10.       end loop; 
  11.    end Normalise; 
  12.  
  13.    function Current_Planes return plane_Array  is 
  14.  
  15.       the_Planes  : plane_Array; 
  16.  
  17.       Proj : array (0 .. 15) of aliased GL.C_Float; 
  18.       Modl : array (0 .. 15) of aliased GL.C_Float; 
  19.       Clip : array (0 .. 15) of GL.C_Float; 
  20.  
  21.    begin 
  22.  
  23.       GL.GetFloatv (GL.PROJECTION_MATRIX, Proj (0)'Unchecked_Access);      -- Get the current PROJECTION matrix from OpenGL 
  24.       GL.GetFloatv (GL.MODELVIEW_MATRIX,  Modl (0)'Unchecked_Access);      -- Get the current MODELVIEW  matrix from OpenGL 
  25.  
  26.       -- Combine the two matrices (multiply projection by modelview) 
  27.       -- 
  28.       Clip (0) := Modl (0) * Proj (0) + Modl (1) * Proj (4) + Modl (2) * Proj (8) + Modl (3) * Proj (12); 
  29.       Clip (1) := Modl (0) * Proj (1) + Modl (1) * Proj (5) + Modl (2) * Proj (9) + Modl (3) * Proj (13); 
  30.       Clip (2) := Modl (0) * Proj (2) + Modl (1) * Proj (6) + Modl (2) * Proj (10) + Modl (3) * Proj (14); 
  31.       Clip (3) := Modl (0) * Proj (3) + Modl (1) * Proj (7) + Modl (2) * Proj (11) + Modl (3) * Proj (15); 
  32.  
  33.       Clip (4) := Modl (4) * Proj (0) + Modl (5) * Proj (4) + Modl (6) * Proj (8) + Modl (7) * Proj (12); 
  34.       Clip (5) := Modl (4) * Proj (1) + Modl (5) * Proj (5) + Modl (6) * Proj (9) + Modl (7) * Proj (13); 
  35.       Clip (6) := Modl (4) * Proj (2) + Modl (5) * Proj (6) + Modl (6) * Proj (10) + Modl (7) * Proj (14); 
  36.       Clip (7) := Modl (4) * Proj (3) + Modl (5) * Proj (7) + Modl (6) * Proj (11) + Modl (7) * Proj (15); 
  37.  
  38.       Clip (8) := Modl (8) * Proj (0) + Modl (9) * Proj (4) + Modl (10) * Proj (8) + Modl (11) * Proj (12); 
  39.       Clip (9) := Modl (8) * Proj (1) + Modl (9) * Proj (5) + Modl (10) * Proj (9) + Modl (11) * Proj (13); 
  40.       Clip (10) := Modl (8) * Proj (2) + Modl (9) * Proj (6) + Modl (10) * Proj (10) + Modl (11) * Proj (14); 
  41.       Clip (11) := Modl (8) * Proj (3) + Modl (9) * Proj (7) + Modl (10) * Proj (11) + Modl (11) * Proj (15); 
  42.  
  43.       Clip (12) := Modl (12) * Proj (0) + Modl (13) * Proj (4) + Modl (14) * Proj (8) + Modl (15) * Proj (12); 
  44.       Clip (13) := Modl (12) * Proj (1) + Modl (13) * Proj (5) + Modl (14) * Proj (9) + Modl (15) * Proj (13); 
  45.       Clip (14) := Modl (12) * Proj (2) + Modl (13) * Proj (6) + Modl (14) * Proj (10) + Modl (15) * Proj (14); 
  46.       Clip (15) := Modl (12) * Proj (3) + Modl (13) * Proj (7) + Modl (14) * Proj (11) + Modl (15) * Proj (15); 
  47.  
  48.       -- Extract the RIGHT plane 
  49.       the_Planes (Right) (0) := GL.Double (Clip (3) - Clip (0)); 
  50.       the_Planes (Right) (1) := GL.Double (Clip (7) - Clip (4)); 
  51.       the_Planes (Right) (2) := GL.Double (Clip (11) - Clip (8)); 
  52.       the_Planes (Right) (3) := GL.Double (Clip (15) - Clip (12)); 
  53.  
  54.       -- Extract the LEFT plane 
  55.       the_Planes (Left) (0) := GL.Double (Clip (3) + Clip (0)); 
  56.       the_Planes (Left) (1) := GL.Double (Clip (7) + Clip (4)); 
  57.       the_Planes (Left) (2) := GL.Double (Clip (11) + Clip (8)); 
  58.       the_Planes (Left) (3) := GL.Double (Clip (15) + Clip (12)); 
  59.  
  60.       -- Extract the LOW plane 
  61.       the_Planes (Low) (0) := GL.Double (Clip (3) + Clip (1)); 
  62.       the_Planes (Low) (1) := GL.Double (Clip (7) + Clip (5)); 
  63.       the_Planes (Low) (2) := GL.Double (Clip (11) + Clip (9)); 
  64.       the_Planes (Low) (3) := GL.Double (Clip (15) + Clip (13)); 
  65.  
  66.       -- Extract the HIGH plane 
  67.       the_Planes (High) (0) := GL.Double (Clip (3) - Clip (1)); 
  68.       the_Planes (High) (1) := GL.Double (Clip (7) - Clip (5)); 
  69.       the_Planes (High) (2) := GL.Double (Clip (11) - Clip (9)); 
  70.       the_Planes (High) (3) := GL.Double (Clip (15) - Clip (13)); 
  71.  
  72.       -- Extract the FAR plane 
  73.       the_Planes (Far) (0) := GL.Double (Clip (3) - Clip (2)); 
  74.       the_Planes (Far) (1) := GL.Double (Clip (7) - Clip (6)); 
  75.       the_Planes (Far) (2) := GL.Double (Clip (11) - Clip (10)); 
  76.       the_Planes (Far) (3) := GL.Double (Clip (15) - Clip (14)); 
  77.  
  78.       -- Extract the NEAR plane 
  79.       the_Planes (Near) (0) := GL.Double (Clip (3) + Clip (2)); 
  80.       the_Planes (Near) (1) := GL.Double (Clip (7) + Clip (6)); 
  81.       the_Planes (Near) (2) := GL.Double (Clip (11) + Clip (10)); 
  82.       the_Planes (Near) (3) := GL.Double (Clip (15) + Clip (14)); 
  83.  
  84.       Normalise (the_Planes); 
  85.       return the_Planes; 
  86.    end Current_Planes; 
  87.  
  88. end GL.Frustums;