1+ #include " math3D.h"
2+ #include " transformation.h"
3+ #include < math.h>
4+ #include < iostream>
5+
6+ using namespace std ;
7+
8+ namespace ijengine {
9+ Transformation::Transformation (){
10+ loadIdentity (m_Trans);
11+ loadIdentity (m_Scale);
12+ loadIdentity (m_RotX);
13+ loadIdentity (m_RotY);
14+ loadIdentity (m_RotZ);
15+ loadIdentity (m_Perspective);
16+ }
17+ Transformation::~Transformation (){
18+
19+ }
20+ void
21+ Transformation::loadIdentity (matrix4f& Trans){
22+ Trans = {1 , 0 , 0 , 0 ,
23+ 0 , 1 , 0 , 0 ,
24+ 0 , 0 , 1 , 0 ,
25+ 0 , 0 , 0 , 1 };
26+ }
27+ void
28+ Transformation::setTranslation (float x, float y, float z){
29+ m_Trans.m [0 ][3 ] = x;
30+ m_Trans.m [1 ][3 ] = y;
31+ m_Trans.m [2 ][3 ] = z;
32+ printMatrix (m_Trans);
33+ }
34+ void
35+ Transformation::setRotationX (float angle){
36+ m_RotX.m [1 ][1 ] = cos (angle);
37+ m_RotX.m [2 ][1 ] = -sin (angle);
38+ m_RotX.m [1 ][2 ] = sin (angle);
39+ m_RotX.m [2 ][2 ] = cos (angle);
40+ printMatrix (m_RotX);
41+ }
42+ void
43+ Transformation::setRotationY (float angle){
44+ m_RotY.m [0 ][0 ] = cos (angle);
45+ m_RotY.m [0 ][2 ] = sin (angle);
46+ m_RotY.m [2 ][0 ] = -sin (angle);
47+ m_RotY.m [2 ][2 ] = cos (angle);
48+ printMatrix (m_RotY);
49+ }
50+ void
51+ Transformation::setRotationZ (float angle){
52+ m_RotZ.m [0 ][0 ] = cos (angle);
53+ m_RotZ.m [0 ][1 ] = sin (angle);
54+ m_RotZ.m [1 ][0 ] = -sin (angle);
55+ m_RotZ.m [1 ][1 ] = cos (angle);
56+ printMatrix (m_RotZ);
57+ }
58+ void
59+ Transformation::setScale (float scale){
60+ m_Scale.m [0 ][0 ] = scale;
61+ m_Scale.m [1 ][1 ] = scale;
62+ m_Scale.m [2 ][2 ] = scale;
63+ printMatrix (m_Scale);
64+ }
65+
66+ void
67+ Transformation::setPerspective (float near, float far, float angle, float width, float height){
68+ m_Perspective.m [0 ][0 ] = 1 /((width/height)*tan (angle/2 ));
69+ m_Perspective.m [1 ][1 ] = 1 /(tan (angle/2 ));
70+ m_Perspective.m [2 ][2 ] = (-near-far)/(near-far);
71+ m_Perspective.m [2 ][3 ] = (2 *(near*far))/(near-far);
72+ printMatrix (m_Perspective);
73+ }
74+
75+ void
76+ Transformation::printMatrix (matrix4f matrix){
77+ for (int i = 0 ; i < 4 ; ++i) {
78+ for (int j = 0 ; j < 4 ; ++j)
79+ cout << matrix.m [i][j] << " " ;
80+ cout << endl;
81+ }
82+ }
83+
84+ matrix4f
85+ Transformation::getTransformation (){
86+ matrix4f Trans;
87+ // Trans = Mult(m_RotX, m_Scale);
88+ // Mult(m_Trans ,Mult(m_RotZ ,Mult(m_RotY ,(Mult(m_RotX, m_Scale))));
89+ return Trans;
90+ }
91+ }
0 commit comments