+ 6

Correct 3D Rotation Along Y and Z Axis? X is Perfect

This code was made based off my understanding of 3D, and how it is simulated in a 2D environment. Problem: Rotate all axes at random. After a while, stop them (not reset), and only rotate the x-axis (RX buttons). You will notice that the cuboid rotates relative to that red line, no matter the position or angle of the red line. Now reset and rotate them randomly again. This time choose to rotate only either the y axis or z axis. They do not rotate along their respective yellow and blue lines like intended. (Even the yellow and blue lines rotate incorrectly too along these unknown axes) I have no idea what is going on, but if anyone can understand the code or give me advice, help would be appreciated. https://code.sololearn.com/WxtqC6Ji8ZkL/?ref=app

28th Jun 2018, 3:07 AM
Andre Daniel
Andre Daniel - avatar
3 odpowiedzi
+ 6
To help you troubleshoot, stroke() your front face red, the back face black, and the connectors blue. Drop your speed to 1 (from 10). Show the axes if you like, but the face colors will help with what I'm saying next. First, the easier one to see: Regardless of the rotation around X, when you stop and then rotate around Z, the entire scene rotates as if Z is still a vector pointing directly through the screen, i.e., you appear to be rotating the projected/output points on the flat 2D canvas, not the translated axis. Try to ignore the axes here, just stare at the centerpoint and you should see it. Similarly, when you stop X at some point and then rotate around Y, that axis of rotation is still vertically from top to bottom on the output display; not the axis translated at the object. I am out of time tonight, but I hope this helps you.
28th Jun 2018, 6:51 AM
Kirk Schafer
Kirk Schafer - avatar
+ 1
Kirk Schafer Yes, I noticed those too. The difficulty is trying to get the Z to rotate on the blue line and not the entire screen, and to get the Y to rotate on the yellow line and not vertically from top to bottom. I'm going to look into the code some more to see where I can find the values for the translated canvas. But any more suggestions would be appreciated. Thanks! ☺
28th Jun 2018, 7:04 AM
Andre Daniel
Andre Daniel - avatar
0
Andre Daniel Hi. I currently dont have enough time to fully go trough your code. But i will at a later point. I have done rotation in 3D space aswell. In my code i have 3 functions rotXVec, rotYVec, and rotZVec. Maybe those will help you. If not i will write you if i found the bug in your code. https://code.sololearn.com/WMAMcxsrDQsM/?ref=app
29th Jun 2018, 3:37 PM
Dragonxiv
Dragonxiv - avatar