1997-05-30 19:25:54 +00:00
|
|
|
/* #include "HEADERS.h" */
|
|
|
|
/* Copyright 1988, Brown Computer Graphics Group. All Rights Reserved. */
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------
|
|
|
|
* This file contains routines that operate solely on matrices.
|
|
|
|
* -------------------------------------------------------------------------*/
|
|
|
|
|
1998-04-08 23:35:37 +00:00
|
|
|
|
1998-04-24 00:43:12 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
1998-04-08 23:35:37 +00:00
|
|
|
|
1998-01-06 01:20:19 +00:00
|
|
|
#ifdef WIN32
|
1998-11-23 21:46:36 +00:00
|
|
|
# ifndef HAVE_STL_SGI_PORT
|
|
|
|
# include <memory.h> /* required for memset() and memcpy() */
|
|
|
|
# endif
|
1998-01-06 01:20:19 +00:00
|
|
|
#endif
|
|
|
|
|
1998-02-03 23:20:27 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <Math/mat3defs.h>
|
|
|
|
|
|
|
|
#define USE_MEM
|
1998-01-31 00:43:18 +00:00
|
|
|
|
1997-05-30 19:25:54 +00:00
|
|
|
/* #include "macros.h" */
|
|
|
|
|
|
|
|
/* -------------------------- Static Routines ---------------------------- */
|
|
|
|
|
|
|
|
/* ------------------------- Internal Routines --------------------------- */
|
|
|
|
|
|
|
|
/* -------------------------- Public Routines ---------------------------- */
|
|
|
|
|
|
|
|
|
1998-08-24 20:04:08 +00:00
|
|
|
#if !defined( USE_XTRA_MAT3_INLINES )
|
|
|
|
|
1997-05-30 19:25:54 +00:00
|
|
|
/*
|
|
|
|
* Sets a matrix to identity.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
MAT3identity (register MAT3mat mat)
|
|
|
|
{
|
|
|
|
register int i;
|
|
|
|
|
1998-02-03 23:20:27 +00:00
|
|
|
#ifdef USE_MEM /* WIN32 */
|
|
|
|
memset(mat, 0x00, sizeof(MAT3mat));
|
1998-01-06 01:20:19 +00:00
|
|
|
#else
|
1997-05-30 19:25:54 +00:00
|
|
|
bzero (mat, sizeof(MAT3mat));
|
1998-01-06 01:20:19 +00:00
|
|
|
#endif
|
|
|
|
|
1997-05-30 19:25:54 +00:00
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
mat[i][i] = 1.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Sets a matrix to zero.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
MAT3zero (MAT3mat mat)
|
|
|
|
{
|
1998-02-03 23:20:27 +00:00
|
|
|
#ifdef USE_MEM /* WIN32 */
|
1998-01-06 01:20:19 +00:00
|
|
|
memset(mat,0x00, sizeof(MAT3mat));
|
|
|
|
#else
|
1997-05-30 19:25:54 +00:00
|
|
|
bzero (mat, sizeof(MAT3mat));
|
1998-01-06 01:20:19 +00:00
|
|
|
#endif
|
1997-05-30 19:25:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copies one matrix to another.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
MAT3copy(MAT3mat to, MAT3mat from)
|
|
|
|
{
|
1998-02-03 23:20:27 +00:00
|
|
|
#ifdef USE_MEM /* WIN32 */
|
1998-01-06 01:20:19 +00:00
|
|
|
memcpy(to, from, sizeof(MAT3mat));
|
|
|
|
#else
|
|
|
|
bcopy(from, to, sizeof(MAT3mat));
|
|
|
|
#endif
|
1997-05-30 19:25:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This multiplies two matrices, producing a third, which may the same as
|
|
|
|
* either of the first two.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
1998-01-19 18:40:33 +00:00
|
|
|
MAT3mult (double (*result_mat)[4], register double (*mat1)[4], register double (*mat2)[4])
|
1997-05-30 19:25:54 +00:00
|
|
|
{
|
|
|
|
register int i, j;
|
|
|
|
MAT3mat tmp_mat;
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
for (j = 0; j < 4; j++)
|
|
|
|
tmp_mat[i][j] = (mat1[i][0] * mat2[0][j] +
|
|
|
|
mat1[i][1] * mat2[1][j] +
|
|
|
|
mat1[i][2] * mat2[2][j] +
|
|
|
|
mat1[i][3] * mat2[3][j]);
|
|
|
|
MAT3copy (result_mat, tmp_mat);
|
|
|
|
}
|
1998-08-24 20:04:08 +00:00
|
|
|
#endif // !defined( USE_XTRA_MAT3_INLINES )
|
1997-05-30 19:25:54 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This returns the transpose of a matrix. The result matrix may be
|
|
|
|
* the same as the one to transpose.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
1998-01-19 18:40:33 +00:00
|
|
|
MAT3transpose (double (*result_mat)[4], register double (*mat)[4])
|
1997-05-30 19:25:54 +00:00
|
|
|
{
|
|
|
|
register int i, j;
|
|
|
|
MAT3mat tmp_mat;
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
for (j = 0; j < 4; j++)
|
|
|
|
tmp_mat[i][j] = mat[j][i];
|
|
|
|
|
|
|
|
MAT3copy (result_mat, tmp_mat);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This prints the given matrix to the given file pointer.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
1998-01-19 18:40:33 +00:00
|
|
|
MAT3print(double (*mat)[4], FILE *fp)
|
1997-05-30 19:25:54 +00:00
|
|
|
{
|
|
|
|
MAT3print_formatted(mat, fp, CNULL, CNULL, CNULL, CNULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This prints the given matrix to the given file pointer.
|
|
|
|
* use the format string to pass to fprintf. head and tail
|
|
|
|
* are printed at the beginning and end of each line.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
1998-01-19 18:40:33 +00:00
|
|
|
MAT3print_formatted(double (*mat)[4], FILE *fp, char *title, char *head, char *format, char *tail)
|
1997-05-30 19:25:54 +00:00
|
|
|
{
|
|
|
|
register int i, j;
|
|
|
|
|
|
|
|
/* This is to allow this to be called easily from a debugger */
|
|
|
|
if (fp == NULL) fp = stderr;
|
|
|
|
|
|
|
|
if (title == NULL) title = "MAT3 matrix:\n";
|
|
|
|
if (head == NULL) head = " ";
|
|
|
|
if (format == NULL) format = "%#8.4lf ";
|
|
|
|
if (tail == NULL) tail = "\n";
|
|
|
|
|
|
|
|
(void) fprintf(fp, title);
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
(void) fprintf(fp, head);
|
|
|
|
for (j = 0; j < 4; j++) (void) fprintf(fp, format, mat[i][j]);
|
|
|
|
(void) fprintf(fp, tail);
|
|
|
|
}
|
|
|
|
}
|