[2444324] | 1 | #include <glm/glm.hpp> |
---|
| 2 | #include <iostream> |
---|
| 3 | |
---|
| 4 | using namespace glm; |
---|
| 5 | |
---|
| 6 | std::ostream& operator<<(std::ostream& os, glm::tvec2<int>& v) { |
---|
| 7 | os << "<" << v.x << "," << v.y << ">"; |
---|
| 8 | return os; |
---|
| 9 | } |
---|
| 10 | std::ostream& operator<<(std::ostream& os, glm::tvec2<int>&& v) { |
---|
| 11 | os << "<" << v.x << "," << v.y << ">"; |
---|
| 12 | return os; |
---|
| 13 | } |
---|
| 14 | |
---|
| 15 | int length_squared(glm::tvec2<float> v) { |
---|
| 16 | return dot(v, v); |
---|
| 17 | } |
---|
| 18 | |
---|
| 19 | // tvec2<int> project(glm::tvec2<int> u, glm::tvec2<int> v) { |
---|
| 20 | // return normalize(v) * dot(u, normalize(v)); |
---|
| 21 | // } |
---|
| 22 | |
---|
| 23 | int main(void) { |
---|
| 24 | tvec2<int> v1 = {1,2}; |
---|
| 25 | std::cout << "ctor(x,y):" << v1 << std::endl; |
---|
| 26 | |
---|
| 27 | tvec2<int> v2 = v1; |
---|
| 28 | std::cout << "copy ctor:" << v2 << std::endl; |
---|
| 29 | |
---|
| 30 | v2 = (tvec2<int>){3, 4}; |
---|
| 31 | std::cout << "assignment:" << v2 << std::endl; |
---|
| 32 | |
---|
| 33 | v2 = v1; |
---|
| 34 | std::cout << "move assignment:" << v2 << std::endl; |
---|
| 35 | |
---|
| 36 | |
---|
| 37 | // NOT SUPPORTED BY GLM |
---|
| 38 | // tvec2<int> v3 = 0; |
---|
| 39 | // std::cout << "zero-init:" << v3 << std::endl; |
---|
| 40 | |
---|
| 41 | // v1 = 0; |
---|
| 42 | // std::cout << "zero-assign:" << v1 << std::endl; |
---|
| 43 | |
---|
| 44 | // tvec2<int> v4 = {1.23f}; |
---|
| 45 | // std::cout << "fill-ctor:" << v4 << std::endl; |
---|
| 46 | |
---|
| 47 | |
---|
| 48 | v1 = (tvec2<int>){1, 3}; |
---|
| 49 | std::cout << "?-?:" << (v1 - (tvec2<int>){1003, -14}) << std::endl; |
---|
| 50 | |
---|
| 51 | v1 -= (tvec2<int>){1003, -14}; |
---|
| 52 | std::cout << "?-=?:" << v1 << std::endl; |
---|
| 53 | |
---|
| 54 | v1 = -v1; |
---|
| 55 | std::cout << "-?:" << v1 << std::endl; |
---|
| 56 | |
---|
| 57 | v1 = (tvec2<int>){1, 3}; |
---|
| 58 | std::cout << "?+?:" << (v1 + (tvec2<int>){1003, -14}) << std::endl; |
---|
| 59 | |
---|
| 60 | v1 += (tvec2<int>){1003, -14}; |
---|
| 61 | std::cout << "?+=?:" << v1 << std::endl; |
---|
| 62 | |
---|
| 63 | v1 = (tvec2<int>){15, 275}; |
---|
| 64 | std::cout << "v*s:" << v1 * 3 << std::endl; |
---|
| 65 | |
---|
| 66 | std::cout << "s*v:" << 3 * v1 << std::endl; |
---|
| 67 | |
---|
| 68 | v1 *= 3; |
---|
| 69 | std::cout << "?*=?:" << v1 << std::endl; |
---|
| 70 | |
---|
| 71 | v1 = (tvec2<int>){21, -10}; |
---|
| 72 | std::cout << "?/?:" << (v1 / 3) << std::endl; |
---|
| 73 | |
---|
| 74 | v1 /= 3; |
---|
| 75 | std::cout << "?/=?:" << v1 << std::endl; |
---|
| 76 | |
---|
| 77 | // FORCE GLM TO FLOAT, BUT WORKS |
---|
| 78 | tvec2<float> v1_f = (tvec2<float>){2.f, 3}; |
---|
| 79 | tvec2<float> v2_f = (tvec2<float>){-3.f, 2.f}; |
---|
| 80 | std::cout << "dot_1:" << dot(v1_f, v2_f) << std::endl; |
---|
| 81 | |
---|
| 82 | v2_f = (tvec2<float>){13, 2}; |
---|
| 83 | std::cout << "dot_2:" << dot(v1_f, v2_f) << std::endl; |
---|
| 84 | |
---|
| 85 | |
---|
| 86 | // NOT IN GLM BUT |
---|
| 87 | // USES DOT, BUT THAT'S FLOATING-POINT ONLY! |
---|
| 88 | std::cout << "length_squared:" << length_squared(v1_f) << std::endl; |
---|
| 89 | |
---|
| 90 | // FLOATING-POINT ONLY GLM |
---|
| 91 | // v1 = (tvec2<int>){100, -101}; |
---|
| 92 | // v2 = (tvec2<int>){6, 3}; |
---|
| 93 | // std::cout << "distance:" << distance(v1, v2) << std::endl; |
---|
| 94 | // |
---|
| 95 | // std::cout << "normalize:" << normalize(v2) << std::endl; |
---|
| 96 | // |
---|
| 97 | // v1 = (tvec2<int>){1,0}; |
---|
| 98 | // std::cout << "normalize_2:" << normalize(v1) << std::endl; |
---|
| 99 | // |
---|
| 100 | // std::cout << "project:" << project((tvec2<int>){5,6}, (tvec2<int>){1, 0}) << std::endl; |
---|
| 101 | // std::cout << "project_2:" << project((tvec2<int>){5,6}, (tvec2<int>){1, 1}) << std::endl; |
---|
| 102 | // |
---|
| 103 | // v1 = (tvec2<int>){5,6}; |
---|
| 104 | // v2 = (tvec2<int>){1,0}; |
---|
| 105 | // std::cout << "reflect:" << reflect(v1,v2) << std::endl; |
---|
| 106 | // |
---|
| 107 | // v2 = (tvec2<int>){0,-1}; |
---|
| 108 | // std::cout << "refract:" << refract(v1,normalize(v2),1) << std::endl; |
---|
| 109 | // std::cout << "refract:" << refract(v1,normalize(v2),1.f/1.33f) << std::endl; |
---|
| 110 | // |
---|
| 111 | // |
---|
| 112 | // FLOATING-POINT ONLY IN GLM BUT JUST USES DOT SO... |
---|
| 113 | tvec2<float> geometric_normal = {5,6}; |
---|
| 114 | tvec2<float> perturbed_normal = {4,5}; |
---|
| 115 | tvec2<float> eyeline = {-1,0}; |
---|
| 116 | std::cout << "faceforward_nochange:" << faceforward(perturbed_normal, eyeline, geometric_normal) << std::endl; |
---|
| 117 | |
---|
| 118 | eyeline = (tvec2<int>){1,0}; |
---|
| 119 | std::cout << "faceforward_flip:" << faceforward(perturbed_normal, eyeline, geometric_normal) << std::endl; |
---|
| 120 | } |
---|