source: tests/vector_math/vec3_float.cfa @ eae8b37

Last change on this file since eae8b37 was aefb247, checked in by Thierry Delisle <tdelisle@…>, 5 years ago

Changed vector tests to properly refer to vecX.hfa like normal language headers

  • Property mode set to 100644
File size: 2.7 KB
Line 
1#include <vec/vec3.hfa>
2#include <fstream.hfa>
3
4int main(void) {
5    vec3(float) v1 = {1.f,2.f,3.f};
6    sout | "ctor(x,y):" | v1;
7
8    vec3(float) v2 = v1;
9    sout | "copy ctor:" | v2;
10
11    v2 = (vec3(float)){3.f, 4.2f, -2.f};
12    sout | "assignment:" | v2;
13
14    v2 = v1;
15    sout | "move assignment:" | v2;
16
17    vec3(float) v3 = 0;
18    sout | "zero-init:" | v3;
19
20    v1 = 0;
21    sout | "zero-assign:" | v1;
22
23    vec3(float) v4 = {1.23f};
24    sout | "fill-ctor:" | v4;
25
26    v1 = (vec3(float)){1.23f, 3.43f, 0.000002f};
27    sout | "?-?:" | (v1 - (vec3(float)){1.21f,3,1});
28
29    v1 -= (vec3(float)){1.23f, 3.43f, 0.000002f};
30    sout | "?-=?:" | v1;
31
32    v1 = -v1;
33    sout | "-?:" | v1;
34
35    v1 = (vec3(float)){1.5f, 2.75f, -14.2f};
36    sout | "?+?:" | (v1 + (vec3(float)){0.8f, -0.3f, 5});
37
38    v1 += (vec3(float)){0.8f, -0.3f, 5};
39    sout | "?+=?:" | v1;
40
41    v1 = (vec3(float)){1.5f, 2.75f, 100.3f};
42    sout | "v*s:" | v1 * 3.f;
43
44    sout | "s*v:" | 3.f * v1;
45
46    v1 *= 3;
47    sout | "?*=?:" | v1;
48
49    {
50        vec3(float) u = {1, 2, 3};
51        vec3(float) v = {2, 3, 4.5f};
52        sout | "?*?(vec):" | (u * v);
53        sout | "?*=?(vec):" | (u *= v);
54    }
55
56    v1 = (vec3(float)){2, -0.1f, 45};
57    sout | "?/?:" | (v1 / 3.f);
58
59    v1 /= 3.f;
60    sout | "?/=?:" | v1;
61
62    {
63        vec3(float) u = {2, -0.1f, 3};
64        vec3(float) v = {2, 3, 4.5f};
65        sout | "?/?(vec):" | (u / v);
66        sout | "?/=?(vec):" | (u /= v);
67    }
68
69    v1 = (vec3(float)){4,2,3};
70    v2 = (vec3(float)){0,-3,2};
71    sout | "dot_1:" | dot(v1, v2);
72
73    v2 = (vec3(float)){1.3f, -2, 12.2f};
74    sout | "dot_2:" | dot(v1, v2);
75
76    v2 = cross((vec3(float)){3,-3,1},(vec3(float)){4,9,2});
77    sout | "cross:" | v2;
78
79    v1 = (vec3(float)){1,2,3};
80    sout | "length:" | length(v1);
81
82    sout | "length_squared:" | length_squared(v1);
83
84    v2 = (vec3(float)){6, -3.2f, 1};
85    sout | "distance:" | distance(v1, v2);
86
87    sout | "normalize:" | normalize(v2);
88
89    sout | "project:" | project((vec3(float)){5,6,0}, (vec3(float)){0, 0, 1});
90    sout | "project_2:" | project((vec3(float)){5,6,3.2f}, (vec3(float)){10, 1, 4});
91
92    v1 = (vec3(float)){5,6,2.333f};
93    v2 = (vec3(float)){1,0,-13.5f};
94    sout | "reflect:" | reflect(v1,v2);
95
96    v2 = (vec3(float)){0,-1,2};
97    sout | "refract:" | refract(normalize(v1),normalize(v2),1.f);
98    sout | "refract:" | refract(normalize(v1),normalize(v2),1.f/1.33f);
99
100    vec3(float) geometric_normal = {5,6,1};
101    vec3(float) perturbed_normal = {4,5.5f,2};
102    vec3(float) eyeline = {-1,0.002f,-1.0345f};
103    sout | "faceforward_nochange:" | faceforward(perturbed_normal, eyeline, geometric_normal);
104
105    eyeline = (vec3(float)){1,0.002f,-1.0345f};
106    sout | "faceforward_flip:" | faceforward(perturbed_normal, eyeline, geometric_normal);
107}
Note: See TracBrowser for help on using the repository browser.