This is a document for Affine Matrix Library. Affine Matrix Library is a set of classes for affine matrix, which are necessary for 3D simulation.
Affine Matrix Library consist only from some header files. You can use this library just coping some header files (TAffine.h, TinyVec.h, TinyMat.h, TMatrix.h, TMatrixUtility.h, TVector.h) and including them from your .cpp files.
#include "Affine.h" // TAffine行列ライブラリのインクルードする.
#include <iostream>
// Affine matrix class is declared in the name space of Spr.
void main(){
Affinef af=Affinef::Rad(Rad(30), 'z'); // Declare an Affine matrix of float element.
Initializing as a matrix of rotation of 30 degrees around z axis.
Vec3f vec(1,0,0); // Declare a vector of float element.
std::cout << af;
std::cout << vec << std::endl;
std::cout << af * vec << std::endl;
}
Normal calculations are supported.
-
+:addition, -:subtraction, *:multiplication/inner product, /:division
-
==:comparison, =:assign
-
<<:output, >>:input
-
:cross product
Affine transformation is executed by:
TAffine<float> af; TVec3<float> v, af_v;
af_v = af * v;
You can extract some portion of the Affine matrix as:
-
af.Ex(): base vector for x axis (3 dimensional vector)
-
af.Ey(): base vector for y axis (3 dimensional vector)
-
af.Ez(): base vector for z axis (3 dimensional vector)
-
af.Trn(): portion of translation.(3 dimensional vector)
-
af.Rot(): portion of rotation.(3x3 matrix)
You can assign portion of affine matrx.
TAffine<float> af;
af.Pos() = Vec3f(10,0,0);
af.Rot() = TAffine<float>::Rot(Rad(30), 'x').Rot() * af.Rot();
a vector has following members.
-
unit(): return a unit vector.
-
norm(): return the size (norm) of a vector.
TAffine行列(Spr::TAffine)には便利なコンストラクタや初期化関数を用意しました. いくつかをここで紹介します.
-
Affinef(float x, float y, float z): (x,y,z) 平行移動する行列に初期化
-
Affinef(Vec3f ex, Vec3f ey, Vec3f pos): 直接代入して初期化, ez = ex%ey とする.
-
Affinef::Rot(float rad, char axis): 回転行列を返す. axisは,'x', 'y', 'z'.
-
Affinef::Rot(float rad, Vec3f axis): 回転行列を返す.
-
Affinef::ProjectionD3D(Vec3f screen, Vec2f size, float f, float b): D3D用射影行列として初期化.
-
Affinef::ProjectionGL(Vec3f screen, Vec2f size, float f, float b): D3D用射影行列として初期化.
OpenGL用射影行列として初期化(-Zが前).
-
screen カメラから見たビューポートの中心の位置
-
size ビューポートのサイズ
-
f 手前のクリッピング平面とカメラの距離
-
b 奥のクリッピング平面とカメラの距離
-
void LookAtGL(Vec3f posz, Vec3f posy):位置はそのままで,poszに-Ez(), posy に Ey() が向くようなTAffine行列
LU分解,逆行列,ガウス消去法などの行列計算アルゴリズムは,
「『C言語による最新アルゴリズム事典』全ソースコード」
ftp://ftp.matsusaka-u.ac.jp/pub/algorithms
奥村 晴彦 Haruhiko Okumura
を改変して流用させていただきました. 自由にコードを使わせてくださって,ありがとうございます.
Generated on Sun Apr 16 02:07:53 2006 for Springhead by
1.4.1