How can we convert coordinates of a 3D object into a 2D image?

Technical Source
1 min readOct 22, 2019

--

We provide latest MatLab Homework, Assignment Help for students, engineers and researchers in Multiple Branches like ECE, EEE, CSE, Mechanical, Civil with 100% output.
Matlab Code for B.E, B.Tech,M.E,M.Tech, Ph.D. Scholars with 100% privacy guaranteed. Get MATLAB projects with source code for your learning and research.

You use a projection matrix — 3D projection

For example:

  1. mat4x4 makeProj(float fFovDegrees, float fAspectRatio,
  2. float fNear, float fFar)
  3. {
  4. float fFovRad = 1.0f / tanf(fFovDegrees * 0.5f /
  5. 180.0f * 3.14159f);
  6. mat4x4 matrix;
  7. matrix.m[0][0] = fAspectRatio * fFovRad;
  8. matrix.m[1][1] = fFovRad;
  9. matrix.m[2][2] = fFar / (fFar — fNear);
  10. matrix.m[3][2] = (-fFar * fNear) / (fFar — fNear);
  11. matrix.m[2][3] = 1.0f;
  12. matrix.m[3][3] = 0.0f;
  13. return matrix;
  14. }
  15. mat4x4 matProj = makeProj(90,
  16. (float)SCREEN_HEIGHT / (float)SCREEN_WIDTH,
  17. 0.1f, 1000.0f);
  18. for (triangle& tri : gameObj.tris) {
  19. triangle triProj;
  20. triProj.p[0] = matProj * tri.p[0];
  21. triProj.p[1] = matProj * tri.p[1];
  22. triProj.p[2] = matProj * tri.p[2];
  23. // do stuff with triProj, which is now 2D
  24. }

--

--

Technical Source
Technical Source

Written by Technical Source

Simple! That is me, a simple person. I am passionate about knowledge and reading. That’s why I have decided to write and share a bit of my life and thoughts to.

No responses yet