Subversion Repositories gelsvn

Rev

Rev 107 | Rev 326 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
107 bj 1
#include <iostream>
2
 
3
#include "CGLA/Mat4x4f.h"
4
#include "CGLA/Mat2x2f.h"
5
#include "CGLA/Mat3x3f.h"
6
#include "CGLA/Mat2x3f.h"
7
#include "CGLA/eigensolution.h"
8
 
9
#include "CGLA/Vec2f.h"
10
#include "CGLA/Vec2i.h"
11
#include "CGLA/Vec3i.h"
12
#include "CGLA/Vec3f.h"
13
#include "CGLA/Vec3Hf.h"
14
 
15
using namespace std;
16
using namespace CGLA;
17
 
18
 
19
/* This is a non-exhaustive test program for CGLA */
194 jrf 20
int main()
107 bj 21
{
22
 
23
	Mat2x3f m23(Vec3f(1,1,1),Vec3f(2,2,2));
24
	Mat3x2f m32;
25
 
26
	// Try transpose of non-sq matrix
27
	transpose(m23, m32);
28
	cout << "2 by 3 " << m23 << endl;
29
	cout << "Transpose " << m32 << endl;
30
 
31
 
32
	m32[0] = Vec2f(1,2);
33
	m32[1] = Vec2f(10,20);
34
	m32[2] = Vec2f(100,200);
35
 
36
	Mat2x2f m22;
37
 
38
	// Multiply 2x3 and 3x2 matrices
39
	mul(m23, m32, m22);
40
	cout << "Multiplication of non. sq. mat " << m22 << endl;
41
 
42
	// Check matrix mul using * operator for sq matrices.
43
	Mat2x2f m22_2(1,2,3,4);
44
	cout << "multiplication of sq. mats " << m22_2 * m22 << endl;
45
	cout << "Trace " << trace(m22) << endl;
46
 
47
	m22_2 += m22 + m22;
48
	m22_2 -= 2* m22;
49
 
50
	Mat4x4f m44(0.0f);
51
	m44[0][0] = 1;
52
	m44[1][2] = 2;
53
	m44[2][1] = 3;
54
	m44[3][3] = 4;
55
 
56
	Mat4x4f m44_2 = transpose(m44);
57
	cout << m44 << m44_2 << endl; 
58
 
59
	// Compile should fail if line below is uncommented
60
	// mul(m23, m44, m22);
61
	// Compile should fail if line below is uncommented
62
	// transpose(m23,m44);
63
 
64
	cout << "Determinant of 4x4 " << m44 << determinant(m44) << endl;
65
	cout << "Determinant of 2x2 " << m22 << determinant(m22) << endl;
66
 
67
	Mat4x4f mna(Vec4f(10,120,10,40),
68
							Vec4f(43,10,31254,10),
69
							Vec4f(43,11,54,10),
70
							Vec4f(0,0,0,1));
71
 
72
	cout << fixed << endl;
73
	try
74
		{
75
			cout << "Invert: " << invert_affine(mna) << endl;
76
			cout << "Test: " << invert_affine(mna)*mna << endl;
77
		}
78
	catch(const Mat4x4fException& me)
79
		{
80
			me.print(cout);
81
		}
82
	try
83
		{	
84
			cout << "Invert " << invert(mna) << endl;
85
			cout << "test " << invert(mna)*mna << endl;
86
		}
87
	catch(const Mat4x4fException& me)
88
		{
89
			me.print(cout);
90
		}
91
 
92
	Vec2f v2(2,3);
93
	Vec3f v3(1,2,3);
94
	Mat2x3f m23_2;
95
	outer_product(v2,v3,m23_2);
96
	cout << "outer product of " << v2 << " , " << v3 << " = " << m23_2 << endl;
97
 
98
	Mat4x4f A(Vec4f(1, 2, 3, 4), 
99
						Vec4f(2, 9,-7,2), 
100
						Vec4f(3,-7, 8, 1),
101
						Vec4f(4,2, 31,12)
102
						);
103
	Mat4x4f Q,L;
104
 
105
	int n = power_eigensolution(A, Q, L);
106
 
107
	cout << "The " << n << " eigensolutions of " << A << " are ";
108
	cout << Q << L << endl;
109
 
110
	m44 = identity_Mat4x4f();
111
 
112
	Mat3x3f m33(Vec3f(1,2,3), Vec3f(4,5,6), Vec3f(7,8,9));
113
 
114
	copy_matrix(m33, m44);
115
 
116
	cout << "The matrix " << m33 << " is copied to " << m44 << endl;
117
 
118
 
194 jrf 119
	return 0;
107 bj 120
}