Ada计算机图形DirectX之d3dx9math

----------------------------------------
-- Microsoft DirectX Ada binding lib  --
-- File : d3dx9math.ads               --
-- Translator:Dongfeng.Gu,2018/11/15  --
-- Mail: [email protected]                --
-- Progress:100%                      --
----------------------------------------

with System;
with Ada.Unchecked_Conversion;

with win32;                  use win32;
with win32.rpcdce;
with win32.Objbase;          use win32.objbase;

with d3d9;                   use d3d9;
with d3d9types;              use d3d9types;



package d3dx9math is
   
   type FLOAT_ARRAY is array (Natural range<>) of FLOAT;
   type LPFLOAT is access all win32.FLOAT;
   type LPCFLOAT is access constant win32.FLOAT;
   
   D3DX_PI:constant:=3.141592654;
   D3DX_1BYPI:constant:=0.318309886;
   
   function D3DXToRadian(degree:float) return float is ((degree) * (D3DX_PI / 180.0));
   
   function D3DXToDegree(radian:float) return float is ((radian) * (180.0 / D3DX_PI));
   
   D3DX_16F_DIG          :constant:=3;                -- # of decimal digits of precision
   D3DX_16F_EPSILON      :constant:=4.8875809e-4;     -- smallest such that 1.0 + epsilon != 1.0
   D3DX_16F_MANT_DIG     :constant:=11;               -- # of bits in mantissa
   D3DX_16F_MAX          :constant:=6.550400e+004;    -- max value
   D3DX_16F_MAX_10_EXP   :constant:=4;                -- max decimal exponent
   D3DX_16F_MAX_EXP      :constant:=15;               -- max binary exponent
   D3DX_16F_MIN          :constant:=6.1035156e-5;     -- min positive value
   D3DX_16F_MIN_10_EXP   :constant:=(-4);             -- min decimal exponent
   D3DX_16F_MIN_EXP      :constant:=(-14);            -- min binary exponent
   D3DX_16F_RADIX        :constant:=2;                -- exponent radix
   D3DX_16F_ROUNDS       :constant:=1;                -- addition rounding: near
   

   --
   -- FLOAT16
   --
   
   type D3DXFLOAT16 is record
      value:word;
   end record with size=>16;
   type LPD3DXFLOAT16 is access all D3DXFLOAT16;
   
   type LPCD3DXFLOAT16 is access constant D3DXFLOAT16;
   type D3DXFLOAT16_ARRAY is array (Natural range<>) of D3DXFLOAT16;
   
   -- 构造函数
   function NEW_D3DXFLOAT16 return access D3DXFLOAT16 with Inline;
   function NEW_D3DXFLOAT16(f:FLOAT) return access D3DXFLOAT16 with Inline;
   function NEW_D3DXFLOAT16(f:D3DXFLOAT16) return access D3DXFLOAT16 with Inline;
   
   function TO_FLOAT(This:LPD3DXFLOAT16) return FLOAT with Inline;
   
   function "="(This:D3DXFLOAT16;f:D3DXFLOAT16) return BOOL with Inline;
   function "/="(This:D3DXFLOAT16;f:D3DXFLOAT16) return BOOL with Inline;
   
   
   
   --
   -- 2D Vector
   --
   
   type D3DXVECTOR2 is record
      x,y:float;
   end record;
   type LPD3DXVECTOR2 is access all D3DXVECTOR2;
   type LPCD3DXVECTOR2 is access constant D3DXVECTOR2;
   
   -- 构造函数
   function NEW_D3DXVECTOR2 return access D3DXVECTOR2 with Inline;
   
   -- argument array length should >=2,else return (0.0,0.0);
   function NEW_D3DXVECTOR2(pf:access constant float) return access D3DXVECTOR2 with Inline;
   function NEW_D3DXVECTOR2(pf:access FLOAT_ARRAY) return access D3DXVECTOR2 with Inline;
   function NEW_D3DXVECTOR2(pf:FLOAT_ARRAY) return access D3DXVECTOR2 with Inline;
   
   function NEW_D3DXVECTOR2(pf:access constant D3DXFLOAT16) return access D3DXVECTOR2 with Inline;
   function NEW_D3DXVECTOR2(pf:access constant D3DXFLOAT16_ARRAY) return access D3DXVECTOR2 with Inline;
   function NEW_D3DXVECTOR2(pf:D3DXFLOAT16_ARRAY) return access D3DXVECTOR2 with Inline;
   
   function NEW_D3DXVECTOR2(x,y:float) return access D3DXVECTOR2 with Inline;
   
   -- 类型转换
   function TO_LPFLOAT(This:LPD3DXVECTOR2) return access FLOAT with Inline;
   function TO_LPCFLOAT(This:LPD3DXVECTOR2) return access FLOAT with Inline;
   function TO_LPFLOAT_ARRAY(This:LPD3DXVECTOR2) return access FLOAT_ARRAY with Inline;
   function TO_LPCFLOAT_ARRAY(This:LPD3DXVECTOR2) return access constant FLOAT_ARRAY with Inline;
   
   -- 自操作
   procedure SInc(This:in out D3DXVECTOR2;v:D3DXVECTOR2) with Inline;
   procedure SDec(This:in out D3DXVECTOR2;v:D3DXVECTOR2) with Inline;
   procedure SMul(This:in out D3DXVECTOR2;f:FLOAT) with Inline;
   procedure SDiv(This:in out D3DXVECTOR2;f:FLOAT) with Inline;
   
   -- 一元操作
   function "+"(This:D3DXVECTOR2) return D3DXVECTOR2 with Inline;
   function "-"(This:D3DXVECTOR2) return D3DXVECTOR2 with Inline;
   
   -- 二元操作
   function "+"(This:D3DXVECTOR2;v:D3DXVECTOR2) return D3DXVECTOR2 with Inline;
   function "-"(This:D3DXVECTOR2;v:D3DXVECTOR2) return D3DXVECTOR2 with Inline;
   function "*"(This:D3DXVECTOR2;f:Float) return D3DXVECTOR2 with Inline;
   function "/"(This:D3DXVECTOR2;f:Float) return D3DXVECTOR2 with Inline;
   -- friend function
   function "*"(f:Float;v:D3DXVECTOR2) return D3DXVECTOR2 with Inline;
   
   function "="(This:D3DXVECTOR2;v:D3DXVECTOR2) return win32.BOOL;
   function "/="(This:D3DXVECTOR2;v:D3DXVECTOR2) return win32.BOOL;
   
   
   
   --
   -- 2D Vector (16 bit)
   --
   
   type D3DXVECTOR2_16F is record
      x,y:D3DXFLOAT16;
   end record;
   type LPD3DXVECTOR2_16F is access all D3DXVECTOR2_16F;
   
   function NEW_D3DXVECTOR2_16F return access D3DXVECTOR2_16F with Inline;
   
   function NEW_D3DXVECTOR2_16F(pf:access constant FLOAT) return access D3DXVECTOR2_16F with Inline;
   function NEW_D3DXVECTOR2_16F(pf:access constant FLOAT_ARRAY) return access D3DXVECTOR2_16F with Inline;
   function NEW_D3DXVECTOR2_16F(pf:FLOAT_ARRAY) return access D3DXVECTOR2_16F with Inline;
   
   function NEW_D3DXVECTOR2_16F(pf:access constant D3DXFLOAT16) return access D3DXVECTOR2_16F with Inline;
   function NEW_D3DXVECTOR2_16F(pf:access constant D3DXFLOAT16_ARRAY) return access D3DXVECTOR2_16F with Inline;
   function NEW_D3DXVECTOR2_16F(pf:D3DXFLOAT16_ARRAY) return access D3DXVECTOR2_16F with Inline;
   
   function NEW_D3DXVECTOR2_16F(fx,fy:D3DXFLOAT16) return access D3DXVECTOR2_16F with Inline;
   
   function TO_LPD3DXFLOAT16(This:LPD3DXVECTOR2_16F) return access D3DXFLOAT16 with Inline;
   function TO_LPCD3DXFLOAT16(This:LPD3DXVECTOR2_16F) return access constant D3DXFLOAT16 with Inline;
   
   function "="(This:D3DXVECTOR2_16F;v:D3DXVECTOR2_16F) return win32.BOOL with Inline;
   function "/="(This:D3DXVECTOR2_16F;v:D3DXVECTOR2_16F) return win32.BOOL with Inline;
   

   --
   -- 3D Vector
   --
   
   type D3DXVECTOR3 is record
      x,y,z:Float;
   end record;
   type LPD3DXVECTOR3 is access all D3DXVECTOR3;
   
   function NEW_D3DXVECTOR3 return access D3DXVECTOR3 with Inline;
   
   -- FLOAT_ARRAY LENGTH SHOULD >=3
   function NEW_D3DXVECTOR3(pf:access constant FLOAT) return access D3DXVECTOR3 with Inline;
   function NEW_D3DXVECTOR3(pf:access constant FLOAT_ARRAY) return access D3DXVECTOR3 with Inline;
   function NEW_D3DXVECTOR3(fa:float_Array) return access D3DXVECTOR3 with Inline,pre=>fa'Length>=3;
   
   function NEW_D3DXVECTOR3(v:D3DXVECTOR3) return access D3DXVECTOR3 with Inline;
   
   function NEW_D3DXVECTOR3(pf:access constant D3DXFLOAT16) return access D3DXVECTOR3 with Inline;
   function NEW_D3DXVECTOR3(pf:access constant D3DXFLOAT16_ARRAY) return access D3DXVECTOR3 with Inline;
   function NEW_D3DXVECTOR3(pf:D3DXFLOAT16_ARRAY) return access D3DXVECTOR3 with Inline;
   
   function NEW_D3DXVECTOR3(x,y,z:FLOAT) return access D3DXVECTOR3 with Inline;
   
   -- CASTING
   function TO_LPFLOAT(This:LPD3DXVECTOR3) return access FLOAT with Inline;
   function TO_LPFLOAT_ARRAY(This:LPD3DXVECTOR3) return access FLOAT_ARRAY with Inline;
   
   function TO_LPCFLOAT(This:LPD3DXVECTOR3) return access FLOAT with Inline;
   function TO_LPCFLOAT_ARRAY(This:LPD3DXVECTOR3) return access FLOAT_ARRAY with Inline;
   
   procedure SInc(This:in out D3DXVECTOR3;v:D3DXVECTOR3) with Inline;
   procedure SDec(This:in out D3DXVECTOR3;v:D3DXVECTOR3) with Inline;
   procedure SMul(This:in out D3DXVECTOR3;f:FLOAT) with Inline;
   procedure SDiv(This:in out D3DXVECTOR3;F:FLOAT) with Inline;
   
   function "+"(This:D3DXVECTOR3) return D3DXVECTOR3 with Inline;
   function "-"(This:D3DXVECTOR3) return D3DXVECTOR3 with Inline;
   
   
   function "+"(This:D3DXVECTOR3;v:D3DXVECTOR3) return D3DXVECTOR3 with Inline;
   function "-"(This:D3DXVECTOR3;v:D3DXVECTOR3) return D3DXVECTOR3 with Inline;
   function "*"(This:D3DXVECTOR3;f:Float) return D3DXVECTOR3 with Inline;
   function "/"(This:D3DXVECTOR3;f:Float) return D3DXVECTOR3 with Inline;

   function "*"(f:Float;v:D3DXVECTOR3) return D3DXVECTOR3 with Inline;
   
   function "="(This:D3DXVECTOR3;v:D3DXVECTOR3) return win32.BOOL with Inline;
   function "/="(This:D3DXVECTOR3;v:D3DXVECTOR3) return win32.BOOL with Inline;
   
   
   --
   -- 3D Vector(16 bit)
   --
   
   type D3DXVECTOR3_16F is record
      x,y,z:D3DXFLOAT16;
   end record;
   type LPD3DXVECTOR3_16F is access all D3DXVECTOR3_16F;
   type LPCD3DXVECTOR3_16F is access constant D3DXVECTOR3_16F;
   
   
   -- 构造函数
   function NEW_D3DXVECTOR3_16F return access D3DXVECTOR3_16F with Inline;
   function NEW_D3DXVECTOR3_16F(pf:access constant FLOAT) return access D3DXVECTOR3_16F with Inline;
   function NEW_D3DXVECTOR3_16F(pf:access constant FLOAT_ARRAY) return access D3DXVECTOR3_16F with Inline;
   function NEW_D3DXVECTOR3_16F(pf:FLOAT_ARRAY) return access D3DXVECTOR3_16F with Inline;
   function NEW_D3DXVECTOR3_16F(v:D3DVECTOR) return access D3DXVECTOR3_16F with Inline;
   
   -- !!!参数是数组的首元素
   function NEW_D3DXVECTOR3_16F(pf:access constant D3DXFLOAT16) return access D3DXVECTOR3_16F with Inline;
   function NEW_D3DXVECTOR3_16F(pf:access constant D3DXFLOAT16_ARRAY) return access D3DXVECTOR3_16F with Inline;
   function NEW_D3DXVECTOR3_16F(pf:D3DXFLOAT16_ARRAY) return access D3DXVECTOR3_16F with Inline;
   
   function NEW_D3DXVECTOR3_16F(fx,fy,fz:D3DXFLOAT16) return access D3DXVECTOR3_16F with Inline;
   
   -- 类型转换
   function TO_LPD3DXVECTOR3_16F(This:LPD3DXVECTOR3_16F) return access D3DXFLOAT16 with Inline;
   function TO_LPCD3DXVECTOR3_16F(This:LPD3DXVECTOR3_16F) return access constant D3DXFLOAT16 with Inline;
   
   function "="(This:D3DXVECTOR3_16F;v:D3DXVECTOR3_16F) return win32.BOOL with Inline;
   function "/="(This:D3DXVECTOR3_16F;v:D3DXVECTOR3_16F) return win32.BOOL with Inline;
   
   
   --
   -- 4D Vector
   --
   
   type D3DXVECTOR4 is record
      x,y,z,w:Float;
   end record;
   type LPD3DXVECTOR4 is access all D3DXVECTOR4;
   type LPCDEDXVECTOR4 is access constant D3DXVECTOR4;
   
   -- Construct
   function NEW_D3DXVECTOR4 return access D3DXVECTOR4 with Inline;
   function NEW_D3DXVECTOR4(pf:access constant FLOAT) return access D3DXVECTOR4 with Inline;
   function NEW_D3DXVECTOR4(pf:access constant FLOAT_ARRAY) return access D3DXVECTOR4 with Inline;
   function NEW_D3DXVECTOR4(FA:FLOAT_ARRAY) return access D3DXVECTOR4 with Inline,pre=>FA'Length>=4;
   
   function NEW_D3DXVECTOR4(pf:access constant D3DXFLOAT16) return access D3DXVECTOR4 with Inline;
   function NEW_D3DXVECTOR4(pf:access constant D3DXFLOAT16_ARRAY) return access D3DXVECTOR4 with Inline;
   function NEW_D3DXVECTOR4(pf:D3DXFLOAT16_ARRAY) return access D3DXVECTOR4 with Inline;
     
   
   function NEW_D3DXVECTOR4(v:D3DVECTOR;w:FLOAT) return access D3DXVECTOR4 with Inline;
   function NEW_D3DXVECTOR4(fx,fy,fz,fw:FLOAT) return access D3DXVECTOR4 with Inline;
   
   -- Conversion
   function TO_LPFLOAT_ARRAY(This:LPD3DXVECTOR4) return access FLOAT_ARRAY with Inline;
   function TO_FLOAT_ARRAY(This:D3DXVECTOR4) return FLOAT_ARRAY with Inline;
   function TO_LPCFLOAT_ARRAY(This:LPD3DXVECTOR4) return access constant FLOAT_ARRAY with Inline;
   
   -- Self operate
   procedure SInc(This:in out D3DXVECTOR4;v:D3DXVECTOR4) with Inline;
   procedure SDec(This:in out D3DXVECTOR4;v:D3DXVECTOR4) with Inline;
   procedure SMul(This:in out D3DXVECTOR4;f:FLOAT) with Inline;
   procedure SDiv(This:in out D3DXVECTOR4;F:FLOAT) with Inline;
   
   -- unary
   function "+"(This:D3DXVECTOR4) return D3DXVECTOR4 with Inline;
   function "-"(This:D3DXVECTOR4) return D3DXVECTOR4 with Inline;
   
   -- binary
   function "+"(This:D3DXVECTOR4;v:D3DXVECTOR4) return D3DXVECTOR4 with Inline;
   function "-"(This:D3DXVECTOR4;v:D3DXVECTOR4) return D3DXVECTOR4 with Inline;
   
   function "*"(This:D3DXVECTOR4;f:Float) return D3DXVECTOR4 with Inline;
   function "*"(f:Float;This:D3DXVECTOR4) return D3DXVECTOR4 with Inline;
   function "/"(This:D3DXVECTOR4;f:Float) return D3DXVECTOR4 with Inline;
   
   function "="(This:D3DXVECTOR4;v:D3DXVECTOR4) return BOOL with Inline;
   function "/="(This:D3DXVECTOR4;v:D3DXVECTOR4) return BOOL with Inline;
   
   
   
   
   --
   -- 4D Vector (16 bit)
   --
   
   type D3DXVECTOR4_16F is record
      x,y,z,w:D3DXFLOAT16;
   end record;
   type LPD3DXVECTOR4_16F is access all D3DXVECTOR4_16F;
   
   -- Construct
   function NEW_D3DXVECTOR4_16F return access D3DXVECTOR4_16F with Inline;
   function NEW_D3DXVECTOR4_16F(pf:access constant FLOAT) return access D3DXVECTOR4_16F with Inline;
   function NEW_D3DXVECTOR4_16F(pf:access constant FLOAT_ARRAY) return access D3DXVECTOR4_16F with Inline;
   function NEW_D3DXVECTOR4_16F(pf:FLOAT_ARRAY) return access D3DXVECTOR4_16F with Inline;
   function NEW_D3DXVECTOR4_16F(pf:access constant D3DXFLOAT16) return access D3DXVECTOR4_16F with Inline;
   function NEW_D3DXVECTOR4_16F(pf:access constant D3DXFLOAT16_ARRAY) return access D3DXVECTOR4_16F with Inline;
   function NEW_D3DXVECTOR4_16F(pf:D3DXFLOAT16_ARRAY) return access D3DXVECTOR4_16F with Inline;
   
   
   function NEW_D3DXVECTOR4_16F(v:D3DXVECTOR3_16F;w:D3DXFLOAT16) return access D3DXVECTOR4_16F with Inline;
   function NEW_D3DXVECTOR4_16F(x,y,z,w:D3DXFLOAT16) return access D3DXVECTOR4_16F with Inline;
   
   -- Conversion
   function TO_LPD3DXFLOAT16(This:LPD3DXVECTOR4_16F) return access D3DXFLOAT16 with Inline;
   function TO_LPD3DXFLOAT16_ARRAY(This:LPD3DXVECTOR4_16F) return access D3DXFLOAT16_ARRAY with Inline;
   
   function TO_LPCD3DXFLOAT16(This:LPD3DXVECTOR4_16F) return access constant D3DXFLOAT16 with Inline;
   function TO_LPCD3DXFLOAT16_ARRAY(This:LPD3DXVECTOR4_16F) return access constant D3DXFLOAT16_ARRAY with Inline;
   
   -- binary
   function "="(This:D3DXVECTOR4_16F;V:D3DXVECTOR4_16F) return win32.BOOL with Inline;
   function "/="(This:D3DXVECTOR4_16F;V:D3DXVECTOR4_16F) return win32.BOOL with Inline;
   
   
   --
   -- matrix
   --
   
   subtype D3DXMATRIX is d3d9types.D3DMATRIX;
   type LPD3DXMATRIX is access all D3DXMATRIX;
   
   
   --  Construct
   function NEW_D3DXMATRIX return access D3DXMATRIX with Inline;
   function NEW_D3DXMATRIX(f:access constant Float) return access D3DXMATRIX with Inline;
   function NEW_D3DXMATRIX(f:access constant FLOAT_ARRAY) return access D3DXMATRIX with Inline;
   function NEW_D3DXMATRIX(f:FLOAT_ARRAY) return access D3DXMATRIX with Inline;
   function NEW_D3DXMATRIX(mat:D3DXMATRIX) return access D3DXMATRIX with Inline;
   function NEW_D3DXMATRIX(pf:access constant D3DXFLOAT16) return access D3DXMATRIX with Inline;
   function NEW_D3DXMATRIX(pf:access constant D3DXFLOAT16_ARRAY) return access D3DXMATRIX with Inline;
   function NEW_D3DXMATRIX(pf:D3DXFLOAT16_ARRAY) return access D3DXMATRIX with Inline;
   
   
   function NEW_D3DXMATRIX(f11,f12,f13,f14,f21,f22,f23,f24,f31,f32,f33,f34,f41,f42,f43,f44:Float) return access D3DXMATRIX with Inline;
   
   -- access member
   function Member(mat:D3DXMATRIX;row,col:int) return access float with Inline; 
   function Member(mat:D3DXMATRIX;row,col:int) return float with Inline;
   
   -- Conversion
   function TO_LPFLOAT(mat:LPD3DXMATRIX) return access FLOAT with Inline;
   function TO_LPFLOAT_ARRAY(mat:LPD3DXMATRIX) return access FLOAT_ARRAY with Inline;
   
   function TO_LPCFLOAT(mat:LPD3DXMATRIX) return access constant FLOAT with Inline;
   function TO_LPCFLOAT_ARRAY(mat:LPD3DXMATRIX) return access constant FLOAT_ARRAY with Inline;
   
   procedure SInc(This:in out D3DXMATRIX;mat:D3DXMATRIX) with Inline;
   procedure SDec(This:in out D3DXMATRIX;mat:D3DXMATRIX) with Inline;
   procedure SMul(This:in out D3DXMATRIX;f:FLOAT) with Inline;
   procedure SMul(This:in out D3DXMATRIX;mat:D3DXMATRIX) with Inline;
   procedure SDiv(This:in out D3DXMATRIX;f:FLOAT) with Inline;
   
   -- unary
   function "+"(This:D3DXMATRIX) return D3DXMATRIX with Inline;
   function "-"(This:D3DXMATRIX) return D3DXMATRIX with Inline;
   
   -- binary
   function "+"(This:D3DXMATRIX;mat:D3DXMATRIX) return D3DXMATRIX with Inline;
   function "-"(This:D3DXMATRIX;mat:D3DXMATRIX) return D3DXMATRIX with Inline;
   function "*"(This:D3DXMATRIX;f:Float) return D3DXMATRIX with Inline;
   function "*"(f:Float;This:D3DXMATRIX) return D3DXMATRIX with Inline;
   function "/"(This:D3DXMATRIX;f:Float) return D3DXMATRIX with Inline;
   function "="(This:D3DXMATRIX;mat:D3DXMATRIX) return BOOL with Inline;
   function "/="(This:D3DXMATRIX;mat:D3DXMATRIX) return BOOL with Inline;
   
   
   --
   -- MATRIX ALIGN 16
   --
   
   -- use sse
   type D3DXMATRIXA16 is new D3DXMATRIX with Alignment=>16;
   
   -- Construct
   function NEW_D3DXMATRIXA16 return access D3DXMATRIXA16 with Inline;
   function NEW_D3DXMATRIXA16(f:access constant Float) return access D3DXMATRIXA16 with Inline;
   function NEW_D3DXMATRIXA16(f:access constant FLOAT_ARRAY) return access D3DXMATRIXA16 with Inline;
   function NEW_D3DXMATRIXA16(f:FLOAT_ARRAY) return access D3DXMATRIXA16 with Inline;
   function NEW_D3DXMATRIXA16(mat:D3DXMATRIX) return access D3DXMATRIXA16 with Inline;
   function NEW_D3DXMATRIXA16(pf:access constant D3DXFLOAT16) return access D3DXMATRIXA16 with Inline;
   function NEW_D3DXMATRIXA16(pf:access constant D3DXFLOAT16_ARRAY) return access D3DXMATRIXA16 with Inline;
   function NEW_D3DXMATRIXA16(pf:D3DXFLOAT16_ARRAY) return access D3DXMATRIXA16 with Inline;
   function NEW_D3DXMATRIXA16(f11,f12,f13,f14,f21,f22,f23,f24,f31,f32,f33,f34,f41,f42,f43,f44:Float) return access D3DXMATRIXA16 with Inline;
   
   -- assignment
   procedure equ(This:in out D3DXMATRIXA16;mat:D3DXMATRIX) with Inline;
   
   
   
   
   --
   -- Quaternions
   --
   
   type D3DXQUATERNION is record
      x,y,z,w:Float;
   end record;
   type LPD3DXQUATERNION is access all D3DXQUATERNION;
   type LPCD3DXQUATERNION is access constant D3DXQUATERNION;
   
   -- Construct
   function NEW_D3DXQUATERNION return access D3DXQUATERNION with Inline;
   function NEW_D3DXQUATERNION(pf:access constant FLOAT) return access D3DXQUATERNION with Inline;
   function NEW_D3DXQUATERNION(pf:access constant FLOAT_ARRAY) return access D3DXQUATERNION with Inline;
   function NEW_D3DXQUATERNION(pf: FLOAT_ARRAY) return access D3DXQUATERNION with Inline;
   function NEW_D3DXQUATERNION(pf:access constant D3DXFLOAT16) return access D3DXQUATERNION with Inline;
   function NEW_D3DXQUATERNION(pf:access constant D3DXFLOAT16_ARRAY) return access D3DXQUATERNION with Inline;
   function NEW_D3DXQUATERNION(pf:D3DXFLOAT16_ARRAY) return access D3DXQUATERNION with Inline;
   
   function NEW_D3DXQUATERNION(x,y,z,w:FLOAT) return access D3DXQUATERNION with Inline;
   
   -- Conversion(casting)
   function TO_LPFLOAT_ARRAY(This:LPD3DXQUATERNION) return access FLOAT_ARRAY with Inline;
   function TO_LPCFLOAT_ARRAY(This:LPD3DXQUATERNION) return access constant FLOAT_ARRAY with Inline;
   
   -- Self operate
   procedure SInc(This:in out D3DXQUATERNION;v:D3DXQUATERNION) with Inline;
   procedure SDec(This:in out D3DXQUATERNION;v:D3DXQUATERNION) with Inline;
   procedure SMul(This:in out D3DXQUATERNION;f:FLOAT) with Inline;
   procedure SDiv(This:in out D3DXQUATERNION;f:FLOAT) with Inline;
   
   -- unary
   function "+"(This:D3DXQUATERNION) return D3DXQUATERNION with Inline;
   function "-"(This:D3DXQUATERNION) return D3DXQUATERNION with Inline;
   
   -- binary
   function "+"(This:D3DXQUATERNION;v:D3DXQUATERNION) return D3DXQUATERNION with Inline;
   function "-"(This:D3DXQUATERNION;v:D3DXQUATERNION) return D3DXQUATERNION with Inline;
   function "*"(This:D3DXQUATERNION;f:FLOAT) return D3DXQUATERNION with Inline;
   function "*"(f:FLOAT;This:D3DXQUATERNION) return D3DXQUATERNION with Inline;
   function "*"(This:D3DXQUATERNION;q:D3DXQUATERNION) return D3DXQUATERNION with Inline;
   function "/"(This:D3DXQUATERNION;f:FLOAT) return D3DXQUATERNION with Inline;
   function "="(This:D3DXQUATERNION;v:D3DXQUATERNION) return win32.BOOL with Inline;
   function "/="(This:D3DXQUATERNION;v:D3DXQUATERNION) return win32.BOOL with Inline;
   
   
   --
   -- Planes
   --
   
   type D3DXPLANE is record
      a,b,c,d:FLOAT;
   end record;
   type LPD3DXPLANE is access all D3DXPLANE;
   type LPCD3DXPLANE is access constant D3DXPLANE;
   
   -- Construct
   function NEW_D3DXPLANE return access D3DXPLANE with Inline;
   function NEW_D3DXPLANE(pf:access constant FLOAT) return access D3DXPLANE with Inline;
   function NEW_D3DXPLANE(pf:access constant FLOAT_ARRAY) return access D3DXPLANE with Inline;
   function NEW_D3DXPLANE(pf:FLOAT_ARRAY) return access D3DXPLANE with Inline;
   function NEW_D3DXPLANE(pf:access constant D3DXFLOAT16) return access D3DXPLANE with Inline;
   function NEW_D3DXPLANE(pf:access constant D3DXFLOAT16_ARRAY) return access D3DXPLANE with Inline;
   function NEW_D3DXPLANE(pf:D3DXFLOAT16_ARRAY) return access D3DXPLANE with Inline;
   function NEW_D3DXPLANE(a,b,c,d:FLOAT) return access D3DXPLANE with Inline;
   
   -- Conversion
   function TO_LPFLOAT_ARRAY(p:LPD3DXPLANE) return access FLOAT_ARRAY with Inline;
   function TO_LPCFLOAT_ARRAY(p:LPD3DXPLANE) return access constant FLOAT_ARRAY with Inline;
   
   -- self operate
   procedure SMul(p:in out D3DXPLANE;f:Float) with Inline;
   procedure SDiv(p:in out D3DXPLANE;f:Float) with Inline;
   
   -- unary
   function "+"(p:D3DXPLANE) return D3DXPLANE with Inline;
   function "-"(p:D3DXPLANE) return D3DXPLANE with Inline;
   
   --binary
   function "*"(p:D3DXPLANE;f:Float) return D3DXPLANE with Inline;
   function "/"(p:D3DXPLANE;f:Float) return D3DXPLANE with Inline;
   function "="(p:D3DXPLANE;p2:D3DXPLANE) return win32.BOOL with Inline;
   function "/="(p:D3DXPLANE;p2:D3DXPLANE) return win32.BOOL with Inline;
   
   
   --
   -- Colors
   --
   
   type D3DXCOLOR is record
      r,g,b,a:FLOAT;
   end record;
   type LPD3DXCOLOR is access all D3DXCOLOR;
   type LPCD3DXCOLOR is access constant D3DXCOLOR;
   
   -- Construct
   function NEW_D3DXCOLOR return access D3DXCOLOR with Inline;
   function NEW_D3DXCOLOR(argb:DWORD) return access D3DXCOLOR with Inline;
   function NEW_D3DXCOLOR(pf:access constant FLOAT_ARRAY) return access D3DXCOLOR with Inline;
   function NEW_D3DXCOLOR(pf:access constant FLOAT) return access D3DXCOLOR with Inline;
   function NEW_D3DXCOLOR(pf:FLOAT_ARRAY) return access D3DXCOLOR with Inline;
   function NEW_D3DXCOLOR(C:D3DXCOLOR) return access D3DXCOLOR with Inline;
   function NEW_D3DXCOLOR(r,g,b,a:FLOAT) return access D3DXCOLOR with Inline;
   
   -- Conversion(casting)
   function TO_DWORD(C:D3DXCOLOR) return DWORD with Inline;
   function TO_LPFLOAT_ARRAY(This:LPD3DXCOLOR) return access FLOAT_ARRAY with Inline;
   function TO_FLOAT_ARRAY(This:D3DXCOLOR) return FLOAT_ARRAY with Inline;
   function TO_LPCFLOAT_ARRAY(This:LPD3DXCOLOR) return access constant FLOAT_ARRAY with Inline;
   function TO_LPD3DCOLORVALUE(C:D3DXCOLOR) return access D3DCOLORVALUE with Inline;
   function TO_LPCD3DCOLORVALUE(C:D3DXCOLOR) return access constant D3DCOLORVALUE with Inline;
   function TO_D3DCOLORVALUE(C:D3DXCOLOR) return D3DCOLORVALUE with Inline;
   function TO_CONST_D3DCOLORVALUE(C:D3DXCOLOR) return D3DCOLORVALUE with Inline;
   
   -- self operate
   procedure SInc(This:in out D3DXCOLOR;v:D3DXCOLOR) with Inline;
   procedure SDec(This:in out D3DXCOLOR;v:D3DXCOLOR) with Inline;
   procedure SMul(This:in out D3DXCOLOR;f:FLOAT) with Inline;
   procedure SDiv(This:in out D3DXCOLOR;f:FLOAT) with Inline;
   
   -- unary
   function "+"(This:D3DXCOLOR) return D3DXCOLOR with Inline;
   function "-"(This:D3DXCOLOR) return D3DXCOLOR with Inline;
   
   -- binary
   function "+"(This:D3DXCOLOR;v:D3DXCOLOR) return D3DXCOLOR with Inline;
   function "-"(This:D3DXCOLOR;v:D3DXCOLOR) return D3DXCOLOR with Inline;
   function "*"(This:D3DXCOLOR;f:FLOAT) return D3DXCOLOR with Inline;
   function "*"(f:FLOAT;This:D3DXCOLOR) return D3DXCOLOR with Inline;
   function "/"(This:D3DXCOLOR;f:FLOAT) return D3DXCOLOR with Inline;
   function "="(This:D3DXCOLOR;v:D3DXCOLOR) return win32.BOOL with Inline;
   function "/="(This:D3DXCOLOR;v:D3DXCOLOR) return win32.BOOL with Inline;
   
   
   --
   -- d3dx math functions
   --
   
   

   -- 2DVector
   
   function D3DXVec2Length(pv:access constant D3DXVECTOR2) return FLOAT with Inline;
   function D3DXVec2LengthSq(pv:access constant D3DXVECTOR2) return FLOAT with Inline;
   function D3DXVec2Dot(pV1:access constant D3DXVECTOR2;pV2:access constant D3DXVECTOR2) return FLOAT with Inline;
   function D3DXVec2CCW(pV1:access constant D3DXVECTOR2;pV2:access constant D3DXVECTOR2) return FLOAT with Inline;
   function D3DXVec2Add(pOut:access D3DXVECTOR2;pV1:access constant D3DXVECTOR2;pV2:access constant D3DXVECTOR2) return access D3DXVECTOR2 with Inline;
   function D3DXVec2Subtract(pOut:access D3DXVECTOR2;pV1:access constant D3DXVECTOR2;pV2:access constant D3DXVECTOR2) return access D3DXVECTOR2 with Inline;
   function D3DXVec2Minimize(pOut:access D3DXVECTOR2;pV1:access constant D3DXVECTOR2;pV2:access constant D3DXVECTOR2) return access D3DXVECTOR2 with Inline;
   function D3DXVec2Maximize(pOut:access D3DXVECTOR2;pV1:access constant D3DXVECTOR2;pV2:access constant D3DXVECTOR2) return access D3DXVECTOR2 with Inline;
   function D3DXVec2Scale(pOut:access D3DXVECTOR2;pV:access constant D3DXVECTOR2;s:FLOAT) return access D3DXVECTOR2 with Inline;
   function D3DXVec2Lerp(pOut:access D3DXVECTOR2;pV1:access constant D3DXVECTOR2;pV2:access constant D3DXVECTOR2;s:FLOAT) return access D3DXVECTOR2 with Inline;
   
   
   -- 3D Vector
   function D3DXVec3Length(pV:access constant D3DXVECTOR3) return FLOAT with Inline;
   function D3DXVec3LengthSq(pV:access constant D3DXVECTOR3) return FLOAT with Inline;
   function D3DXVec3Dot(pV1:access constant D3DXVECTOR3;pV2:access constant D3DXVECTOR3) return FLOAT with Inline;
   function D3DXVec3Cross(pOut:access D3DXVECTOR3;pV1:access constant D3DXVECTOR3;pV2:access constant D3DXVECTOR3) return access D3DXVECTOR3 with Inline;
   function D3DXVec3Add(pOut:access D3DXVECTOR3;pV1:access constant D3DXVECTOR3;pV2:access constant D3DXVECTOR3) return access D3DXVECTOR3 with Inline;
   function D3DXVec3Subtract(pOut:access D3DXVECTOR3;pV1:access constant D3DXVECTOR3;pV2:access constant D3DXVECTOR3) return access D3DXVECTOR3 with Inline;
   function D3DXVec3Minimize(pOut:access D3DXVECTOR3;pV1:access constant D3DXVECTOR3;pV2:access constant D3DXVECTOR3) return access D3DXVECTOR3 with Inline;
   function D3DXVec3Maximize(pOut:access D3DXVECTOR3;pV1:access constant D3DXVECTOR3;pV2:access constant D3DXVECTOR3) return access D3DXVECTOR3 with Inline;
   function D3DXVec3Scale(pOut:access D3DXVECTOR3;pV:access constant D3DXVECTOR3;s:FLOAT) return access D3DXVECTOR3 with Inline;
   function D3DXVec3Lerp(pOut:access D3DXVECTOR3;pV1:access constant D3DXVECTOR3;pV2:access constant D3DXVECTOR3;s:FLOAT) return access D3DXVECTOR3 with Inline;
   
   -- 4D Vector
   function D3DXVec4Length(pV:access constant D3DXVECTOR4) return FLOAT with Inline;
   function D3DXVec4LengthSq(pV:access constant D3DXVECTOR4) return FLOAT with Inline;
   function D3DXVec4Dot(pV1:access constant D3DXVECTOR4;pV2:access constant D3DXVECTOR4) return FLOAT with Inline;
   function D3DXVec4Add(pOut:access D3DXVECTOR4;pV1:access constant D3DXVECTOR4;pV2:access constant D3DXVECTOR4) return access D3DXVECTOR4 with Inline;
   function D3DXVec4Subtract(pOut:access D3DXVECTOR4;pV1:access constant D3DXVECTOR4;pV2:access constant D3DXVECTOR4) return access D3DXVECTOR4 with Inline;
   function D3DXVec4Minimize(pOut:access D3DXVECTOR4;pV1:access constant D3DXVECTOR4;pV2:access constant D3DXVECTOR4) return access D3DXVECTOR4 with Inline;
   function D3DXVec4Maximize(pOut:access D3DXVECTOR4;pV1:access constant D3DXVECTOR4;pV2:access constant D3DXVECTOR4) return access D3DXVECTOR4 with Inline;
   function D3DXVec4Scale(pOut:access D3DXVECTOR4;pV:access constant D3DXVECTOR4;s:FLOAT) return access D3DXVECTOR4 with Inline;
   function D3DXVec4Lerp(pOut:access D3DXVECTOR4;pV1:access constant D3DXVECTOR4;pV2:access constant D3DXVECTOR4;s:FLOAT) return access D3DXVECTOR4 with Inline;
   
   
   -- 4D Matrix
   function D3DXMatrixIdentity(pOut:access D3DXMATRIX) return access D3DXMATRIX with Inline;
   function D3DXMatrixIsIdentity(pOut:access constant D3DXMATRIX) return Win32.BOOL with Inline;
   
   -- D3DXQuaternion
   function D3DXQuaternionLength(pQ:access constant D3DXQuaternion) return FLOAT with Inline;
   function D3DXQuaternionLengthSq(pQ:access constant D3DXQuaternion) return FLOAT with Inline;
   function D3DXQuaternionDot(pQ1:access constant D3DXQuaternion;pQ2:access constant D3DXQuaternion) return FLOAT with Inline;
   function D3DXQuaternionIsIdentity(pQ:access constant D3DXQuaternion) return Win32.BOOL with Inline;
   function D3DXQuaternionIdentity(pOut:access D3DXQuaternion) return access D3DXQUATERNION with Inline;
   function D3DXQuaternionConjugate(pOut:access D3DXQuaternion;pQ:access constant D3DXQuaternion) return access D3DXQUATERNION with Inline;
   
   -- Plane
   function D3DXPlaneDot(pP:access constant D3DXPLANE;pV:access constant D3DXVECTOR4) return FLOAT with Inline;
   function D3DXPlaneDotCoord(pP:access constant D3DXPLANE;pV:access constant D3DXVECTOR3) return FLOAT with Inline;
   function D3DXPlaneDotNormal(pP:access constant D3DXPLANE;pV:access constant D3DXVECTOR3) return FLOAT with Inline;
   function D3DXPlaneScale(pOut:access D3DXPLANE;pP:access constant D3DXPLANE;s:Float) return access D3DXPLANE with Inline;
   
   
   -- Color
   function D3DXColorNegative(pOut:access D3DXCOLOR;pC:access constant D3DXCOLOR) return access D3DXCOLOR with Inline;
   function D3DXColorAdd(pOut:access D3DXColor;pC1:access constant D3DXColor;pC2:access constant D3DXColor) return access D3DXColor with Inline;
   function D3DXColorSubtract(pOut:access D3DXColor;pC1:access constant D3DXColor;pC2:access constant D3DXColor) return access D3DXColor with Inline;
   function D3DXColorScale(pOut:access D3DXColor;pC:access constant D3DXColor;s:FLOAT) return access D3DXColor with Inline;
   function D3DXColorModulate(pOut:access D3DXColor;pC1:access constant D3DXColor;pC2:access constant D3DXColor) return access D3DXColor with Inline;
   function D3DXColorLerp(pOut:access D3DXColor;pC1:access constant D3DXColor;pC2:access constant D3DXColor;s:FLOAT) return access D3DXColor with Inline;
   

   function D3DXFloat32To16Array(pOut:access D3DXFLOAT16;pIn:access constant FLOAT;n:UINT) return access D3DXFLOAT16 with Import,Convention=>stdcall,external_name=>"D3DXFloat32To16Array";

   function D3DXFloat16To32Array(pOut:access FLOAT;pIn:access constant D3DXFLOAT16;n:UINT) return access FLOAT with Import,Convention=>Stdcall,external_Name=>"D3DXFloat16To32Array";
   
   function D3DXVec2Normalize(pOut:LPD3DXVECTOR2;pV:LPCD3DXVECTOR2) return LPD3DXVECTOR2 with Import,Convention=>stdcall,external_name=>"D3DXVec2Normalize";

   function D3DXVec2Hermite(pOut:LPD3DXVECTOR2;pV1:LPCD3DXVECTOR2;pT1:LPCD3DXVECTOR2;pV2:LPCD3DXVECTOR2;pT2:LPCD3DXVECTOR2;s:FLOAT) return LPD3DXVECTOR2 with Import,Convention=>stdcall,external_name=>"D3DXVec2Hermite";

   function D3DXVec2CatmullRom(pOut:LPD3DXVECTOR2;pV0:LPCD3DXVECTOR2;pV1:LPCD3DXVECTOR2;pV2:LPCD3DXVECTOR2;pV3:LPCD3DXVECTOR2;s:FLOAT) return LPD3DXVECTOR2 with Import,Convention=>stdcall,external_name=>"D3DXVec2CatmullRom";

   function D3DXVec2BaryCentric(pOut:LPD3DXVECTOR2;pV1:LPCD3DXVECTOR2;pV2:LPCD3DXVECTOR2;pV3:LPCD3DXVECTOR2;f:FLOAT;g:FLOAT) return LPD3DXVECTOR2 with Import,Convention=>stdcall,external_name=>"D3DXVec2BaryCentric";

   function D3DXVec2Transform(pOut:LPD3DXVECTOR4;pV:LPCD3DXVECTOR2;pM:LPCD3DXMATRIX) return LPD3DXVECTOR4 with Import,Convention=>stdcall,external_name=>"D3DXVec2Transform";

   function D3DXVec2TransformCoord(pOut:LPD3DXVECTOR2;pV:LPCD3DXVECTOR2;pM:LPCD3DXMATRIX) return LPD3DXVECTOR2 with Import,Convention=>stdcall,external_name=>"D3DXVec2TransformCoord";

   function D3DXVec2TransformNormal(pOut:LPD3DXVECTOR2;pV:LPCD3DXVECTOR2;pM:LPCD3DXMATRIX) return LPD3DXVECTOR2 with Import,Convention=>stdcall,external_name=>"D3DXVec2TransformNormal";

   function D3DXVec2TransformArray(pOut:LPD3DXVECTOR4;OutStride:UINT;pV:LPCD3DXVECTOR2;VStride:UINT;pM:LPCD3DXMATRIX;n:UINT) return LPD3DXVECTOR4 with Import,Convention=>stdcall,external_name=>"D3DXVec2TransformArray";

   function D3DXVec2TransformCoordArray(pOut:LPD3DXVECTOR2;OutStride:UINT;pV:LPCD3DXVECTOR2;VStride:UINT;pM:LPCD3DXMATRIX;n:UINT) return LPD3DXVECTOR2 with Import,Convention=>stdcall,external_name=>"D3DXVec2TransformCoordArray";

   function D3DXVec2TransformNormalArray(pOut:LPD3DXVECTOR2;OutStride:UINT;pV:LPCD3DXVECTOR2;VStride:UINT;pM:LPCD3DXMATRIX;n:UINT) return LPD3DXVECTOR2 with Import,Convention=>stdcall,external_name=>"D3DXVec2TransformNormalArray";

   function D3DXVec3Normalize(pOut:LPD3DXVECTOR3;pV:LPCD3DXVECTOR3) return LPD3DXVECTOR3 with Import,Convention=>stdcall,external_name=>"D3DXVec3Normalize";

   function D3DXVec3Hermite(pOut:LPD3DXVECTOR3;pV1:LPCD3DXVECTOR3;pT1:LPCD3DXVECTOR3;pV2:LPCD3DXVECTOR3;pT2:LPCD3DXVECTOR3;s:FLOAT) return LPD3DXVECTOR3 with Import,Convention=>stdcall,external_name=>"D3DXVec3Hermite";

   function D3DXVec3CatmullRom(pOut:LPD3DXVECTOR3;pV0:LPCD3DXVECTOR3;pV1:LPCD3DXVECTOR3;pV2:LPCD3DXVECTOR3;pV3:LPCD3DXVECTOR3;s:FLOAT) return LPD3DXVECTOR3 with Import,Convention=>stdcall,external_name=>"D3DXVec3CatmullRom";

   function D3DXVec3BaryCentric(pOut:LPD3DXVECTOR3;pV1:LPCD3DXVECTOR3;pV2:LPCD3DXVECTOR3;pV3:LPCD3DXVECTOR3;f:FLOAT;g:FLOAT) return LPD3DXVECTOR3 with Import,Convention=>stdcall,external_name=>"D3DXVec3BaryCentric";

   function D3DXVec3Transform(pOut:LPD3DXVECTOR4;pV:LPCD3DXVECTOR3;pM:LPCD3DXMATRIX) return LPD3DXVECTOR4 with Import,Convention=>stdcall,external_name=>"D3DXVec3Transform";

   function D3DXVec3TransformCoord(pOut:LPD3DXVECTOR3;pV:LPCD3DXVECTOR3;pM:LPCD3DXMATRIX) return LPD3DXVECTOR3 with Import,Convention=>stdcall,external_name=>"D3DXVec3TransformCoord";

   function D3DXVec3TransformNormal(pOut:LPD3DXVECTOR3;pV:LPCD3DXVECTOR3;pM:LPCD3DXMATRIX) return LPD3DXVECTOR3 with Import,Convention=>stdcall,external_name=>"D3DXVec3TransformNormal";

   function D3DXVec3TransformArray(pOut:LPD3DXVECTOR4;OutStride:UINT;pV:LPCD3DXVECTOR3;VStride:UINT;pM:LPCD3DXMATRIX;n:UINT) return LPD3DXVECTOR4 with Import,Convention=>stdcall,external_name=>"D3DXVec3TransformArray";

   function D3DXVec3TransformCoordArray(pOut:LPD3DXVECTOR3;OutStride:UINT;pV:LPCD3DXVECTOR3;VStride:UINT;pM:LPCD3DXMATRIX;n:UINT) return LPD3DXVECTOR3 with Import,Convention=>stdcall,external_name=>"D3DXVec3TransformCoordArray";

   function D3DXVec3TransformNormalArray(pOut:LPD3DXVECTOR3;OutStride:UINT;pV:LPCD3DXVECTOR3;VStride:UINT;pM:LPCD3DXMATRIX;n:UINT) return LPD3DXVECTOR3 with Import,Convention=>stdcall,external_name=>"D3DXVec3TransformNormalArray";

   function D3DXVec3Project(pOut:LPD3DXVECTOR3;pV:LPCD3DXVECTOR3;pViewport:LPCD3DVIEWPORT9;pProjection:LPCD3DXMATRIX;pView:LPCD3DXMATRIX;pWorld:LPCD3DXMATRIX) return LPD3DXVECTOR3 with Import,Convention=>stdcall,external_name=>"D3DXVec3Project";

   function D3DXVec3Unproject(pOut:LPD3DXVECTOR3;pV:LPCD3DXVECTOR3;pViewport:LPCD3DVIEWPORT9;pProjection:LPCD3DXMATRIX;pView:LPCD3DXMATRIX;pWorld:LPCD3DXMATRIX) return LPD3DXVECTOR3 with Import,Convention=>stdcall,external_name=>"D3DXVec3Unproject";

   function D3DXVec3ProjectArray(pOut:LPD3DXVECTOR3;OutStride:UINT;pV:LPCD3DXVECTOR3;VStride:UINT;pViewport:LPCD3DVIEWPORT9;pProjection:LPCD3DXMATRIX;pView:LPCD3DXMATRIX;pWorld:LPCD3DXMATRIX;n:UINT) return LPD3DXVECTOR3 with Import,Convention=>stdcall,external_name=>"D3DXVec3ProjectArray";

   function D3DXVec3UnprojectArray(pOut:LPD3DXVECTOR3;OutStride:UINT;pV:LPCD3DXVECTOR3;VStride:UINT;pViewport:LPCD3DVIEWPORT9;pProjection:LPCD3DXMATRIX;pView:LPCD3DXMATRIX;pWorld:LPCD3DXMATRIX;n:UINT) return LPD3DXVECTOR3 with Import,Convention=>stdcall,external_name=>"D3DXVec3UnprojectArray";

   function D3DXVec4Cross(pOut:LPD3DXVECTOR4;pV1:LPCD3DXVECTOR4;pV2:LPCD3DXVECTOR4;pV3:LPCD3DXVECTOR4) return LPD3DXVECTOR4 with Import,Convention=>stdcall,external_name=>"D3DXVec4Cross";

   function D3DXVec4Normalize(pOut:LPD3DXVECTOR4;pV:LPCD3DXVECTOR4) return LPD3DXVECTOR4 with Import,Convention=>stdcall,external_name=>"D3DXVec4Normalize";

   function D3DXVec4Hermite(pOut:LPD3DXVECTOR4;pV1:LPCD3DXVECTOR4;pT1:LPCD3DXVECTOR4;pV2:LPCD3DXVECTOR4;pT2:LPCD3DXVECTOR4;s:FLOAT) return LPD3DXVECTOR4 with Import,Convention=>stdcall,external_name=>"D3DXVec4Hermite";

   function D3DXVec4CatmullRom(pOut:LPD3DXVECTOR4;pV0:LPCD3DXVECTOR4;pV1:LPCD3DXVECTOR4;pV2:LPCD3DXVECTOR4;pV3:LPCD3DXVECTOR4;s:FLOAT) return LPD3DXVECTOR4 with Import,Convention=>stdcall,external_name=>"D3DXVec4CatmullRom";

   function D3DXVec4BaryCentric(pOut:LPD3DXVECTOR4;pV1:LPCD3DXVECTOR4;pV2:LPCD3DXVECTOR4;pV3:LPCD3DXVECTOR4;f:FLOAT;g:FLOAT) return LPD3DXVECTOR4 with Import,Convention=>stdcall,external_name=>"D3DXVec4BaryCentric";

   function D3DXVec4Transform(pOut:LPD3DXVECTOR4;pV:LPCD3DXVECTOR4;pM:LPCD3DXMATRIX) return LPD3DXVECTOR4 with Import,Convention=>stdcall,external_name=>"D3DXVec4Transform";

   function D3DXVec4TransformArray(pOut:LPD3DXVECTOR4;OutStride:UINT;pV:LPCD3DXVECTOR4;VStride:UINT;pM:LPCD3DXMATRIX;n:UINT) return LPD3DXVECTOR4 with Import,Convention=>stdcall,external_name=>"D3DXVec4TransformArray";

   function D3DXMatrixDeterminant(pM:LPCD3DXMATRIX) return FLOAT with Import,Convention=>stdcall,external_name=>"D3DXMatrixDeterminant";

   function D3DXMatrixDecompose(pOutScale:LPD3DXVECTOR3;pOutRotation:LPD3DXQUATERNION;pOutTranslation:LPD3DXVECTOR3;pM:LPCD3DXMATRIX) return Objbase.HRESULT with Import,Convention=>stdcall,external_name=>"D3DXMatrixDecompose";

   function D3DXMatrixTranspose(pOut:LPD3DXMATRIX;pM:LPCD3DXMATRIX) return LPD3DXMATRIX with Import,Convention=>stdcall,external_name=>"D3DXMatrixTranspose";

   function D3DXMatrixMultiply(pOut:LPD3DXMATRIX;pM1:LPCD3DXMATRIX;pM2:LPCD3DXMATRIX) return LPD3DXMATRIX with Import,Convention=>stdcall,external_name=>"D3DXMatrixMultiply";

   function D3DXMatrixMultiplyTranspose(pOut:LPD3DXMATRIX;pM1:LPCD3DXMATRIX;pM2:LPCD3DXMATRIX) return LPD3DXMATRIX with Import,Convention=>stdcall,external_name=>"D3DXMatrixMultiplyTranspose";

   function D3DXMatrixInverse(pOut:LPD3DXMATRIX;pDeterminant:LPFLOAT;pM:LPCD3DXMATRIX) return LPD3DXMATRIX with Import,Convention=>stdcall,external_name=>"D3DXMatrixInverse";

   function D3DXMatrixScaling(pOut:LPD3DXMATRIX;sx:FLOAT;sy:FLOAT;sz:FLOAT) return LPD3DXMATRIX with Import,Convention=>stdcall,external_name=>"D3DXMatrixScaling";

   function D3DXMatrixTranslation(pOut:LPD3DXMATRIX;x:FLOAT;y:FLOAT;z:FLOAT) return LPD3DXMATRIX with Import,Convention=>stdcall,external_name=>"D3DXMatrixTranslation";

   function D3DXMatrixRotationX(pOut:LPD3DXMATRIX;Angle:FLOAT) return LPD3DXMATRIX with Import,Convention=>stdcall,external_name=>"D3DXMatrixRotationX";

   function D3DXMatrixRotationY(pOut:LPD3DXMATRIX;Angle:FLOAT) return LPD3DXMATRIX with Import,Convention=>stdcall,external_name=>"D3DXMatrixRotationY";

   function D3DXMatrixRotationZ(pOut:LPD3DXMATRIX;Angle:FLOAT) return LPD3DXMATRIX with Import,Convention=>stdcall,external_name=>"D3DXMatrixRotationZ";

   function D3DXMatrixRotationAxis(pOut:LPD3DXMATRIX;pV:LPCD3DXVECTOR3;Angle:FLOAT) return LPD3DXMATRIX with Import,Convention=>stdcall,external_name=>"D3DXMatrixRotationAxis";

   function D3DXMatrixRotationQuaternion(pOut:LPD3DXMATRIX;pQ:LPCD3DXQUATERNION) return LPD3DXMATRIX with Import,Convention=>stdcall,external_name=>"D3DXMatrixRotationQuaternion";

   function D3DXMatrixRotationYawPitchRoll(pOut:LPD3DXMATRIX;Yaw:FLOAT;Pitch:FLOAT;Roll:FLOAT) return LPD3DXMATRIX with Import,Convention=>stdcall,external_name=>"D3DXMatrixRotationYawPitchRoll";

   function D3DXMatrixTransformation(pOut:LPD3DXMATRIX;pScalingCenter:LPCD3DXVECTOR3;pScalingRotation:LPCD3DXQUATERNION;pScaling:LPCD3DXVECTOR3;pRotationCenter:LPCD3DXVECTOR3;pRotation:LPCD3DXQUATERNION;pTranslation:LPCD3DXVECTOR3) return LPD3DXMATRIX with Import,Convention=>stdcall,external_name=>"D3DXMatrixTransformation";

   function D3DXMatrixTransformation2D(pOut:LPD3DXMATRIX;pScalingCenter:LPCD3DXVECTOR2;ScalingRotation:FLOAT;pScaling:LPCD3DXVECTOR2;pRotationCenter:LPCD3DXVECTOR2;Rotation:FLOAT;pTranslation:LPCD3DXVECTOR2) return LPD3DXMATRIX with Import,Convention=>stdcall,external_name=>"D3DXMatrixTransformation2D";

   function D3DXMatrixAffineTransformation(pOut:LPD3DXMATRIX;Scaling:FLOAT;pRotationCenter:LPCD3DXVECTOR3;pRotation:LPCD3DXQUATERNION;pTranslation:LPCD3DXVECTOR3) return LPD3DXMATRIX with Import,Convention=>stdcall,external_name=>"D3DXMatrixAffineTransformation";

   function D3DXMatrixAffineTransformation2D(pOut:LPD3DXMATRIX;Scaling:FLOAT;pRotationCenter:LPCD3DXVECTOR2;Rotation:FLOAT;pTranslation:LPCD3DXVECTOR2) return LPD3DXMATRIX with Import,Convention=>stdcall,external_name=>"D3DXMatrixAffineTransformation2D";

   function D3DXMatrixLookAtRH(pOut:LPD3DXMATRIX;pEye:LPCD3DXVECTOR3;pAt:LPCD3DXVECTOR3;pUp:LPCD3DXVECTOR3) return LPD3DXMATRIX with Import,Convention=>stdcall,external_name=>"D3DXMatrixLookAtRH";

   function D3DXMatrixLookAtLH(pOut:LPD3DXMATRIX;pEye:LPCD3DXVECTOR3;pAt:LPCD3DXVECTOR3;pUp:LPCD3DXVECTOR3) return LPD3DXMATRIX with Import,Convention=>stdcall,external_name=>"D3DXMatrixLookAtLH";

   function D3DXMatrixPerspectiveRH(pOut:LPD3DXMATRIX;w:FLOAT;h:FLOAT;zn:FLOAT;zf:FLOAT) return LPD3DXMATRIX with Import,Convention=>stdcall,external_name=>"D3DXMatrixPerspectiveRH";

   function D3DXMatrixPerspectiveLH(pOut:LPD3DXMATRIX;w:FLOAT;h:FLOAT;zn:FLOAT;zf:FLOAT) return LPD3DXMATRIX with Import,Convention=>stdcall,external_name=>"D3DXMatrixPerspectiveLH";

   function D3DXMatrixPerspectiveFovRH(pOut:LPD3DXMATRIX;fovy:FLOAT;Aspect:FLOAT;zn:FLOAT;zf:FLOAT) return LPD3DXMATRIX with Import,Convention=>stdcall,external_name=>"D3DXMatrixPerspectiveFovRH";

   function D3DXMatrixPerspectiveFovLH(pOut:LPD3DXMATRIX;fovy:FLOAT;Aspect:FLOAT;zn:FLOAT;zf:FLOAT) return LPD3DXMATRIX with Import,Convention=>stdcall,external_name=>"D3DXMatrixPerspectiveFovLH";

   function D3DXMatrixPerspectiveOffCenterRH(pOut:LPD3DXMATRIX;l:FLOAT;r:FLOAT;b:FLOAT;t:FLOAT;zn:FLOAT;zf:FLOAT) return LPD3DXMATRIX with Import,Convention=>stdcall,external_name=>"D3DXMatrixPerspectiveOffCenterRH";

   function D3DXMatrixPerspectiveOffCenterLH(pOut:LPD3DXMATRIX;l:FLOAT;r:FLOAT;b:FLOAT;t:FLOAT;zn:FLOAT;zf:FLOAT) return LPD3DXMATRIX with Import,Convention=>stdcall,external_name=>"D3DXMatrixPerspectiveOffCenterLH";

   function D3DXMatrixOrthoRH(pOut:LPD3DXMATRIX;w:FLOAT;h:FLOAT;zn:FLOAT;zf:FLOAT) return LPD3DXMATRIX with Import,Convention=>stdcall,external_name=>"D3DXMatrixOrthoRH";

   function D3DXMatrixOrthoLH(pOut:LPD3DXMATRIX;w:FLOAT;h:FLOAT;zn:FLOAT;zf:FLOAT) return LPD3DXMATRIX with Import,Convention=>stdcall,external_name=>"D3DXMatrixOrthoLH";

   function D3DXMatrixOrthoOffCenterRH(pOut:LPD3DXMATRIX;l:FLOAT;r:FLOAT;b:FLOAT;t:FLOAT;zn:FLOAT;zf:FLOAT) return LPD3DXMATRIX with Import,Convention=>stdcall,external_name=>"D3DXMatrixOrthoOffCenterRH";

   function D3DXMatrixOrthoOffCenterLH(pOut:LPD3DXMATRIX;l:FLOAT;r:FLOAT;b:FLOAT;t:FLOAT;zn:FLOAT;zf:FLOAT) return LPD3DXMATRIX with Import,Convention=>stdcall,external_name=>"D3DXMatrixOrthoOffCenterLH";

   function D3DXMatrixShadow(pOut:LPD3DXMATRIX;pLight:LPCD3DXVECTOR4;pPlane:LPCD3DXPLANE) return LPD3DXMATRIX with Import,Convention=>stdcall,external_name=>"D3DXMatrixShadow";

   function D3DXMatrixReflect(pOut:LPD3DXMATRIX;pPlane:LPCD3DXPLANE) return LPD3DXMATRIX with Import,Convention=>stdcall,external_name=>"D3DXMatrixReflect";

   procedure D3DXQuaternionToAxisAngle(pQ:LPCD3DXQUATERNION;pAxis:LPD3DXVECTOR3;pAngle:LPFLOAT) with Import,Convention=>stdcall,external_name=>"D3DXQuaternionToAxisAngle";

   function D3DXQuaternionRotationMatrix(pOut:LPD3DXQUATERNION;pM:LPCD3DXMATRIX) return LPD3DXQUATERNION with Import,Convention=>stdcall,external_name=>"D3DXQuaternionRotationMatrix";

   function D3DXQuaternionRotationAxis(pOut:LPD3DXQUATERNION;pV:LPCD3DXVECTOR3;Angle:FLOAT) return LPD3DXQUATERNION with Import,Convention=>stdcall,external_name=>"D3DXQuaternionRotationAxis";

   function D3DXQuaternionRotationYawPitchRoll(pOut:LPD3DXQUATERNION;Yaw:FLOAT;Pitch:FLOAT;Roll:FLOAT) return LPD3DXQUATERNION with Import,Convention=>stdcall,external_name=>"D3DXQuaternionRotationYawPitchRoll";

   function D3DXQuaternionMultiply(pOut:LPD3DXQUATERNION;pQ1:LPCD3DXQUATERNION;pQ2:LPCD3DXQUATERNION) return LPD3DXQUATERNION with Import,Convention=>stdcall,external_name=>"D3DXQuaternionMultiply";

   function D3DXQuaternionNormalize(pOut:LPD3DXQUATERNION;pQ:LPCD3DXQUATERNION) return LPD3DXQUATERNION with Import,Convention=>stdcall,external_name=>"D3DXQuaternionNormalize";

   function D3DXQuaternionInverse(pOut:LPD3DXQUATERNION;pQ:LPCD3DXQUATERNION) return LPD3DXQUATERNION with Import,Convention=>stdcall,external_name=>"D3DXQuaternionInverse";

   function D3DXQuaternionLn(pOut:LPD3DXQUATERNION;pQ:LPCD3DXQUATERNION) return access D3DXQUATERNION with Import,Convention=>stdcall,external_name=>"D3DXQuaternionLn";

   function D3DXQuaternionSlerp(pOut:LPD3DXQUATERNION;pQ1:LPCD3DXQUATERNION;pQ2:LPCD3DXQUATERNION;t:FLOAT) return LPD3DXQUATERNION with Import,Convention=>stdcall,external_name=>"D3DXQuaternionSlerp";

   function D3DXQuaternionSquad(pOut:LPD3DXQUATERNION;pQ1:LPCD3DXQUATERNION;pA:LPCD3DXQUATERNION;pB:LPCD3DXQUATERNION;pC:LPCD3DXQUATERNION;t:FLOAT) return LPD3DXQUATERNION with Import,Convention=>stdcall,external_name=>"D3DXQuaternionSquad";

   procedure D3DXQuaternionSquadSetup(pAOut:LPD3DXQUATERNION;pBOut:LPD3DXQUATERNION;pCOut:LPD3DXQUATERNION;pQ0:LPCD3DXQUATERNION;pQ1:LPCD3DXQUATERNION;pQ2:LPCD3DXQUATERNION;pQ3:LPCD3DXQUATERNION) with Import,Convention=>stdcall,external_name=>"D3DXQuaternionSquadSetup";

   function D3DXQuaternionBaryCentric(pOut:LPD3DXQUATERNION;pQ1:LPCD3DXQUATERNION;pQ2:LPCD3DXQUATERNION;pQ3:LPCD3DXQUATERNION;f:FLOAT;g:FLOAT) return LPD3DXQUATERNION with Import,Convention=>stdcall,external_name=>"D3DXQuaternionBaryCentric";

   function D3DXPlaneNormalize(pOut:LPD3DXPLANE;pP:LPCD3DXPLANE) return LPD3DXPLANE with Import,Convention=>stdcall,external_name=>"D3DXPlaneNormalize";

   function D3DXPlaneIntersectLine(pOut:LPD3DXVECTOR3;pP:LPCD3DXPLANE;pV1:LPCD3DXVECTOR3;pV2:LPCD3DXVECTOR3) return LPD3DXVECTOR3 with Import,Convention=>stdcall,external_name=>"D3DXPlaneIntersectLine";

   function D3DXPlaneFromPointNormal(pOut:LPD3DXPLANE;pPoint:LPCD3DXVECTOR3;pNormal:LPCD3DXVECTOR3) return LPD3DXPLANE with Import,Convention=>stdcall,external_name=>"D3DXPlaneFromPointNormal";

   function D3DXPlaneFromPoints(pOut:LPD3DXPLANE;pV1:LPCD3DXVECTOR3;pV2:LPCD3DXVECTOR3;pV3:LPCD3DXVECTOR3) return LPD3DXPLANE with Import,Convention=>stdcall,external_name=>"D3DXPlaneFromPoints";

   function D3DXPlaneTransform(pOut:LPD3DXPLANE;pP:LPCD3DXPLANE;pM:LPCD3DXMATRIX) return LPD3DXPLANE with Import,Convention=>stdcall,external_name=>"D3DXPlaneTransform";

   function D3DXPlaneTransformArray(pOut:LPD3DXPLANE;OutStride:UINT;pP:LPCD3DXPLANE;PStride:UINT;pM:LPCD3DXMATRIX;n:UINT) return LPD3DXPLANE with Import,Convention=>stdcall,external_name=>"D3DXPlaneTransformArray";

   function D3DXColorAdjustSaturation(pOut:LPD3DXCOLOR;pC:LPCD3DXCOLOR;s:FLOAT) return LPD3DXCOLOR with Import,Convention=>stdcall,external_name=>"D3DXColorAdjustSaturation";

   function D3DXColorAdjustContrast(pOut:LPD3DXCOLOR;pC:LPCD3DXCOLOR;c:FLOAT) return LPD3DXCOLOR with Import,Convention=>stdcall,external_name=>"D3DXColorAdjustContrast";

   function D3DXFresnelTerm(CosTheta:FLOAT;RefractionIndex:FLOAT) return FLOAT with Import,Convention=>stdcall,external_name=>"D3DXFresnelTerm";

   IID_ID3DXMatrixStack:constant win32.rpcdce.GUID:=(16#c7885ba7#,16#f990#,16#4fe7#,(16#92#,16#2d#,16#85#,16#15#,16#e4#,16#77#,16#dd#,16#85#));

   type ID3DXMatrixStack;
   type LPID3DXMatrixStack is access all ID3DXMatrixStack;
   type LPLPID3DXMatrixStack is access all LPID3DXMatrixStack;
   subtype LPD3DXMatrixStack is LPID3DXMatrixStack;
   subtype LPLPD3DXMatrixStack is LPLPID3DXMatrixStack;
   
   type ID3DXMatrixStack_vtbl is record
      QueryInterface:access function(THIS:LPID3DXMatrixStack;riid:REFIID;ppvObj:LPLPVOID) return HRESULT with Convention=>Stdcall;
      AddRef:access function(THIS:LPID3DXMatrixStack) return ULONG with Convention=>Stdcall;
      Release:access function(THIS:LPID3DXMatrixStack) return ULONG with Convention=>Stdcall;
      Pop:access function(THIS:LPID3DXMatrixStack) return HRESULT with Convention=>Stdcall;
      Push:access function(THIS:LPID3DXMatrixStack) return HRESULT with Convention=>Stdcall;
      LoadIdentity:access function(THIS:LPID3DXMatrixStack) return HRESULT with Convention=>Stdcall;
      LoadMatrix:access function(THIS:LPID3DXMatrixStack;pM:LPCD3DXMATRIX) return HRESULT with Convention=>Stdcall;
      MultMatrix:access function(THIS:LPID3DXMatrixStack;pM:LPCD3DXMATRIX) return HRESULT with Convention=>Stdcall;
      MultMatrixLocal:access function(THIS:LPID3DXMatrixStack;pM:LPCD3DXMATRIX) return HRESULT with Convention=>Stdcall;
      RotateAxis:access function(THIS:LPID3DXMatrixStack;pV:LPCD3DXVECTOR3;Angle:FLOAT) return HRESULT with Convention=>Stdcall;
      RotateAxisLocal:access function(THIS:LPID3DXMatrixStack;pV:LPCD3DXVECTOR3;Angle:FLOAT) return HRESULT with Convention=>Stdcall;
      RotateYawPitchRoll:access function(THIS:LPID3DXMatrixStack;Yaw:FLOAT;Pitch:FLOAT;Roll:FLOAT) return HRESULT with Convention=>Stdcall;
      RotateYawPitchRollLocal:access function(THIS:LPID3DXMatrixStack;Yaw:FLOAT;Pitch:FLOAT;Roll:FLOAT) return HRESULT with Convention=>Stdcall;
      Scale:access function(THIS:LPID3DXMatrixStack;x:FLOAT;y:FLOAT;z:FLOAT) return HRESULT with Convention=>Stdcall;
      ScaleLocal:access function(THIS:LPID3DXMatrixStack;x:FLOAT;y:FLOAT;z:FLOAT) return HRESULT with Convention=>Stdcall;
      Translate:access function(THIS:LPID3DXMatrixStack;x:FLOAT;y:FLOAT;z:FLOAT) return HRESULT with Convention=>Stdcall;
      TranslateLocal:access function(THIS:LPID3DXMatrixStack;x:FLOAT;y:FLOAT;z:FLOAT) return HRESULT with Convention=>Stdcall;
      GetTop:access function(THIS:LPID3DXMatrixStack) return LPD3DXMATRIX with Convention=>Stdcall;
   end record;
   type  ID3DXMatrixStack is access all ID3DXMatrixStack_vtbl;

   function D3DXCreateMatrixStack(Flags:DWORD;ppStack:LPLPD3DXMATRIXSTACK) return HRESULT with Import,Convention=>stdcall,external_name=>"D3DXCreateMatrixStack";

   D3DXSH_MINORDER : constant := 2;

   D3DXSH_MAXORDER : constant := 6;

   function D3DXSHEvalDirection(pOut:LPFLOAT;Order:UINT;pDir:LPCD3DXVECTOR3) return LPFLOAT with Import,Convention=>stdcall,external_name=>"D3DXSHEvalDirection";

   function D3DXSHRotate(pOut:LPFLOAT;Order:UINT;pMatrix:LPCD3DXMATRIX;pIn:LPCFLOAT) return LPFLOAT with Import,Convention=>stdcall,external_name=>"D3DXSHRotate";

   function D3DXSHRotateZ(pOut:LPFLOAT;Order:UINT;Angle:FLOAT;pIn:LPCFLOAT) return LPFLOAT with Import,Convention=>stdcall,external_name=>"D3DXSHRotateZ";

   function D3DXSHAdd(pOut:LPFLOAT;Order:UINT;pA:LPCFLOAT;pB:LPCFLOAT) return LPFLOAT with Import,Convention=>stdcall,external_name=>"D3DXSHAdd";

   function D3DXSHScale(pOut:LPFLOAT;Order:UINT;pIn:LPCFLOAT;Scale:FLOAT) return LPFLOAT with Import,Convention=>stdcall,external_name=>"D3DXSHScale";

   function D3DXSHDot(Order:UINT;pA:LPCFLOAT;pB:LPCFLOAT) return FLOAT with Import,Convention=>stdcall,external_name=>"D3DXSHDot";

   function D3DXSHMultiply2(pOut:LPFLOAT;pF:LPCFLOAT;pG:LPCFLOAT) return LPFLOAT with Import,Convention=>stdcall,external_name=>"D3DXSHMultiply2";

   function D3DXSHMultiply3(pOut:LPFLOAT;pF:LPCFLOAT;pG:LPCFLOAT) return LPFLOAT with Import,Convention=>stdcall,external_name=>"D3DXSHMultiply3";

   function D3DXSHMultiply4(pOut:LPFLOAT;pF:LPCFLOAT;pG:LPCFLOAT) return LPFLOAT with Import,Convention=>stdcall,external_name=>"D3DXSHMultiply4";

   function D3DXSHMultiply5(pOut:LPFLOAT;pF:LPCFLOAT;pG:LPCFLOAT) return LPFLOAT with Import,Convention=>stdcall,external_name=>"D3DXSHMultiply5";

   function D3DXSHMultiply6(pOut:LPFLOAT;pF:LPCFLOAT;pG:LPCFLOAT) return LPFLOAT with Import,Convention=>stdcall,external_name=>"D3DXSHMultiply6";

   function D3DXSHEvalDirectionalLight(Order:UINT;pDir:LPCD3DXVECTOR3;RIntensity:FLOAT;GIntensity:FLOAT;BIntensity:FLOAT;pROut:LPFLOAT;pGOut:LPFLOAT;pBOut:LPFLOAT) return HRESULT with Import,Convention=>stdcall,external_name=>"D3DXSHEvalDirectionalLight";

   function D3DXSHEvalSphericalLight(Order:UINT;pPos:LPCD3DXVECTOR3;Radius:FLOAT;RIntensity:FLOAT;GIntensity:FLOAT;BIntensity:FLOAT;pROut:LPFLOAT;pGOut:LPFLOAT;pBOut:LPFLOAT) return HRESULT with Import,Convention=>stdcall,external_name=>"D3DXSHEvalSphericalLight";

   function D3DXSHEvalConeLight(Order:UINT;pDir:LPCD3DXVECTOR3;Radius:FLOAT;RIntensity:FLOAT;GIntensity:FLOAT;BIntensity:FLOAT;pROut:LPFLOAT;pGOut:LPFLOAT;pBOut:LPFLOAT) return HRESULT with Import,Convention=>stdcall,external_name=>"D3DXSHEvalConeLight";

   function D3DXSHEvalHemisphereLight(Order:UINT;pDir:LPCD3DXVECTOR3;Top:D3DXCOLOR;Bottom:D3DXCOLOR;pROut:LPFLOAT;pGOut:LPFLOAT;pBOut:LPFLOAT) return HRESULT with Import,Convention=>stdcall,external_name=>"D3DXSHEvalHemisphereLight";

   function D3DXSHProjectCubeMap(uOrder:UINT;pCubeMap:LPDIRECT3DCUBETEXTURE9;pROut:LPFLOAT;pGOut:LPFLOAT;pBOut:LPFLOAT) return HRESULT with Import,Convention=>stdcall,external_name=>"D3DXSHProjectCubeMap";






   --
   -- THE END.
   --

end d3dx9math;
























----------------------------------------
-- Microsoft DirectX Ada binding lib  --
-- File : d3dx9math.adb               --
-- Translator:Dongfeng.Gu,2018/11/15  --
-- Mail: [email protected]                --
-- Progress:100%                      --
----------------------------------------


pragma Allow_Integer_Address;

with Interfaces.C;           use  Interfaces.C;

with win32.crt.Strings;      use win32.crt.Strings;

package body d3dx9math is

   --
   -- FLOAT16
   --
   
   function NEW_D3DXFLOAT16 return access D3DXFLOAT16 is
      This:access D3DXFLOAT16:=new D3DXFLOAT16'(value=>0);
   begin
      return This;
   end;
   
   function NEW_D3DXFLOAT16(f:FLOAT) return access D3DXFLOAT16 is
      This:access D3DXFLOAT16:=new D3DXFLOAT16;
   begin
      declare
         pf16:access D3DXFLOAT16;
      begin
         pf16:=D3DXFloat32To16Array(this, f'Unrestricted_Access, 1);
      end;
      return This;
   end;
   
   function NEW_D3DXFLOAT16(f:D3DXFLOAT16) return access D3DXFLOAT16 is
      This:access D3DXFLOAT16:=new D3DXFLOAT16'(f);
   begin
      return This;
   end;
   
   function TO_FLOAT(This:LPD3DXFLOAT16) return FLOAT is
      f:FLOAT;
      Self:access FLOAT;
   begin
      Self:=D3DXFloat16To32Array(f'Unrestricted_Access, this, 1);
      return f;
   end TO_FLOAT;
   
   function "="(This:D3DXFLOAT16;f:D3DXFLOAT16) return BOOL is
   begin
      if This=f then
         return win32.TRUE;
      end if;
      return win32.FALSE;
   end;
   
   function "/="(This:D3DXFLOAT16;f:D3DXFLOAT16) return BOOL is
   begin
      if This/=f then
         return win32.TRUE;
      end if;
      return win32.FALSE;
   end;
   
   
   
   --
   -- 2D Vector
   --
   
   function NEW_D3DXVECTOR2 return access D3DXVECTOR2 is
      This:access D3DXVECTOR2:=new D3DXVECTOR2'(0.0,0.0);
   begin
      return This;
   end;
   
   function NEW_D3DXVECTOR2(pf:access constant float) return access D3DXVECTOR2 is
      This:access D3DXVECTOR2:=new D3DXVECTOR2;
   begin      
      if pf/=Null then
         declare
            pf1:float with Address=>(pf.all'Address+4);
         begin
            This.x:=pf.all;
            This.y:=pf1;
         end;
      end if;
      return This;
   end;
   
   function NEW_D3DXVECTOR2(pf:access FLOAT_ARRAY) return access D3DXVECTOR2 is
      This:access D3DXVECTOR2:=new D3DXVECTOR2'(0.0,0.0);
   begin      
      if pf/=Null and then pf'Length>=2 then
         declare
            pf1:float with Address=>(pf(pf'First+1)'Address);
         begin
            This.x:=pf(pf'First);
            This.y:=pf1;
         end;
      end if;
      return This;
   end;
   
   function NEW_D3DXVECTOR2(pf:FLOAT_ARRAY) return access D3DXVECTOR2 is
      This:access D3DXVECTOR2:=new D3DXVECTOR2'(0.0,0.0);
   begin      
      if pf'Length>=2 then
         declare
            pf1:float with Address=>(pf(pf'First+1)'Address);
         begin
            This.x:=pf(pf'First);
            This.y:=pf1;
         end;
      end if;
      return This;
   end;
   
   function NEW_D3DXVECTOR2(pf:access constant D3DXFLOAT16) return access D3DXVECTOR2 is
      This:access D3DXVECTOR2:=new D3DXVECTOR2'(0.0,0.0);
   begin
      declare
         af:access FLOAT;
      begin
         af:=D3DXFloat16To32Array(This.x'Unrestricted_Access, pf, 2);
         return This;
      end;
   exception when others=>
         return This;
   end;
   
   function NEW_D3DXVECTOR2(pf:access constant D3DXFLOAT16_ARRAY) return access D3DXVECTOR2 is
      This:access D3DXVECTOR2:=new D3DXVECTOR2'(0.0,0.0);
      af:access FLOAT;
   begin
      if pf/=null and then pf'Length>=2 then
         af:=D3DXFloat16To32Array(This.x'Unrestricted_Access, pf(pf'First)'unrestricted_access, 2);
      end if;
      return This;
   end;
   
   function NEW_D3DXVECTOR2(pf:D3DXFLOAT16_ARRAY) return access D3DXVECTOR2 is
      This:access D3DXVECTOR2:=new D3DXVECTOR2'(0.0,0.0);
      af:access FLOAT;
   begin
      if pf'Length>=2 then
         af:=D3DXFloat16To32Array(This.x'Unrestricted_Access, pf(pf'First)'unrestricted_access, 2);
      end if;
      return This;
   end;
   
   
   function NEW_D3DXVECTOR2(x,y:float) return access D3DXVECTOR2 is
      This:access D3DXVECTOR2:=new D3DXVECTOR2;
   begin
      This.x:=x;
      This.y:=y;
      return This;
   end;
   
   function TO_LPFLOAT(This:LPD3DXVECTOR2) return access FLOAT is
   begin
      if This=null then
         return null;
      end if;
      return This.x'Unrestricted_Access;
   end;
   
   function TO_LPCFLOAT(This:LPD3DXVECTOR2) return access FLOAT is
   begin
      if This=null then
         return null;
      end if;
      return This.x'Unrestricted_Access;
   end;
   
   function TO_LPFLOAT_ARRAY(This:LPD3DXVECTOR2) return access FLOAT_ARRAY is
   begin
      if This=null then
         return null;
      end if;
      declare
         FA:FLOAT_ARRAY(0..1) with Import,Address=>This.all'Address;
      begin
         return FA'Unrestricted_Access;
      end;
   end;
   
   function TO_LPCFLOAT_ARRAY(This:LPD3DXVECTOR2) return access constant FLOAT_ARRAY is
   begin
      if This=null then
         return null;
      end if;
      declare
         FA:constant FLOAT_ARRAY(0..1) with Import,Address=>This.all'Address;
      begin
         return FA'Unrestricted_Access;
      end;
   end;
   
   procedure SInc(This:in out D3DXVECTOR2;v:D3DXVECTOR2) is
   begin
      This.x:=This.x+v.x;
      This.y:=This.y+v.y;
   end;
   
   procedure SDec(This:in out D3DXVECTOR2;v:D3DXVECTOR2) is
   begin
      This.x:=This.x-v.x;
      This.y:=This.y-v.y;
   end;
   
   procedure SMul(This:in out D3DXVECTOR2;f:FLOAT) is
   begin
      This.x:=This.x*f;
      This.y:=This.y*f;
   end;
   
   procedure SDiv(This:in out D3DXVECTOR2;f:FLOAT) is
   begin
      if f/=0.0 then
         declare
            fInv:FLOAT:=1.0/f;
         begin
            This.x:=This.x*fInv;
            This.y:=This.y*fInv;
         end;
      else
         This:=(others=>FLOAT'Last);
      end if;
   end;
   
   --
   -- Ò»Ôª²Ù×÷·û
   --
   function "+"(This:D3DXVECTOR2) return D3DXVECTOR2 is  
   begin
      return (This); 
   end "+";
   
   function "-"(This:D3DXVECTOR2) return D3DXVECTOR2 is
   begin
      return (-This.x,-This.y);
   end "-";
   
   --
   -- ¶þÔª²Ù×÷·û
   --
   function "+"(This:D3DXVECTOR2;v:D3DXVECTOR2) return D3DXVECTOR2 is
   begin
      return (This.x+v.x,This.y+v.y);
   end "+";
   
   function "-"(This:D3DXVECTOR2;v:D3DXVECTOR2) return D3DXVECTOR2 is
   begin
      return (This.x-v.x,This.y-v.y);
   end "-";
   
   function "*"(This:D3DXVECTOR2;f:Float) return D3DXVECTOR2 is
   begin
      return (This.x*f,This.y*f);
   end "*";
   
   function "*"(f:Float;v:D3DXVECTOR2) return D3DXVECTOR2 is
   begin
      return (v.x*f,v.y*f);
   end "*";
   
   function "/"(This:D3DXVECTOR2;f:Float) return D3DXVECTOR2 is
   begin
      if f/=0.0 then
         declare
            fInv:float:=1.0/f;
         begin
            return (This.x*fInv,This.y*fInv); 
         end;
      else
         return (others=>FLOAT'Last);
      end if;
   end "/";
   
   function "="(This:D3DXVECTOR2;v:D3DXVECTOR2) return win32.BOOL is
   begin
      if This=v then
         return win32.True;
      end if;
      return win32.FALSE;
   end "=";
   
   function "/="(This:D3DXVECTOR2;v:D3DXVECTOR2) return win32.BOOL is
   begin
      if This/=v then
         return win32.True;
      end if;
      return win32.FALSE;
   end "/=";
   
   
   --
   -- 2D Vector (16 bit)
   --
   
   function NEW_D3DXVECTOR2_16F return access D3DXVECTOR2_16F is
      This:access D3DXVECTOR2_16F:=new D3DXVECTOR2_16F'((value=>0),(value=>0));
   begin
      return This;
   end NEW_D3DXVECTOR2_16F;
   
   function NEW_D3DXVECTOR2_16F(pf:access constant FLOAT) return access D3DXVECTOR2_16F is
      This:access D3DXVECTOR2_16F:=new D3DXVECTOR2_16F;
   begin
      declare
         self:access D3DXFLOAT16;
      begin
         self:=D3DXFloat32To16Array(This.x'Unrestricted_Access, pf, 2);
         return This;
      end;
   end;
   
   function NEW_D3DXVECTOR2_16F(pf:access constant FLOAT_ARRAY) return access D3DXVECTOR2_16F is
      This:access D3DXVECTOR2_16F:=new D3DXVECTOR2_16F'(others=>(value=>0));
   begin
      if pf/=null and then pf'Length>=2 then
         declare
            self:access D3DXFLOAT16;
         begin
            self:=D3DXFloat32To16Array(This.x'Unrestricted_Access, pf(pf'First)'unrestricted_access, 2);
            return This;
         end;
      end if;
      return This;
   end;
   
   function NEW_D3DXVECTOR2_16F(pf:FLOAT_ARRAY) return access D3DXVECTOR2_16F is
      This:access D3DXVECTOR2_16F:=new D3DXVECTOR2_16F'(others=>(value=>0));
   begin
      if pf'Length>=2 then
         declare
            self:access D3DXFLOAT16;
         begin
            self:=D3DXFloat32To16Array(This.x'Unrestricted_Access, pf(pf'First)'unrestricted_access, 2);
            return This;
         end;
      end if;
      return This;
   end;
   
   function NEW_D3DXVECTOR2_16F(pf:access constant D3DXFLOAT16) return access D3DXVECTOR2_16F is
      This:access D3DXVECTOR2_16F:=new D3DXVECTOR2_16F;
   begin
      declare
         dw1:DWORD with Address=>This.all'Address;
         dw2:DWORD with Address=>pf.all'Address;
      begin
         dw1:=dw2;
         return This;
      end;
   end;
   
   function NEW_D3DXVECTOR2_16F(pf:access constant D3DXFLOAT16_ARRAY) return access D3DXVECTOR2_16F is
      This:access D3DXVECTOR2_16F:=new D3DXVECTOR2_16F'(others=>(value=>0));
   begin
      if pf/=null and then pf'Length>=2 then
         declare
            dw1:DWORD with Address=>This.all'Address;
            dw2:DWORD with Address=>pf.all'Address;
         begin
            dw1:=dw2;
            return This;
         end;
      end if;
      return This;
   end;
   
   function NEW_D3DXVECTOR2_16F(pf:D3DXFLOAT16_ARRAY) return access D3DXVECTOR2_16F is
      This:access D3DXVECTOR2_16F:=new D3DXVECTOR2_16F'(others=>(value=>0));
   begin
      if pf'Length>=2 then
         declare
            dw1:DWORD with Address=>This.all'Address;
            dw2:DWORD with Address=>pf'Address;
         begin
            dw1:=dw2;
            return This;
         end;
      end if;
      return This;
   end;
   
   function NEW_D3DXVECTOR2_16F(fx,fy:D3DXFLOAT16) return access D3DXVECTOR2_16F is
      This:access D3DXVECTOR2_16F:=new D3DXVECTOR2_16F'(fx,fy);
   begin
      return This;
   end;
   
   
   function TO_LPD3DXFLOAT16(This:LPD3DXVECTOR2_16F) return access D3DXFLOAT16 is
   begin
      if This/=null then
         return This.x'Unrestricted_Access;
      end if;
      return null;
   end;
   
   function TO_LPCD3DXFLOAT16(This:LPD3DXVECTOR2_16F) return access constant D3DXFLOAT16 is
   begin
      if This/=null then
         return This.x'Unrestricted_Access;
      end if;
      return null;
   end;
   
   function "="(This:D3DXVECTOR2_16F;v:D3DXVECTOR2_16F) return win32.BOOL is
   begin
      if This=v then
         return win32.TRUE;
      end if;
      return win32.FALSE;
   end "=";
   
   function "/="(This:D3DXVECTOR2_16F;v:D3DXVECTOR2_16F) return win32.BOOL is
   begin
      if This/=v then
         return Win32.TRUE;
      end if;
      return WIN32.FALSE;
   end "/=";
   
   
   
   
   --
   -- 3D Vector
   --
   
   function NEW_D3DXVECTOR3 return access D3DXVECTOR3 is
   begin
      return new D3DXVECTOR3'(others=>0.0);
   end;
   
   function NEW_D3DXVECTOR3(pf:access constant FLOAT) return access D3DXVECTOR3 is
      This:access D3DXVECTOR3:=new D3DXVECTOR3'(others=>0.0);
   begin
      if pf=null then
         return This;
      end if;
      
      declare
         f3:array(0..2) of FLOAT with Import,Address=>pf.all'Address;
      begin
         This.x:=f3(0);
         This.y:=f3(1);
         This.z:=f3(2);
         return This;
      end;
   exception when others=>
         return This;
   end;
   
   function NEW_D3DXVECTOR3(pf:access constant FLOAT_ARRAY) return access D3DXVECTOR3 is
      This:access D3DXVECTOR3:=new D3DXVECTOR3'(others=>0.0);
   begin
      if pf/=null and then pf'length>=3 then
         declare
            f3:array(0..2) of FLOAT with Import,Address=>pf.all'Address;
         begin
            This.x:=f3(0);
            This.y:=f3(1);
            This.z:=f3(2);
         end;
      end if;
      return This;
   end;
   
   
   function NEW_D3DXVECTOR3(fa:float_Array) return access D3DXVECTOR3 is
   begin
      return new D3DXVECTOR3'(fa(fa'first),fa(fa'First+1),fa(fa'First+2));
   end;
   
   function NEW_D3DXVECTOR3(v:D3DXVECTOR3) return access D3DXVECTOR3 is
   begin
      return new D3DXVECTOR3'(v);
   end;
   
   
   function NEW_D3DXVECTOR3(pf:access constant D3DXFLOAT16) return access D3DXVECTOR3 is
      This:access D3DXVECTOR3:=new D3DXVECTOR3;
   begin
      declare
         af:access Float;
      begin
         af:=D3DXFloat16To32Array(This.x'Unrestricted_Access, pf, 3);
         return This;
      end;
   end;
   
   function NEW_D3DXVECTOR3(pf:access constant D3DXFLOAT16_ARRAY) return access D3DXVECTOR3 is
      This:access D3DXVECTOR3:=new D3DXVECTOR3;
   begin
      if pf/=null and then pf'Length>=3 then
         declare
            af:access Float;
         begin
            af:=D3DXFloat16To32Array(This.x'Unrestricted_Access, pf(pf'First)'unrestricted_access, 3);
            return This;
         end;
      end if;
      This.all:=(0.0,0.0,0.0);
      return This;
   end;
   
   function NEW_D3DXVECTOR3(pf:D3DXFLOAT16_ARRAY) return access D3DXVECTOR3 is
      This:access D3DXVECTOR3:=new D3DXVECTOR3;
   begin
      if pf'Length>=3 then
         declare
            af:access Float;
         begin
            af:=D3DXFloat16To32Array(This.x'Unrestricted_Access, pf(pf'First)'unrestricted_access, 3);
            return This;
         end;
      end if;
      This.all:=(0.0,0.0,0.0);
      return This;
   end;
   
   function NEW_D3DXVECTOR3(x,y,z:FLOAT) return access D3DXVECTOR3 is
   begin
      return new D3DXVECTOR3'(x,y,z);
   end;
   
   function TO_LPFLOAT(This:LPD3DXVECTOR3) return access FLOAT is
   begin
      if This=null then
         return null;
      end if;
      return This.x'Unrestricted_Access;
   end;
   
   function TO_LPFLOAT_ARRAY(This:LPD3DXVECTOR3) return access FLOAT_ARRAY is
   begin
      if This=null then
         return null;
      end if;
      declare
         fa:FLOAT_ARRAY(0..2) with Import,Address=>This.all'Address;
      begin
         return fa'Unrestricted_Access;
      end;
   end;
   
   
   function TO_LPCFLOAT(This:LPD3DXVECTOR3) return access FLOAT is
   begin
      if This=null then
         return null;
      end if;
      return This.x'Unrestricted_Access;
   end;
   
   function TO_LPCFLOAT_ARRAY(This:LPD3DXVECTOR3) return access FLOAT_ARRAY is
   begin
      if This=null then
         return null;
      end if;
      declare
         fa:FLOAT_ARRAY(0..2) with Import,Address=>This.all'Address;
      begin
         return fa'Unrestricted_Access;
      end;
   end;
   
   procedure SInc(This:in out D3DXVECTOR3;v:D3DXVECTOR3) is
   begin
      This.x:=This.x+v.x;
      This.y:=This.y+v.y;
      This.z:=This.z+v.z;
   end;
   
   procedure SDec(This:in out D3DXVECTOR3;v:D3DXVECTOR3) is
   begin
      This.x:=This.x-v.x;
      This.y:=This.y-v.y;
      This.z:=This.z-v.z;
   end;
   
   procedure SMul(This:in out D3DXVECTOR3;f:FLOAT) is
   begin
      This.x:=This.x*f;
      This.y:=This.y*f;
      This.z:=This.z*f;
   end;
   
   procedure SDiv(This:in out D3DXVECTOR3;f:FLOAT) is
   begin
      if f/=0.0 then
         declare
            fInv:FLOAT:=1.0/f;
         begin
            This.x:=This.x*fInv;
            This.y:=This.y*fInv;
            This.z:=This.x*fInv;
         end;
      else
         This:=(others=>FLOAT'Last);
      end if;
   end;
   
   function "+"(This:D3DXVECTOR3) return D3DXVECTOR3 is
   begin
      return This;
   end;
   
   function "-"(This:D3DXVECTOR3) return D3DXVECTOR3 is
   begin
      return (-This.x,-This.y,-This.z);
   end;
   
   
   function "+"(This:D3DXVECTOR3;v:D3DXVECTOR3) return D3DXVECTOR3 is
   begin
      return (This.x+v.x,This.y+v.y,This.z+v.z);
   end;
   
   function "-"(This:D3DXVECTOR3;v:D3DXVECTOR3) return D3DXVECTOR3 is
   begin
      return (This.x-v.x,This.y-v.y,This.z-v.z);
   end;
   
   
   function "*"(This:D3DXVECTOR3;f:float) return D3DXVECTOR3 is
   begin
      return (This.x*f,This.y*f,This.z*f);
   end;
   
   function "*"(f:float;v:D3DXVECTOR3) return D3DXVECTOR3 is
   begin
      return (v.x*f,v.y*f,v.z*f);
   end;
   
   function "/"(This:D3DXVECTOR3;f:float) return D3DXVECTOR3 is
   begin
      if f=0.0 then
         return (float'last,float'last,float'last);
      else
         declare
            fInv:Float:=1.0/f;
         begin
            return (This.x*fInv,This.y*fInv,This.z*fInv);
         end;
      end if;
   end;
   
   
   
   function "="(This:D3DXVECTOR3;v:D3DXVECTOR3) return win32.BOOL is
   begin
      if This=v then
         return win32.TRUE;
      end if;
      return win32.FALSE;
   end;
   
   
   function "/="(This:D3DXVECTOR3;v:D3DXVECTOR3) return win32.BOOL is
   begin
      if This/=v then
         return win32.TRUE;
      end if;
      return win32.FALSE;
   end "/=";
   
   
   
   --
   -- 3D Vector (16 bit)
   --
   function NEW_D3DXVECTOR3_16F return access D3DXVECTOR3_16F is
      This:access D3DXVECTOR3_16F:=new D3DXVECTOR3_16F'(others=>(Value=>0));
   begin
      return This;
   end;
   
   function NEW_D3DXVECTOR3_16F(pf:access constant FLOAT) return access D3DXVECTOR3_16F is
      This:access D3DXVECTOR3_16F:=new D3DXVECTOR3_16F;
   begin
      declare
         f:access D3DXFLOAT16;
      begin
         f:=D3DXFloat32To16Array(This.x'Unrestricted_Access, pf, 3);
         return This;
      end;
   end;
   
   
   function NEW_D3DXVECTOR3_16F(pf:access constant FLOAT_ARRAY) return access D3DXVECTOR3_16F is
      This:access D3DXVECTOR3_16F:=new D3DXVECTOR3_16F'(others=>(value=>0));
   begin
      if pf/=null and then pf'Length>=3 then
         declare
            f:access D3DXFLOAT16;
         begin
            f:=D3DXFloat32To16Array(This.x'Unrestricted_Access, pf(pf'First)'unrestricted_access, 3);
            return This;
         end;
      end if;
      return This;
   end;
   
   function NEW_D3DXVECTOR3_16F(pf:FLOAT_ARRAY) return access D3DXVECTOR3_16F is
      This:access D3DXVECTOR3_16F:=new D3DXVECTOR3_16F'(others=>(value=>0));
   begin
      if pf'Length>=3 then
         declare
            f:access D3DXFLOAT16;
         begin
            f:=D3DXFloat32To16Array(This.x'Unrestricted_Access, pf(pf'First)'unrestricted_access, 3);
            return This;
         end;
      end if;
      return This;
   end;
   
   
   function NEW_D3DXVECTOR3_16F(v:D3DVECTOR) return access D3DXVECTOR3_16F is
      This:access D3DXVECTOR3_16F:=new D3DXVECTOR3_16F;
   begin
      declare
         f:access D3DXFLOAT16;
      begin
         f:=D3DXFloat32To16Array(This.x'Unrestricted_Access, v.x'Unrestricted_Access, 1);
         f:=D3DXFloat32To16Array(This.y'Unrestricted_Access, v.y'Unrestricted_Access, 1);
         f:=D3DXFloat32To16Array(This.z'Unrestricted_Access, v.z'Unrestricted_Access, 1);
         return This;
      end;
   end;
   
   function NEW_D3DXVECTOR3_16F(pf:access constant D3DXFLOAT16) return access D3DXVECTOR3_16F is
      This:access D3DXVECTOR3_16F:=new D3DXVECTOR3_16F;
   begin
      declare
         type UINT48 is mod 2**48;
         U:UINT48 with Address=>This.x'Address;
         u1:UINT48 with Address=>pf.all'Address;
      begin
         u:=u1;
         return This;
      end;
   exception when others=>
         This.all:=(others=>(value=>0));
         return This;
   end;
   
   function NEW_D3DXVECTOR3_16F(pf:access constant D3DXFLOAT16_ARRAY) return access D3DXVECTOR3_16F is
      This:access D3DXVECTOR3_16F:=new D3DXVECTOR3_16F;
   begin
      if pf/=null and then pf'Length>=3 then
         declare
            type UINT48 is mod 2**48;
            U:UINT48 with Address=>This.x'Address;
            u1:UINT48 with Address=>pf.all'Address;
         begin
            u:=u1;
            return This;
         end;
      end if;
      This.all:=(others=>(value=>0));
      return This;
   end;
   
   function NEW_D3DXVECTOR3_16F(pf: D3DXFLOAT16_ARRAY) return access D3DXVECTOR3_16F is
      This:access D3DXVECTOR3_16F:=new D3DXVECTOR3_16F;
   begin
      if pf'Length>=3 then
         declare
            type UINT48 is mod 2**48;
            U:UINT48 with Address=>This.x'Address;
            u1:UINT48 with Address=>pf'Address;
         begin
            u:=u1;
            return This;
         end;
      end if;
      This.all:=(others=>(value=>0));
      return This;
   end;
   
   
   function NEW_D3DXVECTOR3_16F(fx,fy,fz:D3DXFLOAT16) return access D3DXVECTOR3_16F is
      This:access D3DXVECTOR3_16F:=new D3DXVECTOR3_16F'(fx,fy,fz);
   begin
      return This;
   end;
   
   function TO_LPD3DXVECTOR3_16F(This:LPD3DXVECTOR3_16F) return access D3DXFLOAT16 is
   begin
      if This=null then
         return null;
      end if;
      return This.x'Unrestricted_Access;
   end;
   
   function TO_LPCD3DXVECTOR3_16F(This:LPD3DXVECTOR3_16F) return access constant D3DXFLOAT16 is
   begin
      if This=null then
         return null;
      end if;
      return This.x'Unrestricted_Access;
   end;
   
   function "="(This:D3DXVECTOR3_16F;v:D3DXVECTOR3_16F) return win32.BOOL is
   begin
      if This=v then
         return win32.TRUE;
      end if;
      return win32.FALSE;
   end;
   
   function "/="(This:D3DXVECTOR3_16F;v:D3DXVECTOR3_16F) return win32.BOOL is
   begin
      if This/=v then
         return win32.TRUE;
      end if;
      return win32.FALSE;
   end;
   
   
   --
   -- 4D Vector
   --
   
   -- ¹¹Ô캯Êý
   function NEW_D3DXVECTOR4 return access D3DXVECTOR4 is
      This:access D3DXVECTOR4:=new D3DXVECTOR4'(others=>0.0);
   begin
      return This;
   end;
   
   function NEW_D3DXVECTOR4(pf:access constant FLOAT) return access D3DXVECTOR4 is
      This:access D3DXVECTOR4:=new D3DXVECTOR4'(others=>0.0);
   begin
      if pf/=null then
         declare
            FA:FLOAT_ARRAY(0..3) with Address=>pf.all'Address;
         begin
            This.all:=(FA(0),FA(1),FA(2),FA(3));
         end;
      end if;
      return This;
   exception when others=>
         return This;
   end;
   
   function NEW_D3DXVECTOR4(pf:access constant FLOAT_ARRAY) return access D3DXVECTOR4 is
      This:access D3DXVECTOR4:=new D3DXVECTOR4'(others=>0.0);
   begin
      if pf/=null and then pf'length>=4 then
         This.all:=(pf(pf'First),pf(pf'First+1),pf(pf'First+2),pf(pf'First+3));
      end if;
      return This;
   end;
   
   
   function NEW_D3DXVECTOR4(FA:FLOAT_ARRAY) return access D3DXVECTOR4 is
      This:access D3DXVECTOR4:=new D3DXVECTOR4'(FA(FA'First),FA(FA'First+1),FA(FA'First+2),FA(FA'First+3));
   begin
      return This;
   end;
   
   function NEW_D3DXVECTOR4(pf:access constant D3DXFLOAT16) return access D3DXVECTOR4 is
      This:access D3DXVECTOR4:=new D3DXVECTOR4;
   begin
      if pf/=null then
         declare
            x:access Float;
         begin
            x:=D3DXFloat16To32Array(This.x'Unrestricted_Access, pf, 4);
            return This;
         end;
      end if;
      This.all:=(others=>0.0);
      return This;
   exception when others=>
         return This;
   end;
   
   function NEW_D3DXVECTOR4(pf:access constant D3DXFLOAT16_ARRAY) return access D3DXVECTOR4 is
      This:access D3DXVECTOR4:=new D3DXVECTOR4;
   begin
      if pf/=null and then pf'Length>=4 then
         declare
            x:access Float;
         begin
            x:=D3DXFloat16To32Array(This.x'Unrestricted_Access, pf(pf'First)'unrestricted_access, 4);
            return This;
         end;
      end if;
      This.all:=(others=>0.0);
      return This;
   end;
   
   function NEW_D3DXVECTOR4(pf:D3DXFLOAT16_ARRAY) return access D3DXVECTOR4 is
      This:access D3DXVECTOR4:=new D3DXVECTOR4;
   begin
      if pf'Length>=4 then
         declare
            x:access Float;
         begin
            x:=D3DXFloat16To32Array(This.x'Unrestricted_Access, pf(pf'first)'unrestricted_access, 4);
            return This;
         end;
      end if;
      This.all:=(others=>0.0);
      return This;
   end;
   
   
   
   
   function NEW_D3DXVECTOR4(v:D3DVECTOR;w:FLOAT) return access D3DXVECTOR4 is
      This:access D3DXVECTOR4:=new D3DXVECTOR4'(v.x,v.y,v.z,w);
   begin
      return This;
   end;
   
   function NEW_D3DXVECTOR4(fx,fy,fz,fw:FLOAT) return access D3DXVECTOR4 is
      This:access D3DXVECTOR4:=new D3DXVECTOR4'(fx,fy,fz,fw);
   begin
      return This;
   end;
   
   function TO_LPFLOAT_ARRAY(This:LPD3DXVECTOR4) return access FLOAT_ARRAY is
   begin
      if This=null then
         return null;
      end if;
      declare
         FA:FLOAT_ARRAY(0..3) with Address=>This.all'Address;
      begin
         return FA'Unrestricted_Access;
      end;
   end;
   
   function TO_FLOAT_ARRAY(This:D3DXVECTOR4) return FLOAT_ARRAY is
   begin
      declare
         FA:FLOAT_ARRAY(0..3) with Import,Address=>This'Address;
      begin
         return (FA);
      end;
   end;
   
   function TO_LPCFLOAT_ARRAY(This:LPD3DXVECTOR4) return access constant FLOAT_ARRAY is
   begin
      if This=null then
         return null;
      end if;
      declare
         FA:constant FLOAT_ARRAY(0..3) with Import,Address=>This.all'Address;
      begin
         return FA'Unrestricted_Access;
      end;
   end;
   
   
   procedure SInc(This:in out D3DXVECTOR4;v:D3DXVECTOR4) is
   begin
      This.x:=This.x+v.x;
      This.y:=This.y+v.y;
      This.z:=This.z+v.z;
      This.w:=This.w+v.w;
   end;
   
   procedure SDec(This:in out D3DXVECTOR4;v:D3DXVECTOR4) is
   begin
      This.x:=This.x-v.x;
      This.y:=This.y-v.y;
      This.z:=This.z-v.z;
      This.w:=This.w-v.w;
   end;
   
   procedure SMul(This:in out D3DXVECTOR4;f:FLOAT) is
   begin
      This.x:=This.x*f;
      This.y:=This.y*f;
      This.z:=This.z*f;
      This.w:=This.w*f;
   end;
   
   procedure SDiv(This:in out D3DXVECTOR4;f:FLOAT) is
   begin
      if f/=0.0 then
         declare
            fInv:FLOAT:=1.0/f;
         begin
            This.x:=This.x*fInv;
            This.y:=This.y*fInv;
            This.z:=This.x*fInv;
            This.w:=This.y*fInv;
         end;
      else
         This:=(others=>FLOAT'Last);
      end if;
   end;
   
   function "+"(This:D3DXVECTOR4) return D3DXVECTOR4 is
   begin
      return This;
   end;
   
   function "-"(This:D3DXVECTOR4) return D3DXVECTOR4 is
   begin
      return (-This.x,-This.y,-This.z,-This.w);
   end;
   
   function "+"(This:D3DXVECTOR4;v:D3DXVECTOR4) return D3DXVECTOR4 is
   begin
      return (This.x+v.x,This.y+v.y,This.z+v.z,This.w+v.w);
   end;
   
   function "-"(This:D3DXVECTOR4;v:D3DXVECTOR4) return D3DXVECTOR4 is
   begin
      return (This.x-v.x,This.y-v.y,This.z-v.z,This.w-v.w);
   end;
   
   function "*"(This:D3DXVECTOR4;f:FLOAT) return D3DXVECTOR4 is
   begin
      return (This.x*f,This.y*f,This.z*f,This.w*f);
   end;
   
   function "*"(f:FLOAT;This:D3DXVECTOR4) return D3DXVECTOR4 is
   begin
      return (This.x*f,This.y*f,This.z*f,This.w*f);
   end;
   
   function "/"(This:D3DXVECTOR4;f:FLOAT) return D3DXVECTOR4 is
   begin
      if f=0.0 then
         return (others=>FLOAT'Last);
      end if;
      declare
         fInv:FLOAT:=1.0/f;
      begin
         return (This.x*fInv,This.y*fInv,This.z*fInv,This.w*fInv);
      end;
   end;
   
   function "="(This:D3DXVECTOR4;v:D3DXVECTOR4) return win32.BOOL is
   begin
      if This=v then
         return Win32.TRUE;
      end if;
      return win32.FALSE;
   end "=";
   
   function "/="(This:D3DXVECTOR4;v:D3DXVECTOR4) return win32.BOOL is
   begin
      if This/=v then
         return Win32.TRUE;
      end if;
      return win32.FALSE;
   end "/=";
   
   
   
   
   
   --
   -- 4D Vector (16 bit)
   --
   
   function NEW_D3DXVECTOR4_16F return access D3DXVECTOR4_16F is
   begin
      return new D3DXVECTOR4_16F'(others=>(value=>0));
   end;
   
   function NEW_D3DXVECTOR4_16F(pf:access constant FLOAT) return access D3DXVECTOR4_16F is
      This:access D3DXVECTOR4_16F:=new D3DXVECTOR4_16F;
      df16:access D3DXFLOAT16;
   begin
      if pf/=null then
         df16:=D3DXFloat32To16Array(This.x'unrestricted_access, pf, 4);
      else
         This.all:=(others=>(value=>0));
      end if;
      return This;
   end;
   
   function NEW_D3DXVECTOR4_16F(pf:access constant FLOAT_ARRAY) return access D3DXVECTOR4_16F is
      This:access D3DXVECTOR4_16F:=new D3DXVECTOR4_16F'(others=>(value=>0));
      df16:access D3DXFLOAT16;
   begin
      if pf/=null and then pf'Length>=4 then
         df16:=D3DXFloat32To16Array(This.x'unrestricted_access, pf(pf'First)'unrestricted_access, 4);
      end if;
      return This;
   end;
   
   function NEW_D3DXVECTOR4_16F(pf:FLOAT_ARRAY) return access D3DXVECTOR4_16F is
      This:access D3DXVECTOR4_16F:=new D3DXVECTOR4_16F'(others=>(value=>0));
      df16:access D3DXFLOAT16;
   begin
      if pf'Length>=4 then
         df16:=D3DXFloat32To16Array(This.x'unrestricted_access, pf(pf'First)'unrestricted_access, 4);
      end if;
      return This;
   end;
   
   function NEW_D3DXVECTOR4_16F(pf:access constant D3DXFLOAT16) return access D3DXVECTOR4_16F is
      This:access D3DXVECTOR4_16F:=new D3DXVECTOR4_16F'(others=>(value=>0));
   begin
      if pf/=null then
         declare
            type qword is mod 2**64;
            qw1:qword with Import,Address=>This.all'Address;
            qw2:qword with Import,Address=>pf.all'Address;
         begin
            qw1:=qw2;
         end;
      end if;
      return This;
   exception when others=>
         return This;
   end;
   
   function NEW_D3DXVECTOR4_16F(pf:access constant D3DXFLOAT16_ARRAY) return access D3DXVECTOR4_16F is
      This:access D3DXVECTOR4_16F:=new D3DXVECTOR4_16F'(others=>(value=>0));
   begin
      if pf/=null and then pf'Length>=4 then
         declare
            type qword is mod 2**64;
            qw1:qword with Import,Address=>This.all'Address;
            qw2:qword with Import,Address=>pf.all'Address;
         begin
            qw1:=qw2;
         end;
      end if;
      return This;
   end;
   
   function NEW_D3DXVECTOR4_16F(pf:D3DXFLOAT16_ARRAY) return access D3DXVECTOR4_16F is
      This:access D3DXVECTOR4_16F:=new D3DXVECTOR4_16F'(others=>(value=>0));
   begin
      if pf'Length>=4 then
         declare
            type qword is mod 2**64;
            qw1:qword with Import,Address=>This.all'Address;
            qw2:qword with Import,Address=>pf'Address;
         begin
            qw1:=qw2;
         end;
      end if;
      return This;
   end;
   
   
   function NEW_D3DXVECTOR4_16F(v:D3DXVECTOR3_16F;w:D3DXFLOAT16) return access D3DXVECTOR4_16F is
   begin
      return new D3DXVECTOR4_16F'(v.x,v.y,v.z,w);
   end;
   
   function NEW_D3DXVECTOR4_16F(x,y,z,w:D3DXFLOAT16) return access D3DXVECTOR4_16F is
   begin
      return new D3DXVECTOR4_16F'(x,y,z,w);
   end;
   
   function TO_LPD3DXFLOAT16(This:LPD3DXVECTOR4_16F) return access D3DXFLOAT16 is
   begin
      if This=null then
         return null;
      end if;
      return This.x'Unrestricted_Access;
   end;
   
   function TO_LPD3DXFLOAT16_ARRAY(This:LPD3DXVECTOR4_16F) return access D3DXFLOAT16_ARRAY is
   begin
      declare
         f16a:D3DXFLOAT16_ARRAY(0..3) with Import,Address=>This.x'Address;
      begin
         return f16a'Unrestricted_Access;
      end;
   end;
   
   function TO_LPCD3DXFLOAT16(This:LPD3DXVECTOR4_16F) return access constant D3DXFLOAT16 is
   begin
      if This=null then
         return null;
      end if;
      return This.x'Unrestricted_Access;
   end;
   
   function TO_LPCD3DXFLOAT16_ARRAY(This:LPD3DXVECTOR4_16F) return access constant D3DXFLOAT16_ARRAY is
   begin
      declare
         f16a:constant D3DXFLOAT16_ARRAY(0..3) with Import,Address=>This.x'Address;
      begin
         return f16a'Unrestricted_Access;
      end;
   end;
   
   function "="(This:D3DXVECTOR4_16F;V:D3DXVECTOR4_16F) return win32.BOOL is
   begin
      if This=v then
         return win32.TRUE;
      end if;
      return win32.FALSE;
   end;
   
   function "/="(This:D3DXVECTOR4_16F;V:D3DXVECTOR4_16F) return win32.BOOL is
   begin
      if This/=v then
         return win32.TRUE;
      end if;
      return win32.FALSE;
   end;
   
   
   --
   -- D3DXMATRIX
   --
   
   function NEW_D3DXMATRIX return access D3DXMATRIX is
   begin
      return new D3DXMATRIX'(true,others=>0.0);
   end;
   
   function NEW_D3DXMATRIX(f:access constant Float) return access D3DXMATRIX is
      This:access D3DXMATRIX:=new D3DXMATRIX;
      x:win32.PVOID;
   begin
      if f/=null then
         x:=memcpy(This.m11'Address,f.all'Address,64);
      else
         x:=memset(This.m11'Address,0,16);
      end if;
      return This;
   exception when others=>
         return This;
   end;
   
   function NEW_D3DXMATRIX(f:access constant FLOAT_ARRAY) return access D3DXMATRIX is
      This:access D3DXMATRIX:=new D3DXMATRIX;
      x:win32.PVOID;
   begin
      if f/=null and then f'length>=16 then
         x:=memcpy(This.m11'Address,f.all'Address,64);
      end if;
      x:=memset(This.m11'Address,0,16);
      return This;
   end;
   
   
   function NEW_D3DXMATRIX(f:FLOAT_ARRAY) return access D3DXMATRIX is
      This:access D3DXMATRIX:=new D3DXMATRIX;
      x:win32.PVOID;
   begin
      if f'length>=16 then
         x:=memcpy(This.m11'Address,f'Address,64);
      end if;
      x:=memset(This.m11'Address,0,16);
      return This;
   end;
   
   
   
   function NEW_D3DXMATRIX(mat:D3DXMATRIX) return access D3DXMATRIX is
      This:access D3DXMATRIX:=new D3DXMATRIX;
      x:win32.PVOID;
   begin
      x:=memcpy(This.m11'Address,mat.m11'Address,64);
      return This;
   end;
   
   function NEW_D3DXMATRIX(pf:access constant D3DXFLOAT16) return access D3DXMATRIX is
      This:access D3DXMATRIX:=new D3DXMATRIX;
      f:access float;
   begin
      if pf/=null then
         f:=D3DXFloat16To32Array(This.m11'Unrestricted_Access, pf, 16);
      else
         This.all:=(true,others=>0.0);
      end if;
      return This;
   end;
   
   function NEW_D3DXMATRIX(pf:access constant D3DXFLOAT16_ARRAY) return access D3DXMATRIX is
      This:access D3DXMATRIX:=new D3DXMATRIX;
      f:access float;
   begin
      if pf/=null and then pf'Length>=16 then
         f:=D3DXFloat16To32Array(This.m11'Unrestricted_Access, pf(pf'First)'unrestricted_access, 16);
      else
         This.all:=(true,others=>0.0);
      end if;
      return This;
   end;
   
   function NEW_D3DXMATRIX(pf:D3DXFLOAT16_ARRAY) return access D3DXMATRIX is
      This:access D3DXMATRIX:=new D3DXMATRIX;
      f:access float;
   begin
      if pf'Length>=16 then
         f:=D3DXFloat16To32Array(This.m11'Unrestricted_Access, pf(pf'First)'unrestricted_access, 16);
      else
         This.all:=(true,others=>0.0);
      end if;
      return This;
   end;
   
   function NEW_D3DXMATRIX(f11,f12,f13,f14,f21,f22,f23,f24,f31,f32,f33,f34,f41,f42,f43,f44:Float) return access D3DXMATRIX is
   begin
      return new D3DXMATRIX'(true,f11,f12,f13,f14,f21,f22,f23,f24,f31,f32,f33,f34,f41,f42,f43,f44);
   end;

   
   function Member(mat:D3DXMATRIX;row,col:win32.int) return float is
   begin
      return mat.m(Integer(row),Integer(col));
   end;
   
   function Member(mat:D3DXMATRIX;row,col:win32.int) return access float is
   begin
      return mat.m(Integer(row),Integer(col))'unrestricted_access;
   end;
   
   function TO_LPFLOAT(mat:LPD3DXMATRIX) return access FLOAT is
   begin
      if mat/=null then
         return mat.m11'Unrestricted_Access;
      end if;
      return null;
   end;
   
   function TO_LPFLOAT_ARRAY(mat:LPD3DXMATRIX) return access FLOAT_ARRAY is
   begin
      if mat/=null then
         declare
            FA:FLOAT_ARRAY(0..15) with Import,Address=>mat.m11'Address;
         begin
            return FA'Unrestricted_Access;
         end;
      end if;
      return null;
   end;
   
   function TO_LPCFLOAT(mat:LPD3DXMATRIX) return access constant FLOAT is
   begin
      if mat/=null then
         return mat.m11'Unrestricted_Access;
      end if;
      return null;
   end;
   
   function TO_LPCFLOAT_ARRAY(mat:LPD3DXMATRIX) return access constant FLOAT_ARRAY is
   begin
      if mat/=null then
         declare
            FA:constant FLOAT_ARRAY(0..15) with Import,Address=>mat.m11'Address;
         begin
            return FA'Unrestricted_Access;
         end;
      end if;
      return null;
   end;
   
   procedure SInc(This:in out D3DXMATRIX;mat:D3DXMATRIX) is
   begin
      for i in 0..3 loop
         for j in 0..3 loop
            This.m(i,j):=This.m(i,j)+mat.m(i,j);
         end loop;
      end loop;
   end;
   
   procedure SDec(This:in out D3DXMATRIX;mat:D3DXMATRIX) is
   begin
      for i in 0..3 loop
         for j in 0..3 loop
            This.m(i,j):=This.m(i,j)-mat.m(i,j);
         end loop;
      end loop;
   end;
   
   procedure SMul(This:in out D3DXMATRIX;f:FLOAT) is
   begin
      for i in 0..3 loop
         for j in 0..3 loop
            This.m(i,j):=This.m(i,j)*f;
         end loop;
      end loop;
   end;
   
   procedure SMul(This:in out D3DXMATRIX;mat:D3DXMATRIX) is
      pm:access D3DXMATRIX;
   begin
      pm:=D3DXMatrixMultiply(this'Unrestricted_Access, this'Unrestricted_Access, mat'Unrestricted_Access);
   end;
   
   procedure SDiv(This:in out D3DXMATRIX;f:FLOAT) is
   begin
      if f=0.0 then
         This:=(True,others=>FLOAT'Last);
      end if;
      declare
         fInv:float:=1.0/f;
      begin
         for i in 0..3 loop
            for j in 0..3 loop
               This.m(i,j):=This.m(i,j)*fInv;
            end loop;
         end loop;
      end;
   end;
   
   function "+"(This:D3DXMATRIX) return D3DXMATRIX is
   begin
      return This;
   end;
   
   function "-"(This:D3DXMATRIX) return D3DXMATRIX is
   begin
      return (True,-This.m11,-This.m12,-This.m13,-This.m14,
              -This.m21,-This.m22,-This.m23,-This.m24,
              -This.m31,-This.m32,-This.m33,-This.m34,
              -This.m41,-This.m42,-This.m43,-This.m44
             );
   end;
   
   function "+"(This:D3DXMATRIX;mat:D3DXMATRIX) return D3DXMATRIX is
      r:D3DXMATRIX;
   begin
      for i in 0..3 loop
         for j in 0..3 loop
            r.m(i,j):=This.m(i,j)+mat.m(i,j);
         end loop;
      end loop;
      return r;
   end;
   
   function "-"(This:D3DXMATRIX;mat:D3DXMATRIX) return D3DXMATRIX is
      r:D3DXMATRIX;
   begin
      for i in 0..3 loop
         for j in 0..3 loop
            r.m(i,j):=This.m(i,j)-mat.m(i,j);
         end loop;
      end loop;
      return r;
   end;
   
   function "*"(This:D3DXMATRIX;f:Float) return D3DXMATRIX is
      r:D3DXMATRIX;
   begin
      for i in 0..3 loop
         for j in 0..3 loop
            r.m(i,j):=This.m(i,j)*f;
         end loop;
      end loop;
      return r;
   end;
   
   function "*"(f:Float;This:D3DXMATRIX) return D3DXMATRIX is
      r:D3DXMATRIX;
   begin
      for i in 0..3 loop
         for j in 0..3 loop
            r.m(i,j):=This.m(i,j)*f;
         end loop;
      end loop;
      return r;
   end;
   
   function "/"(This:D3DXMATRIX;f:Float) return D3DXMATRIX is
      r:D3DXMATRIX;
   begin
      if f/=0.0 then
         declare
            fInv:Float:=1.0/f;
         begin
            for i in 0..3 loop
               for j in 0..3 loop
                  r.m(i,j):=This.m(i,j)*fInv;
               end loop;
            end loop;
         end;
      else
         r:=(true,others=>FLOAT'LAST);
      end if;
      return r;
   end;
   
   function "="(This:D3DXMATRIX;mat:D3DXMATRIX) return BOOL is
   begin
      if This=mat then
         return win32.TRUE;
      end if;
      return win32.FALSE;
   end;
   
   function "/="(This:D3DXMATRIX;mat:D3DXMATRIX) return BOOL is
   begin
      if This/=mat then
         return win32.TRUE;
      end if;
      return win32.FALSE;
   end;
   
   
   --
   -- D3DXMATRIXA16
   --
   
   function NEW_D3DXMATRIXA16 return access D3DXMATRIXA16 is
   begin
      return new D3DXMATRIXA16'(true,others=>0.0);
   end;
   
   function NEW_D3DXMATRIXA16(f:access constant Float) return access D3DXMATRIXA16 is
      This:access D3DXMATRIXA16:=new D3DXMATRIXA16;
      x:win32.PVOID;
   begin
      if f/=null then
         x:=memcpy(This.m11'Address,f.all'Address,64);
      else
         x:=memset(This.m11'Address,0,16);
      end if;
      return This;
   end;
   
   function NEW_D3DXMATRIXA16(f:access constant FLOAT_ARRAY) return access D3DXMATRIXA16 is
      This:access D3DXMATRIXA16:=new D3DXMATRIXA16;
      x:win32.PVOID;
   begin
      if f/=null and then f'Length>=64 then
         x:=memcpy(This.m11'Address,f.all'Address,64);
      else
         x:=memset(This.m11'Address,0,16);
      end if;
      return This;
   end;
   
   function NEW_D3DXMATRIXA16(f:FLOAT_ARRAY) return access D3DXMATRIXA16 is
      This:access D3DXMATRIXA16:=new D3DXMATRIXA16;
      x:win32.PVOID;
   begin
      if f'Length>=64 then
         x:=memcpy(This.m11'Address,f'Address,64);
      else
         x:=memset(This.m11'Address,0,16);
      end if;
      return This;
   end;
   
   function NEW_D3DXMATRIXA16(mat:D3DXMATRIX) return access D3DXMATRIXA16 is
      This:access D3DXMATRIXA16:=new D3DXMATRIXA16;
      x:win32.PVOID;
   begin
      x:=memcpy(This.m11'Address,mat.m11'Address,64);
      return This;
   end;
   
   function NEW_D3DXMATRIXA16(pf:access constant D3DXFLOAT16) return access D3DXMATRIXA16 is
      This:access D3DXMATRIXA16:=new D3DXMATRIXA16;
      f:access float;
   begin
      if pf/=null then
         f:=D3DXFloat16To32Array(This.m11'Unrestricted_Access, pf, 16);
      else
         This.all:=(true,others=>0.0);
      end if;
      return This;
   end;
   
   function NEW_D3DXMATRIXA16(pf:access constant D3DXFLOAT16_ARRAY) return access D3DXMATRIXA16 is
      This:access D3DXMATRIXA16:=new D3DXMATRIXA16;
      f:access float;
   begin
      if pf/=null and then pf'Length>=16 then
         f:=D3DXFloat16To32Array(This.m11'Unrestricted_Access, pf(pf'First)'unrestricted_access, 16);
      else
         This.all:=(true,others=>0.0);
      end if;
      return This;
   end;
   
   function NEW_D3DXMATRIXA16(pf:D3DXFLOAT16_ARRAY) return access D3DXMATRIXA16 is
      This:access D3DXMATRIXA16:=new D3DXMATRIXA16;
      f:access float;
   begin
      if pf'Length>=16 then
         f:=D3DXFloat16To32Array(This.m11'Unrestricted_Access, pf(pf'First)'unrestricted_access, 16);
      else
         This.all:=(true,others=>0.0);
      end if;
      return This;
   end;
   
   function NEW_D3DXMATRIXA16(f11,f12,f13,f14,f21,f22,f23,f24,f31,f32,f33,f34,f41,f42,f43,f44:Float) return access D3DXMATRIXA16 is
   begin
      return new D3DXMATRIXA16'(true,f11,f12,f13,f14,f21,f22,f23,f24,f31,f32,f33,f34,f41,f42,f43,f44);
   end;
   
   
   procedure equ(This:in out D3DXMATRIXA16;mat:D3DXMATRIX) is
   begin
      This:=D3DXMATRIXA16(mat);
   end;
   
   
   
   
   
   --
   -- D3DXQUATERNION
   --
   
   function NEW_D3DXQUATERNION return access D3DXQUATERNION is
   begin
      return new D3DXQUATERNION'(others=>0.0);
   end;
   
   function NEW_D3DXQUATERNION(pf:access constant FLOAT) return access D3DXQUATERNION is
      This:access D3DXQUATERNION:=new D3DXQUATERNION;
   begin
      if pf/=null then
         declare
            x1:FLOAT_ARRAY(0..3) with Import,Address=>This.all'Address;
            x2:FLOAT_ARRAY(0..3) with Import,Address=>pf.all'Address;
         begin
            x1:=x2;
         end;
      else
         This.all:=(others=>0.0);
      end if;
      return This;
   end;
   
   function NEW_D3DXQUATERNION(pf:access constant FLOAT_ARRAY) return access D3DXQUATERNION is
      This:access D3DXQUATERNION:=new D3DXQUATERNION;
   begin
      if pf/=null and then pf'Length>=4 then
         declare
            x1:FLOAT_ARRAY(0..3) with Import,Address=>This.all'Address;
            x2:FLOAT_ARRAY(0..3) with Import,Address=>pf.all'Address;
         begin
            x1:=x2;
         end;
      else
         This.all:=(others=>0.0);
      end if;
      return This;
   end;
   
   function NEW_D3DXQUATERNION(pf:FLOAT_ARRAY) return access D3DXQUATERNION is
      This:access D3DXQUATERNION:=new D3DXQUATERNION;
   begin
      if pf'Length>=4 then
         declare
            x1:FLOAT_ARRAY(0..3) with Import,Address=>This.all'Address;
            x2:FLOAT_ARRAY(0..3) with Import,Address=>pf'Address;
         begin
            x1:=x2;
         end;
      else
         This.all:=(others=>0.0);
      end if;
      return This;
   end;
   
   function NEW_D3DXQUATERNION(pf:access constant D3DXFLOAT16) return access D3DXQUATERNION is
      This:access D3DXQUATERNION:=new D3DXQUATERNION;
      af:access float;
   begin
      af:=D3DXFloat16To32Array(This.x'Unrestricted_Access, pf, 4);
      return This;
   end;
   
   function NEW_D3DXQUATERNION(pf:access constant D3DXFLOAT16_ARRAY) return access D3DXQUATERNION is
      This:access D3DXQUATERNION:=new D3DXQUATERNION;
      af:access float;
   begin
      if pf/=null and then pf'Length>=4 then
         af:=D3DXFloat16To32Array(This.x'Unrestricted_Access, pf(pf'First)'unrestricted_access, 4);
      end if;
      This.all:=(others=>0.0);
      return This;
   end;
   
   function NEW_D3DXQUATERNION(pf:D3DXFLOAT16_ARRAY) return access D3DXQUATERNION is
      This:access D3DXQUATERNION:=new D3DXQUATERNION;
      af:access float;
   begin
      if pf'Length>=4 then
         af:=D3DXFloat16To32Array(This.x'Unrestricted_Access, pf(pf'First)'unrestricted_access, 4);
      end if;
      This.all:=(others=>0.0);
      return This;
   end;
   
   function NEW_D3DXQUATERNION(x,y,z,w:FLOAT) return access D3DXQUATERNION is
   begin
      return new D3DXQUATERNION'(x,y,z,w);   
   end;
   
   function TO_LPFLOAT_ARRAY(This:LPD3DXQUATERNION) return access FLOAT_ARRAY is
   begin
      if This=null then
         return null;
      end if;
      declare
         FA:FLOAT_ARRAY(0..3) with Import,Address=>This.all'Address;
      begin
         return FA'Unrestricted_Access;
      end;
   end;
   
   function TO_LPCFLOAT_ARRAY(This:LPD3DXQUATERNION) return access constant FLOAT_ARRAY is
   begin
      if This=null then
         return null;
      end if;
      declare
         FA:constant FLOAT_ARRAY(0..3) with Import,Address=>This.all'Address;
      begin
         return FA'Unrestricted_Access;
      end;
   end;
   
   procedure SInc(This:in out D3DXQUATERNION;v:D3DXQUATERNION) is
   begin
      This.x:=This.x+v.x;
      This.y:=This.y+v.y;
      This.z:=This.z+v.z;
      This.w:=This.w+v.w;
   end;
   
   procedure SDec(This:in out D3DXQUATERNION;v:D3DXQUATERNION) is
   begin
      This.x:=This.x-v.x;
      This.y:=This.y-v.y;
      This.z:=This.z-v.z;
      This.w:=This.w-v.w;
   end;
   
   procedure SMul(This:in out D3DXQUATERNION;f:FLOAT) is
   begin
      This.x:=This.x*f;
      This.y:=This.y*f;
      This.z:=This.z*f;
      This.w:=This.w*f;
   end;
   
   procedure SDiv(This:in out D3DXQUATERNION;f:FLOAT) is
   begin
      if f/=0.0 then
         declare
            fInv:FLOAT:=1.0/f;
         begin
            This.x:=This.x*fInv;
            This.y:=This.y*fInv;
            This.z:=This.x*fInv;
            This.w:=This.y*fInv;
         end;
      else
         This:=(others=>FLOAT'Last);
      end if;
   end;
   
   function "+"(This:D3DXQUATERNION) return D3DXQUATERNION is
   begin
      return This;
   end;
   
   function "-"(This:D3DXQUATERNION) return D3DXQUATERNION is
   begin
      return (-This.x,-This.y,-This.z,-This.w);
   end;
   
   function "+"(This:D3DXQUATERNION;v:D3DXQUATERNION) return D3DXQUATERNION is
   begin
      return (This.x+v.x,This.y+v.y,This.z+v.z,This.w+v.w);
   end;
   
   function "-"(This:D3DXQUATERNION;v:D3DXQUATERNION) return D3DXQUATERNION is
   begin
      return (This.x-v.x,This.y-v.y,This.z-v.z,This.w-v.w);
   end;
   
   function "*"(This:D3DXQUATERNION;f:FLOAT) return D3DXQUATERNION is
   begin
      return (This.x*f,This.y*f,This.z*f,This.w*f);
   end;
   
   function "*"(f:FLOAT;This:D3DXQUATERNION) return D3DXQUATERNION is
   begin
      return (This.x*f,This.y*f,This.z*f,This.w*f);
   end;
   
   function "*"(This:D3DXQUATERNION;q:D3DXQUATERNION) return D3DXQUATERNION is
      qt:D3DXQUATERNION;
      pq:access D3DXQUATERNION;
   begin
      PQ:=D3DXQuaternionMultiply(qT'Unrestricted_Access, this'Unrestricted_Access, q'Unrestricted_Access);
      return qt;
   end;
   
   function "/"(This:D3DXQUATERNION;f:FLOAT) return D3DXQUATERNION is
   begin
      if f=0.0 then
         return (others=>FLOAT'Last);
      end if;
      declare
         fInv:FLOAT:=1.0/f;
      begin
         return (This.x*fInv,This.y*fInv,This.z*fInv,This.w*fInv);
      end;
   end;
   
   function "="(This:D3DXQUATERNION;v:D3DXQUATERNION) return win32.BOOL is
   begin
      if This=v then
         return Win32.TRUE;
      end if;
      return win32.FALSE;
   end "=";
   
   function "/="(This:D3DXQUATERNION;v:D3DXQUATERNION) return win32.BOOL is
   begin
      if This/=v then
         return Win32.TRUE;
      end if;
      return win32.FALSE;
   end "/=";
   
   
   --
   -- D3DXPLANE
   --
   
   function NEW_D3DXPLANE return access D3DXPLANE is
   begin
      return new D3DXPLANE'(others=>0.0);
   end;
   
   function NEW_D3DXPLANE(pf:access constant FLOAT) return access D3DXPLANE is
      This:access D3DXPLANE:=new D3DXPLANE;
   begin
      if pf=null then
         This.all:=(others=>0.0);
         return This;
      end if;
      
      declare
         x1:FLOAT_ARRAY(0..3) with Import,address=>This.all'address;
         x2:FLOAT_ARRAY(0..3) with Import,address=>pf.all'Address;
      begin
         x1:=x2;
         return This;
      end;
   end;
   
   function NEW_D3DXPLANE(pf:access constant FLOAT_ARRAY) return access D3DXPLANE is
      This:access D3DXPLANE:=new D3DXPLANE;
   begin
      if pf/=null and then pf'Length>=4 then
         declare
            x1:FLOAT_ARRAY(0..3) with Import,address=>This.all'address;
            x2:FLOAT_ARRAY(0..3) with Import,address=>pf.all'Address;
         begin
            x1:=x2;
            return This;
         end;
      end if;
      This.all:=(others=>0.0);
      return This;
   end;
   
   function NEW_D3DXPLANE(pf:FLOAT_ARRAY) return access D3DXPLANE is
      This:access D3DXPLANE:=new D3DXPLANE;
   begin
      if pf'Length>=4 then
         declare
            x1:FLOAT_ARRAY(0..3) with Import,address=>This.all'address;
            x2:FLOAT_ARRAY(0..3) with Import,address=>pf'Address;
         begin
            x1:=x2;
            return This;
         end;
      end if;
      This.all:=(others=>0.0);
      return This;
   end;
   
   
   function NEW_D3DXPLANE(pf:access constant D3DXFLOAT16) return access D3DXPLANE is
      This:access D3DXPLANE:=new D3DXPLANE;
      af:access float;
   begin
      af:=D3DXFloat16To32Array(This.a'Unrestricted_Access, pf, 4);
      return This;
   end;
   
   function NEW_D3DXPLANE(pf:access constant D3DXFLOAT16_ARRAY) return access D3DXPLANE is
      This:access D3DXPLANE:=new D3DXPLANE;
      af:access float;
   begin
      if pf/=null and then pf'Length>=4 then
         af:=D3DXFloat16To32Array(This.a'Unrestricted_Access, pf(pf'First)'unrestricted_access, 4);
         return This;
      end if;
      This.all:=(others=>0.0);
      return This;
   end;
   
   function NEW_D3DXPLANE(pf:D3DXFLOAT16_ARRAY) return access D3DXPLANE is
      This:access D3DXPLANE:=new D3DXPLANE;
      af:access float;
   begin
      if pf'Length>=4 then
         af:=D3DXFloat16To32Array(This.a'Unrestricted_Access, pf(pf'First)'unrestricted_access, 4);
         return This;
      end if;
      This.all:=(others=>0.0);
      return This;
   end;
   
   function NEW_D3DXPLANE(a,b,c,d:FLOAT) return access D3DXPLANE is
   begin
      return new D3DXPLANE'(a,b,c,d);
   end;
   
   function TO_LPFLOAT_ARRAY(p:LPD3DXPLANE) return access FLOAT_ARRAY is 
   begin
      if p=null then
         return null;
      end if;
      declare
         fa:FLOAT_ARRAY(0..3) with Import,Address=>p.all'Address;
      begin
         return fa'Unrestricted_Access;
      end;
   end;
   
   function TO_LPCFLOAT_ARRAY(p:LPD3DXPLANE) return access constant FLOAT_ARRAY is 
   begin
      if p=null then
         return null;
      end if;
      declare
         fa:constant FLOAT_ARRAY(0..3) with Import,Address=>p.all'Address;
      begin
         return fa'Unrestricted_Access;
      end;
   end;
   
   procedure SMul(p:in out D3DXPLANE;f:Float) is
   begin
      p.a:=p.a*f;
      p.b:=p.b*f;
      p.c:=p.c*f;
      p.d:=p.d*f;
   end;
   
   procedure SDiv(p:in out D3DXPLANE;f:Float) is
      fInv:float;
   begin
      if f/=0.0 then
         fInv:=1.0/f;
         p.a:=p.a*fInv;
         p.b:=p.b*fInv;
         p.c:=p.c*fInv;
         p.d:=p.d*fInv;
      else
         p:=(others=>FLOAT'Last);
      end if;
   end;
   
   function "+"(p:D3DXPLANE) return D3DXPLANE is
   begin
      return p;
   end;
   
   function "-"(p:D3DXPLANE) return D3DXPLANE is
   begin
      return (-p.a,-p.b,-p.c,-p.d);
   end;
   
   function "*"(p:D3DXPLANE;f:Float) return D3DXPLANE is
   begin
      return (p.a*f,p.b*f,p.c*f,p.d*f);
   end;
   
   function "/"(p:D3DXPLANE;f:Float) return D3DXPLANE is
      fInv:Float;
   begin
      if f/=0.0 then
         fInv:=1.0/f;
         return (p.a*fInv,p.b*fInv,p.c*fInv,p.d*fInv);
      else
         return (others=>Float'Last);
      end if;
   end;
   
   function "="(p:D3DXPLANE;p2:D3DXPLANE) return win32.BOOL is
   begin
      if p=p2 then
         return win32.true;
      end if;
      return win32.false;
   end;
   
   function "/="(p:D3DXPLANE;p2:D3DXPLANE) return win32.BOOL is
   begin
      if p/=p2 then
         return win32.true;
      end if;
      return win32.false;
   end;
   
   
   
   --
   -- D3DXCOLOR
   --
   
   function NEW_D3DXCOLOR return access D3DXCOLOR is
   begin
      return new D3DXCOLOR'(others=>0.0);
   end;
   
   type Targb is record
      b,g,r,a:BYTE;
   end record with size=>32;
   
   function NEW_D3DXCOLOR(argb:DWORD) return access D3DXCOLOR is
      C1:Targb with Import,Address=>argb;
      C2:access D3DXCOLOR:=new D3DXCOLOR;
      f:constant FLOAT:=1.0/255.0;
   begin
      C2.r:=float(C1.r)*f;
      C2.g:=float(C1.g)*f;
      C2.b:=float(C1.b)*f;
      C2.a:=float(C1.a)*f;
      return C2;
   end;
   
   function NEW_D3DXCOLOR(pf:access constant FLOAT_ARRAY) return access D3DXCOLOR is
      This:access D3DXCOLOR:=new D3DXCOLOR;
   begin
      if pf/=null and then pf'Length>=4 then
         declare
            FA:FLOAT_ARRAY(0..3) with Import,Address=>pf.all'Address;
            TH:FLOAT_ARRAY(0..3) with Import,Address=>This.all'Address;
         begin
            TH:=FA;
         end;
      else  
         This.all:=(others=>0.0);
      end if;
      return This;
   end;
   
   function NEW_D3DXCOLOR(pf:access constant FLOAT) return access D3DXCOLOR is
      This:access D3DXCOLOR:=new D3DXCOLOR;
   begin
      if pf/=null then
         declare
            FA:FLOAT_ARRAY(0..3) with Import,Address=>pf.all'Address;
            TH:FLOAT_ARRAY(0..3) with Import,Address=>This.all'Address;
         begin
            TH:=FA;
         end;
      else  
         This.all:=(others=>0.0);
      end if;
      return This;
   exception when others=>
         This.all:=(others=>0.0);
         return This;
   end;
   
   function NEW_D3DXCOLOR(pf:FLOAT_ARRAY) return access D3DXCOLOR is
      This:access D3DXCOLOR:=new D3DXCOLOR;
   begin
      if pf'Length>=4 then
         declare
            FA:FLOAT_ARRAY(0..3) with Import,Address=>pf'Address;
            TH:FLOAT_ARRAY(0..3) with Import,Address=>This.all'Address;
         begin
            TH:=FA;
         end;
      else  
         This.all:=(others=>0.0);
      end if;
      return This;
   end;
   
   function NEW_D3DXCOLOR(C:D3DXCOLOR) return access D3DXCOLOR is
   begin
      return new D3DXCOLOR'(C);
   end;
   
   function NEW_D3DXCOLOR(r,g,b,a:FLOAT) return access D3DXCOLOR is
   begin
      return NEW D3DXCOLOR'(r,g,b,a);
   end;
   
   function TO_DWORD(C:D3DXCOLOR) return DWORD is
      argb:Targb;
      dw:DWORD with Import,Address=>argb'Address;
   begin
      argb.r:=(if C.r>=1.0 then 16#ff# elsif C.r<=0.0 then 0 else BYTE(C.r*255.0+0.5));
      argb.g:=(if C.g>=1.0 then 16#ff# elsif C.g<=0.0 then 0 else BYTE(C.g*255.0+0.5));
      argb.b:=(if C.b>=1.0 then 16#ff# elsif C.b<=0.0 then 0 else BYTE(C.b*255.0+0.5));
      argb.a:=(if C.a>=1.0 then 16#ff# elsif C.a<=0.0 then 0 else BYTE(C.a*255.0+0.5));
      return dw;
   end;
   
   function TO_LPFLOAT_ARRAY(This:LPD3DXCOLOR) return access FLOAT_ARRAY is
   begin
      if This=null then
         return null;
      end if;
      declare
         FA:FLOAT_ARRAY(0..3) with Address=>This.all'Address;
      begin
         return FA'Unrestricted_Access;
      end;
   end;
   
   function TO_FLOAT_ARRAY(This:D3DXCOLOR) return FLOAT_ARRAY is
   begin
      declare
         FA:FLOAT_ARRAY(0..3) with Import,Address=>This'Address;
      begin
         return (FA);
      end;
   end;
   
   function TO_LPCFLOAT_ARRAY(This:LPD3DXCOLOR) return access constant FLOAT_ARRAY is
   begin
      if This=null then
         return null;
      end if;
      declare
         FA:constant FLOAT_ARRAY(0..3) with Import,Address=>This.all'Address;
      begin
         return FA'Unrestricted_Access;
      end;
   end;
   
   function TO_LPD3DCOLORVALUE(C:D3DXCOLOR) return access D3DCOLORVALUE is
      cv:D3DCOLORVALUE with Import,Address=>C'Address;
   begin
      return CV'Unrestricted_Access;
   end;
   
   function TO_LPCD3DCOLORVALUE(C:D3DXCOLOR) return access constant D3DCOLORVALUE is
      cv:constant D3DCOLORVALUE with Import,Address=>C'Address;
   begin
      return CV'Unrestricted_Access;
   end;
   
   function TO_D3DCOLORVALUE(C:D3DXCOLOR) return D3DCOLORVALUE is
      cv:D3DCOLORVALUE with Import,Address=>C'Address;
   begin
      return CV;
   end;
   
   function TO_CONST_D3DCOLORVALUE(C:D3DXCOLOR) return D3DCOLORVALUE is
      cv:constant D3DCOLORVALUE with Import,Address=>C'Address;
   begin
      return CV;
   end;
   
   
   procedure SInc(This:in out D3DXCOLOR;v:D3DXCOLOR) is
   begin
      This.r:=This.r+v.r;
      This.g:=This.g+v.g;
      This.b:=This.b+v.b;
      This.a:=This.a+v.a;
   end;
   
   procedure SDec(This:in out D3DXCOLOR;v:D3DXCOLOR) is
   begin
      This.r:=This.r-v.r;
      This.g:=This.g-v.g;
      This.b:=This.b-v.b;
      This.a:=This.a-v.a;
   end;
   
   procedure SMul(This:in out D3DXCOLOR;f:FLOAT) is
   begin
      This.r:=This.r*f;
      This.g:=This.g*f;
      This.b:=This.b*f;
      This.a:=This.a*f;
   end;
   
   procedure SDiv(This:in out D3DXCOLOR;f:FLOAT) is
   begin
      if f/=0.0 then
         declare
            fInv:FLOAT:=1.0/f;
         begin
            This.r:=This.r*fInv;
            This.g:=This.g*fInv;
            This.b:=This.b*fInv;
            This.a:=This.a*fInv;
         end;
      else
         This:=(others=>FLOAT'Last);
      end if;
   end;
   
   function "+"(This:D3DXCOLOR) return D3DXCOLOR is
   begin
      return This;
   end;
   
   function "-"(This:D3DXCOLOR) return D3DXCOLOR is
   begin
      return (-This.r,-This.g,-This.b,-This.a);
   end;
   
   function "+"(This:D3DXCOLOR;v:D3DXCOLOR) return D3DXCOLOR is
   begin
      return (This.r+v.r,This.g+v.g,This.b+v.b,This.a+v.a);
   end;
   
   function "-"(This:D3DXCOLOR;v:D3DXCOLOR) return D3DXCOLOR is
   begin
      return (This.r-v.r,This.g-v.g,This.b-v.b,This.a-v.a);
   end;
   
   function "*"(This:D3DXCOLOR;f:FLOAT) return D3DXCOLOR is
   begin
      return (This.r*f,This.g*f,This.b*f,This.a*f);
   end;
   
   function "*"(f:FLOAT;This:D3DXCOLOR) return D3DXCOLOR is
   begin
      return (This.r*f,This.g*f,This.b*f,This.a*f);
   end;
   
   function "/"(This:D3DXCOLOR;f:FLOAT) return D3DXCOLOR is
   begin
      if f=0.0 then
         return (others=>FLOAT'Last);
      end if;
      declare
         fInv:FLOAT:=1.0/f;
      begin
         return (This.r*fInv,This.g*fInv,This.b*fInv,This.a*fInv);
      end;
   end;
   
   function "="(This:D3DXCOLOR;v:D3DXCOLOR) return win32.BOOL is
   begin
      if This=v then
         return Win32.TRUE;
      end if;
      return win32.FALSE;
   end "=";
   
   function "/="(This:D3DXCOLOR;v:D3DXCOLOR) return win32.BOOL is
   begin
      if This/=v then
         return Win32.TRUE;
      end if;
      return win32.FALSE;
   end "/=";
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
      
   
   
   
   
   
   
   
   
   
   
   
   
   function Sqrtf(f:FLOAT) return FLOAT with Import,external_name=>"Sqrtf";
   
   
   --
   -- 2D Vector Inline functions
   --
   
   function D3DXVec2Length(pv:access constant D3DXVECTOR2) return FLOAT is
   begin
      if pv=null then
         return 0.0;
      end if;
      return Sqrtf(pv.x*pv.x+pv.y*pv.y);
   end D3DXVec2Length;
   
   function D3DXVec2LengthSq(pv:access constant D3DXVECTOR2) return FLOAT is
   begin
      if pv=null then
         return 0.0;
      end if;
      return (pv.x*pv.x+pv.y*pv.y);
   end D3DXVec2LengthSq;
   
   function D3DXVec2Dot(pV1:access constant D3DXVECTOR2;pV2:access constant D3DXVECTOR2) return FLOAT is
   begin
      if pV1=null or pV2=null then
         return 0.0;
      end if;
      return (pV1.x*pV2.x+pV1.y*pV2.y);
   end D3DXVec2Dot;
   
   function D3DXVec2CCW(pV1:access constant D3DXVECTOR2;pV2:access constant D3DXVECTOR2) return FLOAT is
   begin
      if pV1=null or pV2=null then
         return 0.0;
      end if;
      return (pV1.x*pV2.y-pV1.y*pV2.x);
   end D3DXVec2CCW;
   
   
   function D3DXVec2Add(pOut:access D3DXVECTOR2;pV1:access constant D3DXVECTOR2;pV2:access constant D3DXVECTOR2) return access D3DXVECTOR2 is
   begin
      if pOut=null or pV1=null or pV2=null then
         return Null;
      end if;
      pOut.x:=pV1.x+pV2.x;
      pOut.y:=pV1.y+pV2.y;
      return pOut;
   end D3DXVec2Add;
   
   
   function D3DXVec2Subtract(pOut:access D3DXVECTOR2;pV1:access constant D3DXVECTOR2;pV2:access constant D3DXVECTOR2) return access D3DXVECTOR2 is   
   begin
      if pOut=null or pV1=null or pV2=null then
         return Null;
      end if;
      pOut.x:=pV1.x+pV2.x;
      pOut.y:=pV1.y+pV2.y;
      return pOut;
   end D3DXVec2Subtract;
   
   function D3DXVec2Minimize(pOut:access D3DXVECTOR2;pV1:access constant D3DXVECTOR2;pV2:access constant D3DXVECTOR2) return access D3DXVECTOR2 is
   begin
      if pOut=null or pV1=null or pV2=null then
         return Null;
      end if;
      pOut.x:=(if pV1.x<pV2.x then pV1.x else pV2.x);
      pOut.y:=(if pV1.y<pV2.y then pV1.y else pV2.y);
      return pOut;
   end D3DXVec2Minimize;
   
   function D3DXVec2Maximize(pOut:access D3DXVECTOR2;pV1:access constant D3DXVECTOR2;pV2:access constant D3DXVECTOR2) return access D3DXVECTOR2 is
   begin
      if pOut=null or pV1=null or pV2=null then
         return Null;
      end if;
      pOut.x:=(if pV1.x>pV2.x then pV1.x else pV2.x);
      pOut.y:=(if pV1.y>pV2.y then pV1.y else pV2.y);
      return pOut;
   end D3DXVec2Maximize;
   
   function D3DXVec2Scale(pOut:access D3DXVECTOR2;pV:access constant D3DXVECTOR2;s:FLOAT) return access D3DXVECTOR2 is
   begin
      if pOut=null or pV=null then
         return Null;
      end if;
      pOut.x:=pV.x*s;
      pOut.y:=pV.y*s;
      return pOut;
   end D3DXVec2Scale;
   
   function D3DXVec2Lerp(pOut:access D3DXVECTOR2;pV1:access constant D3DXVECTOR2;pV2:access constant D3DXVECTOR2;s:FLOAT) return access D3DXVECTOR2 is
   begin
      if pOut=null or pV1=null or pV2=null then
         return Null;
      end if;
      pOut.x:=pV1.x+s*(pV2.x-pV1.x);
      pOut.y:=pV1.y+s*(pV2.y-pV1.y);
      return pOut;
   end D3DXVec2Lerp;
   
   
   --
   -- 3D Vector Inline Functions
   --
   
   function D3DXVec3Length(pV:access constant D3DXVECTOR3) return FLOAT is
   begin
      if pV=null then
         return 0.0;
      end if;
      return Sqrtf(pV.x*pV.x+pV.y*pV.y+pV.z*pV.z);
   end D3DXVec3Length;
   
   function D3DXVec3LengthSq(pV:access constant D3DXVECTOR3) return FLOAT is
   begin
      if pV=null then
         return 0.0;
      end if;
      return (pV.x*pV.x+pV.y*pV.y+pV.z*pV.z);
   end D3DXVec3LengthSq;
   
   function D3DXVec3Dot(pV1:access constant D3DXVECTOR3;pV2:access constant D3DXVECTOR3) return FLOAT is
   begin
      if pV1=null or pV2=null then
         return 0.0;
      end if;
      return (pV1.x*pV2.x+pV1.y*pV2.y+pV1.z*pV2.z);
   end D3DXVec3Dot;
   
   function D3DXVec3Cross(pOut:access D3DXVECTOR3;pV1:access constant D3DXVECTOR3;pV2:access constant D3DXVECTOR3) return access D3DXVECTOR3 is
      v:D3DXVECTOR3;
   begin
      if pOut=null or pV1=null or pV2=null then
         return Null;
      end if;
      v.x:=pV1.y*pV2.z-pV1.z*pV2.y;
      v.y:=pV1.z*pV2.x-pV1.x*pV2.z;
      v.z:=pV1.x*pV2.y-pV1.y*pV2.x;
      pOut.all:=v;
      return pOut;
   end D3DXVec3Cross;
   
   function D3DXVec3Add(pOut:access D3DXVECTOR3;pV1:access constant D3DXVECTOR3;pV2:access constant D3DXVECTOR3) return access D3DXVECTOR3 is
   begin
      if pOut=null or pV1=null or pV2=null then
         return Null;
      end if;
      pOut.x:=pV1.x+pV2.x;
      pOut.y:=pV1.y+pV2.y;
      pOut.z:=pV1.z+pV2.z;
      return pOut;
   end D3DXVec3Add;
   
   
   function D3DXVec3Subtract(pOut:access D3DXVECTOR3;pV1:access constant D3DXVECTOR3;pV2:access constant D3DXVECTOR3) return access D3DXVECTOR3 is   
   begin
      if pOut=null or pV1=null or pV2=null then
         return Null;
      end if;
      pOut.x:=pV1.x-pV2.x;
      pOut.y:=pV1.y-pV2.y;
      pOut.z:=pV1.z-pV2.z;
      return pOut;
   end D3DXVec3Subtract;
   
   function D3DXVec3Minimize(pOut:access D3DXVECTOR3;pV1:access constant D3DXVECTOR3;pV2:access constant D3DXVECTOR3) return access D3DXVECTOR3 is
   begin
      if pOut=null or pV1=null or pV2=null then
         return Null;
      end if;
      pOut.x:=(if pV1.x<pV2.x then pV1.x else pV2.x);
      pOut.y:=(if pV1.y<pV2.y then pV1.y else pV2.y);
      pOut.z:=(if pV1.z<pV2.z then pV1.z else pV2.z);
      return pOut;
   end D3DXVec3Minimize;
   
   function D3DXVec3Maximize(pOut:access D3DXVECTOR3;pV1:access constant D3DXVECTOR3;pV2:access constant D3DXVECTOR3) return access D3DXVECTOR3 is
   begin
      if pOut=null or pV1=null or pV2=null then
         return Null;
      end if;
      pOut.x:=(if pV1.x>pV2.x then pV1.x else pV2.x);
      pOut.y:=(if pV1.y>pV2.y then pV1.y else pV2.y);
      pOut.z:=(if pV1.z>pV2.z then pV1.z else pV2.z);
      return pOut;
   end D3DXVec3Maximize;
   
   function D3DXVec3Scale(pOut:access D3DXVECTOR3;pV:access constant D3DXVECTOR3;s:FLOAT) return access D3DXVECTOR3 is
   begin
      if pOut=null or pV=null then
         return Null;
      end if;
      pOut.x:=pV.x*s;
      pOut.y:=pV.y*s;
      pOut.z:=pV.z*s;
      return pOut;
   end D3DXVec3Scale;
   
   function D3DXVec3Lerp(pOut:access D3DXVECTOR3;pV1:access constant D3DXVECTOR3;pV2:access constant D3DXVECTOR3;s:FLOAT) return access D3DXVECTOR3 is
   begin
      if pOut=null or pV1=null or pV2=null then
         return Null;
      end if;
      pOut.x:=pV1.x+s*(pV2.x-pV1.x);
      pOut.y:=pV1.y+s*(pV2.y-pV1.y);
      pOut.z:=pV1.z+s*(pV2.z-pV1.z);
      return pOut;
   end D3DXVec3Lerp;
   
   
   --
   -- 4D Vector Inline Functions
   --
   
   function D3DXVec4Length(pV:access constant D3DXVECTOR4) return FLOAT is
   begin
      if pV=null then
         return 0.0;
      end if;
      return Sqrtf(pV.x*pV.x+pV.y*pV.y+pV.z*pV.z+pV.w*pV.w);
   end D3DXVec4Length;
   
   function D3DXVec4LengthSq(pV:access constant D3DXVECTOR4) return FLOAT is
   begin
      if pV=null then
         return 0.0;
      end if;
      return (pV.x*pV.x+pV.y*pV.y+pV.z*pV.z+pV.w*pV.w);
   end D3DXVec4LengthSq;
   
   function D3DXVec4Dot(pV1:access constant D3DXVECTOR4;pV2:access constant D3DXVECTOR4) return FLOAT is
   begin
      if pV1=null or pV2=null then
         return 0.0;
      end if;
      return (pV1.x*pV2.x+pV1.y*pV2.y+pV1.z*pV2.z+pV1.w*pV2.w);
   end D3DXVec4Dot;
   
   function D3DXVec4Add(pOut:access D3DXVECTOR4;pV1:access constant D3DXVECTOR4;pV2:access constant D3DXVECTOR4) return access D3DXVECTOR4 is
   begin
      if pOut=null or pV1=null or pV2=null then
         return Null;
      end if;
      pOut.x:=pV1.x+pV2.x;
      pOut.y:=pV1.y+pV2.y;
      pOut.z:=pV1.z+pV2.z;
      pOut.w:=pV1.w+pV2.w;
      return pOut;
   end D3DXVec4Add;
   
   
   function D3DXVec4Subtract(pOut:access D3DXVECTOR4;pV1:access constant D3DXVECTOR4;pV2:access constant D3DXVECTOR4) return access D3DXVECTOR4 is   
   begin
      if pOut=null or pV1=null or pV2=null then
         return Null;
      end if;
      pOut.x:=pV1.x-pV2.x;
      pOut.y:=pV1.y-pV2.y;
      pOut.z:=pV1.z-pV2.z;
      pOut.w:=pV1.w-pV2.w;
      return pOut;
   end D3DXVec4Subtract;
   
   function D3DXVec4Minimize(pOut:access D3DXVECTOR4;pV1:access constant D3DXVECTOR4;pV2:access constant D3DXVECTOR4) return access D3DXVECTOR4 is
   begin
      if pOut=null or pV1=null or pV2=null then
         return Null;
      end if;
      pOut.x:=(if pV1.x<pV2.x then pV1.x else pV2.x);
      pOut.y:=(if pV1.y<pV2.y then pV1.y else pV2.y);
      pOut.z:=(if pV1.z<pV2.z then pV1.z else pV2.z);
      pOut.z:=(if pV1.w<pV2.w then pV1.w else pV2.w);
      return pOut;
   end D3DXVec4Minimize;
   
   function D3DXVec4Maximize(pOut:access D3DXVECTOR4;pV1:access constant D3DXVECTOR4;pV2:access constant D3DXVECTOR4) return access D3DXVECTOR4 is
   begin
      if pOut=null or pV1=null or pV2=null then
         return Null;
      end if;
      pOut.x:=(if pV1.x>pV2.x then pV1.x else pV2.x);
      pOut.y:=(if pV1.y>pV2.y then pV1.y else pV2.y);
      pOut.z:=(if pV1.z>pV2.z then pV1.z else pV2.z);
      pOut.w:=(if pV1.w>pV2.w then pV1.w else pV2.w);
      return pOut;
   end D3DXVec4Maximize;
   
   function D3DXVec4Scale(pOut:access D3DXVECTOR4;pV:access constant D3DXVECTOR4;s:FLOAT) return access D3DXVECTOR4 is
   begin
      if pOut=null or pV=null then
         return Null;
      end if;
      pOut.x:=pV.x*s;
      pOut.y:=pV.y*s;
      pOut.z:=pV.z*s;
      pOut.w:=pV.w*s;
      return pOut;
   end D3DXVec4Scale;
   
   function D3DXVec4Lerp(pOut:access D3DXVECTOR4;pV1:access constant D3DXVECTOR4;pV2:access constant D3DXVECTOR4;s:FLOAT) return access D3DXVECTOR4 is
   begin
      if pOut=null or pV1=null or pV2=null then
         return Null;
      end if;
      pOut.x:=pV1.x+s*(pV2.x-pV1.x);
      pOut.y:=pV1.y+s*(pV2.y-pV1.y);
      pOut.z:=pV1.z+s*(pV2.z-pV1.z);
      pOut.w:=pV1.w+s*(pV2.w-pV1.w);
      return pOut;
   end D3DXVec4Lerp;
   
   
   --
   -- 4D Matrix
   --
   
   function D3DXMatrixIdentity(pOut:access D3DXMATRIX) return access D3DXMATRIX is
   begin
      if pOut=null then
         return Null;
      end if;
      pOut.all:=(True,m11|m22|m33|m44=>1.0,others=>0.0); -- ÕâÐÐÓï¾ä±ÈC++ÀïÃæÓÅÃÀÌ«¶à
      return pOut;
   end D3DXMatrixIdentity;
   
   function D3DXMatrixIsIdentity(pOut:access constant D3DXMATRIX) return Win32.BOOL is
   begin
      if pOut=null then
         return win32.FALSE;
      end if;
      
      for i in 0..3 loop
         for j in 0..3 loop
            if i=j then
               if pOut.m(i,j)/=1.0 then
                  return win32.FALSE;
               end if;
            else
               if pOut.m(i,j)/=0.0 then
                  return win32.FALSE;
               end if;
            end if;
         end loop;
      end loop;
      return win32.True;
   end D3DXMatrixIsIdentity;
   
   
   --
   -- D3DXQuaternion
   --
   
   function D3DXQuaternionLength(pQ:access constant D3DXQuaternion) return FLOAT is
   begin
      if pQ=null then
         return 0.0;
      end if;
      return Sqrtf(pQ.x*pQ.x+pQ.y*pQ.y+pQ.z*pQ.z+pQ.w*pQ.w);
   end D3DXQuaternionLength;
   
   function D3DXQuaternionLengthSq(pQ:access constant D3DXQuaternion) return FLOAT is
   begin
      if pQ=null then
         return 0.0;
      end if;
      return (pQ.x*pQ.x+pQ.y*pQ.y+pQ.z*pQ.z+pQ.w*pQ.w);
   end D3DXQuaternionLengthSq;
   
   function D3DXQuaternionDot(pQ1:access constant D3DXQuaternion;pQ2:access constant D3DXQuaternion) return FLOAT is
   begin
      if pQ1=null or pQ2=null then
         return 0.0;
      end if;
      return (pQ1.x*pQ2.x+pQ1.y*pQ2.y+pQ1.z*pQ2.z+pQ1.w*pQ2.w);
   end D3DXQuaternionDot;
   
   function D3DXQuaternionIsIdentity(pQ:access constant D3DXQuaternion) return Win32.BOOL is
   begin
      if pQ=null then
         return Win32.FALSE;
      end if;
      return (if (pQ.x=0.0 and pQ.y=0.0 and pQ.z=0.0 and pQ.w=1.0) then win32.TRUE else win32.FALSE);
   end D3DXQuaternionIsIdentity;
   
   function D3DXQuaternionIdentity(pOut:access D3DXQuaternion) return access D3DXQUATERNION is
   begin
      if pOut=null then
         return null;
      end if;
      pOut.all:=(w=>1.0,others=>0.0);
      return pOut;
   end D3DXQuaternionIdentity;
   
   function D3DXQuaternionConjugate(pOut:access D3DXQuaternion;pQ:access constant D3DXQuaternion) return access D3DXQUATERNION is
   begin
      if pOut=null or pQ=null then
         return null;
      end if;
      pOut.all:=(-pQ.x,-pQ.y,-pQ.z,pQ.w);
      return pOut;
   end D3DXQuaternionConjugate;
   
   
   
   --
   -- Plane
   --
   
   function D3DXPlaneDot(pP:access constant D3DXPLANE;pV:access constant D3DXVECTOR4) return FLOAT is
   begin
      if pP=null or pV=null then
         return 0.0;
      end if;
      
      return (pP.a * pV.x + pP.b * pV.y + pP.c * pV.z + pP.d * pV.w);
      
   end D3DXPlaneDot;
   
   
   function D3DXPlaneDotCoord(pP:access constant D3DXPLANE;pV:access constant D3DXVECTOR3) return FLOAT is
   begin
      if pP=null or pV=null then
         return 0.0;
      end if;
      
      return (pP.a * pV.x + pP.b * pV.y + pP.c * pV.z + pP.d);
      
   end D3DXPlaneDotCoord;
   
   function D3DXPlaneDotNormal(pP:access constant D3DXPLANE;pV:access constant D3DXVECTOR3) return FLOAT is
   begin
      if pP=null or pV=null then
         return 0.0;
      end if;
      
      return (pP.a * pV.x + pP.b * pV.y + pP.c * pV.z);
      
   end D3DXPlaneDotNormal;
   
   
   function D3DXPlaneScale(pOut:access D3DXPLANE;pP:access constant D3DXPLANE;s:Float) return access D3DXPLANE is
   begin
      if pOut=null or pP=null then
         return null;
      end if;
      
      pOut.a := pP.a * s;
      pOut.b := pP.b * s;
      pOut.c := pP.c * s;
      pOut.d := pP.d * s;
      return pOut;
      
   end D3DXPlaneScale;
   
   
   --
   -- Color
   --
   
   function D3DXColorNegative(pOut:access D3DXCOLOR;pC:access constant D3DXCOLOR) return access D3DXCOLOR is
   begin
      if pOut=null or pC=null then
         return null;
      end if;
      
      pOut.r := 1.0 - pC.r;
      pOut.g := 1.0 - pC.g;
      pOut.b := 1.0 - pC.b;
      pOut.a := pC.a;
      return pOut;
      
   end D3DXColorNegative;
   
   function D3DXColorAdd(pOut:access D3DXColor;pC1:access constant D3DXColor;pC2:access constant D3DXColor) return access D3DXColor is
   begin
      if pOut=null or pC1=null or pC2=null then
         return Null;
      end if;
      pOut.r:=pC1.r+pC2.r;
      pOut.g:=pC1.g+pC2.g;
      pOut.b:=pC1.b+pC2.b;
      pOut.a:=pC1.a+pC2.a;
      return pOut;
   end D3DXColorAdd;
   
   
   function D3DXColorSubtract(pOut:access D3DXColor;pC1:access constant D3DXColor;pC2:access constant D3DXColor) return access D3DXColor is   
   begin
      if pOut=null or pC1=null or pC2=null then
         return Null;
      end if;
      pOut.r:=pC1.r-pC2.r;
      pOut.g:=pC1.g-pC2.g;
      pOut.b:=pC1.b-pC2.b;
      pOut.a:=pC1.a-pC2.a;
      return pOut;
   end D3DXColorSubtract;
   
   
   function D3DXColorScale(pOut:access D3DXColor;pC:access constant D3DXColor;s:FLOAT) return access D3DXColor is   
   begin
      if pOut=null or pC=null then
         return Null;
      end if;
      pOut.r:=pC.r*s;
      pOut.g:=pC.g*s;
      pOut.b:=pC.b*s;
      pOut.a:=pC.a*s;
      return pOut;
   end D3DXColorScale;
   
   function D3DXColorModulate(pOut:access D3DXColor;pC1:access constant D3DXColor;pC2:access constant D3DXColor) return access D3DXColor is   
   begin
      if pOut=null or pC1=null or pC2=null then
         return Null;
      end if;
      pOut.r:=pC1.r*pC2.r;
      pOut.g:=pC1.g*pC2.g;
      pOut.b:=pC1.b*pC2.b;
      pOut.a:=pC1.a*pC2.a;
      return pOut;
   end D3DXColorModulate;
   
   function D3DXColorLerp(pOut:access D3DXColor;pC1:access constant D3DXColor;pC2:access constant D3DXColor;s:FLOAT) return access D3DXColor is   
   begin
      if pOut=null or pC1=null or pC2=null then
         return Null;
      end if;
      pOut.r:=pC1.r+s*(pC2.r-pC1.r);
      pOut.g:=pC1.g+s*(pC2.g-pC1.g);
      pOut.b:=pC1.b+s*(pC2.b-pC1.b);
      pOut.a:=pC1.a+s*(pC2.a-pC1.a);
      return pOut;
   end D3DXColorLerp;
   
   
   
   
   
   
   --
   -- THE END.
   --
   

end d3dx9math;












猜你喜欢

转载自blog.csdn.net/adacore/article/details/84102360
今日推荐