Subversion Repositories gelsvn

Rev

Rev 194 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

#include <iostream>

#include "CGLA/Mat4x4f.h"
#include "CGLA/Mat2x2f.h"
#include "CGLA/Mat3x3f.h"
#include "CGLA/Mat2x3f.h"
#include "CGLA/eigensolution.h"

#include "CGLA/Vec2f.h"
#include "CGLA/Vec2i.h"
#include "CGLA/Vec3i.h"
#include "CGLA/Vec3f.h"
#include "CGLA/Vec3Hf.h"

using namespace std;
using namespace CGLA;


/* This is a non-exhaustive test program for CGLA */
main()
{

        Mat2x3f m23(Vec3f(1,1,1),Vec3f(2,2,2));
        Mat3x2f m32;
        
        // Try transpose of non-sq matrix
        transpose(m23, m32);
        cout << "2 by 3 " << m23 << endl;
        cout << "Transpose " << m32 << endl;
        
        
        m32[0] = Vec2f(1,2);
        m32[1] = Vec2f(10,20);
        m32[2] = Vec2f(100,200);

        Mat2x2f m22;
        
        // Multiply 2x3 and 3x2 matrices
        mul(m23, m32, m22);
        cout << "Multiplication of non. sq. mat " << m22 << endl;

        // Check matrix mul using * operator for sq matrices.
        Mat2x2f m22_2(1,2,3,4);
        cout << "multiplication of sq. mats " << m22_2 * m22 << endl;
        cout << "Trace " << trace(m22) << endl;
        
        m22_2 += m22 + m22;
        m22_2 -= 2* m22;
        
        Mat4x4f m44(0.0f);
        m44[0][0] = 1;
        m44[1][2] = 2;
        m44[2][1] = 3;
        m44[3][3] = 4;

        Mat4x4f m44_2 = transpose(m44);
        cout << m44 << m44_2 << endl; 

        // Compile should fail if line below is uncommented
        // mul(m23, m44, m22);
        // Compile should fail if line below is uncommented
        // transpose(m23,m44);

        cout << "Determinant of 4x4 " << m44 << determinant(m44) << endl;
        cout << "Determinant of 2x2 " << m22 << determinant(m22) << endl;

        Mat4x4f mna(Vec4f(10,120,10,40),
                                                        Vec4f(43,10,31254,10),
                                                        Vec4f(43,11,54,10),
                                                        Vec4f(0,0,0,1));

        cout << fixed << endl;
        try
                {
                        cout << "Invert: " << invert_affine(mna) << endl;
                        cout << "Test: " << invert_affine(mna)*mna << endl;
                }
        catch(const Mat4x4fException& me)
                {
                        me.print(cout);
                }
        try
                {       
                        cout << "Invert " << invert(mna) << endl;
                        cout << "test " << invert(mna)*mna << endl;
                }
        catch(const Mat4x4fException& me)
                {
                        me.print(cout);
                }

        Vec2f v2(2,3);
        Vec3f v3(1,2,3);
        Mat2x3f m23_2;
        outer_product(v2,v3,m23_2);
        cout << "outer product of " << v2 << " , " << v3 << " = " << m23_2 << endl;

        Mat4x4f A(Vec4f(1, 2, 3, 4), 
                                                Vec4f(2, 9,-7,2), 
                                                Vec4f(3,-7, 8, 1),
                                                Vec4f(4,2, 31,12)
                                                );
        Mat4x4f Q,L;
        
        int n = power_eigensolution(A, Q, L);

        cout << "The " << n << " eigensolutions of " << A << " are ";
        cout << Q << L << endl;

        m44 = identity_Mat4x4f();

        Mat3x3f m33(Vec3f(1,2,3), Vec3f(4,5,6), Vec3f(7,8,9));

        copy_matrix(m33, m44);

        cout << "The matrix " << m33 << " is copied to " << m44 << endl;


        
}