GLProgramming.com

home :: about :: development guides :: irc :: forums :: search :: paste :: links :: contribute :: code dump

-> Click here to learn how to get live help <-


New Paste :: Recent Pastes:: Add Line Numbers


static member by jeickmann
    class Matrix
    {
    private:
        float data[16];
        static int index(int row, int column) { return column*4+row; } ;
        
    public:
        static const Matrix identity;

        Matrix() { loadIdentity(); };
        Matrix( const float m[] ) { memcpy(data, m, 16*sizeof(float)); };

        Matrix(const Matrix &m) { memcpy(data, m.data, 16*sizeof(float)); };

        void loadIdentity() { for(int i=0;i<16;i++) { data[i]=(i%5==0)?1.0f:0.0f;} };

        float * getData() { return data; };
        float element(int i, int j) const;
        void setElement(int row, int column, float value);
        Matrix operator*(const Matrix &m) const;
        Matrix& operator*=(const Matrix &m);
        vec3 operator*(const vec3 &v) const;
        vec4 operator*(const vec4 &v) const;

        void translate(const vec3 &v);
        void translate(float x, float y, float z);

        void rotate(float angle, float x, float y, float z);
        void rotate(float angle, vec3 &axis);
        
        Matrix getRigidInverse();

        void print();
    };