CS580
Building and Using Transformations
Ulrich Neumann
CS580
Computer Graphics Rendering
Building the matrices (Xsp)
Xsp matrix scales NDC to output device (FB size)
NDC is a used as a fixed rendering-target space(LH coords)
NDC is display-device and window-size independent
Perspective (NDC) space has a [-1, 1] visible range for (x,y) and origin at screen center
Square aspect-ratio for screen size and pixels (our definitions)
Screen coords are RH coords with origin in upper left
Map entire NDC visible range to screen with a scale and translation
Do a best-fit to NDC when Display FB is not square
Xsp = T S Where:
T shifts the origin and
S scales the NDC screen size to the FB size
Xsp=xs/200 xs/2
0-ys/20 ys/2
00 1 0
00 0 1
Building the matrices (Xsp)
Recall that NDC space is defined to have a bounded
z-range : z [0, 1]
Integer Z-buffer resolution has a fixed range [0-MAXINT] and we should scale z to use all of it
Scale NDC z by MAXINT
put MAXINT in Xsp[2][2]to scale screen-space
z-range :z [0, MAXINT]
Try it at extreme corners of NDC space
??= Xsp[0,0,0,1]
??= Xsp[1,1,0,1]
??= Xsp[0,0,1,1]
??= Xsp[-1,1,0,1]
.
You could set up 12 eqs like these to solve for top 3 rows of matrix terms.
Its much easier to build it as a T S transformation that meets our definitions of screen space and perspective space.
Note that Xsp has non-uniform scaling.This is one of the special cases where such a transformation occurs.
Xsp=xs/200 xs/2
0-ys/2 0 ys/2
00 MAXINT0
00 01
Building the matrices (Xpi)
Xpi matrix takes image space to perspective space
Image space has no bounds on X,Y, or Z
Perspective space (NDC) has the same origin and axis, but there is a singularity for points with Z = -d(due to perspective divide)
clip or cull all triangles with any vertex Z<0The projection term in Xpi is defined by the distance d from the view plane to focal point (also FOV)Points that project to visible-range of NDC space will be on screenPoints that project outside of visible-range should NOT appear in FBdFOV+1-11/d=tan(FOV/2)Xpi=1 00 00 10 00 01 00 01/d1 Building the matrices (Xpi)Recall that perspective-z is bounded z [0,d] by the perspective transformWe defined NDC z-range to be : z [0,1] so we need to scale z by 1/dPut 1/d into Xpi[2][2]Final Xpi maps all visible points into NDC bounded rangeNote that Xpi has non-uniform scaling.Xsp and Xpi are both special cases where suchtransformations are used. Xpi=1 00 00 10 00 01/d00 01/d1 Building the matrices (Xiw)XiwCamera matrix puts world coordinates into image-space (camera space) where they are relative to the camera and ready for projectionChoose a world coord position for the camera (view plane origin) = cChoose a world coord look-at point = lCompute camera Z-axis, Z = cl / || cl ||(normalized world-space vector)When camera z-axis is know, only one more constraint is needed to fully define the camera orientationChoose an up vector (any world-space vector) to constrain the cameras spin-orientation about its z-axisConstruct the camera Y-axis to lie in the plane created by the camera Z-axis and the up vectorThe Z-axis and up vector directions can not be the samePick (0, 1, 0) as the up vector in world space (for our example)Note that up vector need not be normalized so we could also use (3, 100, -20), for examplelcZupBuilding the matrices (Xiw)Construct : up’ = up – (up Z)Z The up vector is orthogonal to the camera Z-axis, by constructionup also lies in the plane created by the up-vector and Z-axisSo, up is the direction of the camera Y-axis, but we need to normalize it to use it as the camera axis : Y = up’ / || up’|| The camera X-axis is orthogonal to the Y-axis and Z-axis, so we can construct it by cross-product :X = (Y x Z)(LH coords for camera)The X axis should point out of the screen for the case drawnX = (Y x Z) = i (Yy Zz – Yz Zy) + j (Yz Zx – Yx Zz) + k (Yx Zy – Yy Zx) change the up direction to spin the camera about its Z-axislcZupupYXoutBuilding the matrices (Xwi)Computed camera X, Y, Zaxes are all normalized and orthogonal — and expressed as world space coords, so we can build Xwi directlyCamera origin in world coords : [cx, cy, cz] = Xwi [0, 0, 0]T camera origin translates to camera location in world spaceright column of Xwi matrix does this translation3x3 UR rotation has column vectors with the 3 camera axisX,Y,Z prior slides computed in world spacean input camera axis vector of [1,0,0] or [0,1,0] or [0,0,1] will output one of these columns as the world space vector for that axisXwi= Xx Yx ZxCx Xy Yy ZyCyXz Yz ZzCz 0 001 Building the matrices (Xiw)Xiw is the inverse of Xwi, shown on prior slideUse the decomposition : Xwi = T R Create R-1 and T-1 and concatenate them to get Xiw = R-1 T-1-The translation column elements become dot-products of two vectors during concatenationThe final result is shown below :Xiw=Xx XyXz -XCYx YyYz -YC Zx ZyZz -ZC0 001 *Using Transformations for Animation and Scene SetupPlace a model in the worldModels world position and orientation is defined by Xwm Push Xwm onto initialized stack with XswNow stack has Xsm so render the model If Xwm = T then model origin becomes point = T in world spaceNote that the model and world axes are aligned so the model orientation in the world is determined by the world axesIf Xwm = TSR then model coords/axes are rotated about model origin, scaled in/out of model origin, and then translated with the origin moving to point T in world spaceModel in Model SpaceWorld Space origin-axisXwm places model in World SpaceThink of the model origin (0,0,0)and axes (1,0,0) (0,1,0) (0,0,1) transformedby Xwm to their world position and orientations camera looking at origin, for example, is setup as part of Xswxyz xyz yxzHow to Instance N-ChairsGiven a chair world position T, orientation R, and size SXwm = T R S Assume origin of chair model is suitable for scaling and rotationA good suitable origin is a point in the middle of the leg-bottomsScale the chair model about its origin to the desired sizeRotate the scaled chair about its origin to the desired orientationTranslate the chair to its desired position in the world Concatenate above transforms to create one matrix Xwm = T R S Start with initialized Xsw on stackPush a new Xwm on stack(stack now has Xsm )Render the chair modelPop to remove Xwmrepeat this 3-step sequence with new Xwm = TRS for each chairOrbit a Model about a PointPushing Xwm = TSR on stack places/orients the model.R rotates the model about its origin prior to scale and translation (spinning in place)To orbit the model about point P (rotation about Y-axis), position and orient the model to a point along the orbit path (at radius from P with same Y-coord) Then move the origin to P and use it as a fixed point for the rotation about the Y-axis (P is defined in World Space)Lastly, put the origin back to the world space axes so the model cords are in world space again for renderingNote, the same cube face will always face PModel in Model SpaceWorld Space origin-axisP = Point in World SpaceXwm=TSR places model in World SpaceThe cube always faces Pxyz xyz Orbit a Model about a Point (2)Application builds an Ri as a pure rotation about the Y-axis whose angle can be varied from frame to frame (to create an animation)Orient cube in model space and place model in world with X =TSR[X]Translate by Tp = P to move origin from world origin to P[Tp]Rotate by Ri about P(about Y-axis)[Ri]Translate by P or [Tp]-1 to reset world origin[Tp]-1Assume initial stack state = Xsw ready for model matrixPush[Tp]-1then[Ri]then[Tp]then[X]Stack has: [Xsw] [Tp]-1 [Ri] [Tp] [X] ready for model renderingModel in Model SpaceWorld Space origin-axisX=TSR places model in World SpaceP = Point in World SpaceThe cube always faces Pxyz xyz Orbit a Model about a Point (3)* Follow the origin/axes in the transformations:[Xsw] [Tp-1] [Ri] [Tp] [X] OriginAxes[Xsw] [Tp-1] [Ri] [Tp] [X] * : Model Model (given)[Xsw] [Tp-1] [Ri] [Tp] * [X] :Worldrotated World[Xsw] [Tp-1] [Ri] * [Tp] [X] 😛 rotated World[Xsw] [Tp-1] * [Ri] [Tp] [X] 😛 World[Xsw] * [Tp-1] [Ri] [Tp] [X] : World World (given)Model in Model SpaceWorld Space origin-axisX=TSR places model in World SpaceP = Point in World SpaceThe cube always faces Pxyz xyz Orbit a Model about a Point (4)PLooking down the y-axisMAfter:[X] M places/orients model in world PMAfter:[Tp] [X] M moves origin to P (-15,0,0) (-10,0,0)(0,0,0)(0,0,0)(5,0,0) (15,0,0)PM(0,0,0)(4.9 ,0, .85) (14.7, 0, 2.25)After:[Ri] [Tp] [X] M rotates about P(10 degree rotation for example)PM(-15,0,0)(-10.1, 0, 0.85)(0, 0, 0)After: [Tp]-1 [Ri] [Tp] [X] resets originNote: the original origin and the new origin are not the same pointsxzWxzxzWxzxzWxzxzxzWOrbit a Model about a Point (5)Other transformation sequences can be created to get a similar resultOrbit about P is also achieved by this sequence:Use [X]=TSR to place model at desired radius from world origin : [X]Do the incremental rotation about world origin : [R] [X]Translate model by Tp=P to make it appear to rotate about P : [Tp] [R] [X]Final stack transformation sequence is : [ Xsw ] [Tp] [R] [X]Model in Model SpaceWorld Space origin-axisP = Point in World Spacexyz xyz
Reviews
There are no reviews yet.