source: tests/vector_math/vec4_float.cfa @ 4e28d2e9

ADTast-experimentalenumforall-pointer-decaypthread-emulationqualifiedEnum
Last change on this file since 4e28d2e9 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.4 KB
Line 
1#include <vec/vec4.hfa>
2#include <fstream.hfa>
3
4int main(void) {
5    vec4(float) v1 = {1.f,2.f,3.f,4.f};
6    sout | "ctor(x,y):" | v1;
7
8    vec4(float) v2 = v1;
9    sout | "copy ctor:" | v2;
10
11    v2 = (vec4(float)){3.f,4.2f,-2.f,-100.f};
12    sout | "assignment:" | v2;
13
14    v2 = v1;
15    sout | "move assignment:" | v2;
16
17    vec4(float) v3 = 0;
18    sout | "zero-init:" | v3;
19
20    v1 = 0;
21    sout | "zero-assign:" | v1;
22
23    vec4(float) v4 = {1.23f};
24    sout | "fill-ctor:" | v4;
25
26    v1 = (vec4(float)){1.23f, 3.43f, 0.000002f, -0.000002f};
27    sout | "?-?:" | (v1 - (vec4(float)){1.21f,3,1,-0.000001f});
28
29    v1 -= (vec4(float)){1.21f,3,1,-0.000001f};
30    sout | "?-=?:" | v1;
31
32    v1 = -v1;
33    sout | "-?:" | v1;
34
35    v1 = (vec4(float)){1.5f, 2.75f, -14.2f, -13.5f};
36    sout | "?+?:" | (v1 + (vec4(float)){0.8f, -0.3f, 5, 1});
37
38    v1 += (vec4(float)){0.8f, -0.3f, 5, 1};
39    sout | "?+=?:" | v1;
40
41    v1 = (vec4(float)){1.5f, 2.75f, 100.3f, -2.f};
42    sout | "v*s:" | v1 * 3.f;
43
44    sout | "s*v:" | 3.f * v1;
45
46    v1 *= 3;
47    sout | "?*=?:" | v1;
48
49    v1 = (vec4(float)){2, -0.1f, 45, -15};
50    sout | "?/?:" | (v1 / 3.f);
51
52    v1 /= 3.f;
53    sout | "?/=?:" | v1;
54
55    v1 = (vec4(float)){4,3,2,1};
56    v2 = (vec4(float)){0,4,-3,-6};
57    sout | "dot_1:" | dot(v1, v2);
58
59    v2 = (vec4(float)){1.3f, -2, 12.2f, 24.1345f};
60    sout | "dot_2:" | dot(v1, v2);
61
62    v1 = (vec4(float)){1,2,3,4};
63    sout | "length:" | length(v1);
64
65    sout | "length_squared:" | length_squared(v1);
66
67    v2 = (vec4(float)){6, -3.2f, 1, 12};
68    sout | "distance:" | distance(v1, v2);
69
70    sout | "normalize:" | normalize(v2);
71
72    sout | "project:" | project((vec4(float)){5,6,0,-1}, (vec4(float)){0, 0, 0, 1});
73    sout | "project_2:" | project((vec4(float)){5,6,3.2f,-16.75f}, (vec4(float)){10, 1, 4, 2});
74
75    v1 = (vec4(float)){5,6,2.333f,1};
76    v2 = (vec4(float)){1,0,-13.5f,2};
77    sout | "reflect:" | reflect(v1,v2);
78
79    v2 = (vec4(float)){0,-1,2,0.5f};
80    sout | "refract:" | refract(normalize(v1),normalize(v2),1.f);
81    sout | "refract:" | refract(normalize(v1),normalize(v2),1.f/1.33f);
82
83    vec4(float) geometric_normal = {5,6,1,2};
84    vec4(float) perturbed_normal = {4,5.5f,2,2};
85    vec4(float) eyeline = {-1,0.002f,-1.0345f,-2};
86    sout | "faceforward_nochange:" | faceforward(perturbed_normal, eyeline, geometric_normal);
87
88    eyeline = (vec4(float)){1,0.002f,-1.0345f,-2};
89    sout | "faceforward_flip:" | faceforward(perturbed_normal, eyeline, geometric_normal);
90}
Note: See TracBrowser for help on using the repository browser.