1 / 33

CS 376

Michael Eckmann - Skidmore College - CS 376 - Spring 2007. Specifying an arbitrary view ... One note, the VUP vector is allowed to be specified as not perpendicular to VPN. ...

Angelica
Télécharger la présentation

CS 376

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


    Slide 1:CS 376 Introduction to Computer Graphics

    02 / 26 / 2007 Instructor: Michael Eckmann

    Slide 2:Todays Topics

    Questions? Specifying an arbitrary perspective view Developing the composite transform for an arbitrary perspective view Arbitrary view examples 3D view volume clipping

    Slide 3:Specifying an arbitrary view

    To specify an arbitrary view, we should be able to place the view plane anywhere in 3d. we'll need to specify the direction of the plane and where it lives within the world reference coordinate system (WRC) we'll also need to know which direction is up (to know what is displayed at the top of the image when we transform to viewport. A common way to specify an arbitrary view is to specify the following: a View Reference Point (VRP) which is a point on the plane a View Plane Normal (VPN) which is the normal vector to the plane a View Up Vector (VUP) which is a vector from which we determine which way is up See diagram. Is that enough info to specify an arbitrary view in your opinion? One note, the VUP vector is allowed to be specified as not perpendicular to VPN. The up direction (determined by a relation of the directions of VPN and VUP) though is perpendicular to VPN.

    Slide 4:Specifying an arbitrary view

    The VRP, VPN and VUP create another reference coordinate system. We call this the view reference coordinate system (VRC). We name the principle axes u, v and n. Within VRC we specify a window on the view plane with Center of Window (CW) and min and max u and v values a Projection Reference Point (PRP) which is the CoP for perspective views Front and Back clipping planes specified as distances F and B, from VRP along the VPN see next diagram. In the World Reference Coordinate (WRC) system we define VRP, VPN and VUP In the View Reference Coordinate (VRC) system we define CW, PRP, F and B

    Slide 5:View Volumes

    To be able to clip against the canonical view volume and still allow any desired arbitrary view volume we'll need to normalize the desired view volume to the canonical view volume. So, the procedure to project from 3d to 2d given a finite view volume, will be as follows: apply a normalizing transform to get to the canonical view volume clip against the canonical view volume project onto the view plane transform into viewport

    Slide 6:Normalizing to CVV

    Now we're ready to develop the normalizing transformation for perspective projections. This will transform world coordinate positions so that the view volume is transformed into the canonical view volume. After this transform is applied, we would clip against the CVV and then project onto the view plane (via a perspective projection matrix).

    Slide 7:Normalizing to CVV

    The steps to do this are as follows: Given the following: VRP, VPN, VUP, PRP, u and v min and max, F and B 1. Translate VRP (view reference point) to origin 2. Rotate the VRC (view reference coordinate system) so that VPN (n-axis) lies on the z-axis, the u-axis lies on the x-axis and the v-axis lies on the y-axis 3. Translate PRP (the Projection Reference Point which is CoP) to the origin 4. Shear so the center line of the view volume lies on the z-axis 5. Scale so that the view volume becomes the canonical view volume Take a look at the pictures

    Slide 8:Translate VRP to origin

    1. T(-VRP) = [ 1 0 0 -VRPx ] [ 0 1 0 -VRPy ] [ 0 0 1 -VRPz ] [ 0 0 0 1 ]

    Slide 9:Rotate VRC

    2. Rotate the VRC in the following way: we want u to go to (1, 0, 0) we want v to go to (0, 1, 0) we want n to go to (0, 0, 1) make them have the correct directions and magnitude 1 n = VPN / | VPN | u = (VUP x n) / | VUP x n | v = n x u

    Slide 10:Rotate VRC

    2. we want u to go to (1, 0, 0) we want v to go to (0, 1, 0) we want n to go to (0, 0, 1) R = [ ux uy uz 0 ] [ vx vy vz 0 ] [ nx ny nz 0 ] [ 0 0 0 1 ] example: This matrix transforms the v vector to (0, 1, 0)

    Slide 11:Rotate VRC

    2. To check, show this matrix transforms the v vector to (0, 1, 0) [ ux uy uz 0 ] [ vx ] [ u . v ] [ 0 ] [ vx vy vz 0 ] [ vy ] = [ v . v ] = [ 1 ] [ nx ny nz 0 ] [ vz ] [ n . v ] [ 0 ] [ 0 0 0 1 ] [ 1 ] [ 1 ] [ 1 ] dot product of perpendicular vectors is 0 (cos 90 = 0) and dot product of a vector with itself is its magnitude squared 1*1 = 1

    Slide 12:Translate PRP to origin

    3. T(-PRP) = [ 1 0 0 -PRPu ] [ 0 1 0 -PRPv ] [ 0 0 1 -PRPn ] [ 0 0 0 1 ]

    Slide 13:Shear

    4. Now we want to shear so the center line is on z-axis. (To see why we don't simply want to rotate look at the diagram on the handout to see the cross-section of the view volume after the first 3 steps are performed.) Notice the CW is on that line and so is the origin (which PRP got translated to.) So, to get that center line on the z-axis, we want the direction of the vector CW PRP to be in the (DoP) direction of projection [0,0,z].

    Slide 14:Shear

    4. [ ( umin + umax) /2 ] [ PRPu ] CW = [ ( vmin + vmax) /2 ] PRP = [ PRPv ] [ 0 ] [ PRPn ] [ ( umin + umax) /2 PRPu ] CW PRP = [ ( vmin + vmax) /2 PRPv ] [ 0 PRPn ]

    Slide 15:Shear

    4. SHper = [ 1 0 SHx 0 ] [ 0 1 SHy 0 ] [ 0 0 1 0 ] [ 0 0 0 1 ] [ 1 0 SHx 0 ] [ ( umin + umax) /2 PRPu ] [ 0 ] [ 0 1 SHy 0 ] [ ( vmin + vmax) /2 PRPv ] = [ 0 ] [ 0 0 1 0 ] [ 0 PRPn ] [ DoPz ] [ 0 0 0 1 ] [ 1 ] [ 1 ] So, DoPz = PRPn Solve for SHx and SHy and get SHx = ( ( umin + umax) /2 PRPu ) / PRPn SHy = ( ( vmin + vmax) /2 PRPv ) / PRPn

    Slide 16:Scale

    5. A few notes about the diagram that shows the scaling There is a mistake where y= (vmax vmin )/2 and y= -(vmax vmin )/2 are pointing to the top of the back clipping plane. Instead they should be pointing to the top of the viewing window which is the middle vertical line. Second, the diagram shows a value vrp'z which is equal to -PRPn

    Slide 17:Scale

    5. scaling done in 2 steps first scale in x and y (to make the sloped planes be unit slopes) second scale uniformly (in x,y,z) so that back clipping plane is at z = -1, and the unit slopes remain unit slopes To scale in x and y we have a matrix of the form: [ sx1 0 0 0 ] [ 0 sy1 0 0 ] [ 0 0 1 0 ] [ 0 0 0 1 ] From the diagram (a) y= -(vmax vmin )/2 is the y value of the bottom of the window. We want that bottom side of the view volume to lie on the y=z plane which is a unit slope, so we want y= -(vmax vmin )/2 = z. z for the viewing window is -PRPn . So, we need to figure out what scale factor will make -(vmax vmin )/2 equal to -PRPn . sy1 = 2 PRPn / (vmax vmin )

    Slide 18:Scale

    5. (see diagram) This is similar in the x direction, but the viewing window range in x direction is (umax to umin ) so, to scale in x and y so that the 4 sloped planes are unit slope, we set the scales to be: sx1 = 2 PRPn / (umax umin ) sy1 = 2 PRPn / (vmax vmin )

    Slide 19:Scale

    5. (see diagram) to then scale so that back clipping plane is at z = -1 (do the scaling uniformly (in x y and z) so that the 4 sloped planes remain unit slope.) We have a matrix of the form [ sx2 0 0 0 ] [ 0 sy2 0 0 ] [ 0 0 sz2 0 ] [ 0 0 0 1 ] we want the z = -PRPn + B plane to be the z = -1 plane . So, we need to figure out what scale factor will make -PRPn + B be -1. sx2 = -1 / (-PRPn + B) sy2 = -1 / (-PRPn + B) sz2 = -1 / (-PRPn + B) where B is the distance to the back clipping plane from -PRPn

    Slide 20:Scale

    5. final scale matrix Sper = [ sx2 0 0 0 ] [ sx1 0 0 0 ] [ 0 sy2 0 0 ] [ 0 sy1 0 0 ] [ 0 0 sz2 0 ] [ 0 0 1 0 ] [ 0 0 0 1 ] [ 0 0 0 1 ]

    Slide 21:Perspective Normalization

    Composit matrix transformation to do Normalization of arbitrary perspective projection view volume to canonical view volume Nper = Sper SHper T(-PRP) R T(-VRP)

    Slide 22:Arbitrary 3d View examples

    Let's take a look at a couple of examples in the handout. 1st let's reacquaint ourselves with the world coordinates of the object (house) 2nd look at figure 6.29 and then its results in 6.28 3rd look at figure 6.30 which gives the same result with different parameters (change VRP, causes a required change in PRP and the Window Coordinates too to give the same result.) Because VRP changes, the origin of the u-v-n VRC system changes. Therefore, since PRP and CW and the umin, umax, vmin and vmax are all within VRC, they need to change if we want to have the same view.

    Slide 23:Arbitrary 3d View examples

    Let's look at the two point perspective view given in 6.22 We need to orient the view plane so that it cuts both the x and z coordinate axes. See figure 6.32 and that VPN is (1,0,1) which is a vector from the origin on the x-z plane at 45 degrees between the positive x and positive z axes. (I'll draw on board.) So, that VPN makes the view plane oriented such that it cuts both x and z axes at the same angle. What can you say about the view plane in relation to y? The parameters as stated in the handout have the VRP at the bottom right corner of object, so that makes the view plane oriented via the VPN and positioned so that VRP is on it.

    Slide 24:Arbitrary 3d View examples

    Also, VRP being where it is has an effect on where you place PRP and the window parameters because these are in the VRC system of which VRP (in WCS) is at the origin (in VRC).

    Slide 25:Arbitrary 3d View examples

    In the handout description of the viewing parameters for figure 6.34 it says all parameters are the same except view up vector is 10 degrees away from y axis. Notice the house is tilted slightly to the right (compared to the figure 6.22) so the up direction is tilted towards the left. To figure out a vector that's 10 degrees away from (0,1,0) we can keep 0 and 1 constant and solve for z of the new vector.

    Slide 26:Arbitrary 3d View examples

    So, the dot product of v1=(0,1,0) with v2=(0,1,z) is 1. Then use other equation for dot product: |v1||v2|cosA = 1 |v1| = 1 |v2| = sqrt(1+z*z) So, sqrt(1+z*z) cos A = 1 A=10 degrees. so, cosA is about .985 So, sqrt(1+z*z) = 1/.985, then square both sides to get 1+z*z = 1.0307, z*z = 0.0307, then sqrt of both to get z = 0.175 A Vup vector of (0, 1, 0.175) could have approximately that effect.

    Slide 27:View volume

    Slide 28:3d Clipping

    The view volume on the last slide has 6 faces For a canonical view volume the faces are the on the following planes: x = z, x = -z, y = z, y = -z, z = -zmin, z = -1 the 2 vertical faces (the front and back clipping planes) are on z = -zmin, z = -1 the two side faces are on x = z, x = -z the top and bottom faces are on y = z, y = -z the view volume lives totally in -z, so which plane is the top face on? y = z or y = -z

    Slide 29:3d Clipping

    Cohen Sutherland's extension into 3d from 2d. A six bit (as opposed to 4 in 2d) outcode is used here. 1 = true, 0 = false Bit 1 = above view volume (y > -z) Bit 2 = below view volume (y < z) Bit 3 = right of view volume (x > -z) Bit 4 = left of view volume (x < z) Bit 5 = behind view volume (z < -1) Bit 6 = in front of view volume (z > zmin) This leads to 27 different outcode volumes See drawing on board.

    Slide 30:3d Clipping

    Trivially accept if both endpoints have outcodes of 000000. Trivially reject if logical AND of the outcodes of the endpoints is 000000. When would the logical AND of the outcodes be 000000? Calculate intersection with borders in order if can't trivially accept or reject.

    Slide 31:3d Clipping

    the parametric equation of a line is: x = x0 + t (x1 x0) y = y0 + t (y1 y0) z = z0 + t (z1 z0), 0 <= t <= 1 To calculate the intersections of lines with the unit slope planes of the cvv, is easy. For y = z, y0 + t (y1 y0) = z0 + t (z1 z0) and we can solve for t. Then use t to find the x and y coordinate and z = y so we already know z.

    Slide 32:3d Clipping

    Then, once we have the x y and z coordinates of the intersection we can determine if the intersection is actually on a face of the view volume or the intersection is not on a face of the view volume if the intersection is not on a face, then we exclude the portion of the line outside that plane (away from the view volume) and recalculate the region code of the intersection if the intersection is on a face, we keep that intersection as a final endpoint and exclude the portion of the line outside that plane, recalculate region code too. Another nice feature of this algorithm is that when given two endpoints of the line segment and their region codes, even if we can't trivially accept or reject them, we can tell which planes they intersect (when corresponding bits are different.) Therefore, we only have to clip that line against those planes.

    Slide 33:3d Clipping

    Calculating the intersections at unit slopes is easier than at arbitrary slopes, hence the decision to normalize to a canonical view volume. x = x0 + t (x1 x0) y = y0 + t (y1 y0) z = z0 + t (z1 z0), 0 <= t <= 1 Recall an arbitrary plane is Ax + By + Cz + D = 0 (the equation of a plane.) Now, it should be obvious that more calculations are involved in finding the intersection of a line with an arbitrary plane than with simple planes like y = z, z = -1, etc.

More Related