|typedef double Matrix;|
|Ident stores an identity matrix in its argument. Matmul stores a×b in a. Matmulr stores b×a in b. Determinant returns the determinant of matrix m. Adjoint stores the adjoint (matrix of cofactors) of m in madj. Invertmat stores the inverse of matrix m in minv, returning ms determinant. Should m be singular (determinant zero), invertmat stores its adjoint in minv.|
|The rest of the routines described here manipulate Spaces and transform Point3s. A Point3 is a point in three-space, represented by its homogeneous coordinates:|
typedef struct Point3 Point3;
double x, y, z, w; };
|The homogeneous coordinates (x, y, z, w) represent the Euclidean point (x/w, y/w, z/w) if w≠0, and a point at infinity if w=0.|
|A Space is just a data structure describing a coordinate system:|
typedef struct Space Space;
Space *next; };
Pushmat creates a new Space. Its argument is a pointer to the parent space. Its result is a newly allocated copy of the parent, but with its next pointer pointing at the parent. Popmat discards the Space that is its argument, returning a pointer to the stack. Nominally, these two functions define a stack of transformations, but pushmat can be called multiple times on the same Space multiple times, creating a transformation tree.
Xformpoint and Xformpointd both transform points from the Space pointed to by from to the space pointed to by to. Either pointer may be null, indicating the root coordinate system. The difference between the two functions is that xformpointd divides x, y, z, and w by w, if w≠0, making (x, y, z) the Euclidean coordinates of the point.
Xformplane transforms planes or normal vectors. A plane is specified by the coefficients (a, b, c, d) of its implicit equation ax+by+cz+d=0. Since this representation is dual to the homogeneous representation of points, libgeometry represents planes by Point3 structures, with (a, b, c, d) stored in (x, y, z, w).
The remaining functions transform the coordinate system represented by a Space. Their Space * argument must be non-null you cant modify the root Space. Rot rotates by angle theta (in radians) about the given axis, which must be one of XAXIS, YAXIS or ZAXIS. Qrot transforms by a rotation about an arbitrary axis, specified by Quaternion q.
Scale scales the coordinate system by the given scale factors in the directions of the three axes. Move translates by the given displacement in the three axial directions.
Xform transforms the coordinate system by the given Matrix. If the matrixs inverse is known a priori, calling ixform will save the work of recomputing it.
Persp does a perspective transformation. The transformation maps the frustum with apex at the origin, central axis down the positive y axis, and apex angle fov and clipping planes y=n and y=f into the double-unit cube. The plane y=n maps to y=-1, y=f maps to y=1.
Look does a view-pointing transformation. The eye point is moved to the origin. The line through the eye and look points is aligned with the y axis, and the plane containing the eye, look and up points is rotated into the x-y plane.
Viewport maps the unit-cube window into the given screen viewport. The viewport rectangle r has r.min at the top left-hand corner, and r.max just outside the lower right-hand corner. Argument aspect is the aspect ratio (dx/dy) of the viewports pixels (not of the whole viewport). The whole window is transformed to fit centered inside the viewport with equal slop on either top and bottom or left and right, depending on the viewports aspect ratio. The window is viewed down the y axis, with x to the left and z up. The viewport has x increasing to the right and y increasing down. The windows y coordinates are mapped, unchanged, into the viewports z coordinates.