Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: 31da2c99e0010290c901e9e707bc5e5c01e98949 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
   math/matrix4f.cc
   This file is part of the Osirion project and is distributed under
   the terms of the GNU General Public License version 2
*/

#include <cstring>
#include <cmath>

#include "math/matrix4f.h"

namespace math
{

Matrix4f::Matrix4f()
{
	clear();
}

Matrix4f::Matrix4f(const Matrix4f & other)
{
	assign(other);
}

Matrix4f::Matrix4f(const Axis & axis)
{
	assign(axis);
}

void Matrix4f::clear()
{
	memset(_matrix, 0, sizeof(float) * 16);
}

void Matrix4f::unity()
{
	memset(_matrix, 0, sizeof(float) * 16);
	for (int i = 0; i < 4; i++)
	{
		_matrix[i][i] = 1;
	}
}

void Matrix4f::assign(const Matrix4f & other)
{
	memcpy(_matrix, other._matrix, sizeof(float) * 16);
}

void Matrix4f::assign(const Axis & axis)
{
	for (int i = 0; i < 3; i++) {
		memcpy(&_matrix[i][0], axis[i].ptr(), sizeof(float) * 3);
	}
	_matrix[0][3] = 0;
	_matrix[1][3] = 0;
	_matrix[2][3] = 0;
	
	_matrix[3][0] = 0;
	_matrix[3][1] = 0;
	_matrix[3][2] = 0;
	
	_matrix[3][3] = 1;
}

Matrix4f & Matrix4f::operator=(const Matrix4f &other)
{
	assign(other);
	return(*this);
}

Matrix4f & Matrix4f::operator=(const Axis & axis)
{
	assign(axis);
	return(*this);
}

const Matrix4f Matrix4f::transpose() const
{
	Matrix4f t;

	for (size_t i = 0; i < 4; i++)
	{
		for (size_t j = 0; j < 4; j++)
		{
			t._matrix[j][i] = _matrix[i][j];
		}
	}
	return t;
}

}