Presentation is loading. Please wait.

Presentation is loading. Please wait.

3D coordinate systems X Y Z Right-Hand Coordinate System X Y Z Left-Hand Coordinate System OpenGL uses this! Direct3D uses this!

Similar presentations


Presentation on theme: "3D coordinate systems X Y Z Right-Hand Coordinate System X Y Z Left-Hand Coordinate System OpenGL uses this! Direct3D uses this!"— Presentation transcript:

1 3D coordinate systems X Y Z Right-Hand Coordinate System X Y Z Left-Hand Coordinate System OpenGL uses this! Direct3D uses this!

2 Visualizing in 3D X Y Z 1.0 z=1.0 x=1.0 y=1.0 A B C D E F G H Counter- clockwise

3 Rendering a Box in OpenGL We render the 6 faces as polygons –Polygons are specified as a list of vertices –Vertices are specified in counterclockwise order looking at the surface of the face! AB C D E F G H

4 OpenGL Polygon Rendering GLdouble size = 1.0; glBegin(GL_POLYGON); // front face glVertex3d(0.0, 0.0, size); glVertex3d(size, 0.0, size); glVertex3d(size, size, size); glVertex3d(0.0, size, size); glEnd();

5 OpenGL Conventions C library –All function names start with gl OpenGL is a retained mode graphics system –It has a state –glBegin(GL_POLYGON) puts us into a polygon rendering state.

6 OpenGL Types Basic numeric types –GLdouble = double –GLfloat = float –GLint = int –GLshort = short Mostly you’ll use GLdouble and GLfloat

7 Function suffixes Many functions have alternatives –Alternatives are specified by the suffix –glVertex2d 2 double parameters void glVertex2d(GLdouble x, GLdouble y); –glVertex3f 3 float parameters void glVertex3f(GLfloat x, GLfloat y, GLfloat z); –glVertex3fv void glVertex3fv(const GLfloat *v);

8 All of dem… glVertex2d, glVertex2f, glVertex2i, glVertex2s, glVertex3d, glVertex3f, glVertex3i, glVertex3s, glVertex4d, glVertex4f, glVertex4i, glVertex4s, glVertex2dv, glVertex2fv, glVertex2iv, glVertex2sv, glVertex3dv, glVertex3fv, glVertex3iv, glVertex3sv, glVertex4dv, glVertex4fv, glVertex4iv, glVertex4sv

9 Specifying a color (no lighting) glColor3f(red, green, blue); Most of the same suffixes apply… GLdouble size = 1.0; glColor3d(1.0, 0.0, 0.0);// red glBegin(GL_POLYGON); // front face glVertex3d(0.0, 0.0, size); glVertex3d(size, 0.0, size); glVertex3d(size, size, size); glVertex3d(size, 0.0, size); glEnd();

10 Moving to 3D Camera Configuration Parameters Tessellation Scene Graphs

11 Structure of Our Programs OnGLDraw() –Clear the buffers –Set up the camera –Position the camera –Configure OpenGL –Render whatever we are rendering –Flush

12 Clear the Buffers void CChildView::OnGLDraw(CDC *pDC) { // Clear to black... glClearColor(0.0f, 0.0f, 0.0f, 0.0f) ; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);...

13 Camera Configuration What does it take to describe a camera?

14 Describing a Camera Where it is in space  Eye location Which way it’s pointing  Or what it’s pointing at Which way is up Zoom characteristics  Field of view angle

15 Setting up the Camera Field of View (angle) Near clipping plane Far clipping plane Nothing is rendered that is:  Closer than the near clipping plane  Farther than the far clipping plane Aspect ratio = w/h w h

16 gluPerspective() void gluPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar ); Fovy = Field of view angle –Degrees, usually less than 90 Aspect = Ratio of width/height of window zNear = distance to near clipping plane zFar = distance to far clipping plane glu = GL Utility

17 Important What do the numbers zFar, zNear represent? –Always select some unit for your application Inches, Feet, Meters, etc. In my sample application, I used inches

18 Using gluPerspective() // // Set up the camera // glMatrixMode(GL_PROJECTION); glLoadIdentity(); // Determine the screen size so // we can determine the aspect ratio int width, height; GetSize(width, height); GLdouble aspectratio = GLdouble(width) / GLdouble(height); // Set the camera parameters gluPerspective(25., // Field of view. aspectratio, // The aspect ratio. 10., // Near clipping 200.); // Far clipping

19 After this The camera is: –At the origin –Looking down the -Z axis

20 Positioning the Camera gluLookAt(eyex, eyey, eyez, atx, aty, atz, upx, upy, upz); Eye – Where the camera is located At – What the camera is looking at Up – Which direction is up –Can’t be the looking direction

21 Matrix Modes GL_PROJECTION –3D to 2D conversion –Camera parameters GL_MODELVIEW –Translation, rotation, etc. of Graphical Models –gluLookAt is a rotation and translation of your graphical model the camera is really at the origin and looking down the z axis.

22 Using gluLookAt() // Set the camera location glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(50., 50., 50., // eye x,y,z 0., 0., 0., // center x,y,z 0., 1., 0.); // Up direction... Render from here on...

23 Some OpenGL Configurations // // Some standard parameters // // Enable depth test glEnable(GL_DEPTH_TEST); // Cull backfacing polygons glCullFace(GL_BACK); glEnable(GL_CULL_FACE);

24 Example: Showing the coordinate axis… if(m_showaxis) { glColor3d(0., 1., 1.); glBegin(GL_LINES); glVertex3d(0., 0., 0.); glVertex3d(12., 0., 0.); glVertex3d(0., 0., 0.); glVertex3d(0., 12., 0.); glVertex3d(0., 0., 0.); glVertex3d(0., 0., 12.); glEnd(); }

25 Example: A Cube void CChildView::Cube(GLdouble size) { GLdouble a[] = {0., 0., size}; GLdouble b[] = {size, 0., size}; GLdouble c[] = {size, size, size}; GLdouble d[] = {0., size, size}; GLdouble e[] = {0., 0., 0.}; GLdouble f[] = {size, 0., 0.}; GLdouble g[] = {size, size, 0.}; GLdouble h[] = {0., size, 0.}; glColor3d(0.8, 0., 0.); glBegin(GL_POLYGON); // Front glVertex3dv(a); glVertex3dv(b); glVertex3dv(c); glVertex3dv(d); glEnd();... ab c d ef gh See example program…


Download ppt "3D coordinate systems X Y Z Right-Hand Coordinate System X Y Z Left-Hand Coordinate System OpenGL uses this! Direct3D uses this!"

Similar presentations


Ads by Google