Three-Dimensional viewing Graphics 455
Perspective Projections of 3-D Objects The graphics pipeline: vertices start in world coordinates; after MV, in eye coordinates, after P, in clip coordinates; after perspective division, in normalized device coordinates; after V, in screen coordinates.
The Viewing Process parallel projection The view volume of the camera is a rectangular parallelepiped. Its side walls are fixed by coordinates of corners
The LookAt Coordinate System Camera in world coordinates:
Camera model - parallel projection y x z Near plane eye P’ Far plane P viewplane normal
Setting the View Volume To view a scene, we move the camera and aim it in a particular direction. glMatrixMode(GL_MODELVIEW); // make the modelview matrix current glLoadIdentity(); // start with a unit matrix gluLookAt(eye.x, eye.y, eye.z, look.x, look.y, look.z, up.x, up.y, up.z);
Example glMatrixMode (GL_PROJECTION); // set the view volume (world coordinates) glLoadIdentity(); glOrtho (-3.2, 3.2, -2.4, 2.4, 1, 50); glMatrixMode (GL_MODELVIEW); // place and aim the camera glLoadIdentity (); gluLookAt (4, 4, 4, 0, 1, 0, 0, 1, 0); // modeling transformations go here
Viewplane normal v -n n eye look_at u n = eye - look_at
gluLookAt and the Camera Coordinate System gluLookAt takes the points eye and look, and the vector up n must be parallel to eye - look, so it sets n = eye - look u points "off to the side", so it makes u perpendicular to both n and up: u = up x n v must be perpendicular to n and u, so it lets v = n x u Note that v and up are not necessarily in the same direction, since v must be perpendicular to n, and up need not be.
Computing vectors of the new coordinate system n = eye – look (new z-coordinate) u = up x n (new x-coordinate) v = n x u (new y-coordinate) v up eye look u
Computing vectors of the new coordinate system Example: glLookAt(4,4,4,0,1,0,0,1,0) eye=(4,4,4) look=(0,1,0) up=(0,1,0) u=(4,0,-4) v=(-12,32,-12) n=(4,3,4) After normalization u = (0.707, 0 , -0.707) v= (-0.331, 0.883, -0.331) n=(0.625, 0.469, 0.625) (dx,dy,dz)=(-eye.u,-eye.v,-eye.n)=(0,-0.883, -6.879)
Computing vectors of the new coordinate system ux uy uz dx eyex 0 vx vy vz dy eyey 0 nx ny nz dz eyez 0 0 0 0 1 1 1 u.eye +dx=0 v.eye +dy=0 n.eye +dz=0 =
Transformation matrix of the new coordinate system 0.707 0 -0.707 dx=0 -0.331 0.883 -0.331 dy=-0.883 0.625 0.469 0.625 dz=-6.879 0 0 0 1 V= Coordinates of vector D=(dx,dy,dz )are chosen to fulfill equation: V x(eyex, eyey,eyez,1 )T=(0,0,0,1) new center of coordinate system is point eye
Camera model – perspective projection y x z Near plane eye Far plane viewplane normal
Perspective projections of 3D- objects The new center of coordinate system after aplication glLookAt(..) function is in the point eye and the direction of projection is z-axis. x,y,z x*,y* focus Projection plane
Perspective projections of 3D- objects How to realize perspective projection in graphical program? Projection plane x P(x,y,z) x*,y* F z z N x*/Px=N/-Pz y
Perspective projections of 3D- objects A similar situation for y* coordinate: (x*,y*)=(N.Px /-Pz , N.Py /-Pz ) Properties of perspective projection 1. Perspective foreshortening, distances between projected points depend on the distance from projective plane B B’ A’ A
Perspective projections of 3D- objects 2. denominator 0 means that the projected point is in the camera position. We clip all objects into predefined volume. 3. By clipping we avoid also situation when projected point is “behind” focal point (positive z-coordinate). 4. Distance N serves as scaling factor. Choosing a new projective plane that is parallel to previous one create similar scaled image. 5. straight line is projected to straight line or to a point.
Projections in Open GL glFrustum(left,right,bott,top,N,F) gluPerspective(viewAngle,aspect,N,F) Both functions work together with LookAt function. After transformation to a new coordinate system, view volume is defined.
Example: Projections of the Barn View #1: The near plane coincides with the front of the barn. In camera coordinates all points on the front wall of the barn have Pz = -1 and those on the back wall have Pz = -2. So any point (Px, Py, Pz) on the front wall projects to P’ = (Px, Py) and any point on the back wall projects to P’ = (Px /2, Py / 2). The foreshortening factor is two for points on the back wall. Note that edges on the rear wall project at half their true length. Also note that edges of the barn that are actually parallel in 3D need not project as parallel.
Example (2) In part b, the camera has been moved right, but everything else is the same.
Example (3) In part c, we look down from above and right on the barn.
Projections in Open GL glFrustum(left,right,bott,top,N,F) gluPerspective(viewAngle,aspect,N,F) Both functions work together with LookAt function. After transformation to a new coordinate system, view volume is defined.
Projections in Open GL glFrustrum(left,right,bott,top,N,F) l,t B B’ eye A’ A N F r,b
Projections in Open GL gluPerspective(viewAngle,aspect,N,F) aspect alpha B B’ eye A’ A N F
Projections in Open GL Adding pseudodepth (x*,y*,z*)=(N.Px /-Pz, N.Py /-Pz, (a.Pz+b)/-Pz,) value of z* varies from -1 to 1 a=-((F+N)/(F-N)), b=(-2FN/F-N) for Pz = -N z*=-1 for Pz = -F z*=1
Projections in Open GL Projection matrix – simple case L=-(R)=B=-(T) N 0 0 0 0 N 0 0 0 0 a b 0 0 -1 0 M.(Px ,Py, Pz ,1)T=(N.Px /-Pz, N.Py /-Pz, (a.Pz+b)/-Pz,)T (N.Px /-Pz, N.Py /-Pz, (a.Pz+b)/-Pz,,1) (N.Px /-Pz, N.Py /-Pz, 0) Projection
Transformation of the view volume glFrustum(left,right,bottom,top,N,F);
Transformation of the view volume glFrustum(-2,2,-2,2,1,10); glFrustum(-2,2,-2,2,1,10);
Transformation of the view volume glFrustum(-2,2,-2,2,1,10); glFrustum(-2,2,-2,2,1,10);
Frustum – Perspective transformation top=N tan(π/180 . viewAngle/2) bott=-top right=top*aspect left-=-right