📄 direct3d.pas
字号:
(*==========================================================================;
*
* Copyright (C) 1995-1998 Microsoft Corporation. All Rights Reserved.
*
* Files: d3dtypes.h d3dcaps.h d3d.h
*
* DirectX 7.0 Delphi adaptation by Erik Unger
*
* Modyfied: 19-Feb-2000
*
* Download: http://www.delphi-jedi.org/DelphiGraphics/
* E-Mail: Erik.Unger@gmx.at
*
***************************************************************************)
unit Direct3D;
{$MINENUMSIZE 4}
{$ALIGN ON}
interface
uses
Windows,
DirectDraw;
(* TD3DValue is the fundamental Direct3D fractional data type *)
type
TRefClsID = TGUID;
type
TD3DValue = Single;
TD3DFixed = LongInt;
float = TD3DValue;
PD3DColor = ^TD3DColor;
TD3DColor = DWORD;
function D3DVal(val: variant) : float;
function D3DDivide(a,b: double) : float;
function D3DMultiply(a,b: double) : float;
(*
* Format of CI colors is
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | alpha | color index | fraction |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*)
// #define CI_GETALPHA(ci) ((ci) >> 24)
function CI_GETALPHA(ci: DWORD) : DWORD;
// #define CI_GETINDEX(ci) (((ci) >> 8) & 0xffff)
function CI_GETINDEX(ci: DWORD) : DWORD;
// #define CI_GETFRACTION(ci) ((ci) & 0xff)
function CI_GETFRACTION(ci: DWORD) : DWORD;
// #define CI_ROUNDINDEX(ci) CI_GETINDEX((ci) + 0x80)
function CI_ROUNDINDEX(ci: DWORD) : DWORD;
// #define CI_MASKALPHA(ci) ((ci) & 0xffffff)
function CI_MASKALPHA(ci: DWORD) : DWORD;
// #define CI_MAKE(a, i, f) (((a) << 24) | ((i) << 8) | (f))
function CI_MAKE(a,i,f: DWORD) : DWORD;
(*
* Format of RGBA colors is
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | alpha | red | green | blue |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*)
// #define RGBA_GETALPHA(rgb) ((rgb) >> 24)
function RGBA_GETALPHA(rgb: TD3DColor) : DWORD;
// #define RGBA_GETRED(rgb) (((rgb) >> 16) & 0xff)
function RGBA_GETRED(rgb: TD3DColor) : DWORD;
// #define RGBA_GETGREEN(rgb) (((rgb) >> 8) & 0xff)
function RGBA_GETGREEN(rgb: TD3DColor) : DWORD;
// #define RGBA_GETBLUE(rgb) ((rgb) & 0xff)
function RGBA_GETBLUE(rgb: TD3DColor) : DWORD;
// #define RGBA_MAKE(r, g, b, a) ((TD3DColor) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b)))
function RGBA_MAKE(r, g, b, a: DWORD) : TD3DColor;
(* D3DRGB and D3DRGBA may be used as initialisers for D3DCOLORs
* The float values must be in the range 0..1
*)
// #define D3DRGB(r, g, b) \
// (0xff000000L | (((long)((r) * 255)) << 16) | (((long)((g) * 255)) << 8) | (long)((b) * 255))
function D3DRGB(r, g, b: float) : TD3DColor;
// #define D3DRGBA(r, g, b, a) \
// ( (((long)((a) * 255)) << 24) | (((long)((r) * 255)) << 16) \
// | (((long)((g) * 255)) << 8) | (long)((b) * 255) \
// )
function D3DRGBA(r, g, b, a: float) : TD3DColor;
(*
* Format of RGB colors is
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | ignored | red | green | blue |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*)
// #define RGB_GETRED(rgb) (((rgb) >> 16) & 0xff)
function RGB_GETRED(rgb: TD3DColor) : DWORD;
// #define RGB_GETGREEN(rgb) (((rgb) >> 8) & 0xff)
function RGB_GETGREEN(rgb: TD3DColor) : DWORD;
// #define RGB_GETBLUE(rgb) ((rgb) & 0xff)
function RGB_GETBLUE(rgb: TD3DColor) : DWORD;
// #define RGBA_SETALPHA(rgba, x) (((x) << 24) | ((rgba) & 0x00ffffff))
function RGBA_SETALPHA(rgba: TD3DColor; x: DWORD) : TD3DColor;
// #define RGB_MAKE(r, g, b) ((TD3DColor) (((r) << 16) | ((g) << 8) | (b)))
function RGB_MAKE(r, g, b: DWORD) : TD3DColor;
// #define RGBA_TORGB(rgba) ((TD3DColor) ((rgba) & 0xffffff))
function RGBA_TORGB(rgba: TD3DColor) : TD3DColor;
// #define RGB_TORGBA(rgb) ((TD3DColor) ((rgb) | 0xff000000))
function RGB_TORGBA(rgb: TD3DColor) : TD3DColor;
(*
* Flags for Enumerate functions
*)
const
(*
* Stop the enumeration
*)
D3DENUMRET_CANCEL = DDENUMRET_CANCEL;
(*
* Continue the enumeration
*)
D3DENUMRET_OK = DDENUMRET_OK;
type
TD3DValidateCallback = function (lpUserArg: Pointer;
dwOffset: DWORD): HResult; stdcall;
TD3DEnumTextureFormatsCallback = function (var lpDdsd: TDDSurfaceDesc;
lpContext: Pointer): HResult; stdcall;
TD3DEnumPixelFormatsCallback = function (var lpDDPixFmt: TDDPixelFormat;
lpContext: Pointer): HResult; stdcall;
PD3DMaterialHandle = ^TD3DMaterialHandle;
TD3DMaterialHandle = DWORD;
PD3DTextureHandle = ^TD3DTextureHandle;
TD3DTextureHandle = DWORD;
PD3DMatrixHandle = ^TD3DMatrixHandle;
TD3DMatrixHandle = DWORD;
PD3DColorValue = ^TD3DColorValue;
TD3DColorValue = packed record
case Integer of
0: (
r: TD3DValue;
g: TD3DValue;
b: TD3DValue;
a: TD3DValue;
);
1: (
dvR: TD3DValue;
dvG: TD3DValue;
dvB: TD3DValue;
dvA: TD3DValue;
);
end;
PD3DRect = ^TD3DRect;
TD3DRect = packed record
case Integer of
0: (
x1: LongInt;
y1: LongInt;
x2: LongInt;
y2: LongInt;
);
1: (
lX1: LongInt;
lY1: LongInt;
lX2: LongInt;
lY2: LongInt;
);
2: (
a: array[0..3] of LongInt;
);
end;
PD3DVector = ^TD3DVector;
TD3DVector = packed record
case Integer of
0: (
x: TD3DValue;
y: TD3DValue;
z: TD3DValue;
);
1: (
dvX: TD3DValue;
dvY: TD3DValue;
dvZ: TD3DValue;
);
end;
(******************************************************************
* *
* D3DVec.inl *
* *
* Float-valued 3D vector class for Direct3D. *
* *
* Copyright (c) 1996-1998 Microsoft Corp. All rights reserved. *
* *
******************************************************************)
// Addition and subtraction
function VectorAdd(const v1, v2: TD3DVector) : TD3DVector;
function VectorSub(const v1, v2: TD3DVector) : TD3DVector;
// Scalar multiplication and division
function VectorMulS(const v: TD3DVector; s: TD3DValue) : TD3DVector;
function VectorDivS(const v: TD3DVector; s: TD3DValue) : TD3DVector;
// Memberwise multiplication and division
function VectorMul(const v1, v2: TD3DVector) : TD3DVector;
function VectorDiv(const v1, v2: TD3DVector) : TD3DVector;
// Vector dominance
function VectorSmaller(v1, v2: TD3DVector) : boolean;
function VectorSmallerEquel(v1, v2: TD3DVector) : boolean;
// Bitwise equality
function VectorEquel(v1, v2: TD3DVector) : boolean;
// Length-related functions
function VectorSquareMagnitude(v: TD3DVector) : TD3DValue;
function VectorMagnitude(v: TD3DVector) : TD3DValue;
// Returns vector with same direction and unit length
function VectorNormalize(const v: TD3DVector) : TD3DVector;
// Return min/max component of the input vector
function VectorMin(v: TD3DVector) : TD3DValue;
function VectorMax(v: TD3DVector) : TD3DValue;
// Return memberwise min/max of input vectors
function VectorMinimize(const v1, v2: TD3DVector) : TD3DVector;
function VectorMaximize(const v1, v2: TD3DVector) : TD3DVector;
// Dot and cross product
function VectorDotProduct(v1, v2: TD3DVector) : TD3DValue;
function VectorCrossProduct(const v1, v2: TD3DVector) : TD3DVector;
type
(*
* Vertex data types supported in an ExecuteBuffer.
*)
(*
* Homogeneous vertices
*)
PD3DHVertex = ^TD3DHVertex;
TD3DHVertex = packed record
dwFlags: DWORD; (* Homogeneous clipping flags *)
case Integer of
0: (
hx: TD3DValue;
hy: TD3DValue;
hz: TD3DValue;
);
1: (
dvHX: TD3DValue;
dvHY: TD3DValue;
dvHZ: TD3DValue;
);
end;
(*
* Transformed/lit vertices
*)
PD3DTLVertex = ^TD3DTLVertex;
TD3DTLVertex = packed record
case Integer of
0: (
sx: TD3DValue; (* Screen coordinates *)
sy: TD3DValue;
sz: TD3DValue;
rhw: TD3DValue; (* Reciprocal of homogeneous w *)
color: TD3DColor; (* Vertex color *)
specular: TD3DColor; (* Specular component of vertex *)
tu: TD3DValue; (* Texture coordinates *)
tv: TD3DValue;
);
1: (
dvSX: TD3DValue;
dvSY: TD3DValue;
dvSZ: TD3DValue;
dvRHW: TD3DValue;
dcColor: TD3DColor;
dcSpecular: TD3DColor;
dvTU: TD3DValue;
dvTV: TD3DValue;
);
end;
(*
* Untransformed/lit vertices
*)
PD3DLVertex = ^TD3DLVertex;
TD3DLVertex = packed record
case Integer of
0: (
x: TD3DValue; (* Homogeneous coordinates *)
y: TD3DValue;
z: TD3DValue;
dwReserved: DWORD;
color: TD3DColor; (* Vertex color *)
specular: TD3DColor; (* Specular component of vertex *)
tu: TD3DValue; (* Texture coordinates *)
tv: TD3DValue;
);
1: (
dvX: TD3DValue;
dvY: TD3DValue;
dvZ: TD3DValue;
UNIONFILLER1d: DWORD;
dcColor: TD3DColor;
dcSpecular: TD3DColor;
dvTU: TD3DValue;
dvTV: TD3DValue;
);
end;
(*
* Untransformed/unlit vertices
*)
PD3DVertex = ^TD3DVertex;
TD3DVertex = packed record
case Integer of
0: (
x: TD3DValue; (* Homogeneous coordinates *)
y: TD3DValue;
z: TD3DValue;
nx: TD3DValue; (* Normal *)
ny: TD3DValue;
nz: TD3DValue;
tu: TD3DValue; (* Texture coordinates *)
tv: TD3DValue;
);
1: (
dvX: TD3DValue;
dvY: TD3DValue;
dvZ: TD3DValue;
dvNX: TD3DValue;
dvNY: TD3DValue;
dvNZ: TD3DValue;
dvTU: TD3DValue;
dvTV: TD3DValue;
);
end;
(*
* Matrix, viewport, and tranformation structures and definitions.
*)
PD3DMatrix = ^TD3DMatrix;
TD3DMatrix = packed record
case integer of
0 : (_11, _12, _13, _14: TD3DValue;
_21, _22, _23, _24: TD3DValue;
_31, _32, _33, _34: TD3DValue;
_41, _42, _43, _44: TD3DValue);
1 : (m : array [0..3, 0..3] of TD3DValue);
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -