void Camera::BuildProjectionMatrix() { float d = 1.0f; //float d = tan( Maths::MathHelper::ToRadian( m_fov ) / 2 ); m_projectionMatrix( 0, 0 ) = -d; m_projectionMatrix( 1, 1 ) = -d * m_aspectRatio; m_projectionMatrix( 2, 2 ) = 1.0f; //m_projectionMatrix._m[2][2] = -d; m_projectionMatrix( 3, 2 ) = 1.0f; m_projectionMatrix( 3, 3 ) = 0.0f; }
void Camera::getGLProjectionMatrixf(float* matrix) { for (unsigned int i = 0; i < 4; ++i){ for (unsigned int j = 0; j < 4; ++j){ matrix[i * 4 + j] = m_projectionMatrix(j, i); } } }
void Camera::setPerspProjection() { float f= 1.0/tan(Utilities::u_radians(m_FOV)/2.0); m_projectionMatrix.setIdentity(); m_projectionMatrix(0,0)=f/m_aspect; m_projectionMatrix(1,1)=f; m_projectionMatrix(2,2)=(m_farPlane+m_nearPlane)/(m_nearPlane-m_farPlane); m_projectionMatrix(3,2)=(2*m_farPlane*m_nearPlane)/(m_nearPlane-m_farPlane); m_projectionMatrix(2,3)=-1; m_projectionMatrix(3,3)=1.0; }
void Camera::computeProjectionMatrix() { switch (m_type) { case CameraType::PERSPECTIVE: { const float f = 1.0 / tan(m_fieldOfView / 2.0); m_projectionMatrix(0, 0) = f / getAspectRatio(); m_projectionMatrix(1, 1) = f; m_projectionMatrix(2, 2) = (m_nearPlane + m_farPlane) / (m_nearPlane - m_farPlane); m_projectionMatrix(3, 2) = -1.0; m_projectionMatrix(2, 3) = 2.0 * m_nearPlane * m_farPlane / (m_nearPlane - m_farPlane); m_projectionMatrix(3, 3) = 0.0; // same as gluPerspective( 180.0*fieldOfView()/M_PI, aspectRatio(), zNear(), zFar() ); break; } case CameraType::ORTHOGRAPHIC: { m_projectionMatrix(0, 0) = 1.0 / static_cast<float>(m_screenWidth); m_projectionMatrix(1, 1) = 1.0 / static_cast<float>(m_screenHeight); m_projectionMatrix(2, 2) = -2.0 / (m_farPlane - m_nearPlane); m_projectionMatrix(3, 2) = 0.0; m_projectionMatrix(2, 3) = (m_farPlane + m_nearPlane) / (m_nearPlane - m_farPlane); m_projectionMatrix(3, 3) = 1.0; // same as glOrtho( -w, w, -h, h, zNear(), zFar() ); break; } } }