openglada_0.9.0_4deb7eff/src/interface/gl-algebra.ads

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
--  part of OpenGLAda, (c) 2017 Felix Krause
--  released under the terms of the MIT license, see the file "COPYING"

with Interfaces.C.Pointers;

with GL.Vectors;
with GL.Matrices;

generic
   type Element_Type is private;
   type Index_Type   is (<>);
   with function "+" (Left, Right : Element_Type) return Element_Type is <>;
   with function "-" (Left, Right : Element_Type) return Element_Type is <>;
   with function "-" (Left        : Element_Type) return Element_Type is <>;
   with function "*" (Left, Right : Element_Type) return Element_Type is <>;
   with function "/" (Left, Right : Element_Type) return Element_Type is <>;
   Null_Value, One_Value : Element_Type;
package GL.Algebra is
   pragma Preelaborate;

   -----------------------------------------------------------------------------
   --                              Vector types                               --
   -----------------------------------------------------------------------------

   package Vectors2 is new Vectors (Index_Type   => Index_2D,
                                    Element_Type => Element_Type);
   package Vectors3 is new Vectors (Index_Type   => Index_3D,
                                    Element_Type => Element_Type);
   package Vectors4 is new Vectors (Index_Type   => Index_Homogeneous,
                                    Element_Type => Element_Type);

   type Vector2 is new Vectors2.Vector;
   type Vector3 is new Vectors3.Vector;
   type Vector4 is new Vectors4.Vector;

   -- Conversion functions between vectors. Default values are:
   -- Z = 0, W = 1
   function To_Vector2 (Vector : Vector3) return Vector2;
   function To_Vector2 (Vector : Vector4) return Vector2;
   function To_Vector3 (Vector : Vector2) return Vector3;
   function To_Vector3 (Vector : Vector4) return Vector3;
   function To_Vector4 (Vector : Vector2) return Vector4;
   function To_Vector4 (Vector : Vector3) return Vector4;

   pragma Inline (To_Vector2);
   pragma Inline (To_Vector3);
   pragma Inline (To_Vector4);

   -----------------------------------------------------------------------------
   --                              Matrix types                               --
   -----------------------------------------------------------------------------

   package Matrices2 is new Matrices (Index_Type   => Index_2D,
                                      Element_Type => Element_Type,
                                      Vector_Type  => Vector2);
   package Matrices3 is new Matrices (Index_Type   => Index_3D,
                                      Element_Type => Element_Type,
                                      Vector_Type  => Vector3);
   package Matrices4 is new Matrices (Index_Type   => Index_Homogeneous,
                                      Element_Type => Element_Type,
                                      Vector_Type  => Vector4);

   type Matrix2 is new Matrices2.Matrix;
   type Matrix3 is new Matrices3.Matrix;
   type Matrix4 is new Matrices4.Matrix;

   Identity2 : constant Matrix2 := ((One_Value, Null_Value), (Null_Value, One_Value));
   Identity3 : constant Matrix3 := ((One_Value, Null_Value, Null_Value),
                                    (Null_Value, One_Value, Null_Value),
                                    (Null_Value, Null_Value, One_Value));
   Identity4 : constant Matrix4 := ((One_Value, Null_Value, Null_Value, Null_Value),
                                    (Null_Value, One_Value, Null_Value, Null_Value),
                                    (Null_Value, Null_Value, One_Value, Null_Value),
                                    (Null_Value, Null_Value, Null_Value, One_Value));

   -----------------------------------------------------------------------------
   --                               Array types                               --
   -----------------------------------------------------------------------------

   type Vector2_Array is array (Index_Type range <>) of aliased Vector2;
   type Vector3_Array is array (Index_Type range <>) of aliased Vector3;
   type Vector4_Array is array (Index_Type range <>) of aliased Vector4;

   type Matrix2_Array is array (Index_Type range <>) of aliased Matrix2;
   type Matrix3_Array is array (Index_Type range <>) of aliased Matrix3;
   type Matrix4_Array is array (Index_Type range <>) of aliased Matrix4;

   pragma Convention (C, Vector2_Array);
   pragma Convention (C, Vector3_Array);
   pragma Convention (C, Vector4_Array);
   pragma Convention (C, Matrix2_Array);
   pragma Convention (C, Matrix3_Array);
   pragma Convention (C, Matrix4_Array);

   -----------------------------------------------------------------------------
   --                              Pointer types                              --
   -- note: These instances of the Pointers package do not have a usable      --
   --       default terminator. Only use the size-based subroutines.          --
   -----------------------------------------------------------------------------

   package Vector2_Pointers is new Interfaces.C.Pointers
     (Index_Type, Vector2, Vector2_Array, Vector2'(others => <>));
   package Vector3_Pointers is new Interfaces.C.Pointers
     (Index_Type, Vector3, Vector3_Array, Vector3'(others => <>));
   package Vector4_Pointers is new Interfaces.C.Pointers
     (Index_Type, Vector4, Vector4_Array, Vector4'(others => <>));

   package Matrix2_Pointers is new Interfaces.C.Pointers
     (Index_Type, Matrix2, Matrix2_Array, Matrix2'(others => (others => <>)));
   package Matrix3_Pointers is new Interfaces.C.Pointers
     (Index_Type, Matrix3, Matrix3_Array, Matrix3'(others => (others => <>)));
   package Matrix4_Pointers is new Interfaces.C.Pointers
     (Index_Type, Matrix4, Matrix4_Array, Matrix4'(others => (others => <>)));

   function Cross_Product (Left, Right : Vector3) return Vector3;
end GL.Algebra;