3D Engine - Projection Matrix
Hi
Im basically building a 3d engine (very simple one) using software rendering (no opengl or directx) for learning purposes.
The 3d engine has one simple rendering method thats suppose to render a point from world space to the 2d space (monitor)
i believe i got the rendering working properly, but it has no perspective
i believe i need a perspective matrix
can you pros help me build one
publicstatic Pixel2D render(Camera c, Pixel3D p){
//matrix transformations (with euler style rotation)
//fm = pm * cm * wm * point
double fm[][];
double om[][] = createMatrix(4, 1);
double cm[][];
double ctm[][] = createIdentityMatrix(4);//camera translation
double crxm[][] = createIdentityMatrix(4);//camera x-axis rotation
double crym[][] = createIdentityMatrix(4);//camera y-axis rotation
double crzm[][] = createIdentityMatrix(4);//camera z-axis rotation
double pm[][] = createIdentityMatrix(4);//perspective matrix
double rx = Math.toRadians(c.getRoll());
double ry = Math.toRadians(c.getPitch());
double rz = Math.toRadians(c.getYaw());
//camera matrix
//translation
ctm[0][3] = c.getX();
ctm[1][3] = c.getY();
ctm[2][3] = c.getZ();
//roll
crxm[1][1] = Math.cos(rx);
crxm[1][2] = Math.sin(rx);
crxm[2][1] = -Math.sin(rx);
crxm[2][2] = Math.cos(rx);
//pitch
crym[0][0] = Math.cos(ry);
crym[0][2] = -Math.sin(ry);
crym[2][0] = Math.sin(ry);
crym[2][2] = Math.cos(ry);
//yaw
crzm[0][0] = Math.cos(rz);
crzm[0][1] = Math.sin(rz);
crzm[1][0] = -Math.sin(rz);
crzm[1][1] = Math.cos(rz);
cm = multiplyMatrix(crxm, crym);
cm = multiplyMatrix(cm, crzm);
cm = multiplyMatrix(cm, ctm);
//projection matrix
pm[3][2] = 1;
pm[3][3] = 0;
//object matrix (point)
om[0][0] = p.getX();
om[1][0] = p.getY();
om[2][0] = p.getZ();
om[3][0] = 1;
//we have no world matrix
//fm = multiplyMatrix(pm, cm);
//fm = multiplyMatrix(cm, om);
fm = multiplyMatrix(cm, om);
returnnew Pixel2D( (int) fm[0][0], (int) fm[1][0], p.getColour());
}
for complete source code so far: http://williamchan.brixonsolutions.com/myworks/java/graphics3d/source.php

