' ########################################################################################
' Microsoft Windows
' File: d3dx9math.inc
' Contents: D3DX math types and functions
' Copyright (c) 2011 Jos? Roca
' Portions Copyright (c) Microsoft Corporation.
' All Rights Reserved.
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
' EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
' MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
' ########################################################################################
#IF NOT %DEF(PBX_d3dx9math_PBI)
#DEFINE PBX_d3dx9math_PBI
%EQUATE `D3DX9MATH_INC = 1
'//===========================================================================
'//
'// General purpose utilities
'//
'//===========================================================================
'#define D3DX_PI ((FLOAT) 3.141592654f)
'#define D3DX_1BYPI ((FLOAT) 0.318309886f)
MACRO D3DX_PI = 3.141592654!
MACRO D3DX_1BYPI = 0.318309886!
'#define D3DXToRadian( degree ) ((degree) * (D3DX_PI / 180.0f))
'#define D3DXToDegree( radian ) ((radian) * (180.0f / D3DX_PI))
MACRO D3DXToRadian(degree) = ((degree) * (D3DX_PI / 180.0))
MACRO D3DXToDegree(radian) = ((radian) * (180.0 / D3DX_PI))
'//===========================================================================
'//
'// Vectors
'//
'//===========================================================================
'//--------------------------
'// 2D Vector
'//--------------------------
' // Size = 8 bytes
TYPE D3DXVECTOR2 DWORD
 x AS SINGLE ' FLOAT
 y AS SINGLE ' FLOAT
END TYPE
'//--------------------------
'// 3D Vector
'//--------------------------
' // Size = 12 bytes
TYPE D3DXVECTOR3 DWORD
 x AS SINGLE ' FLOAT
 y AS SINGLE ' FLOAT
 z AS SINGLE ' FLOAT
END TYPE
'//--------------------------
'// 4D Vector
'//--------------------------
' // Size = 16 bytes
TYPE D3DXVECTOR4 DWORD
 x AS SINGLE ' FLOAT
 y AS SINGLE ' FLOAT
 z AS SINGLE ' FLOAT
 w AS SINGLE ' FLOAT
END TYPE
'//===========================================================================
'//
'// Matrices
'//
'//===========================================================================
' // Size = 64 bytes
TYPE D3DXMATRIX DWORD
 m11 AS SINGLE ' FLOAT
 m12 AS SINGLE ' FLOAT
 m13 AS SINGLE ' FLOAT
 m14 AS SINGLE ' FLOAT
 m21 AS SINGLE ' FLOAT
 m22 AS SINGLE ' FLOAT
 m23 AS SINGLE ' FLOAT
 m24 AS SINGLE ' FLOAT
 m31 AS SINGLE ' FLOAT
 m32 AS SINGLE ' FLOAT
 m33 AS SINGLE ' FLOAT
 m34 AS SINGLE ' FLOAT
 m41 AS SINGLE ' FLOAT
 m42 AS SINGLE ' FLOAT
 m43 AS SINGLE ' FLOAT
 m44 AS SINGLE ' FLOAT
END TYPE
'//===========================================================================
'//
'// Quaternions
'//
'//===========================================================================
' // Size = 16 bytes
TYPE D3DXQUATERNION DWORD
 x AS SINGLE ' FLOAT
 y AS SINGLE ' FLOAT
 z AS SINGLE ' FLOAT
 w AS SINGLE ' FLOAT
END TYPE
'//===========================================================================
'//
'// Planes
'//
'//===========================================================================
' // Size = 16 bytes
TYPE D3DXPLANE DWORD
 a AS SINGLE ' FLOAT
 b AS SINGLE ' FLOAT
 c AS SINGLE ' FLOAT
 d AS SINGLE ' FLOAT
END TYPE
'//===========================================================================
'//
'// Colors
'//
'//===========================================================================
' // Size = 16 bytes
TYPE D3DXCOLOR DWORD
 r AS SINGLE ' FLOAT
 g AS SINGLE ' FLOAT
 b AS SINGLE ' FLOAT
 a AS SINGLE ' FLOAT
END TYPE
' Must be placed here because the above structures are also used by other include files.
#INCLUDE ONCE "Legacy/Graphics/d3dx9.inc"
'//===========================================================================
'//
'// D3DX math functions:
'//
'// NOTE:
'// * All these functions can take the same object as in and out parameters.
'//
'// * Out parameters are typically also returned as return values, so that
'// the output of one function may be used as a parameter to another.
'//
'//===========================================================================
'//--------------------------
'// 2D Vector
'//--------------------------
DECLARE FUNCTION D3DXVec2Normalize IMPORT $D3DX_DLLNAME ALIAS "D3DXVec2Normalize" (_
 BYREF pOut AS D3DXVECTOR2
 , BYREF pV AS D3DXVECTOR2
 ) AS DWORD ' D3DXVECTOR2
'// Hermite interpolation between position V1, tangent T1 (when s == 0)
'// and position V2, tangent T2 (when s == 1).
DECLARE FUNCTION D3DXVec2Hermite IMPORT $D3DX_DLLNAME ALIAS "D3DXVec2Hermite" (_
 BYREF pOut AS D3DXVECTOR2
 , BYREF pV1 AS D3DXVECTOR2
 , BYREF pT1 AS D3DXVECTOR2
 , BYREF pV2 AS D3DXVECTOR2
 , BYREF pT2 AS D3DXVECTOR2
 , BYVAL s AS SINGLE
 ) AS DWORD ' D3DXVECTOR2
'// CatmullRom interpolation between V1 (when s == 0) and V2 (when s == 1)
DECLARE FUNCTION D3DXVec2CatmullRom IMPORT $D3DX_DLLNAME ALIAS "D3DXVec2CatmullRom" (_
 BYREF pOut AS D3DXVECTOR2
 , BYREF pV0 AS D3DXVECTOR2
 , BYREF pV1 AS D3DXVECTOR2
 , BYREF pV2 AS D3DXVECTOR2
 , BYREF pV3 AS D3DXVECTOR2
 , BYVAL s AS SINGLE
 ) AS DWORD ' D3DXVECTOR2
'// Barycentric coordinates. V1 + f(V2-V1) + g(V3-V1)
DECLARE FUNCTION D3DXVec2BaryCentric IMPORT $D3DX_DLLNAME ALIAS "D3DXVec2BaryCentric" (_
 BYREF pOut AS D3DXVECTOR2
 , BYREF pV1 AS D3DXVECTOR2
 , BYREF pV2 AS D3DXVECTOR2
 , BYREF pV3 AS D3DXVECTOR2
 , BYVAL f AS SINGLE
 , BYVAL g AS SINGLE
 ) AS DWORD ' D3DXVECTOR2
'// Transform (x, y, 0, 1) by matrix.
DECLARE FUNCTION D3DXVec2Transform IMPORT $D3DX_DLLNAME ALIAS "D3DXVec2Transform" (_
 BYREF pOut AS D3DXVECTOR4
 , BYREF pV AS D3DXVECTOR2
 , BYREF pM AS D3DMATRIX
 ) AS DWORD ' D3DXVECTOR4
'// Transform (x, y, 0, 1) by matrix, project result back into w=1.
DECLARE FUNCTION D3DXVec2TransformCoord IMPORT $D3DX_DLLNAME ALIAS "D3DXVec2TransformCoord" (_
 BYREF pOut AS D3DXVECTOR2
 , BYREF pV AS D3DXVECTOR2
 , BYREF pM AS D3DMATRIX
 ) AS DWORD ' D3DXVECTOR2
'// Transform (x, y, 0, 0) by matrix.
DECLARE FUNCTION D3DXVec2TransformNormal IMPORT $D3DX_DLLNAME ALIAS "D3DXVec2TransformNormal" (_
 BYREF pOut AS D3DXVECTOR2
 , BYREF pV AS D3DXVECTOR2
 , BYREF pM AS D3DMATRIX
 ) AS DWORD ' D3DXVECTOR2
'// Transform Array (x, y, 0, 1) by matrix.
DECLARE FUNCTION D3DXVec2TransformArray IMPORT $D3DX_DLLNAME ALIAS "D3DXVec2TransformArray" (_
 BYREF pOut AS D3DXVECTOR4
 , BYVAL OutStride AS DWORD
 , BYREF pV AS D3DXVECTOR2
 , BYVAL VStride AS DWORD
 , BYREF pM AS D3DMATRIX
 , BYVAL n AS DWORD
 ) AS DWORD ' D3DXVECTOR4
'// Transform Array (x, y, 0, 1) by matrix, project result back into w=1.
DECLARE FUNCTION D3DXVec2TransformCoordArray IMPORT $D3DX_DLLNAME ALIAS "D3DXVec2TransformCoordArray" (_
 BYREF pOut AS D3DXVECTOR2
 , BYVAL OutStride AS DWORD
 , BYREF pV AS D3DXVECTOR2
 , BYVAL VStride AS DWORD
 , BYREF pM AS D3DMATRIX
 , BYVAL n AS DWORD
 ) AS DWORD ' D3DXVECTOR2
'// Transform Array (x, y, 0, 0) by matrix.
DECLARE FUNCTION D3DXVec2TransformNormalArray IMPORT $D3DX_DLLNAME ALIAS "D3DXVec2TransformNormalArray" (_
 BYREF pOut AS D3DXVECTOR2
 , BYVAL OutStride AS DWORD
 , BYREF pV AS D3DXVECTOR2
 , BYVAL VStride AS DWORD
 , BYREF pM AS D3DMATRIX
 , BYVAL n AS DWORD
 ) AS DWORD ' D3DXVECTOR2
'//--------------------------
'// 3D Vector
'//--------------------------
DECLARE FUNCTION D3DXVec3Normalize IMPORT $D3DX_DLLNAME ALIAS "D3DXVec3Normalize" (_
 BYREF pOut AS D3DXVECTOR3
 , BYREF pV AS D3DXVECTOR3
 ) AS DWORD ' D3DXVECTOR3
'// Hermite interpolation between position V1, tangent T1 (when s == 0)
'// and position V2, tangent T2 (when s == 1).
DECLARE FUNCTION D3DXVec3Hermite IMPORT $D3DX_DLLNAME ALIAS "D3DXVec3Hermite" (_
 BYREF pOut AS D3DXVECTOR3
 , BYREF pV1 AS D3DXVECTOR3
 , BYREF pT1 AS D3DXVECTOR3
 , BYREF pV2 AS D3DXVECTOR3
 , BYREF pT2 AS D3DXVECTOR3
 , BYVAL s AS SINGLE
 ) AS DWORD ' D3DXVECTOR3
'// CatmullRom interpolation between V1 (when s == 0) and V2 (when s == 1)
DECLARE FUNCTION D3DXVec3CatmullRom IMPORT $D3DX_DLLNAME ALIAS "D3DXVec3CatmullRom" (_
 BYREF pOut AS D3DXVECTOR3
 , BYREF pV0 AS D3DXVECTOR3
 , BYREF pV1 AS D3DXVECTOR3
 , BYREF pV2 AS D3DXVECTOR3
 , BYREF pV3 AS D3DXVECTOR3
 , BYVAL s AS SINGLE
 ) AS DWORD ' D3DXVECTOR3
'// Barycentric coordinates. V1 + f(V2-V1) + g(V3-V1)
DECLARE FUNCTION D3DXVec3BaryCentric IMPORT $D3DX_DLLNAME ALIAS "D3DXVec3BaryCentric" (_
 BYREF pOut AS D3DXVECTOR3
 , BYREF pV1 AS D3DXVECTOR3
 , BYREF pV2 AS D3DXVECTOR3
 , BYREF pV3 AS D3DXVECTOR3
 , BYVAL f AS SINGLE
 , BYVAL g AS SINGLE
 ) AS DWORD ' D3DXVECTOR3
'// Transform (x, y, z, 1) by matrix.
DECLARE FUNCTION D3DXVec3Transform IMPORT $D3DX_DLLNAME ALIAS "D3DXVec3Transform" (_
 BYREF pOut AS D3DXVECTOR4
 , BYREF pV AS D3DXVECTOR3
 , BYREF pM AS D3DMATRIX
 ) AS DWORD ' D3DXVECTOR4
'// Transform (x, y, z, 1) by matrix, project result back into w=1.
DECLARE FUNCTION D3DXVec3TransformCoord IMPORT $D3DX_DLLNAME ALIAS "D3DXVec3TransformCoord" (_
 BYREF pOut AS D3DXVECTOR3
 , BYREF pV AS D3DXVECTOR3
 , BYREF pM AS D3DMATRIX
 ) AS DWORD ' D3DXVECTOR3
'// Transform (x, y, z, 0) by matrix. If you transforming a normal by a
'// non-affine matrix, the matrix you pass to this function should be the
'// transpose of the inverse of the matrix you would use to transform a coord.
DECLARE FUNCTION D3DXVec3TransformNormal IMPORT $D3DX_DLLNAME ALIAS "D3DXVec3TransformNormal" (_
 BYREF pOut AS D3DXVECTOR3
 , BYREF pV AS D3DXVECTOR3
 , BYREF pM As D3DMATRIX
 ) AS DWORD ' D3DXVECTOR3
'// Transform Array (x, y, z, 1) by matrix.
DECLARE FUNCTION D3DXVec3TransformArray IMPORT $D3DX_DLLNAME ALIAS "D3DXVec3TransformArray" (_
 BYREF pOut AS D3DXVECTOR4
 , BYVAL OutStride AS DWORD
 , BYREF pV AS D3DXVECTOR3
 , BYVAL VStride AS DWORD
 , BYREF pM AS D3DMATRIX
 , BYVAL n AS DWORD
 ) AS DWORD ' D3DXVECTOR4
'// Transform Array (x, y, z, 1) by matrix, project result back into w=1.
DECLARE FUNCTION D3DXVec3TransformCoordArray IMPORT $D3DX_DLLNAME ALIAS "D3DXVec3TransformCoordArray" (_
 BYREF pOut AS D3DXVECTOR3
 , BYVAL OutStride AS DWORD
 , BYREF pV AS D3DXVECTOR3
 , BYVAL VStride AS DWORD
 , BYREF pM AS D3DMATRIX
 , BYVAL n AS DWORD
 ) AS DWORD ' D3DXVECTOR3
'// Transform (x, y, z, 0) by matrix. If you transforming a normal by a
'// non-affine matrix, the matrix you pass to this function should be the
'// transpose of the inverse of the matrix you would use to transform a coord.
DECLARE FUNCTION D3DXVec3TransformNormalArray IMPORT $D3DX_DLLNAME ALIAS "D3DXVec3TransformNormalArray" (_
 BYREF pOut AS D3DXVECTOR3
 , BYVAL OutStride AS DWORD
 , BYREF pV AS D3DXVECTOR3
 , BYVAL VStride AS DWORD
 , BYREF pM AS D3DMATRIX
 , BYVAL n AS DWORD
 ) AS DWORD ' D3DXVECTOR3
'// Project vector from object space into screen space
DECLARE FUNCTION D3DXVec3Project IMPORT $D3DX_DLLNAME ALIAS "D3DXVec3Project" (_
 BYREF pOut AS D3DXVECTOR3
 , BYREF pV AS D3DXVECTOR3
 , BYREF pViewport AS D3DVIEWPORT9
 , BYREF pProjection AS D3DMATRIX
 , BYREF pView AS D3DMATRIX
 , BYREF pWorld AS D3DMATRIX
 ) AS DWORD ' D3DXVECTOR3
'// Project vector from screen space into object space
DECLARE FUNCTION D3DXVec3Unproject IMPORT $D3DX_DLLNAME ALIAS "D3DXVec3Uproject" (_
 BYREF pOut AS D3DXVECTOR3
 , BYREF pV AS D3DXVECTOR3
 , BYREF pViewport AS D3DVIEWPORT9
 , BYREF pProjection AS D3DMATRIX
 , BYREF pView AS D3DMATRIX
 , BYREF pWorld AS D3DMATRIX
 ) AS DWORD ' D3DXVECTOR3
'// Project vector Array from object space into screen space
DECLARE FUNCTION D3DXVec3ProjectArray IMPORT $D3DX_DLLNAME ALIAS "D3DXVec3ProjectArray" (_
 BYREF pOut AS D3DXVECTOR3
 , BYVAL OutStride AS DWORD
 , BYREF pV AS D3DXVECTOR3
 , BYVAL VStride AS DWORD
 , BYREF pViewport AS D3DVIEWPORT9
 , BYREF pProjection AS D3DMATRIX
 , BYREF pView AS D3DMATRIX
 , BYREF pWorld AS D3DMATRIX
 , BYVAL n AS DWORD
 ) AS DWORD ' D3DXVECTOR3
'// Project vector Array from screen space into object space
DECLARE FUNCTION D3DXVec3UnprojectArray IMPORT $D3DX_DLLNAME ALIAS "D3DXVec3UprojectArray" (_
 BYREF pOut AS D3DXVECTOR3
 , BYVAL OutStride AS DWORD
 , BYREF pV AS D3DXVECTOR3
 , BYVAL VStride AS DWORD
 , BYREF pViewport AS D3DVIEWPORT9
 , BYREF pProjection AS D3DMATRIX
 , BYREF pView AS D3DMATRIX
 , BYREF pWorld AS D3DMATRIX
 , BYVAL n AS DWORD
 ) AS DWORD ' D3DXVECTOR3
'//--------------------------
'// 4D Vector
'//--------------------------
'// Cross-product in 4 dimensions.
DECLARE FUNCTION D3DXVec4Cross IMPORT $D3DX_DLLNAME ALIAS "D3DXVec4Cross" (_
 BYREF pOut AS D3DXVECTOR4
 , BYREF pV1 AS D3DXVECTOR4
 , BYREF pV2 AS D3DXVECTOR4
 , BYREF pV3 AS D3DXVECTOR4
 ) AS DWORD ' D3DXVECTOR4
DECLARE FUNCTION D3DXVec4Normalize IMPORT $D3DX_DLLNAME ALIAS "D3DXVec4Normalize" (_
 BYREF pOut AS D3DXVECTOR4
 , BYREF pV AS D3DXVECTOR4
 ) AS DWORD ' D3DXVECTOR4
'// Hermite interpolation between position V1, tangent T1 (when s == 0)
'// and position V2, tangent T2 (when s == 1).
DECLARE FUNCTION D3DXVec4Hermite IMPORT $D3DX_DLLNAME ALIAS "D3DXVec4Hermite" (_
 BYREF pOut AS D3DXVECTOR4
 , BYREF pV1 AS D3DXVECTOR4
 , BYREF pT1 AS D3DXVECTOR4
 , BYREF pV2 AS D3DXVECTOR4
 , BYREF pT2 AS D3DXVECTOR4
 , BYVAL s AS SINGLE
 ) AS DWORD ' D3DXVECTOR4
'// CatmullRom interpolation between V1 (when s == 0) and V2 (when s == 1)
DECLARE FUNCTION D3DXVec4CatmullRom IMPORT $D3DX_DLLNAME ALIAS "D3DXVec4CatmullRom" (_
 BYREF pOut AS D3DXVECTOR4
 , BYREF pV0 AS D3DXVECTOR4
 , BYREF pV1 AS D3DXVECTOR4
 , BYREF pV2 AS D3DXVECTOR4
 , BYREF pV3 AS D3DXVECTOR4
 , BYVAL s AS SINGLE
 ) AS DWORD ' D3DXVECTOR4
'// Barycentric coordinates. V1 + f(V2-V1) + g(V3-V1)
DECLARE FUNCTION D3DXVec4BaryCentric IMPORT $D3DX_DLLNAME ALIAS "D3DXVec4BaryCentric" (_
 BYREF pOut AS D3DXVECTOR4
 , BYREF pV1 AS D3DXVECTOR4
 , BYREF pV2 AS D3DXVECTOR4
 , BYREF pV3 AS D3DXVECTOR4
 , BYVAL f AS SINGLE
 , BYVAL s AS SINGLE
 ) AS DWORD ' D3DXVECTOR4
'// Transform vector by matrix.
DECLARE FUNCTION D3DXVec4Transform IMPORT $D3DX_DLLNAME ALIAS "D3DXVec4Transform" (_
 BYREF pOut AS D3DXVECTOR4
 , BYREF pV AS D3DXVECTOR4
 , BYREF pM AS D3DMATRIX
 ) AS DWORD ' D3DXVECTOR4
'// Transform vector array by matrix.
DECLARE FUNCTION D3DXVec4TransformArray IMPORT $D3DX_DLLNAME ALIAS "D3DXVec4TransformArray" (_
 BYREF pOut AS D3DXVECTOR4
 , BYVAL OutStride AS DWORD
 , BYREF pV AS D3DXVECTOR4
 , BYVAL VStride AS DWORD
 , BYREF pM AS D3DMATRIX
 , BYVAL n AS DWORD
 ) AS DWORD ' D3DXVECTOR4
'//--------------------------
'// 4D Matrix
'//--------------------------
DECLARE FUNCTION D3DXMatrixDeterminant IMPORT $D3DX_DLLNAME ALIAS "D3DXMatrixDeterminant" (_
 BYREF pM AS D3DMATRIX
 ) AS SINGLE ' FLOAT
DECLARE FUNCTION D3DXMatrixDecompose IMPORT $D3DX_DLLNAME ALIAS "D3DXMatrixDecompose" (_
 BYREF pOutScale AS D3DXVECTOR3
 , BYREF pOutRotation AS D3DXQUATERNION
 , BYREF pOutTranslation AS D3DXVECTOR3
 , BYREF pM AS D3DMATRIX
 ) AS LONG
DECLARE FUNCTION D3DXMatrixTranspose IMPORT $D3DX_DLLNAME ALIAS "D3DXMatrixTranspose" (_
 BYREF pOut AS D3DMATRIX
 , BYREF pM AS D3DMATRIX
 ) AS DWORD ' D3DXMATRIX
'// Matrix multiplication. The result represents the transformation M2
'// followed by the transformation M1. (Out = M1 * M2)
DECLARE FUNCTION D3DXMatrixMultiply IMPORT $D3DX_DLLNAME ALIAS "D3DXMatrixMultiply" (_
 BYREF pOut AS D3DMATRIX
 , BYREF pM1 AS D3DMATRIX
 , BYREF pM2 AS D3DMATRIX
 ) AS DWORD ' D3DXMATRIX
'// Matrix multiplication, followed by a transpose. (Out = T(M1 * M2))
DECLARE FUNCTION D3DXMatrixMultiplyTranspose IMPORT $D3DX_DLLNAME ALIAS "D3DXMatrixMultiplyTranspose" (_
 BYREF pOut AS D3DMATRIX
 , BYREF pM1 AS D3DMATRIX
 , BYREF pM2 AS D3DMATRIX
 ) AS DWORD ' D3DXMATRIX
'// Calculate inverse of matrix. Inversion my fail, in which case NULL will
'// be returned. The determinant of pM is also returned it pfDeterminant
'// is non-NULL.
DECLARE FUNCTION D3DXMatrixInverse IMPORT $D3DX_DLLNAME ALIAS "D3DXMatrixInverse" (_
 BYREF pOut AS D3DMATRIX
 , BYREF pDeterminant AS SINGLE
 , BYREF pM AS D3DMATRIX
 ) AS DWORD ' D3DXMATRIX
'// Build a matrix which scales by (sx, sy, sz)
DECLARE FUNCTION D3DXMatrixScaling IMPORT $D3DX_DLLNAME ALIAS "D3DXMatrixScaling" (_
 BYREF pOut AS D3DMATRIX
 , BYVAL sx AS SINGLE
 , BYVAL sy AS SINGLE
 , BYVAL sz AS SINGLE
 ) AS DWORD ' D3DXMATRIX
'// Build a matrix which translates by (x, y, z)
DECLARE FUNCTION D3DXMatrixTranslation IMPORT $D3DX_DLLNAME ALIAS "D3DXMatrixTranslation" (_
 BYREF pOut AS D3DMATRIX
 , BYVAL x AS SINGLE
 , BYVAL y AS SINGLE
 , BYVAL z AS SINGLE
 ) AS DWORD ' D3DXMATRIX
'// Build a matrix which rotates around the X axis
DECLARE FUNCTION D3DXMatrixRotationX IMPORT $D3DX_DLLNAME ALIAS "D3DXMatrixRotationX" (_
 BYREF pOut AS D3DMATRIX
 , BYVAL Angle AS SINGLE
 ) AS DWORD ' D3DXMATRIX
'// Build a matrix which rotates around the Y axis
DECLARE FUNCTION D3DXMatrixRotationY IMPORT $D3DX_DLLNAME ALIAS "D3DXMatrixRotationY" (_
 BYREF pOut AS D3DMATRIX
 , BYVAL Angle AS SINGLE
 ) AS DWORD ' D3DXMATRIX
'// Build a matrix which rotates around the Z axis
DECLARE FUNCTION D3DXMatrixRotationZ IMPORT $D3DX_DLLNAME ALIAS "D3DXMatrixRotationZ" (_
 BYREF pOut AS D3DMATRIX ' D3DXMATRIX *pOut
 , BYVAL Angle AS SINGLE ' FLOAT Angle
 ) AS DWORD ' D3DXMATRIX
'// Build a matrix which rotates around an arbitrary axis
DECLARE FUNCTION D3DXMatrixRotationAxis IMPORT $D3DX_DLLNAME ALIAS "D3DXMatrixRotationAxis" (_
 BYREF pOut AS D3DMATRIX
 , BYREF pV AS D3DXVECTOR3
 , BYVAL Angle AS SINGLE
 ) AS DWORD ' D3DXMATRIX
'// Build a matrix from a quaternion
DECLARE FUNCTION D3DXMatrixRotationQuaternion IMPORT $D3DX_DLLNAME ALIAS "D3DXMatrixRotationQuaternion" (_
 BYREF pOut AS D3DMATRIX
 , BYREF pQ AS D3DXQUATERNION
 ) AS DWORD ' D3DXMATRIX
'// Yaw around the Y axis, a pitch around the X axis,
'// and a roll around the Z axis.
DECLARE FUNCTION D3DXMatrixRotationYawPitchRoll IMPORT $D3DX_DLLNAME ALIAS "D3DXMatrixRotationYawPitchRoll" (_
 BYREF pOut AS D3DMATRIX
 , BYVAL Yaw AS SINGLE
 , BYVAL Pitch AS SINGLE
 , BYVAL Roll AS SINGLE
 ) AS DWORD ' D3DXMATRIX
'// Build transformation matrix. NULL arguments are treated as identity.
'// Mout = Msc-1 * Msr-1 * Ms * Msr * Msc * Mrc-1 * Mr * Mrc * Mt
DECLARE FUNCTION D3DXMatrixTransformation IMPORT $D3DX_DLLNAME ALIAS "D3DXMatrixTransformation" (_
 BYREF pOut AS D3DMATRIX
 , BYREF pScalingCenter AS D3DXVECTOR3
 , BYREF pScalingRotation AS D3DXQUATERNION
 , BYREF pScaling AS D3DXVECTOR3
 , BYREF pRotationCenter AS D3DXVECTOR3
 , BYREF pRotation AS D3DXQUATERNION
 , BYREF pTranslation AS D3DXVECTOR3
 ) AS DWORD ' D3DXMATRIX
'// Build 2D transformation matrix in XY plane. NULL arguments are treated as identity.
'// Mout = Msc-1 * Msr-1 * Ms * Msr * Msc * Mrc-1 * Mr * Mrc * Mt
DECLARE FUNCTION D3DXMatrixTransformation2D IMPORT $D3DX_DLLNAME ALIAS "D3DXMatrixTransformation2D" (_
 BYREF pOut AS D3DMATRIX
 , BYREF pScalingCenter AS D3DXVECTOR2
 , BYVAL ScalingRotation AS SINGLE
 , BYREF pScaling AS D3DXVECTOR2
 , BYREF pRotationCenter AS D3DXVECTOR2
 , BYVAL Rotation AS SINGLE
 , BYREF pTranslation AS D3DXVECTOR2
 ) AS DWORD ' D3DXMATRIX
'// Build affine transformation matrix. NULL arguments are treated as identity.
'// Mout = Ms * Mrc-1 * Mr * Mrc * Mt
DECLARE FUNCTION D3DXMatrixAffineTransformation IMPORT $D3DX_DLLNAME ALIAS "D3DXMatrixAffineTransformation" (_
 BYREF pOut AS D3DMATRIX
 , BYVAL Scaling AS SINGLE
 , BYREF pRotationCenter AS D3DXVECTOR3
 , BYREF pRotation AS D3DXQUATERNION
 , BYREF pTranslation AS D3DXVECTOR3
 ) AS DWORD ' D3DXMATRIX
'// Build 2D affine transformation matrix in XY plane. NULL arguments are treated as identity.
'// Mout = Ms * Mrc-1 * Mr * Mrc * Mt
DECLARE FUNCTION D3DXMatrixAffineTransformation2D IMPORT $D3DX_DLLNAME ALIAS "D3DXMatrixAffineTransformation2D" (_
 BYREF pOut AS D3DMATRIX
 , BYVAL Scaling AS SINGLE
 , BYREF pRotationCenter AS D3DXVECTOR2
 , BYVAL Rotation AS SINGLE
 , BYREF pTranslation AS D3DXVECTOR2
 ) AS DWORD ' D3DXMATRIX
'// Build a lookat matrix. (right-handed)
DECLARE FUNCTION D3DXMatrixLookAtRH IMPORT $D3DX_DLLNAME ALIAS "D3DXMatrixLookAtRH" (_
 BYREF pOut AS D3DMATRIX
 , BYREF pEye AS D3DXVECTOR3
 , BYREF pAt AS D3DXVECTOR3
 , BYREF pUp AS D3DXVECTOR3
 ) AS DWORD ' D3DXMATRIX
'// Build a lookat matrix. (left-handed)
DECLARE FUNCTION D3DXMatrixLookAtLH IMPORT $D3DX_DLLNAME ALIAS "D3DXMatrixLookAtLH" (_
 BYREF pOut AS D3DMATRIX
 , BYREF pEye AS D3DXVECTOR3
 , BYREF pAt AS D3DXVECTOR3
 , BYREF pUp AS D3DXVECTOR3
 ) AS DWORD ' D3DXMATRIX
'// Build a perspective projection matrix. (right-handed)
DECLARE FUNCTION D3DXMatrixPerspectiveRH IMPORT $D3DX_DLLNAME ALIAS "D3DXMatrixPerspectiveRH" (_
 BYREF pOut AS D3DMATRIX
 , BYVAL w AS SINGLE
 , BYVAL h AS SINGLE
 , BYVAL zn AS SINGLE
 , BYVAL zf AS SINGLE
 ) AS DWORD ' D3DXMATRIX
'// Build a perspective projection matrix. (left-handed)
DECLARE FUNCTION D3DXMatrixPerspectiveLH IMPORT $D3DX_DLLNAME ALIAS "D3DXMatrixPerspectiveLH" (_
 BYREF pOut AS D3DMATRIX
 , BYVAL w AS SINGLE
 , BYVAL h AS SINGLE
 , BYVAL zn AS SINGLE
 , BYVAL zf AS SINGLE
 ) AS DWORD ' D3DXMATRIX
'// Build a perspective projection matrix. (right-handed)
DECLARE FUNCTION D3DXMatrixPerspectiveFovRH IMPORT $D3DX_DLLNAME ALIAS "D3DXMatrixPerspectiveFovRH" (_
 BYREF pOut AS D3DMATRIX
 , BYVAL fovy AS SINGLE
 , BYVAL Aspect AS SINGLE
 , BYVAL zn AS SINGLE
 , BYVAL zf AS SINGLE
 ) AS DWORD ' D3DXMATRIX
'// Build a perspective projection matrix. (left-handed)
DECLARE FUNCTION D3DXMatrixPerspectiveFovLH IMPORT $D3DX_DLLNAME ALIAS "D3DXMatrixPerspectiveFovLH" (_
 BYREF pOut AS D3DMATRIX
 , BYVAL fovy AS SINGLE
 , BYVAL Aspect AS SINGLE
 , BYVAL zn AS SINGLE
 , BYVAL zf AS SINGLE
 ) AS DWORD ' D3DXMATRIX
'// Build a perspective projection matrix. (right-handed)
DECLARE FUNCTION D3DXMatrixPerspectiveOffCenterRH IMPORT $D3DX_DLLNAME ALIAS "D3DXMatrixPerspectiveOffCenterRH" (_
 BYREF pOut AS D3DMATRIX
 , BYVAL l AS SINGLE
 , BYVAL r AS SINGLE
 , BYVAL b AS SINGLE
 , BYVAL t AS SINGLE
 , BYVAL zn AS SINGLE
 , BYVAL zf AS SINGLE
 ) AS DWORD ' D3DXMATRIX
'// Build a perspective projection matrix. (left-handed)
DECLARE FUNCTION D3DXMatrixPerspectiveOffCenterLH IMPORT $D3DX_DLLNAME ALIAS "D3DXMatrixPerspectiveOffCenterLH" (_
 BYREF pOut AS D3DMATRIX
 , BYVAL l AS SINGLE
 , BYVAL r AS SINGLE
 , BYVAL b AS SINGLE
 , BYVAL t AS SINGLE
 , BYVAL zn AS SINGLE
 , BYVAL zf AS SINGLE
 ) AS DWORD ' D3DXMATRIX
'// Build an ortho projection matrix. (right-handed)
DECLARE FUNCTION D3DXMatrixOrthoRH IMPORT $D3DX_DLLNAME ALIAS "D3DXMatrixOrthoRH" (_
 BYREF pOut AS D3DMATRIX
 , BYVAL w AS SINGLE
 , BYVAL h AS SINGLE
 , BYVAL zn AS SINGLE
 , BYVAL zf AS SINGLE
 ) AS DWORD ' D3DXMATRIX
'// Build an ortho projection matrix. (left-handed)
DECLARE FUNCTION D3DXMatrixOrthoLH IMPORT $D3DX_DLLNAME ALIAS "D3DXMatrixOrthoLH" (_
 BYREF pOut AS D3DMATRIX
 , BYVAL w AS SINGLE
 , BYVAL h AS SINGLE
 , BYVAL zn AS SINGLE
 , BYVAL zf AS SINGLE
 ) AS DWORD ' D3DXMATRIX
'// Build an ortho projection matrix. (right-handed)
DECLARE FUNCTION D3DXMatrixOrthoOffCenterRH IMPORT $D3DX_DLLNAME ALIAS "D3DXMatrixOrthoOffCenterRH" (_
 BYREF pOut AS D3DMATRIX
 , BYVAL l AS SINGLE
 , BYVAL r AS SINGLE
 , BYVAL b AS SINGLE
 , BYVAL t AS SINGLE
 , BYVAL zn AS SINGLE
 , BYVAL zf AS SINGLE
 ) AS DWORD ' D3DXMATRIX
'// Build an ortho projection matrix. (left-handed)
DECLARE FUNCTION D3DXMatrixOrthoOffCenterLH IMPORT $D3DX_DLLNAME ALIAS "D3DXMatrixOrthoOffCenterLH" (_
 BYREF pOut AS D3DMATRIX
 , BYVAL l AS SINGLE
 , BYVAL r AS SINGLE
 , BYVAL b AS SINGLE
 , BYVAL t AS SINGLE
 , BYVAL zn AS SINGLE
 , BYVAL zf AS SINGLE
 ) AS DWORD ' D3DXMATRIX
'// Build a matrix which flattens geometry into a plane, as if casting
'// a shadow from a light.
DECLARE FUNCTION D3DXMatrixShadow IMPORT $D3DX_DLLNAME ALIAS "D3DXMatrixShadow" (_
 BYREF pOut AS D3DMATRIX
 , BYREF pLight AS D3DXVECTOR4
 , BYREF pPlane AS D3DXPLANE
 ) AS DWORD ' D3DXMATRIX
'// Build a matrix which reflects the coordinate system about a plane
DECLARE FUNCTION D3DXMatrixReflect IMPORT $D3DX_DLLNAME ALIAS "D3DXMatrixReflect" (_
 BYREF pOut AS D3DMATRIX
 , BYREF pPlane AS D3DXPLANE
 ) AS DWORD ' D3DXMATRIX
'//--------------------------
'// Quaternion
'//--------------------------
'// Compute a quaternin's axis and angle of rotation. Expects unit quaternions.
DECLARE SUB D3DXQuaternionToAxisAngle IMPORT $D3DX_DLLNAME ALIAS "D3DXQuaternionToAxisAngle" (_
 BYREF pQ AS D3DXQUATERNION
 , BYREF pAxis AS D3DXVECTOR3
 , BYREF pAngle AS SINGLE
 ) ' void
'// Build a quaternion from a rotation matrix.
DECLARE FUNCTION D3DXQuaternionRotationMatrix IMPORT $D3DX_DLLNAME ALIAS "D3DXQuaternionRotationMatrix" (_
 BYREF pOut AS D3DXQUATERNION
 , BYREF pM AS D3DMATRIX
 ) AS DWORD ' D3DXQUATERNION
'// Rotation about arbitrary axis.
DECLARE FUNCTION D3DXQuaternionRotationAxis IMPORT $D3DX_DLLNAME ALIAS "D3DXQuaternionRotationAxis" (_
 BYREF pOut AS D3DXQUATERNION
 , BYREF pV AS D3DXVECTOR3
 , BYVAL Angle AS SINGLE
 ) AS DWORD ' D3DXQUATERNION
'// Yaw around the Y axis, a pitch around the X axis,
'// and a roll around the Z axis.
DECLARE FUNCTION D3DXQuaternionRotationYawPitchRoll IMPORT $D3DX_DLLNAME ALIAS "D3DXQuaternionRotationYawPitchRoll" (_
 BYREF pOut AS D3DXQUATERNION
 , BYVAL Yaw AS SINGLE
 , BYVAL Pitch AS SINGLE
 , BYVAL Roll AS SINGLE
 ) AS DWORD ' D3DXQUATERNION
'// Quaternion multiplication. The result represents the rotation Q2
'// followed by the rotation Q1. (Out = Q2 * Q1)
DECLARE FUNCTION D3DXQuaternionMultiply IMPORT $D3DX_DLLNAME ALIAS "D3DXQuaternionMultiply" (_
 BYREF pOut AS D3DXQUATERNION
 , BYREF pQ1 AS D3DXQUATERNION
 , BYREF pQ2 AS D3DXQUATERNION
 ) AS DWORD ' D3DXQUATERNION
DECLARE FUNCTION D3DXQuaternionNormalize IMPORT $D3DX_DLLNAME ALIAS "D3DXQuaternionNormalize" (_
 BYREF pOut AS D3DXQUATERNION
 , BYREF pQ AS D3DXQUATERNION
 ) AS DWORD ' D3DXQUATERNION
'// Conjugate and re-norm
DECLARE FUNCTION D3DXQuaternionInverse IMPORT $D3DX_DLLNAME ALIAS "D3DXQuaternionInverse" (_
 BYREF pOut AS D3DXQUATERNION
 , BYREF pQ AS D3DXQUATERNION
 ) AS DWORD ' D3DXQUATERNION
'// Expects unit quaternions.
'// if q = (cos(theta), sin(theta) * v); ln(q) = (0, theta * v)
DECLARE FUNCTION D3DXQuaternionLn IMPORT $D3DX_DLLNAME ALIAS "D3DXQuaternionLn" (_
 BYREF pOut AS D3DXQUATERNION
 , BYREF pQ AS D3DXQUATERNION
 ) AS DWORD ' D3DXQUATERNION
'// Expects pure quaternions. (w == 0) w is ignored in calculation.
'// if q = (0, theta * v); exp(q) = (cos(theta), sin(theta) * v)
DECLARE FUNCTION D3DXQuaternionExp IMPORT $D3DX_DLLNAME ALIAS "D3DXQuaternionExp" (_
 BYREF pOut AS D3DXQUATERNION
 , BYREF pQ AS D3DXQUATERNION
 ) AS DWORD ' D3DXQUATERNION
'// Spherical linear interpolation between Q1 (t == 0) and Q2 (t == 1).
'// Expects unit quaternions.
DECLARE FUNCTION D3DXQuaternionSlerp IMPORT $D3DX_DLLNAME ALIAS "D3DXQuaternionSlerp" (_
 BYREF pOut AS D3DXQUATERNION
 , BYREF pQ1 AS D3DXQUATERNION
 , BYREF pQ2 AS D3DXQUATERNION
 , BYVAL t AS SINGLE
 ) AS DWORD ' D3DXQUATERNION
'// Spherical quadrangle interpolation.
'// Slerp(Slerp(Q1, C, t), Slerp(A, B, t), 2t(1-t))
DECLARE FUNCTION D3DXQuaternionSquad IMPORT $D3DX_DLLNAME ALIAS "D3DXQuaternionSquad" (_
 BYREF pOut AS D3DXQUATERNION
 , BYREF pQ1 AS D3DXQUATERNION
 , BYREF pA AS D3DXQUATERNION
 , BYREF pB AS D3DXQUATERNION
 , BYREF pC AS D3DXQUATERNION
 , BYVAL t AS SINGLE
 ) AS DWORD ' D3DXQUATERNION
'// Setup control points for spherical quadrangle interpolation
'// from Q1 to Q2. The control points are chosen in such a way
'// to ensure the continuity of tangents with adjacent segments.
DECLARE SUB D3DXQuaternionSquadSetup IMPORT $D3DX_DLLNAME ALIAS "D3DXQuaternionSquadSetup" (_
 BYREF pAOut AS D3DXQUATERNION
 , BYREF pBOut AS D3DXQUATERNION
 , BYREF pCOut AS D3DXQUATERNION
 , BYREF pQ0 AS D3DXQUATERNION
 , BYREF pQ1 AS D3DXQUATERNION
 , BYREF pQ2 AS D3DXQUATERNION
 , BYREF pQ3 AS D3DXQUATERNION
 ) ' void
'// Barycentric interpolation.
'// Slerp(Slerp(Q1, Q2, f+g), Slerp(Q1, Q3, f+g), g/(f+g))
DECLARE FUNCTION D3DXQuaternionBaryCentric IMPORT $D3DX_DLLNAME ALIAS "D3DXQuaternionBaryCentric" (_
 BYREF pOut AS D3DXQUATERNION
 , BYREF pQ1 AS D3DXQUATERNION
 , BYREF pQ2 AS D3DXQUATERNION
 , BYREF pQ3 AS D3DXQUATERNION
 , BYVAL f AS SINGLE
 , BYVAL g AS SINGLE
 ) AS DWORD ' D3DXQUATERNION
'//--------------------------
'// Plane
'//--------------------------
'// Normalize plane (so that |a,b,c| == 1)
DECLARE FUNCTION D3DXPlaneNormalize IMPORT $D3DX_DLLNAME ALIAS "D3DXPlaneNormalize" (_
 BYREF pOut AS D3DXPLANE
 , BYREF pP AS D3DXPLANE
 ) AS DWORD ' D3DXPLANE
'// Find the intersection between a plane and a line. If the line is
'// parallel to the plane, NULL is returned.
DECLARE FUNCTION D3DXPlaneIntersectLine IMPORT $D3DX_DLLNAME ALIAS "D3DXPlaneIntersectLine" (_
 BYREF pOut AS D3DXVECTOR3
 , BYREF pP AS D3DXPLANE
 , BYREF pV1 AS D3DXVECTOR3
 , BYREF pV2 AS D3DXVECTOR3
 ) AS DWORD ' D3DXVECTOR3
'// Construct a plane from a point and a normal
DECLARE FUNCTION D3DXPlaneFromPointNormal IMPORT $D3DX_DLLNAME ALIAS "D3DXPlaneFromPointNormal" (_
 BYREF pOut AS D3DXPLANE
 , BYREF pPoint AS D3DXVECTOR3
 , BYREF pNormal AS D3DXVECTOR3
 ) AS DWORD ' D3DXPLANE
'// Construct a plane from 3 points
DECLARE FUNCTION D3DXPlaneFromPoints IMPORT $D3DX_DLLNAME ALIAS "D3DXPlaneFromPoints" (_
 BYREF pOut AS D3DXPLANE
 , BYREF pV1 AS D3DXVECTOR3
 , BYREF pV2 AS D3DXVECTOR3
 , BYREF pV3 AS D3DXVECTOR3
 ) AS DWORD ' D3DXPLANE
'// Transform a plane by a matrix. The vector (a,b,c) must be normal.
'// M should be the inverse transpose of the transformation desired.
DECLARE FUNCTION D3DXPlaneTransform IMPORT $D3DX_DLLNAME ALIAS "D3DXPlaneTransform" (_
 BYREF pOut AS D3DXPLANE
 , BYREF pP AS D3DXPLANE
 , BYREF pM AS D3DMATRIX
 ) AS DWORD ' D3DXPLANE
'// Transform an array of planes by a matrix. The vectors (a,b,c) must be normal.
'// M should be the inverse transpose of the transformation desired.
DECLARE FUNCTION D3DXPlaneTransformArray IMPORT $D3DX_DLLNAME ALIAS "D3DXPlaneTransformArray" (_
 BYREF pOut AS D3DXPLANE
 , BYVAL OutStride AS DWORD
 , BYREF pP AS D3DXPLANE
 , BYVAL PStride AS DWORD
 , BYREF pM AS D3DMATRIX
 , BYVAL n AS DWORD
 ) AS DWORD ' D3DXPLANE
'//--------------------------
'// Color
'//--------------------------
'// Interpolate r,g,b between desaturated color and color.
'// DesaturatedColor + s(Color - DesaturatedColor)
DECLARE FUNCTION D3DXColorAdjustSaturation IMPORT $D3DX_DLLNAME ALIAS "D3DXColorAdjustSaturation" (_
 BYREF pOut AS D3DXCOLOR
 , BYREF pC AS D3DXCOLOR
 , BYVAL s AS SINGLE
 ) AS DWORD ' D3DXCOLOR
'// Interpolate r,g,b between 50% grey and color. Grey + s(Color - Grey)
DECLARE FUNCTION D3DXColorAdjustContrast IMPORT $D3DX_DLLNAME ALIAS "D3DXColorAdjustContrast" (_
 BYREF pOut AS D3DXCOLOR
 , BYREF pC AS D3DXCOLOR
 , BYVAL s AS SINGLE
 ) AS DWORD ' D3DXCOLOR
'//--------------------------
'// Misc
'//--------------------------
'// Calculate Fresnel term given the cosine of theta (likely obtained by
'// taking the dot of two normals), and the refraction index of the material.
DECLARE FUNCTION D3DXFresnelTerm IMPORT $D3DX_DLLNAME ALIAS "D3DXFresnelTerm" (_
 BYVAL CosTheta AS SINGLE
 , BYVAL RefractionIndex AS SINGLE
 ) AS SINGLE ' FLOAT
'//===========================================================================
'//
'// Matrix Stack
'//
'//===========================================================================
$IID_ID3DXMatrixStack = GUID$("{C7885BA7-F990-4fe7-922D-8515E477DD85}")
INTERFACE ID3DXMatrixStack $IID_ID3DXMatrixStack
 INHERIT IUnknown
 ' =====================================================================================
 METHOD Pop ( ' VTable offset = 12
 ) AS LONG
 ' =====================================================================================
 METHOD Push ( ' VTable offset = 16
 ) AS LONG
 ' =====================================================================================
 METHOD LoadIdentity ( ' VTable offset = 20
 ) AS LONG
 ' =====================================================================================
 METHOD LoadMatrix ( ' VTable offset = 24
 BYREF pM AS D3DXMATRIX
 ) AS LONG
 ' =====================================================================================
 METHOD MultMatrix ( ' VTable offset = 28
 BYREF pM AS D3DXMATRIX
 ) AS LONG
 ' =====================================================================================
 METHOD MultMatrixLocal ( ' VTable offset = 32
 BYREF pM AS D3DXMATRIX
 ) AS LONG
 ' =====================================================================================
 METHOD RotateAxis ( ' VTable offset = 36
 BYREF pV AS D3DXVECTOR3
 , BYVAL Angle AS SINGLE
 ) AS LONG
 ' =====================================================================================
 METHOD RotateAxisLocal ( ' VTable offset = 40
 BYREF pV AS D3DXVECTOR3
 , BYVAL Angle AS SINGLE
 ) AS LONG
 ' =====================================================================================
 METHOD RotateYawPitchRoll ( ' VTable offset = 44
 BYVAL Yaw AS SINGLE
 , BYVAL Pitch AS SINGLE
 , BYVAL Roll AS SINGLE
 ) AS LONG
 ' =====================================================================================
 METHOD RotateYawPitchRollLocal ( ' VTable offset = 48
 BYVAL Yaw AS SINGLE
 , BYVAL Pitch AS SINGLE
 , BYVAL Roll AS SINGLE
 ) AS LONG
 ' =====================================================================================
 METHOD Scale ( ' VTable offset = 52
 BYVAL x AS SINGLE
 , BYVAL y AS SINGLE
 , BYVAL x AS SINGLE
 ) AS LONG
 ' =====================================================================================
 METHOD ScaleLocal ( ' VTable offset = 56
 BYVAL x AS SINGLE
 , BYVAL y AS SINGLE
 , BYVAL x AS SINGLE
 ) AS LONG
 ' =====================================================================================
 METHOD Translate ( ' VTable offset = 60
 BYVAL x AS SINGLE
 , BYVAL y AS SINGLE
 , BYVAL x AS SINGLE
 ) AS LONG
 ' =====================================================================================
 METHOD TranslateLocal ( ' VTable offset = 64
 BYVAL x AS SINGLE
 , BYVAL y AS SINGLE
 , BYVAL x AS SINGLE
 ) AS LONG
 ' =====================================================================================
 METHOD GetTop ( ' VTable offset = 68
 ) AS D3DXMATRIX ' D3DXMATRIX
 ' =====================================================================================
END INTERFACE
DECLARE FUNCTION D3DXCreateMatrixStack IMPORT $D3DX_DLLNAME ALIAS "D3DXCreateMatrixStack" (_
 BYVAL Flags AS DWORD
 , BYREF ppStack AS ID3DXMATRIXStack
 ) AS LONG
'//===========================================================================
'//
'// Spherical Harmonic Runtime Routines
'//
'// NOTE:
'// * Most of these functions can take the same object as in and out parameters.
'// The exceptions are the rotation functions.
'//
'// * Out parameters are typically also returned as return values, so that
'// the output of one function may be used as a parameter to another.
'//
'//============================================================================
'//============================================================================
'//
'// Basic Spherical Harmonic math routines
'//
'//============================================================================
%EQUATE `D3DXSH_MINORDER = 2
%EQUATE `D3DXSH_MAXORDER = 6
'//============================================================================
'//
'// D3DXSHEvalDirection:
'// --------------------
'// Evaluates the Spherical Harmonic basis functions
'//
'// Parameters:
'// pOut
'// Output SH coefficients - basis function Ylm is stored at l*l + m+l
'// This is the pointer that is returned.
'// Order
'// Order of the SH evaluation, generates Order^2 coefs, degree is Order-1
'// pDir
'// Direction to evaluate in - assumed to be normalized
'//
'//============================================================================
DECLARE FUNCTION D3DXSHEvalDirection IMPORT $D3DX_DLLNAME ALIAS "D3DXSHEvalDirection" (_
 BYREF pOut AS SINGLE
 , BYVAL Order AS DWORD
 , BYREF pDir AS D3DXVECTOR3
 ) AS SINGLE ' FLOAT
'//============================================================================
'//
'// D3DXSHRotate:
'// --------------------
'// Rotates SH vector by a rotation matrix
'//
'// Parameters:
'// pOut
'// Output SH coefficients - basis function Ylm is stored at l*l + m+l
'// This is the pointer that is returned (should not alias with pIn.)
'// Order
'// Order of the SH evaluation, generates Order^2 coefs, degree is Order-1
'// pMatrix
'// Matrix used for rotation - rotation sub matrix should be orthogonal
'// and have a unit determinant.
'// pIn
'// Input SH coeffs (rotated), incorect results if this is also output.
'//
'//============================================================================
DECLARE FUNCTION D3DXSHRotate IMPORT $D3DX_DLLNAME ALIAS "D3DXSHRotate" (_
 BYREF pOut AS SINGLE
 , BYVAL Order AS DWORD
 , BYREF pMatrix AS D3DMATRIX
 , BYREF pIn AS SINGLE
 ) AS SINGLE ' FLOAT
'//============================================================================
'//
'// D3DXSHRotateZ:
'// --------------------
'// Rotates the SH vector in the Z axis by an angle
'//
'// Parameters:
'// pOut
'// Output SH coefficients - basis function Ylm is stored at l*l + m+l
'// This is the pointer that is returned (should not alias with pIn.)
'// Order
'// Order of the SH evaluation, generates Order^2 coefs, degree is Order-1
'// Angle
'// Angle in radians to rotate around the Z axis.
'// pIn
'// Input SH coeffs (rotated), incorect results if this is also output.
'//
'//============================================================================
DECLARE FUNCTION D3DXSHRotateZ IMPORT $D3DX_DLLNAME ALIAS "D3DXSHRotateZ" (_
 BYREF pOut AS SINGLE
 , BYVAL Order AS DWORD
 , BYVAL Angle AS SINGLE
 , BYREF pIn AS SINGLE
 ) AS SINGLE ' FLOAT
'//============================================================================
'//
'// D3DXSHAdd:
'// --------------------
'// Adds two SH vectors, pOut[i] = pA[i] + pB[i];
'//
'// Parameters:
'// pOut
'// Output SH coefficients - basis function Ylm is stored at l*l + m+l
'// This is the pointer that is returned.
'// Order
'// Order of the SH evaluation, generates Order^2 coefs, degree is Order-1
'// pA
'// Input SH coeffs.
'// pB
'// Input SH coeffs (second vector.)
'//
'//============================================================================
DECLARE FUNCTION D3DXSHAdd IMPORT $D3DX_DLLNAME ALIAS "D3DXSHAdd" (_
 BYREF pOut AS SINGLE
 , BYVAL Order AS DWORD
 , BYREF pA AS SINGLE
 , BYREF pB AS SINGLE
 ) AS SINGLE ' FLOAT
'//============================================================================
'//
'// D3DXSHScale:
'// --------------------
'// Adds two SH vectors, pOut[i] = pA[i]*Scale;
'//
'// Parameters:
'// pOut
'// Output SH coefficients - basis function Ylm is stored at l*l + m+l
'// This is the pointer that is returned.
'// Order
'// Order of the SH evaluation, generates Order^2 coefs, degree is Order-1
'// pIn
'// Input SH coeffs.
'// Scale
'// Scale factor.
'//
'//============================================================================
DECLARE FUNCTION D3DXSHScale IMPORT $D3DX_DLLNAME ALIAS "D3DXSHScale" (_
 BYREF pOut AS SINGLE
 , BYVAL Order AS DWORD
 , BYREF pIn AS SINGLE
 , BYVAL Scale AS SINGLE
 ) AS SINGLE ' FLOAT
'//============================================================================
'//
'// D3DXSHDot:
'// --------------------
'// Computes the dot product of two SH vectors
'//
'// Parameters:
'// Order
'// Order of the SH evaluation, generates Order^2 coefs, degree is Order-1
'// pA
'// Input SH coeffs.
'// pB
'// Second set of input SH coeffs.
'//
'//============================================================================
DECLARE FUNCTION D3DXSHDot IMPORT $D3DX_DLLNAME ALIAS "D3DXSHDot" (_
 BYVAL Order AS DWORD
 , BYREF pA AS SINGLE
 , BYREF pB AS SINGLE
 ) AS SINGLE ' FLOAT
'//============================================================================
'//
'// Basic Spherical Harmonic lighting routines
'//
'//============================================================================
'//============================================================================
'//
'// D3DXSHEvalDirectionalLight:
'// --------------------
'// Evaluates a directional light and returns spectral SH data. The output
'// vector is computed so that if the intensity of R/G/B is unit the resulting
'// exit radiance of a point directly under the light on a diffuse object with
'// an albedo of 1 would be 1.0. This will compute 3 spectral samples, pROut
'// has to be specified, while pGout and pBout are optional.
'//
'// Parameters:
'// Order
'// Order of the SH evaluation, generates Order^2 coefs, degree is Order-1
'// pDir
'// Direction light is coming from (assumed to be normalized.)
'// RIntensity
'// Red intensity of light.
'// GIntensity
'// Green intensity of light.
'// BIntensity
'// Blue intensity of light.
'// pROut
'// Output SH vector for Red.
'// pGOut
'// Output SH vector for Green (optional.)
'// pBOut
'// Output SH vector for Blue (optional.)
'//
'//============================================================================
DECLARE FUNCTION D3DXSHEvalDirectionalLight IMPORT $D3DX_DLLNAME ALIAS "D3DXSHEvalDirectionalLight" (_
 BYVAL Order AS DWORD
 , BYREF pDir AS D3DXVECTOR3
 , BYVAL RIntensity AS SINGLE
 , BYVAL GIntensity AS SINGLE
 , BYVAL BIntensity AS SINGLE
 , BYREF pROut AS SINGLE
 , BYREF pGOut AS SINGLE
 , BYREF pBOut AS SINGLE
 ) AS LONG
'//============================================================================
'//
'// D3DXSHEvalSphericalLight:
'// --------------------
'// Evaluates a spherical light and returns spectral SH data. There is no
'// normalization of the intensity of the light like there is for directional
'// lights, care has to be taken when specifiying the intensities. This will
'// compute 3 spectral samples, pROut has to be specified, while pGout and
'// pBout are optional.
'//
'// Parameters:
'// Order
'// Order of the SH evaluation, generates Order^2 coefs, degree is Order-1
'// pPos
'// Position of light - reciever is assumed to be at the origin.
'// Radius
'// Radius of the spherical light source.
'// RIntensity
'// Red intensity of light.
'// GIntensity
'// Green intensity of light.
'// BIntensity
'// Blue intensity of light.
'// pROut
'// Output SH vector for Red.
'// pGOut
'// Output SH vector for Green (optional.)
'// pBOut
'// Output SH vector for Blue (optional.)
'//
'//============================================================================
DECLARE FUNCTION D3DXSHEvalSphericalLight IMPORT $D3DX_DLLNAME ALIAS "D3DXSHEvalSphericalLight" (_
 BYVAL Order AS DWORD
 , BYREF pPos AS D3DXVECTOR3
 , BYVAL Radius AS SINGLE
 , BYVAL RIntensity AS SINGLE
 , BYVAL GIntensity AS SINGLE
 , BYVAL BIntensity AS SINGLE
 , BYREF pROut AS SINGLE
 , BYREF pGOut AS SINGLE
 , BYREF pBOut AS SINGLE
 ) AS LONG
'//============================================================================
'//
'// D3DXSHEvalConeLight:
'// --------------------
'// Evaluates a light that is a cone of constant intensity and returns spectral
'// SH data. The output vector is computed so that if the intensity of R/G/B is
'// unit the resulting exit radiance of a point directly under the light oriented
'// in the cone direction on a diffuse object with an albedo of 1 would be 1.0.
'// This will compute 3 spectral samples, pROut has to be specified, while pGout
'// and pBout are optional.
'//
'// Parameters:
'// Order
'// Order of the SH evaluation, generates Order^2 coefs, degree is Order-1
'// pDir
'// Direction light is coming from (assumed to be normalized.)
'// Radius
'// Radius of cone in radians.
'// RIntensity
'// Red intensity of light.
'// GIntensity
'// Green intensity of light.
'// BIntensity
'// Blue intensity of light.
'// pROut
'// Output SH vector for Red.
'// pGOut
'// Output SH vector for Green (optional.)
'// pBOut
'// Output SH vector for Blue (optional.)
'//
'//============================================================================
DECLARE FUNCTION D3DXSHEvalConeLight IMPORT $D3DX_DLLNAME ALIAS "D3DXSHEvalConeLight" (_
 BYVAL Order AS DWORD
 , BYREF pDir AS D3DXVECTOR3
 , BYVAL Radius AS SINGLE
 , BYVAL RIntensity AS SINGLE
 , BYVAL GIntensity AS SINGLE
 , BYVAL BIntensity AS SINGLE
 , BYREF pROut AS SINGLE
 , BYREF pGOut AS SINGLE
 , BYREF pBOut AS SINGLE
 ) AS LONG
'//============================================================================
'//
'// D3DXSHEvalHemisphereLight:
'// --------------------
'// Evaluates a light that is a linear interpolant between two colors over the
'// sphere. The interpolant is linear along the axis of the two points, not
'// over the surface of the sphere (ie: if the axis was (0,0,1) it is linear in
'// Z, not in the azimuthal angle.) The resulting spherical lighting function
'// is normalized so that a point on a perfectly diffuse surface with no
'// shadowing and a normal pointed in the direction pDir would result in exit
'// radiance with a value of 1 if the top color was white and the bottom color
'// was black. This is a very simple model where Top represents the intensity
'// of the "sky" and Bottom represents the intensity of the "ground".
'//
'// Parameters:
'// Order
'// Order of the SH evaluation, generates Order^2 coefs, degree is Order-1
'// pDir
'// Axis of the hemisphere.
'// Top
'// Color of the upper hemisphere.
'// Bottom
'// Color of the lower hemisphere.
'// pROut
'// Output SH vector for Red.
'// pGOut
'// Output SH vector for Green
'// pBOut
'// Output SH vector for Blue
'//
'//============================================================================
DECLARE FUNCTION D3DXSHEvalHemisphereLight IMPORT $D3DX_DLLNAME ALIAS "D3DXSHEvalHemisphereLight" (_
 BYVAL Order AS DWORD
 , BYREF pDir AS D3DXVECTOR3
 , BYREF Top AS D3DXCOLOR
 , BYREF Bottom AS D3DXCOLOR
 , BYREF pROut AS SINGLE
 , BYREF pGOut AS SINGLE
 , BYREF pBOut AS SINGLE
 ) AS LONG
'//============================================================================
'//
'// Basic Spherical Harmonic projection routines
'//
'//============================================================================
'//============================================================================
'//
'// D3DXSHProjectCubeMap:
'// --------------------
'// Projects a function represented on a cube map into spherical harmonics.
'//
'// Parameters:
'// Order
'// Order of the SH evaluation, generates Order^2 coefs, degree is Order-1
'// pCubeMap
'// CubeMap that is going to be projected into spherical harmonics
'// pROut
'// Output SH vector for Red.
'// pGOut
'// Output SH vector for Green
'// pBOut
'// Output SH vector for Blue
'//
'//============================================================================
DECLARE FUNCTION D3DXSHProjectCubeMap IMPORT $D3DX_DLLNAME ALIAS "D3DXSHProjectCubeMap" (_
 BYVAL uOrder AS DWORD
 , BYVAL pCubeMap AS IDirect3DCubeTexture9
 , BYREF pROut AS SINGLE
 , BYREF pGOut AS SINGLE
 , BYREF pBOut AS SINGLE
 ) AS LONG
#INCLUDE ONCE "d3dx9math.inl"
#ENDIF
