[SESI logo]

Prisms Development Toolkit Documentation

Side Effects Software Inc. 1997

Programmers Reference Section

Matrix, Vector and Transform Subroutines

i - Matrix initialization
void MatIdentity33( Mat33 a) void MatIdentity44( Mat44 a) set matrix to identity void MatZero33( Mat33 a) void MatZero44( Mat44 a) set matrix contents to all zero
ii - Matrix return values
float MatCofactor33( Mat33 a, int k, int l) float MatCofactor44( Mat44 a, int k, int l) returns the k,l cofactor of matrix a float MatDet33( Mat33 a) float MatDet44( Mat44 a) return determinant of matrix a void MatRotCrack(Mat33 rotM, char *order, float *pagx, float *pagy, float *pagz) input 3x3 matrix, rotation order as one of "rx ry rz" "rz ry rx" etc returns 3 rotation values, one for each axis void MatExplode44( Mat44, char *rstOrder, char *rotOrder, float *rx, float *ry, float *rz, float *sx, float *sy, float *sz, float *tx, float *ty, float *tz) input 4x4 matrix, character string "srt" or "tsr" or "str" for transform order, and string "rx ry rz" as per MatRotCrack() and return the transform, scale and rotation values to make up that matrix. void MatPrint33(FILE *file, Mat33 a) void MatPrint44(FILE *file, Mat44 a) print the contents of matrix a to given file
iii - Matrix manipulation
void MatAdd33(Mat33 a, Mat33 b, Mat33 c) void MatAdd44( Mat44 a, Mat44 b, Mat44 c) matrix add: c = a + b void MatCopy33( Mat33 a, Mat33 b) void MatCopy44( Mat44 a, Mat44 b) copy matrix a to matrix b void MatCvt3344( Mat33 a, Mat44 b) expand 3x3 matrix to a 4x4 matrix, 4th row and column are 0.0 except the diagonal, which is 1.0 void MatCvt4433( Mat44 a, Mat33 b) extract upper 3x3 sub-matrix from a and put into b int MatInvert33( Mat33 a, Mat33 b) int MatInvert44( Mat44 a, Mat44 b) invert matrix a, put result into b, return 0 if singular otherwise return 1 void MatMpy333( Mat33 a, Mat33 b, Mat33 c) void MatMpy444( Mat44 a, Mat44 b, Mat44 c) c = matrix a times matrix b void MatRotate33( Mat33 m, VECTOR axis, float theta) void MatRotate44( Mat44 m, VECTOR axis, float theta) rotate passed matrix about arbitrary axis by angle theta. void MatRot44( Mat44 m, char axis, float theta) rotate m by angle theta about x, y or z axis (axis is one of 'x' 'X' 'y' 'Y' 'z' 'Z') void MatScale33( Mat33 m, float sx, float sy, float sz) void MatScale44( Mat44 m, float sx, float sy, float sz, float sw) multiply given matrix by passed scale values void MatSpace33( Mat33 m, Vector I0, Vector J0, Vector I1, Vector J1) void MatSpace44( Mat44 m, Vector I0, Vector J0, Vector I1, Vector J1) Right multiply m by the matrix of the transformation which moves the "vector space" defined by (I0, J0, CROSS(I0,J0)) into the space defined by (I1, J1, CROSS(I1,J1)) Granted that I0 and J0 is normalised, and dot(I0,J0) = 0 So this matrix transforms I0 into I1, J0 into J1, and CROSS(I0,J0) into CROSS(I1,J1). void MatStretch33( VECTOR v, float a, Mat33 m) void MatStretch44( Mat44 n, VECTOR v, float a) scale matrix m by a along the vector v. void MatSym33( VECTOR v, Mat33 m) puts in m the 3x3 matrix of the symmetry around the vector v. This matrix transforms any vector w into its symmetry around v two times the projection of w on v, minus w. void MatTranslate44( Mat44 a, float dx, float dy, float dz) multiply a by translation matrix implied by dx, dy & dz void MatTranspose33( Mat33 a, Mat33 b) void MatTranspose44( Mat44 a, Mat44 b) transpose matrix a into matrix b void MatSolve33( Mat33, float cx, float cy, float cz, float *x, float *y, float *z) solve a linear system of equations, return x y z int MatDihedral33( VECTOR a, VECTOR b, Mat33 m) sets m to be the matrix which transforms a into b. If a and b have the same direction m is the identity matrix. If a and b are opposed the rotation is undefinable and -1 is returned. Otherwise 0 is returned. The transformation is a symetry around a, then a symetry around (norm(a0 + norm(b)).
iv - Vector, Point operations
void Norm( VECTOR a) normalize vector a float Dot( VECTOR a, VECTOR b) dot product of a and b void Cross( VECTOR a, VECTOR b, VECTOR c) cross product c = a x b void MatCvt34( VECTOR a, POINT b) convert vector a to point by copying to b and adding 1.0 as fourth coordinate void MatCvt43( POINT a, VECTOR b) copy first 3 components of point a to vector b
v - Transform vectors, points by matrices
note different multiplication orders void MatMpy133( VECTOR a, Mat33 b, VECTOR c) void MatMpy331( Mat33 a, VECTOR b, VECTOR c) vector c = matrix a times vector b void MatMpy144( POINT a, Mat44 b, POINT c) void MatMpy441( Mat44 a, POINT b, POINT c) point c = a times b void MatMpy44V( Mat44 a, VECTOR b, VECTOR c) extends b to a point by adding 1.0 as fourth coordinate, left multiplies by a, truncates result into c void MatMpyV44( VECTOR a, Mat44 b, VECTOR c) extends a to a point by adding 1.0 as fourth coordinate, right multiplies by b, truncates result into c void MatProject33( VECTOR v, Mat33 m)

Tookit Overview
Expression Functions | User Functions | Custom SOPs
Prisms Internal Format | Programmer's Reference
Compiling SOPs | Using sopbuild | SOP Routine Reference
Dynamic SOPs | Prisms Types | Macros
Math Routines | Data Routines | Polygon Routines | Winged-edge Routines

Copyright © 1997 Side Effects Software Inc.
477 Richmond Street West, Toronto, Ontario, Canada M5V 3E7