Honours Graphics 2008 Session 3
Today’s focus Perspective and orthogonal projection Quaternions Graphics camera
Projections Visualizing 3D data on a 2D screen requires projection of the data onto a 2D plane Several projection models exist, with varying qualities We’re interested in orthogonal and perspective projection
Perspective projection
Perspective projection, cont. Starting from world coordinate space:
Increasing focal length and distance of the camera to infinity changes perspective into orthogonal projection
Orthogonal projection Flat, 2D projection Used when precise profiles or measurements need to be displayed Special case of perspective projection, when focal length approaches infinity
Quaternions Developed by Sir William Rowan Hamilton in 1843 Generally superceded by vectors and matrices, but still very useful in applied mathematics and computer graphics Specifically useful to compute 3D rotations Consists of scalar and “vector” components
Quaternions, cont. Defined as an extension to the complex numbers: three components i, j and k all are squareroots of -1, hence Furthermore
Quaternions, cont. Finally Quaternion addition and subtraction
Quaternions, cont. Magnitude of a quaternion Quaternion multiplication
Quaternions, cont. For graphics purposes a unit quaternion is used, which has the property that Unit quaternions represent rotation / orientation
Quaternions, cont. Quaternion to rotation matrix conversion
Graphics camera Both DirectX and OpenGL expose camera parameters that consist of View position View target Relative view-up direction
Camera commands OpenGL void gluLookAt(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ ) DirectX D3DXMatrixLookAtLH(mat, eye, center, up); DX9Device.SetTransform(D3DTS_VIEW, mat);
Homework Write a camera library that makes use of quaternions. Allow for keyboard and mouse input to control the camera. For next session