aboutsummaryrefslogtreecommitdiff
path: root/src/4dvecops/rotations4d.cpp
blob: 62746ebc755f5e7f29abe35d8e8cf293ad789dc0 (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
#include "raytracer/raytracer.h"

glm::mat4 getRotationMatrix4XY(
        float angleRadians) {
    glm::mat4 result;
    result[0][0] = cos(angleRadians);
    result[0][1] = -sin(angleRadians);
    result[1][0] = sin(angleRadians);
    result[1][1] = cos(angleRadians);
    result[2][2] = 1;
    result[3][3] = 1;
    return result;
}

glm::mat4 getRotationMatrix4YZ(
        float angleRadians) {
    glm::mat4 result;
    result[1][1] = cos(angleRadians);
    result[1][2] = -sin(angleRadians);
    result[2][1] = sin(angleRadians);
    result[2][2] = cos(angleRadians);
    result[0][0] = 1;
    result[3][3] = 1;
    return result;
}

glm::mat4 getRotationMatrix4ZX(
        float angleRadians) {
    glm::mat4 result;
    result[2][2] = cos(angleRadians);
    result[2][0] = -sin(angleRadians);
    result[0][2] = sin(angleRadians);
    result[0][0] = cos(angleRadians);
    result[1][1] = 1;
    result[3][3] = 1;
    return result;
}

glm::mat4 getRotationMatrix4XW(
        float angleRadians) {
    glm::mat4 result;
    result[0][0] = cos(angleRadians);
    result[0][3] = -sin(angleRadians);
    result[3][0] = sin(angleRadians);
    result[3][3] = cos(angleRadians);
    result[1][1] = 1;
    result[2][2] = 1;
    return result;
}

glm::mat4 getRotationMatrix4YW(
        float angleRadians) {
    glm::mat4 result;
    result[1][1] = cos(angleRadians);
    result[1][3] = -sin(angleRadians);
    result[3][1] = sin(angleRadians);
    result[3][3] = cos(angleRadians);
    result[0][0] = 1;
    result[2][2] = 1;
    return result;
}

glm::mat4 getRotationMatrix4ZW(
        float angleRadians) {
    glm::mat4 result;
    result[2][2] = cos(angleRadians);
    result[2][3] = -sin(angleRadians);
    result[3][2] = sin(angleRadians);
    result[3][3] = cos(angleRadians);
    result[0][0] = 1;
    result[1][1] = 1;
    return result;
}

glm::mat4 RayTracer::getRotationMatrix4(
        float angleRadiansXY,
        float angleRadiansYZ,
        float angleRadiansZX,
        float angleRadiansXW,
        float angleRadiansYW,
        float angleRadiansZW) {
    return getRotationMatrix4XY(angleRadiansXY) *
           getRotationMatrix4YZ(angleRadiansYZ) *
           getRotationMatrix4ZX(angleRadiansZX) *
           getRotationMatrix4XW(angleRadiansXW) *
           getRotationMatrix4YW(angleRadiansYW) *
           getRotationMatrix4ZW(angleRadiansZW);
}