How can we convert coordinates of a 3D object into a 2D image?
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:
- mat4x4 makeProj(float fFovDegrees, float fAspectRatio,
- float fNear, float fFar)
- {
- float fFovRad = 1.0f / tanf(fFovDegrees * 0.5f /
- 180.0f * 3.14159f);
- mat4x4 matrix;
- matrix.m[0][0] = fAspectRatio * fFovRad;
- matrix.m[1][1] = fFovRad;
- matrix.m[2][2] = fFar / (fFar — fNear);
- matrix.m[3][2] = (-fFar * fNear) / (fFar — fNear);
- matrix.m[2][3] = 1.0f;
- matrix.m[3][3] = 0.0f;
- return matrix;
- }
- mat4x4 matProj = makeProj(90,
- (float)SCREEN_HEIGHT / (float)SCREEN_WIDTH,
- 0.1f, 1000.0f);
- for (triangle& tri : gameObj.tris) {
- triangle triProj;
- triProj.p[0] = matProj * tri.p[0];
- triProj.p[1] = matProj * tri.p[1];
- triProj.p[2] = matProj * tri.p[2];
- // do stuff with triProj, which is now 2D
- }