![Page 1: Interactive 3D Graphics and Virtual Reality Introduction to OpenGL concepts Session 2](https://reader036.vdocument.in/reader036/viewer/2022062308/56649d615503460f94a4368a/html5/thumbnails/1.jpg)
Interactive 3D Graphicsand Virtual Reality
Introduction to OpenGL concepts
Session 2
![Page 2: Interactive 3D Graphics and Virtual Reality Introduction to OpenGL concepts Session 2](https://reader036.vdocument.in/reader036/viewer/2022062308/56649d615503460f94a4368a/html5/thumbnails/2.jpg)
OpenGL and GLUT Overview
![Page 3: Interactive 3D Graphics and Virtual Reality Introduction to OpenGL concepts Session 2](https://reader036.vdocument.in/reader036/viewer/2022062308/56649d615503460f94a4368a/html5/thumbnails/3.jpg)
What Is OpenGL?
Graphics rendering API high-quality color images composed of geometric
and image primitives window system independent operating system independent
![Page 4: Interactive 3D Graphics and Virtual Reality Introduction to OpenGL concepts Session 2](https://reader036.vdocument.in/reader036/viewer/2022062308/56649d615503460f94a4368a/html5/thumbnails/4.jpg)
OpenGL Architecture
DisplayList
PolynomialEvaluator
Per VertexOperations &
PrimitiveAssembly
RasterizationPer Fragment
OperationsFrameBuffer
TextureMemory
CPU
PixelOperations
![Page 5: Interactive 3D Graphics and Virtual Reality Introduction to OpenGL concepts Session 2](https://reader036.vdocument.in/reader036/viewer/2022062308/56649d615503460f94a4368a/html5/thumbnails/5.jpg)
OpenGL as a Renderer
Geometric primitives points, lines and polygons
Image Primitives images and bitmaps separate pipeline for images and geometry
linked through texture mapping Rendering depends on state
colors, materials, light sources, etc.
![Page 6: Interactive 3D Graphics and Virtual Reality Introduction to OpenGL concepts Session 2](https://reader036.vdocument.in/reader036/viewer/2022062308/56649d615503460f94a4368a/html5/thumbnails/6.jpg)
Related APIs
AGL, GLX, WGL glue between OpenGL and windowing systems
GLU (OpenGL Utility Library) part of OpenGL NURBS, tessellators, quadric shapes, etc.
GLUT (OpenGL Utility Toolkit) portable windowing API not officially part of OpenGL
![Page 7: Interactive 3D Graphics and Virtual Reality Introduction to OpenGL concepts Session 2](https://reader036.vdocument.in/reader036/viewer/2022062308/56649d615503460f94a4368a/html5/thumbnails/7.jpg)
OpenGL and Related APIs
GLUT
GLU
GL
GLX, AGLor WGL
X, Win32, Mac O/S
software and/or hardware
application program
OpenGL Motifwidget or similar
![Page 8: Interactive 3D Graphics and Virtual Reality Introduction to OpenGL concepts Session 2](https://reader036.vdocument.in/reader036/viewer/2022062308/56649d615503460f94a4368a/html5/thumbnails/8.jpg)
Preliminaries
Headers Files #include <GL/gl.h> #include <GL/glu.h> #include <GL/glut.h>
Libraries Enumerated Types
OpenGL defines numerous types for compatibility GLfloat, GLint, GLenum, etc.
![Page 9: Interactive 3D Graphics and Virtual Reality Introduction to OpenGL concepts Session 2](https://reader036.vdocument.in/reader036/viewer/2022062308/56649d615503460f94a4368a/html5/thumbnails/9.jpg)
GLUT Basics
Application Structure Configure and open window Initialize OpenGL state Register input callback functions
renderresize input: keyboard, mouse, etc.
Enter event processing loop
![Page 10: Interactive 3D Graphics and Virtual Reality Introduction to OpenGL concepts Session 2](https://reader036.vdocument.in/reader036/viewer/2022062308/56649d615503460f94a4368a/html5/thumbnails/10.jpg)
Sample Program
void main( int argc, char** argv ){ int mode = GLUT_RGB|GLUT_DOUBLE; glutInitDisplayMode( mode ); glutCreateWindow( argv[0] ); init(); glutDisplayFunc( display ); glutReshapeFunc( resize ); glutKeyboardFunc( key ); glutIdleFunc( idle ); glutMainLoop();}
![Page 11: Interactive 3D Graphics and Virtual Reality Introduction to OpenGL concepts Session 2](https://reader036.vdocument.in/reader036/viewer/2022062308/56649d615503460f94a4368a/html5/thumbnails/11.jpg)
OpenGL Initialization
Set up whatever state you’re going to use
void init( void ){ glClearColor( 0.0, 0.0, 0.0, 1.0 ); glClearDepth( 1.0 );
glEnable( GL_LIGHT0 ); glEnable( GL_LIGHTING ); glEnable( GL_DEPTH_TEST );}
![Page 12: Interactive 3D Graphics and Virtual Reality Introduction to OpenGL concepts Session 2](https://reader036.vdocument.in/reader036/viewer/2022062308/56649d615503460f94a4368a/html5/thumbnails/12.jpg)
GLUT Callback Functions
Routine to call when something happens window resize or redraw user input animation
“Register” callbacks with GLUTglutDisplayFunc( display );glutIdleFunc( idle );glutKeyboardFunc( keyboard );
![Page 13: Interactive 3D Graphics and Virtual Reality Introduction to OpenGL concepts Session 2](https://reader036.vdocument.in/reader036/viewer/2022062308/56649d615503460f94a4368a/html5/thumbnails/13.jpg)
Rendering Callback
Do all of your drawing hereglutDisplayFunc( display );
void display( void ){ glClear( GL_COLOR_BUFFER_BIT ); glBegin( GL_TRIANGLE_STRIP ); glVertex3fv( v[0] ); glVertex3fv( v[1] ); glVertex3fv( v[2] ); glVertex3fv( v[3] ); glEnd(); glutSwapBuffers();}
![Page 14: Interactive 3D Graphics and Virtual Reality Introduction to OpenGL concepts Session 2](https://reader036.vdocument.in/reader036/viewer/2022062308/56649d615503460f94a4368a/html5/thumbnails/14.jpg)
Idle Callbacks
Use for animation and continuous updateglutIdleFunc( idle );
void idle( void ){ t += dt; glutPostRedisplay();}
![Page 15: Interactive 3D Graphics and Virtual Reality Introduction to OpenGL concepts Session 2](https://reader036.vdocument.in/reader036/viewer/2022062308/56649d615503460f94a4368a/html5/thumbnails/15.jpg)
User Input CallbacksProcess user input
glutKeyboardFunc( keyboard );void keyboard( unsigned char key, int x, int y ){ switch( key ) { case ‘q’ : case ‘Q’ : exit( EXIT_SUCCESS ); break; case ‘r’ : case ‘R’ : rotate = GL_TRUE;
glutPostRedisplay(); break; }}
![Page 16: Interactive 3D Graphics and Virtual Reality Introduction to OpenGL concepts Session 2](https://reader036.vdocument.in/reader036/viewer/2022062308/56649d615503460f94a4368a/html5/thumbnails/16.jpg)
Elementary Rendering
Geometric PrimitivesManaging OpenGL StateOpenGL Buffers
![Page 17: Interactive 3D Graphics and Virtual Reality Introduction to OpenGL concepts Session 2](https://reader036.vdocument.in/reader036/viewer/2022062308/56649d615503460f94a4368a/html5/thumbnails/17.jpg)
OpenGL Geometric Primitives
GL_QUAD_STRIPGL_QUAD_STRIP
GL_POLYGONGL_POLYGON
GL_TRIANGLE_STRIPGL_TRIANGLE_STRIP
GL_TRIANGLE_FANGL_TRIANGLE_FAN
GL_POINTSGL_POINTSGL_LINESGL_LINES
GL_LINE_LOOPGL_LINE_LOOPGL_LINE_STRIPGL_LINE_STRIP
GL_TRIANGLESGL_TRIANGLES
GL_QUADSGL_QUADS
All geometric primitives are specified by vertices
![Page 18: Interactive 3D Graphics and Virtual Reality Introduction to OpenGL concepts Session 2](https://reader036.vdocument.in/reader036/viewer/2022062308/56649d615503460f94a4368a/html5/thumbnails/18.jpg)
Simple Example
void drawRhombus( GLfloat color[] ){
glBegin( GL_QUADS ); glColor3fv( color ); glVertex2f( 0.0, 0.0 ); glVertex2f( 1.0, 0.0 ); glVertex2f( 1.5, 1.118 ); glVertex2f( 0.5, 1.118 ); glEnd();
}
![Page 19: Interactive 3D Graphics and Virtual Reality Introduction to OpenGL concepts Session 2](https://reader036.vdocument.in/reader036/viewer/2022062308/56649d615503460f94a4368a/html5/thumbnails/19.jpg)
OpenGL Command Formats
glVertex3fv( glVertex3fv( vv ) )
Number ofNumber ofcomponentscomponents
2 - (x,y) 2 - (x,y) 3 - (x,y,z)3 - (x,y,z)4 - (x,y,z,w)4 - (x,y,z,w)
Data TypeData Typeb - byteb - byteub - unsigned byteub - unsigned bytes - shorts - shortus - unsigned shortus - unsigned shorti - inti - intui - unsigned intui - unsigned intf - floatf - floatd - doubled - double
VectorVector
omit “v” foromit “v” forscalar formscalar form
glVertex2f( x, y )glVertex2f( x, y )
![Page 20: Interactive 3D Graphics and Virtual Reality Introduction to OpenGL concepts Session 2](https://reader036.vdocument.in/reader036/viewer/2022062308/56649d615503460f94a4368a/html5/thumbnails/20.jpg)
Specifying Geometric Primitives
Primitives are specified usingglBegin( glBegin( primType primType ););
glEnd();glEnd();
primType determines how vertices are combined
GLfloat red, green, blue;GLfloat red, green, blue;Glfloat coords[3];Glfloat coords[3];glBegin( glBegin( primType primType ););for ( i = 0; i < nVerts; ++i ) { for ( i = 0; i < nVerts; ++i ) { glColor3f( red, green, blue );glColor3f( red, green, blue ); glVertex3fv( coords );glVertex3fv( coords );}}glEnd();glEnd();
![Page 21: Interactive 3D Graphics and Virtual Reality Introduction to OpenGL concepts Session 2](https://reader036.vdocument.in/reader036/viewer/2022062308/56649d615503460f94a4368a/html5/thumbnails/21.jpg)
Controlling Rendering Appearance
From Wireframeto Texture Mapped
![Page 22: Interactive 3D Graphics and Virtual Reality Introduction to OpenGL concepts Session 2](https://reader036.vdocument.in/reader036/viewer/2022062308/56649d615503460f94a4368a/html5/thumbnails/22.jpg)
OpenGL’s State Machine
•All rendering attributes are encapsulated in the OpenGL State
•rendering styles•Shading•Lighting•Texture mapping
![Page 23: Interactive 3D Graphics and Virtual Reality Introduction to OpenGL concepts Session 2](https://reader036.vdocument.in/reader036/viewer/2022062308/56649d615503460f94a4368a/html5/thumbnails/23.jpg)
Manipulating OpenGL State
• Appearance is controlled by current state
for each ( primitive to render ) { update OpenGL state render primitive
}• Manipulating vertex attributes is most common way to manipulate state
glColor*() / glIndex*()glColor*() / glIndex*()glNormal*()glNormal*()glTexCoord*()glTexCoord*()
![Page 24: Interactive 3D Graphics and Virtual Reality Introduction to OpenGL concepts Session 2](https://reader036.vdocument.in/reader036/viewer/2022062308/56649d615503460f94a4368a/html5/thumbnails/24.jpg)
Controlling current state
Setting StateglPointSize( glPointSize( sizesize ); );
glLineStipple( glLineStipple( repeatrepeat, , pattern pattern ););
glShadeModel( glShadeModel( GLGL__SMOOTHSMOOTH ); );
Enabling FeaturesglEnable( glEnable( GLGL__LIGHTING LIGHTING ););
glDisable( glDisable( GL_TEXTURE_2D GL_TEXTURE_2D ););
![Page 25: Interactive 3D Graphics and Virtual Reality Introduction to OpenGL concepts Session 2](https://reader036.vdocument.in/reader036/viewer/2022062308/56649d615503460f94a4368a/html5/thumbnails/25.jpg)
Transformations in OpenGL
Modeling Viewing
orient camera projection
Animation Map to screen
![Page 26: Interactive 3D Graphics and Virtual Reality Introduction to OpenGL concepts Session 2](https://reader036.vdocument.in/reader036/viewer/2022062308/56649d615503460f94a4368a/html5/thumbnails/26.jpg)
Camera paradigm for 3D viewing
3D scene
Camera
2D picture
Content of 2D picture will depend on: • camera parameters (position,
direction, field of view, ...), • properties of scene objects, • illumination, ...
3D viewing is similar to taking picture with camera: 2D view of 3D scene
![Page 27: Interactive 3D Graphics and Virtual Reality Introduction to OpenGL concepts Session 2](https://reader036.vdocument.in/reader036/viewer/2022062308/56649d615503460f94a4368a/html5/thumbnails/27.jpg)
Model description
Models are used to represent the 3D things we are simulating
A standard way of defining models is needed Model made up of points and lines joining the
lines to form faces A co-ordinate system is used to represent the
points
![Page 28: Interactive 3D Graphics and Virtual Reality Introduction to OpenGL concepts Session 2](https://reader036.vdocument.in/reader036/viewer/2022062308/56649d615503460f94a4368a/html5/thumbnails/28.jpg)
Coordinate Systems World coordinate system: reference frame for
specification of (relative) position / orientation of viewer and scene objects (size?)
xw
zw
yw
Scene (head looking at bird)
xm
zm
ymHead model
xm
zm
ym
Bird model
![Page 29: Interactive 3D Graphics and Virtual Reality Introduction to OpenGL concepts Session 2](https://reader036.vdocument.in/reader036/viewer/2022062308/56649d615503460f94a4368a/html5/thumbnails/29.jpg)
Coordinate Systems Viewing coordinate system: reference frame for
specification of scene from viewpoint of camera / viewer
xw
zw
yw
xm
zm
ym
xm
zm
ym
Taking a view of scene (head looking at bird)
Camera
yv
zv
xv
![Page 30: Interactive 3D Graphics and Virtual Reality Introduction to OpenGL concepts Session 2](https://reader036.vdocument.in/reader036/viewer/2022062308/56649d615503460f94a4368a/html5/thumbnails/30.jpg)
3D to 2D
The next part of the process has to take the image from viewpoint and calculate the way the 3D shapes that can be seen can be drawn on a 2D surface.
Any surfaces not seen are eliminated. Involves a mathematical process of
manipulating and generating resultant 2D vertices
![Page 31: Interactive 3D Graphics and Virtual Reality Introduction to OpenGL concepts Session 2](https://reader036.vdocument.in/reader036/viewer/2022062308/56649d615503460f94a4368a/html5/thumbnails/31.jpg)
xw
zw
yw
World coordinates
Viewing Pipeline
Coordinate transformations: generation of 3D view involves sequence
(pipeline) of coordinate transformations
Camera
Modelling coordinates
3D object
2D picture
Device coordinates
xm
zm
ym
xmzm
ym
xm
zm
ym
xvzv
yv
Viewing coordinates
![Page 32: Interactive 3D Graphics and Virtual Reality Introduction to OpenGL concepts Session 2](https://reader036.vdocument.in/reader036/viewer/2022062308/56649d615503460f94a4368a/html5/thumbnails/32.jpg)
Camera Analogy
3D is just like taking a photograph (lots of photographs!)
camera
tripod model
viewingvolume
![Page 33: Interactive 3D Graphics and Virtual Reality Introduction to OpenGL concepts Session 2](https://reader036.vdocument.in/reader036/viewer/2022062308/56649d615503460f94a4368a/html5/thumbnails/33.jpg)
Camera Analogy and Transformations
Projection transformations adjust the lens of the camera
Viewing transformations tripod–define position and orientation of the viewing
volume in the world
Modeling transformations moving the model
Viewport transformations enlarge or reduce the physical photograph
![Page 34: Interactive 3D Graphics and Virtual Reality Introduction to OpenGL concepts Session 2](https://reader036.vdocument.in/reader036/viewer/2022062308/56649d615503460f94a4368a/html5/thumbnails/34.jpg)
Coordinate Systems and Transformations
Steps in Forming an Image specify geometry (world coordinates) specify camera (camera coordinates) project (window coordinates) map to viewport (screen coordinates)
Each step uses transformations Every transformation is equivalent to a change in
coordinate systems (frames)
![Page 35: Interactive 3D Graphics and Virtual Reality Introduction to OpenGL concepts Session 2](https://reader036.vdocument.in/reader036/viewer/2022062308/56649d615503460f94a4368a/html5/thumbnails/35.jpg)
Affine Transformations
Want transformations which preserve geometry lines, polygons, quadrics
Affine = line preserving Rotation, translation, scaling Projection Concatenation (composition)
![Page 36: Interactive 3D Graphics and Virtual Reality Introduction to OpenGL concepts Session 2](https://reader036.vdocument.in/reader036/viewer/2022062308/56649d615503460f94a4368a/html5/thumbnails/36.jpg)
Homogeneous Coordinates
each vertex is a column vector
w is usually 1.0 all operations are matrix multiplications directions (directed line segments) can be
represented with w = 0.0
w
z
y
x
v
![Page 37: Interactive 3D Graphics and Virtual Reality Introduction to OpenGL concepts Session 2](https://reader036.vdocument.in/reader036/viewer/2022062308/56649d615503460f94a4368a/html5/thumbnails/37.jpg)
151173
141062
13951
12840
mmmm
mmmm
mmmm
mmmm
M
3D Transformations
A vertex is transformed by 4 x 4 matrices all affine operations are matrix multiplications all matrices are stored column-major in OpenGL matrices are always post-multiplied product of matrix and vector is
vM
![Page 38: Interactive 3D Graphics and Virtual Reality Introduction to OpenGL concepts Session 2](https://reader036.vdocument.in/reader036/viewer/2022062308/56649d615503460f94a4368a/html5/thumbnails/38.jpg)
Specifying Transformations
Programmer has two styles of specifying transformations specify matrices (glLoadMatrix, glMultMatrixglLoadMatrix, glMultMatrix) specify operation (glRotate, glOrthoglRotate, glOrtho)
Programmer does not have to remember the exact matrices
![Page 39: Interactive 3D Graphics and Virtual Reality Introduction to OpenGL concepts Session 2](https://reader036.vdocument.in/reader036/viewer/2022062308/56649d615503460f94a4368a/html5/thumbnails/39.jpg)
Programming Transformations
Prior to rendering, view, locate, and orient: eye/camera position 3D geometry
Manage the matrices including matrix stack
Combine (composite) transformations
![Page 40: Interactive 3D Graphics and Virtual Reality Introduction to OpenGL concepts Session 2](https://reader036.vdocument.in/reader036/viewer/2022062308/56649d615503460f94a4368a/html5/thumbnails/40.jpg)
vertex
ModelviewMatrix
ProjectionMatrix
PerspectiveDivision
ViewportTransform
Modelview
Modelview
Projection
object eye
clip normalizeddevice
window
other calculations here material color shade model (flat) polygon rendering mode polygon culling clipping
TransformationPipeline
![Page 41: Interactive 3D Graphics and Virtual Reality Introduction to OpenGL concepts Session 2](https://reader036.vdocument.in/reader036/viewer/2022062308/56649d615503460f94a4368a/html5/thumbnails/41.jpg)
Matrix Operations
•Specify Current Matrix StackglMatrixMode( glMatrixMode( GL_MODELVIEWGL_MODELVIEW or or GL_PROJECTIONGL_PROJECTION ) )
•Other Matrix or Stack OperationsglLoadIdentity() glLoadIdentity() glPushMatrix()glPushMatrix()glPopMatrix()glPopMatrix()
•Viewport•usually same as window size•viewport aspect ratio should be same as projection transformation or resulting image may be distorted
glViewport( glViewport( x, y, width, heightx, y, width, height ) )
![Page 42: Interactive 3D Graphics and Virtual Reality Introduction to OpenGL concepts Session 2](https://reader036.vdocument.in/reader036/viewer/2022062308/56649d615503460f94a4368a/html5/thumbnails/42.jpg)
Projection Transformation
Shape of viewing frustum Perspective projection
gluPerspective( gluPerspective( fovy, aspect, zNear, zFarfovy, aspect, zNear, zFar ) )
glFrustumglFrustum(( left,left, right,right, bottom,bottom, top,top, zNear,zNear, zFarzFar ))
Orthographic parallel projectionglOrtho(glOrtho( left,left, right,right, bottom,bottom, top,top, zNear,zNear, zFarzFar ))
gluOrtho2D( gluOrtho2D( left, right, bottom, topleft, right, bottom, top ) ) calls glOrtho with z values near zero
![Page 43: Interactive 3D Graphics and Virtual Reality Introduction to OpenGL concepts Session 2](https://reader036.vdocument.in/reader036/viewer/2022062308/56649d615503460f94a4368a/html5/thumbnails/43.jpg)
Applying Projection Transformations
Typical use (orthographic projection)glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glOrtho( left, right, bottom, top, zNear, zFar );
![Page 44: Interactive 3D Graphics and Virtual Reality Introduction to OpenGL concepts Session 2](https://reader036.vdocument.in/reader036/viewer/2022062308/56649d615503460f94a4368a/html5/thumbnails/44.jpg)
Viewing Transformations
Position the camera/eye in the scene place the tripod down; aim camera
To “fly through” a scene change viewing transformation and
redraw scene gluLookAt( eyex, eyey, eyez,
aimx, aimy, aimz, upx, upy, upz ) up vector determines unique orientation
tripod
![Page 45: Interactive 3D Graphics and Virtual Reality Introduction to OpenGL concepts Session 2](https://reader036.vdocument.in/reader036/viewer/2022062308/56649d615503460f94a4368a/html5/thumbnails/45.jpg)
Modeling Transformations
Move object
glTranslate{fd}( glTranslate{fd}( x, y, zx, y, z ) ) Rotate object around arbitrary axis
glRotate{fd}( glRotate{fd}( angle, x, y, zangle, x, y, z ) ) angle is in degrees
Dilate (stretch or shrink) or mirror object
glScale{fd}( glScale{fd}( x, y, zx, y, z ) )
zyx
![Page 46: Interactive 3D Graphics and Virtual Reality Introduction to OpenGL concepts Session 2](https://reader036.vdocument.in/reader036/viewer/2022062308/56649d615503460f94a4368a/html5/thumbnails/46.jpg)
Connection: Viewing and Modeling
Moving camera is equivalent to moving every object in the world towards a stationary camera
Viewing transformations are equivalent to several modeling transformationsgluLookAt() has its own command
can make your own polar view or pilot view
![Page 47: Interactive 3D Graphics and Virtual Reality Introduction to OpenGL concepts Session 2](https://reader036.vdocument.in/reader036/viewer/2022062308/56649d615503460f94a4368a/html5/thumbnails/47.jpg)
Projection is left handed
Projection transformations (gluPerspective, glOrtho) are left handed think of zNear and zFar as distance from view
point Everything else is right handed, including the
vertexes to be rendered
xx
yy
z+
z+
left handed right handed
![Page 48: Interactive 3D Graphics and Virtual Reality Introduction to OpenGL concepts Session 2](https://reader036.vdocument.in/reader036/viewer/2022062308/56649d615503460f94a4368a/html5/thumbnails/48.jpg)
Common Transformation Usage
3 examples of resize() routine restate projection & viewing transformations
Usually called when window resized Registered as callback for glutReshapeFunc()
![Page 49: Interactive 3D Graphics and Virtual Reality Introduction to OpenGL concepts Session 2](https://reader036.vdocument.in/reader036/viewer/2022062308/56649d615503460f94a4368a/html5/thumbnails/49.jpg)
resize(): Perspective & LookAt
void resize( int w, int h ){ glViewport( 0, 0, (GLsizei) w, (GLsizei) h ); glMatrixMode( GL_PROJECTION ); glLoadIdentity(); gluPerspective( 65.0, (GLdouble) w / h, 1.0, 100.0 );
glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); gluLookAt( 0.0, 0.0, 5.0,
0.0, 0.0, 0.0, 0.0, 1.0, 0.0 );
}
![Page 50: Interactive 3D Graphics and Virtual Reality Introduction to OpenGL concepts Session 2](https://reader036.vdocument.in/reader036/viewer/2022062308/56649d615503460f94a4368a/html5/thumbnails/50.jpg)
50
resize(): Perspective & Translate
Same effect as previous LookAtvoid resize( int w, int h ){ glViewport( 0, 0, (GLsizei) w, (GLsizei) h ); glMatrixMode( GL_PROJECTION ); glLoadIdentity(); gluPerspective( 65.0, (GLdouble) w/h, 1.0, 100.0 ); glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); glTranslatef( 0.0, 0.0, -5.0 );}
![Page 51: Interactive 3D Graphics and Virtual Reality Introduction to OpenGL concepts Session 2](https://reader036.vdocument.in/reader036/viewer/2022062308/56649d615503460f94a4368a/html5/thumbnails/51.jpg)
resize(): Orthovoid resize( int width, int height ){ GLdouble aspect = (GLdouble) width / height; GLdouble left = -2.5, right = 2.5; GLdouble bottom = -2.5, top = 2.5; glViewport( 0, 0, (GLsizei) w, (GLsizei) h ); glMatrixMode( GL_PROJECTION ); glLoadIdentity();
if ( aspect < 1.0 ) { left /= aspect; right /= aspect; } else { bottom *= aspect; top *= aspect; } glOrtho( left, right, bottom, top, near, far ); glMatrixMode( GL_MODELVIEW ); glLoadIdentity();}
![Page 52: Interactive 3D Graphics and Virtual Reality Introduction to OpenGL concepts Session 2](https://reader036.vdocument.in/reader036/viewer/2022062308/56649d615503460f94a4368a/html5/thumbnails/52.jpg)
Compositing Modeling Transformations
Problem 1: hierarchical objects one position depends upon a previous position robot arm or hand; sub-assemblies
Solution 1: moving local coordinate system modeling transformations move coordinate
system post-multiply column-major matrices OpenGL post-multiplies matrices
![Page 53: Interactive 3D Graphics and Virtual Reality Introduction to OpenGL concepts Session 2](https://reader036.vdocument.in/reader036/viewer/2022062308/56649d615503460f94a4368a/html5/thumbnails/53.jpg)
Compositing Modeling Transformations
Problem 2: objects move relative to absolute world origin my object rotates around the wrong origin
make it spin around its center or something else Solution 2: fixed coordinate system
modeling transformations move objects around fixed coordinate system
pre-multiply column-major matrices OpenGL post-multiplies matrices must reverse order of operations to achieve desired effect
![Page 54: Interactive 3D Graphics and Virtual Reality Introduction to OpenGL concepts Session 2](https://reader036.vdocument.in/reader036/viewer/2022062308/56649d615503460f94a4368a/html5/thumbnails/54.jpg)
Recap
Camera Analogy Viewing pipeline Model (geometry etc.) View (Frustrum etc) Rendering (States etc. Changing views