Main Page   Class Hierarchy   Compound List   Header Files   Compound Members  

ddgmatrx.h

This is the verbatim text of the ddgmatrx.h include file.
/*
    Copyright (C) 1997, 1998, 1999, 2000 by Alex Pfaffe
        (Digital Dawn Graphics Inc)
  
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.
  
    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.
  
    You should have received a copy of the GNU Library General Public
    License along with this library; if not, write to the Free
    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef _ddgMatrix_Class_
#define _ddgMatrix_Class_

#ifdef WIN32
#include <string.h>
#endif

#include "math/ddgvec.h"

class WEXP ddgMatrix3 {
public:
  ddgVector3 m[3];
  ddgVector3 operator[](int n)            { return m[n]; }
  ddgMatrix3( ddgVector3 *v1, ddgVector3 *v2, ddgVector3 *v3 ) 
    { m[0].set(v1); m[1].set(v2); m[2].set(v3); }
};

class WEXP ddgMatrix4 {
public:
        ddgVector4 m[4];
        ddgMatrix4(void) { }
        float& operator[](int i)
        { return m[i/4].v[i%4]; }
        float& operator()(int i, int j)
        { return m[i].v[j]; }
        float& operator()(int i)
        { return m[i/4].v[i%4]; }
        ddgMatrix4& operator += ( const ddgMatrix4& m1 )
        { m[0] += m1.m[0]; m[1] += m1.m[1]; m[2] += m1.m[2]; m[3] += m1.m[3]; return *this;}
        ddgMatrix4& operator -= ( const ddgMatrix4& m1 )
        { m[0] -= m1.m[0]; m[1] -= m1.m[1]; m[2] -= m1.m[2]; m[3] -= m1.m[3]; return *this;}
        ddgMatrix4& operator *= ( const ddgMatrix4& m1 );
        friend ddgMatrix4 operator *( const ddgMatrix4& m1, const ddgMatrix4& m2 )
        {
        ddgMatrix4 out(m1);
        out *= m2;
        return out;
        }
        // Scale.
        ddgMatrix4& operator *= ( const float d )
        { m[0] *= d; m[1] *= d; m[2] *= d; m[3] *= d; return *this;}
        // Division
        ddgMatrix4& operator /= ( const float d )
        { m[0] /= d; m[1] /= d; m[2] /= d; m[3] /= d; return *this;}

        ddgMatrix4& operator=(const ddgMatrix4& s)
        { m[0] = s.m[0]; m[1] = s.m[1]; m[2] = s.m[2]; m[3] = s.m[3]; return *this; }
        void identity(void)
        {
                m[0].set(1,0,0,0);
                m[1].set(0,1,0,0);
                m[2].set(0,0,1,0);
                m[3].set(0,0,0,1);
        }
        inline friend ddgVector4 operator* (const ddgMatrix4& a, const ddgVector4& v)
        {
                return ddgVector4(a.m[0][0]*v[0] + a.m[0][1]*v[1] + a.m[0][2]*v[2] + a.m[0][3]*v[3],
                                                  a.m[1][0]*v[0] + a.m[1][1]*v[1] + a.m[1][2]*v[2] + a.m[1][3]*v[3],
                                                  a.m[2][0]*v[0] + a.m[2][1]*v[1] + a.m[2][2]*v[2] + a.m[2][3]*v[3],
                                                  a.m[3][0]*v[0] + a.m[3][1]*v[1] + a.m[3][2]*v[2] + a.m[3][3]*v[3]);
        }

        friend ddgMatrix4 operator - (const ddgMatrix4& a)                                      // -m1
        {
                ddgMatrix4 m1;
                m1 = a;
                m1.m[0] *= -1; m1.m[1] *= -1; m1.m[2] *= -1; m1.m[3] *= -1;
                return m1;
        }
        friend ddgMatrix4 operator + (const ddgMatrix4& a, const ddgMatrix4& b)  // m1 + m2
        {
                ddgMatrix4 m1;
                m1.m[0] = a.m[0] + b.m[0]; m1.m[1] = a.m[1] + b.m[1]; m1.m[2] = a.m[2] + b.m[2]; m1.m[3] = a.m[3] + b.m[3]; 
                return m1;
        }
        friend ddgMatrix4 operator - (const ddgMatrix4& a, const ddgMatrix4& b)  // m1 - m2
        {
                ddgMatrix4 m1;
                m1.m[0] = a.m[0] - b.m[0]; m1.m[1] = a.m[1] - b.m[1]; m1.m[2] = a.m[2] - b.m[2]; m1.m[3] = a.m[3] - b.m[3]; 
                return m1;
        }
        friend ddgMatrix4 operator / (const ddgMatrix4& a, const float d)  // m1 / d
        {
                ddgMatrix4 m1;
                m1 = a;
                m1.m[0] /=d; m1.m[1] /=d; m1.m[2] /=d; m1.m[3] /=d; 
                return m1;
        }

        // Check equality
        friend bool operator == (const ddgMatrix4& a, const ddgMatrix4& b)  // m1 == m2 ?
        {
                return a.m[0] == b.m[0] && a.m[1] == b.m[1] && a.m[2] == b.m[2] && a.m[3] == b.m[3];
        }
        // Check inequality
        friend bool operator != (const ddgMatrix4& a, const ddgMatrix4& b)  // m1 != m2 ?
        {
                return (a.m[0] != b.m[0]) || (a.m[1] != b.m[1]) || (a.m[2] != b.m[2]) || (a.m[3] != b.m[3]);
        }
        ddgMatrix4( ddgVector4 *v1, ddgVector4 *v2, ddgVector4 *v3, ddgVector4 *v4) 
        { m[0].set(v1); m[1].set(v2); m[2].set(v3); m[3].set(v4); }
        ddgMatrix4( float u[16] )
        { m[0].set(&u[0]);  m[1].set(&u[4]); m[2].set(&u[8]); m[3].set(&u[12]);}
        void assignto( float u[16] )
        { int i = 0; do { u[i] = m[i/4].v[i%4]; } while (++i < 16 ); }
        operator float*() { return &m[0].v[0]; };
        void invert(void);
        void transpose(void);
};

void WEXP ddgMatrixMultiply( float product[], const float a[], const float b[] );   
void WEXP ddgRotationMatrix( float angle, float x, float y, float z, float m[] );
#endif

Generated at Sun Sep 17 19:27:55 2000 for Digital Dawn Graphics Toolkit by doxygen 0.49-991205 written by Dimitri van Heesch, © 1997-1999