File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11const std = @import ("std" );
22
3+
34const mach = @import ("../main.zig" );
45const testing = mach .testing ;
56const math = mach .math ;
@@ -142,24 +143,10 @@ pub fn Vec3(comptime Scalar: type) type {
142143 /// Vector * Quat multiplication
143144 /// https://github.com/greggman/wgpu-matrix/blob/main/src/vec3-impl.ts#L718
144145 pub inline fn mulQuat (v : * const VecN , q : * const quat .Quat (Scalar )) VecN {
145- const qx = q .v .x ();
146- const qy = q .v .y ();
147- const qz = q .v .z ();
148- const w2 = q .v .w () * 2 ;
149-
150- const vx = v .x ();
151- const vy = v .y ();
152- const vz = v .z ();
153-
154- const uv_x = qy * vz - qz * vy ;
155- const uv_y = qz * vx - qx * vz ;
156- const uv_z = qx * vy - qy * vx ;
157-
158- return math .vec3 (
159- vx + uv_x * w2 + (qy * uv_z - qz * uv_y ) * 2 ,
160- vy + uv_y * w2 + (qz * uv_x - qx * uv_z ) * 2 ,
161- vz + uv_z * w2 + (qz * uv_y - qy * uv_x ) * 2 ,
162- );
146+ const q_xyz = q .v .swizzle (.x , .y , .z );
147+ const uv = q_xyz .cross (v );
148+ const uuv = q .xyz (& uv );
149+ return v .add (& uv .mulScalar (q .v .w ()).add (& uuv ).mulScalar (2 ));
163150 }
164151
165152 pub const add = Shared .add ;
You can’t perform that action at this time.
0 commit comments