Debian Codegraph @

examples/vector/vec3.ck

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