-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatrix3.h
More file actions
103 lines (79 loc) · 2.36 KB
/
Matrix3.h
File metadata and controls
103 lines (79 loc) · 2.36 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
//////////////////////////////////////////////////////////////////////
//
// University of Leeds
// COMP 5823M Animation & Simulation
//
// September, 2020
//
// ------------------------
// Matrix3.h
// ------------------------
//
// A minimal class for a 3x3 Cartesian matrix
//
///////////////////////////////////////////////////
// include guard
#ifndef __MATRIX3_H
#define __MATRIX3_H
#include <iostream>
#include "Cartesian3.h"
#ifndef M_PI
#define M_PI 3.141592
#endif
#define DEG2RAD(x) (M_PI*(float)(x)/180.0)
// forward declaration
class Matrix3;
// the class itself, stored in row-major form
class Matrix3
{ // Matrix3
public:
// the coordinates
float coordinates[3][3];
// constructor - default to the zero matrix
Matrix3();
// equality operator
bool operator ==(const Matrix3 &other) const;
// indexing - retrieves the beginning of a line
// array indexing will then retrieve an element
float * operator [](const int rowIndex);
// similar routine for const pointers
const float * operator [](const int rowIndex) const;
// scalar operations
// multiplication operator (no division operator)
Matrix3 operator *(float factor) const;
// vector operations on Cartesian coordinates
Cartesian3 operator *(const Cartesian3 &vector) const;
// matrix operations
// addition operator
Matrix3 operator +(const Matrix3 &other) const;
// subtraction operator
Matrix3 operator -(const Matrix3 &other) const;
// multiplication operator
Matrix3 operator *(const Matrix3 &other) const;
// matrix transpose
Matrix3 transpose() const;
// routine that returns a row vector
Cartesian3 row(int rowNum);
// and similar for a column
Cartesian3 column(int colNum);
// methods that return particular matrices
static Matrix3 Zero();
// the identity matrix
static Matrix3 Identity();
// rotations around main axes
static Matrix3 RotateX(float degrees);
static Matrix3 RotateY(float degrees);
static Matrix3 RotateZ(float degrees);
// routine to transpose a matrix
Matrix3 Transpose();
// matrix inverse
Matrix3 Inverse();
}; // Matrix3
// scalar operations
// additional scalar multiplication operator
Matrix3 operator *(float factor, const Matrix3 &matrix);
// stream input
std::istream & operator >> (std::istream &inStream, Matrix3 &value);
// stream output
std::ostream & operator << (std::ostream &outStream, const Matrix3 &value);
#endif