mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-11-27 01:23:45 +01:00
copilot rotate: reapply origin offset
This commit is contained in:
parent
3e123ddc56
commit
cbd2ae7df8
37
rotate.js
37
rotate.js
@ -16,6 +16,7 @@
|
||||
*/
|
||||
function rotate_point_3d(origin, point, x, y, z)
|
||||
{
|
||||
point = [...point];
|
||||
point[0] = point[0] - origin[0];
|
||||
point[1] = point[1] - origin[1];
|
||||
point[2] = point[2] - origin[2];
|
||||
@ -34,8 +35,8 @@ function rotate_point_3d(origin, point, x, y, z)
|
||||
var x3 = x2 * Math.cos(z) - y2 * Math.sin(z);
|
||||
var y3 = x2 * Math.sin(z) + y2 * Math.cos(z);
|
||||
var z3 = z2;
|
||||
|
||||
return [x3, y3, z3];
|
||||
|
||||
return [x3+origin[0], y3+origin[1], z3+origin[2]];
|
||||
}
|
||||
|
||||
function deg_to_rad(deg)
|
||||
@ -48,13 +49,29 @@ function point_to_string(point, decimal_places=3)
|
||||
return "(x " + point[0].toFixed(decimal_places) + ", y " + point[1].toFixed(decimal_places) + ", z " + point[2].toFixed(decimal_places) + ")";
|
||||
}
|
||||
|
||||
function do_test(origin, point, ...args) {
|
||||
const result = rotate_point_3d(origin, point, ...args);
|
||||
console.log(`ORIGIN`, point_to_string(origin), `\tPOINT`, point_to_string(point), `\tRESULT`, point_to_string(result));
|
||||
}
|
||||
|
||||
|
||||
|
||||
console.log(point_to_string(rotate_point_3d(
|
||||
[ 0, 0, 0 ],
|
||||
[ 5, 0, 0 ],
|
||||
do_test(
|
||||
[1, 0, 0],
|
||||
[5, 0, 0],
|
||||
deg_to_rad(0), // rotate around x axis = yz plane
|
||||
deg_to_rad(90), // rotate around y axis = xz plane
|
||||
deg_to_rad(0) // rotate around z axis = xy plane
|
||||
)));
|
||||
deg_to_rad(0), // rotate around y axis = xz plane
|
||||
deg_to_rad(180) // rotate around z axis = xy plane
|
||||
);
|
||||
do_test(
|
||||
[1, 0, 0],
|
||||
[0, 1, 0],
|
||||
deg_to_rad(0), // rotate around x axis = yz plane
|
||||
deg_to_rad(0), // rotate around y axis = xz plane
|
||||
deg_to_rad(180) // rotate around z axis = xy plane
|
||||
);
|
||||
do_test(
|
||||
[10, 100, 0],
|
||||
[0, 0, 0],
|
||||
deg_to_rad(0), // rotate around x axis = yz plane
|
||||
deg_to_rad(0), // rotate around y axis = xz plane
|
||||
deg_to_rad(180) // rotate around z axis = xy plane
|
||||
);
|
Loading…
Reference in New Issue
Block a user