I am currently working on developing a 3D renderer using JavaScript.
Rendering cubes is going well, but I am looking to implement a rotation function for each cube.
The goal is to rotate the x/y/z (pitch, roll, yaw) of every cube around its own axis.
This function handles 3D rotation:
let rotate3d = (points = [0,0,0], pitch = 0, roll = 0, yaw = 0) => {
// rotation function code here
}
And here is a snippet from my renderer routine:
// cube rotation and rendering code here
}
Illustration: When the cube is placed at [0, -1, 0], it rotates around the y-axis in a clockwise direction. But if the spawn point is changed to [1, -1, 0], the cube rotates around the origin with a distance of 1 unit. I want the cube to rotate around its spawn point!
Update: Details of the cube spawning routine:
// cube spawn function code here
My query is: How can I modify the rotate function to specify an origin point for rotating the cube around it?