Debian Codegraph @

src/test/01-Basic/257-vec3.ck

raw
1 // test vec3
2 // including .cross() and .dot(), which were added in 1.5.4.2
3 // vec3 is a primitive type
4
5 @(1,0,0) => vec3 a;
6 // declare another
7 @(0,1,0) => vec3 b;
8
9 // add them
10 a + b => vec3 sum;
11 // difference
12 a - b => vec3 diff;
13 // cross product
14 a * b => vec3 c;
15 // another way to do cross product (function)
16 a.cross(b) => vec3 cross;
17 // dot product (function)
18 a.dot(b) => float dot;
19
20 // print sum!
21 <<< "sum:", sum >>>;
22 // print difference
23 <<< "diff:", diff >>>;
24 // print cross product
25 <<< "cross product:", c >>>;
26 <<< "cross product (function):", cross >>>;
27 // print dot product
28 <<< "dot product:", dot >>>;
29
30 // array
31 [ a, b, @(-1,1,0) ] @=> vec3 group[];
32 // print them
33 <<< group[0], group[1], group[2] >>>;
34
35 // another v
36 vec3 v;
37 // set value
38 v.set( 2,2,2 );
39 // print magnitude
40 <<< "magnitude:", v.magnitude() >>>;
41 // normalize
42 v.normalize();
43 // print vector
44 <<< "normalize:", v >>>;
45
46 // multiply
47 5 * v => vec3 v2;
48 // print result
49 <<< "scalar multiply:", v2 >>>;
50
51 // negate
52 @(1, -2, 3) => vec3 n;
53 <<< "negate:", -@(-1, 2, -3), -n >>>;