In Blender, I can set up an orthographic / isometric camera like so:
With the X, Y, and Z rotation set to those values, a cube has the following properties: all sides are rendered at equal length, and the lines are at perfect 30deg (or 120deg) angles from each other. In other words, if you zoomed into the corner of the square and measured the angles of all three lines going outward, one would be going straight up, and the other two would be 30deg off horizontal, like so:
So, my question is two-fold, I guess, because I want to be able to do this in 2 ways:
-
If I know the rotation of the camera in those X and Z degress in the first picture (assume Y is a constant 0), how can I calculate the resultant angles – those two angles I marked out as 30deg in the second picture? AND how can I calculate the proportional lengths of each side of a rendered square?
-
Basically the reverse of the above – say I just know the angles from the second picture, and I want to find out the camera angle to match – how can I do that?
Are there simple forumlas for these questions?
Best Answer
I actually found the answer. Or rather, kind of invented it.
The first step is to create your 1-unit "room", that hollowed out cube that you see in the question, which is 1 unit tall, 1 unit wide in the x direction, and -1 unit wide in the y direction (which is just the default way blender scenes are set up).
First, I had the idea that I was going to project that view onto a plane that matches the Camera's angle, and then figure out everything I want to know either from that plane, or by then converting all the points on that plane to a plane that's just pointing straight down.
But then I figured out that it's probably easier to actually convert the x,y,z vectors of the Unit Room we set up to be viewed as if they were being viewed from above - so rather than making a projection on to the rotated camera, and then unrotating the projection, what I do is I unrotate EVERYTHING - camera and the room, and then the projection kinda takes care of itself.
So I used this guide to figure out how to "unrotate" the x,y,z vectors of the unit room, and I implemented that. Then, as I was working on figuring out how to project that onto a plane facing straight downwards, I realized -- that's super easy to do! Just take the (x,y) coordinates from the previous step and ignore the z-coordinates.
So at that point, I have 4 points in 2 dimensions - the center point, the point at the end of the z-vector, the point at the end of the y-vector, and the point at the end of the x-vector. Using those points, now only in 2 dimensions, it's actually rather straightforward to calculate the angles between the vectors and the proportional lengths of them as projected onto the camera.
I wrote all my code out and saved it here: https://jsfiddle.net/3aqew0c9/3/
I wrote a bit about it here, but I'm going to make a UI for it as well.