-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTransform.cpp
More file actions
39 lines (32 loc) · 1.14 KB
/
Copy pathTransform.cpp
File metadata and controls
39 lines (32 loc) · 1.14 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
/* Transform.cpp: implementation of the Transform class. */
#include "Transform.h"
#include <iostream>
mat4 Transform::rotate(double degrees, const vec3& axis) {
mat3 parallel( cos(degrees*pi/180.0) );
vec3 a = glm::normalize(axis);
double x = a[0];
double y = a[1];
double z = a[2];
mat3 rotation(x*x, x*y, x*z, x*y, y*y, y*z, x*z, y*z, z*z);
rotation *= (1-cos(degrees*pi/180.0));
mat3 cross(0.0, -z, y, z, 0.0, -x, -y, x, 0.0);
cross *= sin(degrees*pi/180.0);
mat3 result = parallel + rotation + cross;
mat4 ret = mat4(glm::transpose(result));
return ret;
}
mat4 Transform::scale(double sx, double sy, double sz) {
mat4 S(sx,0,0,0,0,sy,0,0,0,0,sz,0,0,0,0,1);
return glm::transpose(S);
}
mat4 Transform::translate(double tx, double ty, double tz) {
mat4 T(1,0,0,tx,0,1,0,ty,0,0,1,tz,0,0,0,1);
return glm::transpose(T);
}
/* Unused constructor and deconstructer */
Transform::Transform(){}
Transform::~Transform(){}
// Some notes about using glm functions.
// You are ONLY permitted to use glm::dot glm::cross glm::normalize
// Do not use more advanced glm functions (in particular, directly using
// glm::lookAt is of course prohibited).