1+ export default class Vec3 {
2+ public x : number ;
3+ public y : number ;
4+ public z : number ;
5+
6+ public constructor ( x : number , y : number , z : number ) {
7+ this . x = x ;
8+ this . y = y ;
9+ this . z = z ;
10+ }
11+
12+ public static From ( other : Vec3 ) {
13+ return new Vec3 ( other . x , other . y , other . z ) ;
14+ }
15+
16+ public set ( other : Vec3 ) {
17+ this . x = other . x ;
18+ this . y = other . y ;
19+ this . z = other . z ;
20+ }
21+
22+ public set_d ( x : number , y : number , z : number ) {
23+ this . x = x ;
24+ this . y = y ;
25+ this . z = z ;
26+ }
27+
28+ public add ( other : Vec3 ) {
29+ this . x += other . x ;
30+ this . y += other . y ;
31+ this . z += other . z ;
32+ }
33+
34+ public add_d ( x : number , y : number , z : number ) {
35+ this . x += x ;
36+ this . y += y ;
37+ this . z += z ;
38+ }
39+
40+ public sub ( other : Vec3 ) {
41+ this . x -= other . x ;
42+ this . y -= other . y ;
43+ this . z -= other . z ;
44+ }
45+
46+ public sub_d ( x : number , y : number , z : number ) {
47+ this . x -= x ;
48+ this . y -= y ;
49+ this . z -= z ;
50+ }
51+
52+ public mult ( other : Vec3 ) {
53+ this . x *= other . x ;
54+ this . y *= other . y ;
55+ this . z *= other . z ;
56+ }
57+
58+ public mult_d ( x : number , y : number , z : number ) {
59+ this . x *= x ;
60+ this . y *= y ;
61+ this . z *= z ;
62+ }
63+
64+ public div ( other : Vec3 ) {
65+ this . x /= other . x ;
66+ this . y /= other . y ;
67+ this . z /= other . z ;
68+ }
69+
70+ public div_d ( x : number , y : number , z : number ) {
71+ this . x /= x ;
72+ this . y /= y ;
73+ this . z /= z ;
74+ }
75+
76+ public dot ( other : Vec3 ) {
77+ return this . x * other . x + this . y * other . y + this . z * other . z ;
78+ }
79+
80+ public dot_d ( x : number , y : number , z : number ) {
81+ return this . x * x + this . y * y + this . z * z ;
82+ }
83+
84+ public cross ( other : Vec3 ) {
85+ return new Vec3 ( this . y * other . z - this . z * other . y , this . z * other . x - this . x * other . z , this . x * other . y - this . y * other . x ) ;
86+ }
87+
88+ public cross_d ( x : number , y : number , z : number ) {
89+ return new Vec3 ( this . y * z - this . z * y , this . z * x - this . x * z , this . x * y - this . y * x ) ;
90+ }
91+
92+ public get length ( ) {
93+ return Math . sqrt ( this . dot ( this ) ) ;
94+ }
95+ }
0 commit comments