3D Rotation Along Local Axis (Not Global) Here's the Code. What's wrong?
The following code rotates an object in 3 dimensions: cosx = Math.cos(radx); sinx = Math.sin(radx); cosy = Math.cos(rady); siny = Math.sin(rady); cosz = Math.cos(radz); sinz = Math.sin(radz); //x-axis tx = x - cx; ty = y - cy; tz = z - cz; y = (ty * cosx) + (tz * sinx) + cy; z = (tz * cosx) - (ty * sinx) + cz; //y-axis tx = x - cx; ty = y - cy; tz = z - cz; x = (tx * cosy) + (tz * siny) + cx; z = (tz * cosy) - (tx * siny) + cz; //z-axis tx = x - cx; ty = y - cy; tz = z - cz; x = (tx * cosz) + (ty * sinz) + cx; y = (ty * cosz) - (tx * sinz) + cy; Since I rotate X first, X turns fine along its axis, but the Y and Z rotate to the global Y and Z instead of their own axes. However, if I rotate Y first, Y turns fine but X and Z doesn't. Similarly, if I rotate Z first, Z turns fine but X and Y doesn't. Any help as to how I can make them relative to each other? See draw() function in the JS section. Approx line: 160 https://code.sololearn.com/WxtqC6Ji8ZkL/?ref=app