Presentation is loading. Please wait.

Presentation is loading. Please wait.

Three-Dimensional viewing

Similar presentations


Presentation on theme: "Three-Dimensional viewing"— Presentation transcript:

1 Three-Dimensional viewing
Graphics 455

2 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.

3 The Viewing Process parallel projection
The view volume of the camera is a rectangular parallelepiped. Its side walls are fixed by coordinates of corners

4 The LookAt Coordinate System
Camera in world coordinates:

5 Camera model - parallel projection
y x z Near plane eye P’ Far plane P viewplane normal

6 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);

7 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

8 Viewplane normal v -n n eye look_at u n = eye - look_at

9 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.

10 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

11 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 , ) v= (-0.331, 0.883, ) n=(0.625, 0.469, 0.625) (dx,dy,dz)=(-eye.u,-eye.v,-eye.n)=(0,-0.883, )

12 Computing vectors of the new coordinate system
ux uy uz dx eyex vx vy vz dy eyey nx ny nz dz eyez u.eye +dx=0 v.eye +dy=0 n.eye +dz=0 =

13 Transformation matrix of the new coordinate system
dx= dy=-0.883 dz=-6.879 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

14 Camera model – perspective projection
y x z Near plane eye Far plane viewplane normal

15 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

16 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

17 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

18 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.

19 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.

20 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.

21 Example (2) In part b, the camera has been moved right, but everything else is the same.

22 Example (3) In part c, we look down from above and right on the barn.

23 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.

24 Projections in Open GL glFrustrum(left,right,bott,top,N,F) l,t B B’
eye A’ A N F r,b

25 Projections in Open GL gluPerspective(viewAngle,aspect,N,F) aspect
alpha B B’ eye A’ A N F

26 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

27 Projections in Open GL Projection matrix – simple case L=-(R)=B=-(T) N N a b 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

28 Transformation of the view volume
glFrustum(left,right,bottom,top,N,F);

29 Transformation of the view volume
glFrustum(-2,2,-2,2,1,10); glFrustum(-2,2,-2,2,1,10);

30 Transformation of the view volume
glFrustum(-2,2,-2,2,1,10); glFrustum(-2,2,-2,2,1,10);

31 Frustum – Perspective transformation
top=N tan(π/180 . viewAngle/2) bott=-top right=top*aspect left-=-right


Download ppt "Three-Dimensional viewing"

Similar presentations


Ads by Google