1. with Ada.Numerics.Generic_Elementary_Functions; 
  2. with Ada.Text_IO; 
  3.  
  4. package GL.Math is 
  5.  
  6.   package REF is new Ada.Numerics.Generic_Elementary_Functions (Double); 
  7.   package RIO is new Ada.Text_IO.Float_IO                      (Double); 
  8.  
  9.   ------------- 
  10.   -- Vectors -- 
  11.   ------------- 
  12.  
  13.   function "*" (l : Double; v : Double_Vector_3D) return Double_Vector_3D; 
  14.   pragma Inline ("*"); 
  15.  
  16.   function "*" (v : Double_Vector_3D; l : Double) return Double_Vector_3D; 
  17.   pragma Inline ("*"); 
  18.  
  19.   function "+" (a, b : Double_Vector_3D) return Double_Vector_3D; 
  20.   pragma Inline ("+"); 
  21.  
  22.   function "-" (a : Double_Vector_3D) return Double_Vector_3D; 
  23.   pragma Inline ("-"); 
  24.  
  25.   function "-" (a, b : Double_Vector_3D) return Double_Vector_3D; 
  26.   pragma Inline ("-"); 
  27.  
  28.   function "*" (a, b : Double_Vector_3D) return Double;      -- dot product 
  29.   pragma Inline ("*"); 
  30.  
  31.   function "*" (a, b : Double_Vector_3D) return Double_Vector_3D; -- cross product 
  32.   pragma Inline ("*"); 
  33.  
  34.   function Norm (a : Double_Vector_3D) return Double; 
  35.   pragma Inline (Norm); 
  36.  
  37.   function Norm2 (a : Double_Vector_3D) return Double; 
  38.   pragma Inline (Norm2); 
  39.  
  40.   function Normalized (a : Double_Vector_3D) return Double_Vector_3D; 
  41.  
  42.   type Vector_4D is array (0 .. 3) of Double; 
  43.  
  44.    -- Angles 
  45.    -- 
  46.  
  47.    function Angle (Point_1, Point_2, Point_3  : Double_Vector_3D) return Double; 
  48.    -- 
  49.    -- returns the angle between the vector Point_1 to Point_2 and the vector Point_3 to Point_2. 
  50.  
  51.    function to_Degrees (Radians  : Double) return Double; 
  52.    function to_Radians (Degrees  : Double) return Double; 
  53.  
  54.   -------------- 
  55.   -- Matrices -- 
  56.   -------------- 
  57.  
  58.   type Matrix    is array (Positive range <>, Positive range <>) of aliased Double; 
  59.   type Matrix_33 is new Matrix (1 .. 3, 1 .. 3); 
  60.   type Matrix_44 is new Matrix (1 .. 4, 1 .. 4); 
  61.   -- type Matrix_44 is array (0 .. 3, 0 .. 3) of aliased Double; -- for GL.MultMatrix 
  62.   pragma Convention (Fortran, Matrix_44);                 -- GL stores matrices columnwise   -- tbd : use same convention for other matrices ? 
  63.  
  64.   Id_33  : constant Matrix_33 := ((1.0, 0.0, 0.0), 
  65.                                 (0.0, 1.0, 0.0), 
  66.                                 (0.0, 0.0, 1.0)); 
  67.  
  68.   function "*" (A, B : Matrix_33) return Matrix_33; 
  69.  
  70.   function "*" (A : Matrix_33; x : Double_Vector_3D) return Double_Vector_3D; 
  71.   function "*" (A : Matrix_44; x : Double_Vector_3D) return Double_Vector_3D; 
  72.   function "*" (A : Matrix_44; x : Double_Vector_3D) return Vector_4D; 
  73.  
  74.   function Transpose (A : Matrix_33) return Matrix_33; 
  75.   function Transpose (A : Matrix_44) return Matrix_44; 
  76.  
  77.   function Det (A : Matrix_33) return Double; 
  78.  
  79.   function XYZ_rotation (ax, ay, az : Double) return Matrix_33; 
  80.  
  81.   function XYZ_rotation (v : Double_Vector_3D) return Matrix_33; 
  82.  
  83.   -- Gives a rotation matrix that corresponds to look into a certain 
  84.   -- direction. Camera swing rotation is arbitrary. 
  85.   -- Left - multiply by XYZ_Rotation (0.0, 0.0, az) to correct it. 
  86.   function Look_at (direction : Double_Vector_3D) return Matrix_33; 
  87.  
  88.    function Look_at (eye, center, up  : Double_Vector_3D) return Matrix_33; 
  89.  
  90.   -- This is for correcting cumulation of small computational 
  91.   -- errors, making the rotation matrix no more orthogonal 
  92.   procedure Re_Orthonormalize (M : in out Matrix_33); 
  93.  
  94.   -- Right - multiply current matrix by A 
  95.   procedure Multiply_GL_Matrix (A : Matrix_33); 
  96.  
  97.   -- Impose A as current matrix 
  98.   procedure Set_GL_Matrix (A : Matrix_33); 
  99.  
  100.   -- For replacing the " = 0.0" test which is a Bad Thing 
  101.   function Almost_zero (x : Double) return Boolean; 
  102.   pragma Inline (Almost_zero); 
  103.   function Almost_zero (x : GL.C_Float) return Boolean; 
  104.   pragma Inline (Almost_zero); 
  105.  
  106.    function Sub_Matrix (Self               : Matrix; 
  107.                         start_Row, end_Row : Positive; 
  108.                         start_Col, end_Col : Positive) return Matrix; 
  109.  
  110. end GL.Math;