//Transformation matrix mat with a scaling void setScale(float *mat, float xScale, float yScale, float zScale) { setIdentMatrix(mat,4); mat[0] = xScale; mat[5] = yScale; mat[10] = zScale; }
// Transformation matrix mat with a translation void setTransMatrix(float *mat, float x, float y, float z) { setIdentMatrix(mat,4); mat[12] = x; mat[13] = y; mat[14] = z; }
void Camera::zoomCam(float zoom) { float zoomMat[16]; setTransMatrix(zoomMat, 0.0f, 0.0f, zoom); multiplyMatrix(zoomMat, viewMatrix); setIdentMatrix(viewMatrix, 4); multiplyMatrix(viewMatrix, zoomMat); }
// Projection Matrix void buildProjMatrix(float fov, float ratio, float nearP, float farP) { float f = 1.0f / tan (fov * (PI / 360.0)); setIdentMatrix(projMatrix,4); projMatrix[0] = f / ratio; projMatrix[1 * 4 + 1] = f; projMatrix[2 * 4 + 2] = (farP + nearP) / (nearP - farP); projMatrix[3 * 4 + 2] = (2.0f * farP * nearP) / (nearP - farP); projMatrix[2 * 4 + 3] = -1.0f; projMatrix[3 * 4 + 3] = 0.0f; }
Camera::Camera() { setIdentMatrix(viewMatrix, 4); }