mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-12-02 12:05:50 +01:00
copilot rotate: reapply origin offset
This commit is contained in:
parent
3e123ddc56
commit
cbd2ae7df8
35
rotate.js
35
rotate.js
@ -16,6 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
function rotate_point_3d(origin, point, x, y, z)
|
function rotate_point_3d(origin, point, x, y, z)
|
||||||
{
|
{
|
||||||
|
point = [...point];
|
||||||
point[0] = point[0] - origin[0];
|
point[0] = point[0] - origin[0];
|
||||||
point[1] = point[1] - origin[1];
|
point[1] = point[1] - origin[1];
|
||||||
point[2] = point[2] - origin[2];
|
point[2] = point[2] - origin[2];
|
||||||
@ -35,7 +36,7 @@ function rotate_point_3d(origin, point, x, y, z)
|
|||||||
var y3 = x2 * Math.sin(z) + y2 * Math.cos(z);
|
var y3 = x2 * Math.sin(z) + y2 * Math.cos(z);
|
||||||
var z3 = z2;
|
var z3 = z2;
|
||||||
|
|
||||||
return [x3, y3, z3];
|
return [x3+origin[0], y3+origin[1], z3+origin[2]];
|
||||||
}
|
}
|
||||||
|
|
||||||
function deg_to_rad(deg)
|
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) + ")";
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
|
do_test(
|
||||||
|
[1, 0, 0],
|
||||||
console.log(point_to_string(rotate_point_3d(
|
[5, 0, 0],
|
||||||
[ 0, 0, 0 ],
|
|
||||||
[ 5, 0, 0 ],
|
|
||||||
deg_to_rad(0), // rotate around x axis = yz plane
|
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 y axis = xz plane
|
||||||
deg_to_rad(0) // rotate around z axis = xy 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