1 / 57

Agile Game Engine Development

Discover what is needed, what tools are available, and how to design and implement a game engine in an agile way.

bridgetter
Download Presentation

Agile Game Engine Development

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Game Engine Development • Yingcai Xiao

  2. Game Engine Development What do we need? What tools do we have? How can we design and implement? We will answer those questions in an agile way.

  3. What do we need?

  4. Video Game: Interactive animation Display Device Driver (GDI) Input Device Driver Game (Software)

  5. Video Game: Interactive animation Similar to all other programs: data, algorithms, input, output. Data: Game Objects Algorithms: Animation Input: Interactive Events Output: Display

  6. Game Objects (GO) GO = Geometry + Attribute

  7. Game Objects (GO) Geometry: primitives: points, lines, triangles, polygons, spheres tetrahedrons, hexahedrons, … meshes: grids: elevation, uniform, rectlinear, structured, tin: triangular integrated network

  8. Game Objects (GO) Geometry: meshes: indexed Free/Smooth curves and surfaces: B-Splines

  9. Game Objects (GO) Geometry: Stroked: stroked primitives stroked free curves and surfaces composited: avatars, prefabs, packages, …

  10. Game Objects (GO) Conversions to indexed meshes:

  11. Game Objects (GO) Convert a plane to an indexed mesh: y = 0; 0<=x<=10 0<=z<=10

  12. Graphics Engine / Display Engine / Shading Engine

  13. OpenGL: https://www.opengl.org • Open Graphics Library • SGI • Open Source • De facto Industry Standard

  14. OpenGL: https://www.opengl.org • With shaders to support GPU. • Without shaders for easy learning. • We are going to start without shaders.

  15. OpenGL: https://www.opengl.org • Tutorial with shaders: • http://www.opengl-tutorial.org • Tutorial without shaders: http://www.cs.uccs.edu/~ssemwal/indexGLTutorial.html • We are going to have examples for both but start with http://www.cs.uccs.edu/~ssemwal/indexGLTutorial.html without shaders.

  16. Computer Graphics Textbooks Edward Angel, University of New Mexico Dave Shreiner, ARM, Inc Interactive Computer Graphics: A Top-Down Approach Using OpenGL, 5E. (no shaders) Interactive Computer Graphics: A Top-Down Approach with Shader-Based OpenGL, 6/E Interactive Computer Graphics: A Top-Down Approach with WebGL, 7/E

  17. Rotating Color CubeAn OpenGL Example for Interactive Animationwithout Using a Game Enginehttps://youtu.be/cwbL47ovzFYhttps://www.youtube.com/watch?v=L5jloVbgAdk

  18. Interactive Animation Programming with OpenGL • Input: interaction, user control: EDP (event driving programming). • Output: Graphics: OpenGL API. • Data Structures: graphics objects representations. • Algorithms: animations in event handlers. • Non OOP: Using C, a subset of C++, for speed.

  19. An OpenGL Example for Interactive Animation • Users: interactive 3D animation • Programmers: event-driven 3D animation of geometric transformations. • C part of C++ • OpenGL for display • Glut (GL Utility Toolkit) for interaction • https://www.opengl.org/resources/libraries/glut/

  20. The “Color Cube” example • The “main” function: • initializes windows, display settings, and event handlers. • Starts the event loop. • Post the first Redisplay event.

  21. The “Color Cube” example • // Initialization • While (1) { // event loop • event = getEvent(); // from the queue • switch (event) { • case Redisplay: display (); break; • case Keyboard: keyboard(); break; • default: idle(); • } }

  22. The “Color Cube” example • The “display” function: • draws the game objects • OpenGL is a state machine: set the active parameters before specifying vertices. • Per vertex setting: color, normal, texture, … • New vertices will use the current settings until they are changed.

  23. The “Color Cube” example • The “keyboard” function: • The event handler for keyboard events. • Change display parameters to control the animation. E.g. rotation angles, parametric variable t, simulation variables such as speed. • Don’t directly call the “display” function. • Post the Redisplay event after everything is set. glutPostRedisplay();

  24. The “Color Cube” example • The “idle” function: • The event handler for the “idle” event. • Invoked when no more event in the event queue. • Change display parameters to control the background animation. E.g. rotation angles, parametric variable t, simulation variables such as speed. • Don’t directly call the “display” function. • Post the Redisplay event after everything is set. glutPostRedisplay();

  25. The “Color Cube” example // Data structures and data, no objects enum AXIS { xAxis = 0, yAxis = 1, zAxis = 2}; double rotate_y=2; double rotate_x=2; double rotate_z=2; int axis = xAxis;

  26. The “Color Cube” example void display(){ // Clear screen and Z-buffer glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glLoadIdentity(); // Set rotation matrix to identity, no rotation // Set rotation (amount of rotation from initial position, vector of rotation) glRotatef( rotate_x, 1.0, 0.0, 0.0 ); // (amount of rotation, x axis) glRotatef( rotate_y, 0.0, 1.0, 0.0 ); // (amount of rotation, y axis) glRotatef( rotate_z, 0.0, 0.0, 1.0 ); // (amount of rotation, z axis)

  27. The “Color Cube” example // display() function continues // Create the color cube (Game Object) as six colored surfaces // FRONT glBegin(GL_POLYGON); glColor3f( 1.0, 0.0, 0.0 ); glVertex3f( 0.5, -0.5, -0.5 ); // P1 is red glColor3f( 0.0, 1.0, 0.0 ); glVertex3f( 0.5, 0.5, -0.5 ); // P2 is green glColor3f( 0.0, 0.0, 1.0 ); glVertex3f( -0.5, 0.5, -0.5 ); // P3 is blue glColor3f( 1.0, 0.0, 1.0 ); glVertex3f( -0.5, -0.5, -0.5 ); // P4 is purple glEnd();

  28. The “Color Cube” example // display() function continues // Create the color cube (Game Object) as six colored surfaces // White side - BACK glBegin(GL_POLYGON); glColor3f( 1.0, 1.0, 1.0 ); glVertex3f( 0.5, -0.5, 0.5 ); glVertex3f( 0.5, 0.5, 0.5 ); glVertex3f( -0.5, 0.5, 0.5 ); glVertex3f( -0.5, -0.5, 0.5 ); glEnd();

  29. The “Color Cube” example // display() function continues // Create the color cube (Game Object) as six colored surfaces // Purple side - RIGHT glBegin(GL_POLYGON); glColor3f( 1.0, 0.0, 1.0 ); glVertex3f( 0.5, -0.5, -0.5 ); glVertex3f( 0.5, 0.5, -0.5 ); glVertex3f( 0.5, 0.5, 0.5 ); glVertex3f( 0.5, -0.5, 0.5 ); glEnd();

  30. The “Color Cube” example // display() function continues // Create the color cube (Game Object) as six colored surfaces // Green side - LEFT glBegin(GL_POLYGON); glColor3f( 0.0, 1.0, 0.0 ); glVertex3f( -0.5, -0.5, 0.5 ); glVertex3f( -0.5, 0.5, 0.5 ); glVertex3f( -0.5, 0.5, -0.5 ); glVertex3f( -0.5, -0.5, -0.5 ); glEnd();

  31. The “Color Cube” example // display() function continues // Create the color cube (Game Object) as six colored surfaces // Blue side - TOP glBegin(GL_POLYGON); glColor3f( 0.0, 0.0, 1.0 ); glVertex3f( 0.5, 0.5, 0.5 ); glVertex3f( 0.5, 0.5, -0.5 ); glVertex3f( -0.5, 0.5, -0.5 ); glVertex3f( -0.5, 0.5, 0.5 ); glEnd();

  32. The “Color Cube” example // display() function continues // Create the color cube (Game Object) as six colored surfaces // Red side - BOTTOM glBegin(GL_POLYGON); glColor3f( 1.0, 0.0, 0.0 ); glVertex3f( 0.5, -0.5, -0.5 ); glVertex3f( 0.5, -0.5, 0.5 ); glVertex3f( -0.5, -0.5, 0.5 ); glVertex3f( -0.5, -0.5, -0.5 ); glEnd();

  33. The “Color Cube” example // display() function continues // Finished creating the color cube // Draw it by flush to the (back) display buffer glFlush(); // Make the back display buffer visible (swap it to the front). Double buffering. glutSwapBuffers(); } // end of display function.

  34. The “Color Cube” example // Keyboard event handler changes display parameter and then invoke display() void keyboard( int key, int x, int y ) { if (key == 'x') axis = xAxis; else if (key == 'y') axis = yAxis; else if (key == 'z') axis = zAxis; glutPostRedisplay(); // create an event to trigger the system to call display() }

  35. The “Color Cube” example // “idle” event handler, changes display parameter and then invoke display() void idle() { if (axis == xAxis) rotate_x += 0.1; else if (axis == yAxis) rotate_y += 0.1; else if (axis == zAxis) rotate_z +=0.1; glutPostRedisplay(); // create an event to trigger the system to call display() }

  36. The “Color Cube” example // The main function for initialization and setup int main(int argc, char* argv[]){ // initialize display window glutInit(&argc,argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutCreateWindow(“Rotating Cube"); glEnable(GL_DEPTH_TEST);

  37. The “Color Cube” example // The main function for initialization and setup // Register event handlers glutDisplayFunc(display); glutSpecialFunc(keyboard); glutIdleFunc(idle); // start the event loop glutMainLoop(); } // end of main

  38. Rotating Cube with Texture Mapping https://www.khronos.org/webgl/wiki/Tutorial

  39. Rotating Cube with Texture Mapping WebGL based. Coding Shaders. Can run on GPUs.

  40. A More Advanced OpenGL Example UA.cpp

  41. The “UA” example • Matrix Stack • Matrix Mode • Display Aspect Ratio • Lighting • Material Properties of GOs.

  42. OpenGL Matrix Stack • Matrices for geometric transformations are stacked. • Stack: first come last serve. The last matrix will be applied first. • The following code segment rotate before translation • glTranslated(-2,-1.0,-6); • glRotatef(rotation.x, 1, 0, 0); • Use glPushMatrix to save the current stack. • Use glPopMatrix to throw away newly added matrices and recover to the last pushed stack.

  43. OpenGL Matrix Mode • Two types of geometric transformation matrices: Projection and ModelView • Two types of projection matrices: perspective and parallel. • Perspective projection: foreshortening effect for realistic landscape display. • Parallel projection: no foreshortening effect for accurate measurements in, e.g., CAD. • ModelView mode take care all non projection matrices (translation, scaling, rotation, view orientation, …)

  44. P1 P2 P’1 z P’2 Default: eye is at a negative z location and looks towards the positive z direction. Perspective Projection: Foreshortening: The size of the projected object becomes smaller when the object moves away from the eye.

  45. Perspective Projection void glFrustum( • GLdouble  left, •   GLdouble  right, •   GLdouble  bottom, •   GLdouble  top, •   GLdouble  nearVal, •   GLdouble  farVal • ); • http://tildegarro.info

  46. Parallel (Orthoganal) Projection void glOrtho( • GLdouble  left, •   GLdouble  right, •   GLdouble  bottom, •   GLdouble  top, •   GLdouble  nearVal, •   GLdouble  farVal • ); • http://www.cs.sun.ac.za/~lvzijl

  47. gluLookAt: eye location and direction void gluLookAt( GLdouble eyeX,  GLdouble eyeY,  GLdouble eyeZ,  GLdouble centerX,  GLdouble centerY,  GLdouble centerZ,  GLdouble upX,  GLdouble upY,  GLdouble upZ); Edward Angel

  48. Display Aspect Ratio • To keep round objects round. • ar = display-width / display-height; • glFrustum(-ar, ar, -1.0, 1.0, 2.0, 100.0); • glOrtho(-ar, ar, -1.0, 1.0, 2.0, 100.0);

  49. Shading • Rendering of shades on 3D objects. • Lighting. • Material Properties of GOs.

  50. Game Engine Design Summary

More Related