410 likes | 503 Views
Learn how to control what's visible on screen using window placement, size, zoom, and viewport mapping techniques in computer graphics. Understand camera settings, transform rectangles, and OpenGL viewport functions. Dive into 3D viewing projections and perspective projections.
E N D
How do we control what we see? • World • Window and viewport • Camera
Window placement • Window size • Mapping viewport
Zoom: • Set_window( -60, +60, -30, +30 )
Zoom • Set_window( -21, +21, -11, +11 )
Window • Pan A. Set_window(-40, +20,-15,+15) B.Set_window(-20,+40,-15,+15)
Window in OpenGL glutInitWindowSize(W,H); glutInitWindowPosition(100,100);
Viewport • define a viewport in Normalized Device Coordinates (NDC) • Map from NDC or Physical device using notes from previous class on mappings Set_viewport2(Xvmin,Xvmax,Yvmin,Yvmax)
Now Map [a,b] [c,d] • First map [a,b] to [0,1] • (We already did this) • Then map [0,1] to [c,d]
Now Map [a,b] [c,d] • Scale [0,1] by (d-c) • Then translate by c • That is, in 1D homogeneous form:
This is the Viewport Transformation • Good for mapping objects from one coordinate system to another • This is what we do with windows and viewports 15
Viewport Set_window( -30, +30, -15, +15); Set_viewport(0.0, 0.5, 0.0, 0.5); -- lower left Draw_house; Set_viewport(0.5, 1.0, 0.0, 0.5); -- lower right Draw_house; Set_viewport(0.0, 0.5, 0.5, 1.0); -- upper left Draw_house; Set_viewport( 0.5, 1.0, 0.5, 1.0); -- upper right Draw_house;
Viewport in OpenGL void glViewport( GLint x, GLint y, GLsizei width, GLsizei height ) x, y Specify the lower left corner of the viewport rectangle, in pixels. The initial value is (0,0). width, height Specify the width and height of the viewport. When a GL context is first attached to a window, width and height are set to the dimensions of that window.
ViewTransformations • Viewport
Perspective Projection Eye = e Gaze = LookAt = g Up = y Distance to viewplane = d Z = distance to object on z axis viewplane y yp g e d z
y x From side User’s point of view viewplane y z z Out of screen x Out of screen
From the Side viewplane y yL z zL x xL Out of screen Out of screen
Frustum Perspective Specifying perspective view in OpenGL
glFrustum void glFrustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far);
gluPerspective aspect = w/h void gluPerspective(GLdouble fovy, GLdouble aspect, GLdouble near, GLdouble far);
Positioning the Camera • Use gluLookAt to specify • Eye location • “Look-at” point • “up” vector • gluLookAt(10,10,10,1,2,3,0,0,1); • Eye is (10,10,10) • Look at point is (1,2,3) • Up is (0,0,1) • Usually done in GL_PROJECTION matrix and combined with perspective matrix
Credits • Slides and text • Rich Riesenfeld’s Introduction to CG slides • SIGGRAPH Educators Hypercard slides • http:///www.siggraph.org/education/materials/HyperGraph/viewing/view3d/3dprojec.htm • Some Image from Ed Angel’s book