470 likes | 646 Views
Chapter 10: Coordinate Systems. This Chapter: we will learn. the w2n transform World and Normalized Device Coordinate Systems World Coordinate Window Coordinate Transformation. Transformation of Tut 3.1 (10.1). In all tutorials, we … Initialize M W M V M P to identity
E N D
Chapter 10: Coordinate Systems Chapter 10
This Chapter: we will learn • the w2n transform • World and Normalized Device Coordinate Systems • World Coordinate Window • Coordinate Transformation Chapter 10
Transformation of Tut 3.1 (10.1) • In all tutorials, we … • Initialize MW MV MP to identity • Compute world2ndc and load into MV Chapter 10
The world2ndc transform Chapter 10
All vertices are transformed! • D3D transforms all vertices (Vi) by • If • Then Chapter 10
Tutorial 3.1: re-visit Transformed to … Chapter 10
Tut 10.2: Drawing without w2n Observation: -1 ≤ x/y ≤ +1 Chapter 10
Tut 10.3: Verify ±1 Range • Window Dimension • 200 pixels x 200 pixels • Draw a unit circle • Center at (0,0) • Radius = 1.0 • Observe indeed: • NDC – Normalized Device Coordinate Chapter 10
Tut 10.4/10.5: Experiment with NDC • Tutorial 10.4: • Same Unit circle • 100x200 pixel area • Tutorial 10.5: • Same Unit circle • 200x100 pixel area Chapter 10
Observations: • Remember: • In this case: • MV MW MP: are initialized to Identity • All vertices are in NDC (±1) • Output always forced into entire device drawing area! Chapter 10
Conclusion: NDC to Device!! • NDC to Device Space automatically • Where: Chapter 10
NDC to Device Transform Chapter 10
Device Coordinate (DC) System • Defined on the device • Lower left as origin • For “Windows” • Units are in pixels • Compare to Hardware Coordinate • Origin at upper left Chapter 10
Normalized Device Coordinate (NDC) System • X/Y ranges between -1 to +1 • 2x2 square area • All Graphics API • Expects NDC! • Automatically transforms from NDC to drawing area • Mn2d is automatic!! • True for ALL Graphics APIs!! Chapter 10
Advantage of NDC • Consistency and Flexibility • Programmer does not need to aware of display dimension • Program will run on any display size • Convenience: • ±1 convenient for scaling • Problem with NDC: • ±1 are not intuitive to humans/programmers! Chapter 10
Drawing a face … Chapter 10
Transformation involve (Tut 9.9) Chapter 10
We have to compute and apply in our program World CoordinateSystem (WC) Graphics API computes and applies automatically World Coordinate System (WC) • Convenient system for design! Chapter 10
Graphics API computes and applies automatically Tut 10.6: DC independence! • Mn2d • Scale to Device Coordinate (DC) automatically by Graphics API • Can draw to any DC space! • Tut 10.6: draws 300x300 face to • 500x500 pixels DC space! • Looks Identical to Tut 9.9! • Tut 9.9: 300x300 pixels DC Chapter 10
Tut 10.7: Same face in different WC Chapter 10
Tut 10.7: WC Window • WC Window • The X/Y bounds that enclose the face Chapter 10
Tut 10.7: Required Mw2n Chapter 10
Tut 10.7: Implementation • Appears identical to Tut: 10.6 and 9.9 • Completely different Mw2n Chapter 10
Tut 10.8: Location of WC Window Chapter 10
Tut 10.8: Implementation • Define the entire geometric human • Draws with defined WC Window Chapter 10
The WC Window and Mw2n • All vertices (Vi) goes through: • In our implementation: • Mw2n is stored in MV Chapter 10
Vertex in Different Coordinate Spaces • Vwc – vetex in WC Space • Vndc – vetex in NDC Space • Vdc – vetex in DC Space Chapter 10
Same Vertex in WC, NDC, DC … Chapter 10
WC to DC transform (Mw2d) Given: Let Or Then Chapter 10
More about Recall: Or Chapter 10
3 Important Pieces • Center (cxwc, cywc) – pan: what/where is visible • Dimension (Wwc, Hwc) – Zoom: size of visible objects • Ratio : WC to DC height/width ratio WC to DC Chapter 10
Lib 10: WC Window Support Chapter 10
Lib10: DC WC Xform To cover later Chapter 10
Lib10: LoadW2NDCXform() (to MV) Chapter 10
Tut 10.9: Work with WC Window • Set WC Window • Must be done during initialization • Before each draw of model • Call LoadW2NDCXform() to define Mw2n Chapter 10
Tut 10.10: Moving WC Window Chapter 10
Tut 10.10: WindowHandler details Chapter 10
Tut 10.10: Implementation Detail Chapter 10
Tut 10.10: Handler::DrawGraphics() • Our App has two instances of WindowHandler • m_main_view instance of CMainHandler • m_small_view instance CDrawOnlyHandler • Both instances will invoke this DrawGraphics() • Each instance has an unique WC Window • Each invocation loads a different Mw2n Chapter 10
Tut 10.11: Scaling WC Window Chapter 10
Tut 10.11: Zooming … • Mw2n is computed and loaded into MV • Intuition … • Larger (WWC, HWC) corresponds to • Smaller scaling factors (in numerators) • Large (WWC, HWC) is zooming out • You see more in the given device space Chapter 10
Width to Height ratios: • From WC to DC: • Translate: by World Center • Scale: from WC window to DC displace size • Translate: to position the drawing area • When: • Objects will be scaled differently in X and Y • Circles will not be round!! Chapter 10
Aspect Ratio … • Define: • To maintain circle square … • Aspect ratio of WC Window must be the same as aspect ratio of DC display area Chapter 10
Inverse Trasnform • Given vertex in WC: Vwc • We know .. • Now, mouse clicks are in DC space! • Given Vdc • How can we compute • what is Chapter 10
Computing … Recall: Let: Then: Or: Finally: Chapter 10
DC to WC: Chapter 10