ゲームの作成などに便利そうな計算ルーチンをパッケージ化したものです。
s_mathpackは、s_mathpack.pasのみから構成されます。
ユニットs_mathpackはクラスを提供せず、以下の型・定数・手続きおよび関数から成ります。
| ベクトル | 2次元ベクトル | TVector2D |
| 同次3次元ベクトル | THgVector | |
| クォータニオン | TQuaternion | |
| 行列 | 3x3行列 | TMatrix33 |
| 3次元プリミティブ | 箱型 | TBox3D |
| 平面 | TPlane3D | |
| 線分 | TLineSeg3D | |
| 直線 | TLine3D | |
| 球 | TSphere3D | |
| カプセル(半径つき線分) | TCapsule3D | |
| 向きのある三角形 | TFacedTriangle3D | |
| D3D7互換頂点フォーマット | D3DTLVERTEX | |
| D3DLVERTEX | ||
| D3DVERTEX |
| 4x4行列 | 単位行列 | NowIdentityMatrix |
| ゼロ行列 | NowZeroMatrix | |
| 3x3行列 | 単位行列 | NowIdentityMatrix33 |
| ゼロ行列 | NowZeroMatrix33 | |
| テーブル | サイン(4096度系) | NowSinT |
| コサイン(4096度系) | NowCosT |
結構な量があるので、関数の概略と、引数見れば何やるか分かるような関数には、それ以上説明つけてません(^^;)
わからんよーなら、実際に自分でサンプル書いて動かしてみるのが吉(ぉ
| 代入 | 2Dベクトル | Vector2D | function Vector2D(_x,_y:Single):TVector2D; |
| 3Dベクトル | Vector | function Vector(_x,_y,_z:Single):D3DVECTOR; | |
| 同次3Dベクトル | HgVector | function HgVector(_x,_y,_z,_w:Single):THgVector; | |
| クォータニオン | Quaternion | function Quaternion(_w,_x,_y,_z:Single):TQuaternion; | |
| 球 | Sphere3D | function Sphere3D(_x,_y,_z,_r:Single):TSphere3D; | |
| 平面 | Plane3D | function Plane3D(_a,_b,_c,_d:Single):TPlane3D; | |
| 直線 | Line3D | function Line3D(_p, _dir:D3DVector):TLine3D; | |
| 線分 | LineSeg3D | function LineSeg3D(_start, _end:D3DVector):TLineSeg3D; | |
| 色演算 | スカラ倍 | NowScaleColor | function NowScaleColor(const col:D3DCOLOR; const scale:Single):D3DCOLOR; |
| 加算 | NowAddColor | function NowAddColor(const col1:D3DCOLOR; const col2:D3DCOLOR):D3DCOLOR; | |
| 線形補間 | NowLerpColor | function NowLerpColor(const col1:D3DCOLOR; const col2:D3DCOLOR; const t:Single):D3DCOLOR; | |
| HSB→RGB変換 | NowHSBToRGB | function NowHSBToRGB(h,s,b:Single):D3DCOLOR; | |
| 変換 | 整数→小数 | NowItoF2D | function NowItoF2D(const a:TPoint):TVector2D; |
| 小数→整数(切捨て) | NowFtoI2D | function NowFtoI2D(const a:TVector2D):TPoint; | |
| 小数→整数(Round) | NowRound2D | function NowRound2D(const a:TVector2D):TPoint; | |
| 3D→同次3D | NowHomoginize | function NowHomoginize(const a:D3DVector):THgVector; | |
| 同次3D→3D | NowHeteroginize | function NowHeteroginize(const a:THgVector; _div:Boolean = False):D3DVector; | |
| LVertex→TLVerex | NowLVToTLV | function NowLVToTLV(const lv:D3DLVERTEX; const transMat:D3DMATRIX):D3DTLVERTEX; | |
| LVertex→TLVerex | NowLVToTLVBatch | procedure NowLVToTLVBatch(src:LPD3DLVERTEX; dest:LPD3DTLVERTEX; const transMat:D3DMATRIX; count:Integer); | |
| 3x3行列→4x4行列 | NowMatrix33To44 | function NowMatrix33To44(m:TMatrix33):D3DMATRIX; | |
| 4x4行列→3x3行列 | NowMatrix44To33 | function NowMatrix44To33(m:D3DMATRIX):TMatrix33; | |
| 平面の作成 | NowPlaneFromPoints | function NowPlaneFromPoints(v1,v2,v3:D3DVector):TPlane3D; | |
| NowPlaneFromVertexNormal | function NowPlaneFromVertexNormal(v,n:D3DVector):TPlane3D; | ||
| スカラ演算 | 3次Bスプライン | NowInterpolate | function NowInterpolate(const p1,p2,p3,p4:Single; const rate:Single):Single; |
| 線形補間 | NowLerp | function NowLerp(const p1,p2:Single; const rate:Single):Single; | |
| 逆正接 | NowArcTan2 | function NowArcTan2(Y, X: Extended): Extended; | |
| 2Dベクトル演算 | 和 | NowAdd2D | function NowAdd2D(const a:TVector2D; const b:TVector2D):TVector2D; |
| 差 | NowSub2D | function NowSub2D(const a:TVector2D; const b:TVector2D):TVector2D; | |
| 内積 | NowDotProduct2D | function NowDotProduct2D(const a:TVector2D; const b:TVector2D):Single; | |
| 距離 | NowDistance2D | function NowDistance2D(const a,b:TVector2D):Single; | |
| 長さ | NowLength2D | function NowLength2D(const a:TVector2D):Single; | |
| 角度 | NowVecToAngle2D | function NowVecToAngle2D(const a:TVector2D):Single; | |
| 回転 | NowRot2D | function NowRot2D(const a:TVector2D; const angle:Integer):TVector2D; | |
| 正規化 | NowNormalize2D | function NowNormalize2D(const a:TVector2D):TVector2D; | |
| スカラ倍 | NowScale2D | function NowScale2D(const a:TVector2D; const scale:Single):TVector2D; | |
| 長さをkにする | NowChangeLength2D | function NowChangeLength2D(const a:TVector2D; const k:Single):TVector2D; | |
| 向き | NowLookAt2D | function NowLookAt2D(const pos:TVector2D; const target:TVector2D; const k:Single):TVector2D; | |
| ランダム | NowRandom2D | function NowRandom2D(const k:Single):TVector2D; | |
| 線形補間 | NowLerp2D | function NowLerp2D(const a:TVector2D; const b:TVector2D; const rate:Single):TVector2D; | |
| 3Dベクトル演算 | 和 | NowAdd | function NowAdd(const a:D3DVECTOR; const b:D3DVECTOR):D3DVECTOR; |
| NowAddHg | function NowAddHg(const a:THgVector; const b:THgVector):THgVector; | ||
| 差 | NowSub | function NowSub(const a:D3DVECTOR; const b:D3DVECTOR):D3DVECTOR; | |
| NowSubHg | function NowSubHg(const a:THgVector; const b:THgVector):THgVector; | ||
| 内積 | NowDotProduct | function NowDotProduct(const a:D3DVECTOR; const b:D3DVECTOR):Single; | |
| 外積 | NowCrossProduct | function NowCrossProduct(const a:D3DVECTOR; const b:D3DVECTOR):D3DVECTOR; | |
| 回転 | NowRotX | function NowRotX(const a:D3DVECTOR; const t:Integer):D3DVECTOR; | |
| NowRotY | function NowRotY(const a:D3DVECTOR; const t:Integer):D3DVECTOR; | ||
| NowRotZ | function NowRotZ(const a:D3DVECTOR; const t:Integer):D3DVECTOR; | ||
| 負のベクトル | NowNeg | function NowNeg(const a:D3DVECTOR):D3DVECTOR; | |
| 正規化 | NowNormalize | function NowNormalize(const a:D3DVECTOR):D3DVECTOR; | |
| 長さ | NowLength | function NowLength(const a:D3DVECTOR):Single; | |
| スカラ倍 | NowScale | function NowScale(const a:D3DVECTOR; const scale:Single):D3DVECTOR; | |
| 向き | NowChangeLength | function NowChangeLength(const a:D3DVECTOR; const k:Single):D3DVECTOR; | |
| 線形補間 | NowLerp3D | function NowLerp3D(const a:D3DVector; const b:D3DVector; const rate:Single):D3DVector; | |
| 向き | NowLookAt | function NowLookAt(const pos:D3DVECTOR; const target:D3DVECTOR; const k:Single):D3DVECTOR; | |
| 法線の計算 | NowNormalFromPoints | function NowNormalFromPoints(const p1,p2,p3:D3DVector):D3DVector; | |
| 反射の計算 | NowReflection | function NowReflection(const v:D3DVector; normal:D3Dvector):D3DVector; function NowReflection(const v:D3DVector; normal:D3Dvector; e:Single):D3DVector; |
|
| クォータニオン演算 | 和 | NowAddQuat | function NowAddQuat(const a:TQuaternion; const b:TQuaternion):TQuaternion; |
| 差 | NowSubQuat | function NowSubQuat(const a:TQuaternion; const b:TQuaternion):TQuaternion; | |
| 積 | NowMulQuat | function NowMulQuat(const a:TQuaternion; const b:TQuaternion):TQuaternion; | |
| 内積 | NowDotQuat | function NowDotQuat(const a:TQuaternion; const b:TQuaternion):Single; | |
| 長さ | NowLengthQuat | function NowLengthQuat(const a:TQuaternion):Single; | |
| 正規化 | NowNormalizeQuat | function NowNormalizeQuat(const a:TQuaternion):TQuaternion; | |
| 軸周りの回転 | NowQuatFromRotation | function NowQuatFromRotation(const axis:D3DVECTOR; const t:Integer):TQuaternion; | |
| 行列生成 | NowMatrixFromQuat | function NowMatrixFromQuat(const a:TQuaternion):D3DMATRIX; | |
| 行列から生成 | NowMatrixFromRotation | function NowMatrixFromRotation(const axis:D3DVECTOR; const t:Integer):D3DMATRIX; | |
| 球面線形補間 | NowSlerpQuat | function NowSlerpQuat(const a:TQuaternion; const b:TQuaternion; const rate:Single):TQuaternion; | |
| 逆クォータニオン | NowInvQuat | function NowInvQuat( srcQuat: TQuaternion ): TQuaternion; | |
| 線形補間 | NowLerpQuat | function NowLerpQuat(const a:TQuaternion; const b:TQuaternion; const rate:Single):TQuaternion; | |
| 4x4行列演算 | ベクトルを変換 | NowTransform | function NowTransform(const a:THgVector; const m:D3DMATRIX):THgVector; function NowTransform(const a:D3DVector; const m:D3DMATRIX):D3DVector; |
| NowTransformBatch | procedure NowTransformBatch(const src:Pointer; const m:D3DMATRIX; const num:Integer; const span:Integer); | ||
| 射影行列 | NowProjectFrustum | function NowProjectFrustum(const halfWidth:Single; const halfHeight:Single; const nearZ:Single; const farZ:Single):D3DMATRIX; | |
| 逆行列 | NowInvMatrix | function NowInvMatrix(const m:D3DMATRIX):D3DMATRIX; | |
| NowInvMatrixRot | function NowInvMatrixRot(const m:D3DMATRIX):D3DMATRIX; | ||
| 転置行列 | NowTMatrix | function NowTMatrix(const m:D3DMATRIX):D3DMATRIX; | |
| 回転成分抽出 | NowExtractRotation | function NowExtractRotation(const m:D3DMATRIX):D3DMATRIX; | |
| 平行移動成分抽出 | NowExtractTranslation | function NowExtractTranslation(const m:D3DMATRIX):D3DMATRIX; | |
| 合成 | NowCompositeMatrix | function NowCompositeMatrix(const m:D3DMATRIX; const n:D3DMATRIX):D3DMATRIX; | |
| NowCompositeRotMatrix | function NowCompositeRotMatrix(const m:D3DMATRIX; const n:D3DMATRIX):D3DMATRIX; | ||
| 回転行列 | NowRotXMatrix | function NowRotXMatrix(const t:Integer):D3DMATRIX; | |
| NowRotYMatrix | function NowRotYMatrix(const t:Integer):D3DMATRIX; | ||
| NowRotZMatrix | function NowRotZMatrix(const t:Integer):D3DMATRIX; | ||
| スケーリング行列 | NowScaleMatrix | function NowScaleMatrix(const x,y,z:Single):D3DMATRIX; | |
| 平行移動行列 | NowTranslateMatrix | function NowTranslateMatrix(const x,y,z:Single):D3DMATRIX; | |
| 3x3行列演算 | 合成 | NowCompositeMatrix33 | function NowCompositeMatrix33(const a:TMatrix33; const b:TMatrix33):TMatrix33; |
| 逆行列 | NowInvMatrix33 | function NowInvMatrix33(const a:TMatrix33; var valid:Boolean):TMatrix33; | |
| ベクトルを変換 | NowTransform33 | function NowTransform33(const a:D3DVector; const m:TMatrix33):D3DVector; | |
| 行列式 | NowDeterminant33 | function NowDeterminant33(const m:TMatrix33):Single; | |
| 距離 | NowDistance | function NowDistance(const a,b:D3DVECTOR):Single; function NowDistance(const p:D3DVECTOR; const lin:TLine3D):Single; function NowDistance(const p:D3DVECTOR; const lseg:TLineSeg3D):Single; function NowDistance(const a:D3Dvector; const plane:TPlane3D):Single; |
|
| 3D包含・交差判定 | 箱の中に点 | NowPointInBox | function NowPointInBox(const p:D3DVector; const box:TBox3D):Boolean; |
| 箱aの中に箱b | NowBoxInBox | function NowBoxInBox(const a:TBox3D; const b:TBox3D):Boolean; | |
| 四面体の中に点 | NowPointInTetrahedron | function NowPointInTetrahedron(const p:D3DVector; const tri:Array of D3DVector):Boolean; | |
| 三角柱の中に点 | NowPointInPillar | function NowPointInPillar(const p:D3DVector; const tri:TFacedTriangle3D; const height:Single):Boolean; | |
| 線分と平面 | NowIntersectLinePlane | function NowIntersectLinePlane(var dest:D3DVector; const seg:TLineSeg3D; const s:TPlane3D):Boolean; | |
| 線分と箱 | NowIntersectLineBox | function NowIntersectLineBox(const seg:TLineSeg3D; const box:TBox3D):Boolean; | |
| カプセル同士 | NowIntersectCapsule | function NowIntersectCapsule(const a,b:TCapsule3D):Boolean; |
type TVector2D = packed record X,Y:Single; end;
二次元ベクトルを示します
type THgVector = packed record X,Y,Z,W:Single; end;
三次元の同次座標を示します。X,Y,Zが座標で、Wがウェイトとなります。
case Integer of
0: (X,Y,Z,W:Single);
1: (
V:D3DVector;
);
end;
クォータニオンを示します
type TMatrix33 = packed record
Case Integer of
0: (
_11,_12,_13:Single;
_21,_22,_23:Single;
_31,_32,_33:Single;
);
1: (
A,B,C,D,E,F,G,H,I:Single;
);
end;
3x3行列を示します
type TBox3D = packed record
case Integer of
Min,Max:D3DVector;;
end;
end;
座標軸と平行な辺を持つ箱型を示します。
Minの各要素は、Maxの各要素より小さい値でなければなりません。
TPlane3D = packed record Case Integer of 0:(A,B,C,D:Single;); 1:(Normal:D3DVector;); end;
平面を構成する点(X,Y,Z)について、aX + bY + cZ + d = 0 を満たす平面を示します。
a^2 + b^2 + c^2 = 1を満たしている必要があるので注意してください。
type TLine3D = packed record Case Integer of 0:(P,Dir:D3DVector;); 1:(Origin, Direction:D3DVector;); end;
点Pを通り、傾きDirなる直線を示します
type TLineSeg3D = packed record Case Integer of 0:(A,B:D3DVector;); 1:(_Start,_End:D3DVector;); end;
点Aを始点とし、点Bを終点とする線分を示します
TSphere3D = packed record
Case Integer of
0:(X,Y,Z,R:Single);
1:(
Center:D3DVector;
Radius:Single;
);
end;
点Centerを始点とする、半径Radiusなる球を示します。
type TCapsule3D = packed record
Case Integer of
0:(
Axis:TLineSeg3D;
Radius:Single;
);
1:(
A,B:D3DVector;
R:Single;
);
end;
線分Axisからの距離がR以下になる点の集合で定義される、カプセル形を示します。
type TFacedTriangle3D = packed record
Case Integer of
0:(
A,B,C:D3Dvector;
N:D3DVector;
);
1:(
Vertices:Array[0..2] of D3Dvector;
Normal:D3DVector;
);
end;
3つの頂点A,B,Cと法線Nで定義される三角形を示します。
法線Nは、3つの頂点を通る平面に対して垂直でなければなりません。
D3DVERTEX = record
case Integer of
0: (
x : Single;
y : Single;
z : Single;
nx : Single;
ny : Single;
nz : Single;
tu : Single;
tv : Single;
);
1: (
dvX : Single;
dvY : Single;
dvZ : Single;
dvNX : Single;
dvNY : Single;
dvNZ : Single;
dvTU : Single;
dvTV : Single;
);
end;
DirectX7では定義されていた、D3DVERTEXです。
位置と法線、一組のテクスチャ座標を含む頂点フォーマットです。
D3DLVERTEX = record case Integer of 0: ( x : Single; y : Single; z : Single; color : D3DCOLOR; specular : D3DCOLOR; tu : Single; tv : Single; ); 1: ( dvX : Single; dvY : Single; dvZ : Single; dcColor : D3DCOLOR; dcSpecular : D3DCOLOR; dvTU : Single; dvTV : Single; ); end;
DirectX7では定義されていた、D3DLVERTEXです。
位置、ディフューズ色、スペキュラ色、一組のテクスチャ座標を含むライティング済み頂点フォーマットです。
D3DTLVERTEX = record case Integer of 0: ( sx : Single; sy : Single; sz : Single; rhw : Single; color : D3DCOLOR; specular : D3DCOLOR; tu : Single; tv : Single; ); 1: ( dvSX : Single; dvSY : Single; dvSZ : Single; dvRHW : Single; dcColor : D3DCOLOR; dcSpecular : D3DCOLOR; dvTU : Single; dvTV : Single; ); end;
DirectX7では定義されていた、D3DTLVERTEXです。
スクリーン上での位置、Zバッファ上でのZ値、1/W値(視点からの距離の逆数)、ディフューズ色、スペキュラ色、一組のテクスチャ座標を含む、変換、ライティング済み頂点フォーマットです。
NowIdentityMatrix:D3DMATRIX = ( _11:1; _12:0; _13:0; _14:0;
_21:0; _22:1; _23:0; _24:0;
_31:0; _32:0; _33:1; _34:0;
_41:0; _42:0; _43:0; _44:1);
4x4の単位行列です。
NowZeroMatrix:D3DMATRIX = ( _11:0; _12:0; _13:0; _14:0;
_21:0; _22:0; _23:0; _24:0;
_31:0; _32:0; _33:0; _34:0;
_41:0; _42:0; _43:0; _44:0);
4x4のゼロ行列です。
NowIdentityMatrix33:TMatrix33 = ( _11:1; _12:0; _13:0;
_21:0; _22:1; _23:0;
_31:0; _32:0; _33:1);
3x3の単位行列です。
NowZeroMatrix33:TMatrix33 = ( _11:0; _12:0; _13:0;
_21:0; _22:0; _23:0;
_31:0; _32:0; _33:0);
3x3のゼロ行列です。
NowSinT:packed Array[0..4095] of Single; NowCosT:packed Array[0..4095] of Single;
サイン、コサインの値を入れたテーブルです。
1回転 = 4096度で表現しています。つまり、NowSinT[t] = Sin(t / 4096 * 2 * Pi) となっています。
function Plane3D(_a,_b,_c,_d:Single):TPlane3D;
平面を返します。ベクトル(_a, _b, _c) が平面の法線(大きさ1)となるように正規化します。
function Line3D(_p, _dir:D3DVector):TLine3D;
点_pを通る、向き_dirなる直線を返します。
function NowScaleColor(const col:D3DCOLOR; const scale:Single):D3DCOLOR;
色colを構成するR,G,B要素にそれぞれscaleを乗じた色を返します。A要素には255を返します。
0を下回った成分は0に、255を上回った成分は255に制限されます。
function NowAddColor(const col1:D3DCOLOR; const col2:D3DCOLOR):D3DCOLOR;
色col1とcol2それぞれを構成するR,G,B要素を足します。A要素には255を返します。
255を上回った成分は255に制限されます。
function NowLerpColor(const col1:D3DCOLOR; const col2:D3DCOLOR; const t:Single):D3DCOLOR;
col1とcol2で示される色のA,R,G,B要素の線形補間を返します。
tは0.0〜1.0の範囲で指定します。t=0の時col1を返し、t=1の時col2を返します。
0を下回った成分は0に、255を上回った成分は255に制限されます。
function NowHSBToRGB(h,s,b:Single):D3DCOLOR;
HSB色表現から、D3DCOLOR値を作ります。
hに色相(0 〜 1)、sに彩度(0 〜 1)、bに明るさ(0 〜 1)を指定してください。
function NowHomoginize(const a:D3DVector):THgVector;
3次元非同次ベクトルに、W要素 = 1を付けて、3次元同次ベクトルに代入します。
function NowHeteroginize(const a:THgVector; _div:Boolean):D3DVector;
3次元同次ベクトルを、3次元非同次ベクトルに変換します。
_div = Trueの時、X,Y,Z要素をWで割った値を返しますが、Falseの時は、X,Y,Z要素をそのまま返します。
function NowLVToTLV(const lv:D3DLVERTEX; const transMat:D3DMATRIX):D3DTLVERTEX;
D3DLVERTEX型の頂点lvを、transMatによって変換し、D3DTLVERTEXにして返します
transMatは、ワールド座標系からスクリーン座標系までの変換行列です。
procedure NowLVToTLVBatch(src:LPD3DLVERTEX; dest:LPD3DTLVERTEX; const transMat:D3DMATRIX; count:Integer);
NowLVToTLVをcount個のD3DLVERTEXについて行います。
function NowMatrix33To44(m:TMatrix33):D3DMATRIX;
3x3行列を、回転を示す4x4行列として拡張します。result_11 〜 result._33 に、m._11〜m._33がそれぞれ入ります。
平行移動成分には(0,0,0)が入ります。つまり、 result._41, result._42, result._43 は 0 で、_result.44 = 1。
function NowMatrix44To33(m:D3DMATRIX):TMatrix33;
4x4行列の回転成分(_11〜_33)を抜き出して、3x3行列に格納します。
function NowPlaneFromPoints(v1,v2,v3:D3DVector):TPlane3D;
3つの頂点v1,v2,v3を通る平面を返します。
但し、v1→v2→v3は面の法線に対して左回りになります。 つまり、三角形v1→v2→v3が視線に対して右回りの時、法線と視線の内積がマイナスになります。
function NowPlaneFromVertexNormal(v,n:D3DVector):TPlane3D;
法線をnとする、頂点vを通る平面を返します。
function NowInterpolate(const p1,p2,p3,p4:Single; const rate:Single):Single;
3次Bスプライン曲線に則って値p1,p2,p3,p4を補間します。
rate = 0 の時、p2に返り値は近くなり、rate = 1の時、p3に返り値が近づきます。
function NowLerp(const p1,p2:Single; const rate:Single):Single;
値p1, p2を線形補間します。rate = 0 の時、返り値はp1となり、rate = 1の時、返り値はp2となります。
function NowArcTan2(Y, X: Extended): Extended;
X = 0.0でもOKな、ArcTan2です。
なんでMathユニットってPersonalについてないんですか(ぉ
function NowVecToAngle2D(const a:TVector2D):Single;
2Dベクトルaの向きを、4096度系の角度で返します。
(1,0)は0度、(0,1)は1024度、(0,-1)は3072度を返します。
function NowRot2D(const a:TVector2D; const angle:Integer):TVector2D;
ベクトルaをangle度回転します。angleは4096度系で指定してください。
function NowLookAt2D(const pos:TVector2D; const target:TVector2D; const k:Single):TVector2D;
位置posから位置targetに向く、長さkのベクトルを返します
function NowRandom2D(const k:Single):TVector2D;
長さk の、ランダムなベクトルを返します
function NowLerp2D(const a:TVector2D; const b:TVector2D; const rate:Single):TVector2D;
ベクトルp1, p2を線形補間します。rate = 0 の時、返り値はp1となり、rate = 1の時、返り値はp2となります。
function NowRotX(const a:D3DVECTOR; const t:Integer):D3DVECTOR; function NowRotY(const a:D3DVECTOR; const t:Integer):D3DVECTOR; function NowRotZ(const a:D3DVECTOR; const t:Integer):D3DVECTOR;
X./Y/Z軸周りにベクトルaをt度回転させます。tは4096度系で指定してください。
function NowLerp(const a:TVector; const b:TVector; const rate:Single):D3DVector;
ベクトルp1, p2を線形補間します。rate = 0 の時、返り値はp1となり、rate = 1の時、返り値はp2となります。
function NowLookAt(const pos:TVector; const target:TVector; const k:Single):D3DVector;
位置posから位置targetに向く、長さkのベクトルを返します
function NowNormalFromPoints(const p1,p2,p3:D3DVector):D3DVector;
頂点p1,p2,p3を持つ3角形の法線を返します。
但し、v1→v2→v3は面の法線に対して左回りになります。 つまり、三角形v1→v2→v3が視線に対して右回りの時、法線と視線の内積がマイナスになります。
function NowReflection(const v:D3DVector; normal:D3Dvector):D3DVector; overload; function NowReflection(const v:D3DVector; normal:D3Dvector; e:Single):D3DVector; overload;
法線をnormalと同じにする平面に 速度ベクトルv で突っ込んだ時の、反射後の速度ベクトルを返します。
eは弾性係数で、省略すると1.0とみなし、完全弾性衝突になります。
摩擦は考慮しません。
function NowSlerpQuat(const a:TQuaternion; const b:TQuaternion; const rate:Single):TQuaternion;
クォータニオンa, b を球面線形補間した値を返します。
rate = 0 の時、返り値はaとなり、rate = 1の時、返り値はbとなります。
function NowLerpQuat(const a:TQuaternion; const b:TQuaternion; const rate:Single):TQuaternion;
クォータニオンa, b を線形補間した値を返します。
rate = 0 の時、返り値はaとなり、rate = 1の時、返り値はbとなります。
function NowInvMatrix(const m:D3DMATRIX):D3DMATRIX;
4x4行列 a の逆行列を返します。
但し a は、回転、平行移動成分のみを含むと仮定しています。 拡大・縮小・シアー成分を示す行列に対しては正しく計算できません。
function NowInvMatrixRot(const m:D3DMATRIX):D3DMATRIX;
回転成分のみを含む4x4行列 a の逆行列を返します。
function NowExtractRotation(const m:D3DMATRIX):D3DMATRIX;
行列m から、回転成分(左上の3x3部分)だけを抜き出した行列を返します。
function NowExtractTranslation(const m:D3DMATRIX):D3DMATRIX;
行列m から、平行移動成分だけを抜き出した行列を返します。回転成分には3x3単位行列(回転ナシ)が入ります
function NowRotXMatrix(const t:Integer):D3DMATRIX; function NowRotYMatrix(const t:Integer):D3DMATRIX; function NowRotZMatrix(const t:Integer):D3DMATRIX;
X/Y/Z 軸周りにt度の回転を表す行列を返します。tは4096度系で指定します。
function NowScaleMatrix(const x,y,z:Single):D3DMATRIX;
各軸方向へx, y, z倍の拡大を表す行列を返します。
function NowTranslateMatrix(const x,y,z:Single):D3DMATRIX;
各軸方向へのx, y, zの平行移動を表す行列を返します。
function NowInvMatrix33(const a:TMatrix33; var valid:Boolean):TMatrix33;
3x3行列 a の逆行列を返します。 validには、a の逆行列が存在するならTrueが入ります。
validがFalseの時は逆行列が存在しません。その際の返り値は不定です。
function NowDeterminant33(const m:TMatrix33):Single;
3x3行列の行列式を返します。
//2点の距離 function NowDistance(const a,b:D3DVECTOR):Single; overload; //点と直線の距離 function NowDistance(const p:D3DVECTOR; const lin:TLine3D):Single; overload; //点と線分の距離 function NowDistance(const p:D3DVECTOR; const lseg:TLineSeg3D):Single; overload; //線分同士の距離 function NowDistance(const a,b:TLineSeg3D):Single; overload; //点と平面の距離 function NowDistance(const a:D3Dvector; const plane:TPlane3D):Single; overload;
プリミティブ同士の距離を返します。
function NowPointInBox(const p:D3DVector; const box:TBox3D):Boolean;
点pが箱型boxに含まれているならTrueを返します。
function NowBoxInBox(const a:TBox3D; const b:TBox3D):Boolean;
箱型 a が箱型 b に含まれているならTrueを返します。
function NowPointInTetrahedron(const p:D3DVector; const t1,t2,t3,t4:D3DVector):Boolean;
点 p が、t1,t2,t3,t4を頂点に持つ4面体に含まれるなら、Trueを返します。
function NowPointInPillar(const p:D3DVector; const tri:TFacedTriangle3D; const height:Single):Boolean;
triで示される三角形を、法線と逆の方向に距離heightだけ動かした時に掃かれる範囲は角柱になります。
点 p が、その角柱に含まれているなら、Trueを返します。
function NowIntersectLinePlane(var dest:D3DVector; const seg:TLineSeg3D; const s:TPlane3D):Boolean;
線分segが、平面sと交わるならTrueを返し、交点をdestに格納します。
function NowIntersectLineBox(const seg:TLineSeg3D; const box:TBox3D):Boolean;
線分segが、箱型boxと交わるなら、Trueを返します。
function NowIntersectCapsule(const a,b:TCapsule3D):Boolean;
カブセル a, b が交わるならTrueを返します。