0
\$\begingroup\$

I have 3d vectors that I want to project as 2d vectors to draw my shapes. I got a 3d vector cameraPosition, a 3d vector cameraDirection, a float renderDistance. I need to create an orthogonal / isometric matrix with those values to project my 3d vectors.

Here is what I currently have :

matrix4x4(vec3 camera, vec3 camreaDir, vec3 camreraScale){
    //get isometric projection matrix
    vec3 xImage = vec3(-sinf(camreaDir.x), cosf(camreaDir.x), 0) * 
camreraScale.x; //unused member : z
    vec3 zImage = vec3(-sinf(camreaDir.x + camreaDir.z), cosf(camreaDir.x + camreaDir.z), 0) * camreraScale.z; //unused member : z

    matrix[0][0] = xImage.x;
    matrix[1][0] = 0;
    matrix[2][0] = zImage.x;
    matrix[0][1] = xImage.y;
    matrix[1][1] = camreraScale.y;
    matrix[2][1] = zImage.y;
}
\$\endgroup\$
0
\$\begingroup\$

You should try having a separate camera and projection matrix, since isometric projection is just ortographic with a very specific camera placement.

If you are using a modern matrix library (you should be), then those two can be created with built-in methods. The projection matrix is just an ortographic matrix, the camera matrix is a model matrix, where you first rotate the camera -45 degrees along the xz plane (y axis) and then -30 degrees along the yz plane (x axis). You could also move it back, but if you set the near and far values of your projection matrix so that it can show stuff behind the camera too, then you won't have any problems with it.

If your library doesn't have these functions or you rolled your own, then you can just replicate them based off of these pictures:

Projection matrix:

enter image description here

Rotation matrices:

enter image description here

\$\endgroup\$
  • \$\begingroup\$ So I create all of those and then I combine them to get the expected result ? (I can't use libraries) \$\endgroup\$ – Telno Mar 12 at 18:45
  • \$\begingroup\$ @Telno Yeah, but make sure the multiplication order is correct \$\endgroup\$ – Bálint Mar 12 at 19:13
  • \$\begingroup\$ What are right left exactly ? Far and near are probably distances to camera. \$\endgroup\$ – Telno Mar 12 at 19:54
  • \$\begingroup\$ @Telno The right and left coordinates of the view. Same for the top and bottom. For instance if you have a rectangle going from (-3, -3) to (0, 0) and your left and top is -3 and -3, then it will occupy the top left corner \$\endgroup\$ – Bálint Mar 12 at 20:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.