360 likes | 517 Views
Lecture 0. Shop ‘til you drop!. Projects. Course Mechanics. Tips for Warmup. Welcome. Welcome to CS195U!. Formally, “Topics in 3D Game Engine Development” For computers, not consoles Centered around developing multiple 3D game engines from scratch
E N D
Lecture 0 Shop ‘til you drop! Projects Course Mechanics Tips for Warmup Welcome
Welcome to CS195U! • Formally, “Topics in 3D Game Engine Development” • For computers, not consoles • Centered around developing multiple 3D game engines from scratch • Engines implement various 3D game technologies covered in class • Three individual projects • Open-ended final group project • Prerequisites: CS123, one of CS32 or CS195N (latter recommended)
Course topics DOES focus on Does NOT focus on Using existing 3D game engines (Unity, UDK, XNA…) Advanced 3D rendering techniques (try CS224) Realistic physics (rigid body, ragdoll, fluid) Advanced AI*, networking*, game design* • Building a 3D game engine from scratch • Using OpenGL to display 3D environments • Collision detection and response • Game object movement and interaction
What is a 3D game engine? • Core set of components that facilitate game creation • Rendering • Physics • Sound • User input • Artificial intelligence • Real-time networking • No such thing as an engine that can support every typeof game
Real-time strategy (RTS) engines • Large number of low-detail game units • Multiple levels of AI (individual units as well as computer players) • Client/server networking with some lag tolerance • Lockstep protocol • Heightmap-based terrain
Vehicle simulation engines • Low number of high-detail models • Level-of-detail (LOD) management • Minimal latency networking • Peer-to-peer • Advanced realistic physical forces
Lecture 0 Pretty demo time! Projects Course Mechanics Tips for Warmup Welcome
Warmup • One-week starter assignment • First-person movement • OpenGL texture loading • Practice using support code, Qt, OpenGL
Minecraft(the real game) • Indie game that made millions • Procedurally-generated block world (voxel-based) • Simple, pixelated graphics • Undirected multiplayer gameplay • Players manipulate the shape of the world
Minecraft(the class project) • Procedural noise for terrain generation • Simple voxel-based collision detection and response • View frustum culling • Infinite in all directions
Platformer • Ellipsoid-mesh collision detection and response • Advanced level representation • Arbitrary 3D levels • Pathfindingover navigation meshes • In-game UI
Final project • Group project with 2-4 other classmates • Your own idea, developed and implemented • Advanced engine features required • Playtesting with the general public • Polish will be important! • You own your creation
Lecture 0 Bureaucracy is fun! Projects Course Mechanics Tips for Warmup Welcome
Project checkpoints • Although there are only four projects, there are weekly checkpoints • Due at 11:59:59pm Tuesdays • Each checkpoint has well-defined objectives • Requirements are minimal, but you get out what you put in • If handin is on-time and meets requirements, it is “complete” • Otherwise, “incomplete”
Fixing incompletes Start • “Retry” within 3.5 days • Hand in a late or fixed version, new grade replaces old • 2 extra retries • Allow you to retry a previous retry • Only consumed if complete • A successful retry results in full credit • If out of retries, you can still complete by end by the end of the semester for half credit • Email the TAs after handing in Full credit Complete? Yes Yes No Use retry? Can use retry? Yes No Half credit Finish anyway? Yes No No credit No
Final grades • Final grades determined solely by number of credits by the end of the semester • There is no curve • Do the work, get an A!
Weeklies & playtesting • In-class project components • Have to be made up if missed • Weeklies: 2-3 minute demo by each student briefly stating progress • Non-final weeks of each project • Playtesting: Playing other students’ games and filling out feedback forms • Final week of each project • Exception: Warmup
Lecture 0 Ignore at your peril! Projects Course Mechanics Tips for Warmup Welcome
Overview • Build beginnings of engine from minimal starter code • Set up game loop • Create app/screen framework • Become familiar with QtCreator • Practice simple OpenGL calls • First-person movement • Orient camera with mouse • Move player with keyboard
Starter code • Based on Qt framework • Huge, cross-platform framework • Qt handles application loop • Your code resides in callbacks • See comments in method stubs for more details • We strongly recommend separating your engine from QGLWidget (view.cpp)
Game loop refresher • Separate logical steps that happen not necessarily in sync: • Handle user input • Read/write network data • Tick game state • Draw game state • We recommend measuring ticks in float secondsrather than intmilliseconds • Some games max out CPU, spinning as fast as possible • Don’t do this if not needed (wasteful, kills laptop batteries) • Starter code uses timer to target 60 updates/second
Coordinate systems y • Different game engines define coordinate systems differently • Most of you will probably use the OpenGL coordinate system • TAs will strive to be coordinate-system independent • “Horizontal plane” • Plane parallel to the ground (in OpenGL, the xz-plane) • “Up-axis” • Axis perpendicular to horizontal plane (in OpenGL, the y-axis) x z z z y x x y
Horizontal player movement • Simple trigonometry for horizontal movement • Player is rotated (yawed) around the up-axis at some angle • Get vector of forward velocity in horizontal plane • Multiply velocity by time since last tick and add to position • Strafing • Same as above, but use angle 90° left or right from the player’s facing direction
Vertical player movement • Acceleration due to gravity • (a reasonable negative constant) • Collision with ground • After previous step:
OpenGL matrix transformations Vertex • Not the same as the five matrices from CS123 • OpenGL conflates them into two matrices (projection, modelview) • Stored in column-major order rather than row-major • Modelview matrix • Transforms object space to camera space, usually changes every frame • Projection matrix • Has camera parameters (aspect ratio, field of view), usually only changes on window resize Object space Modelview matrix Camera space Projectionmatrix Clip space Perspective division Normalized device space Viewport transformation Screen space
First-person camera • Before drawing • Reset modelview matrix to the identity matrix • Rotate to the player’s look orientation (pitch+yaw) • Translate to negative player eyepoint • Reasonable distance above player position • On window resize • Use gluPerspective() to set up projection matrix • Remember to switch glMatrixMode()!
Texture loading • Easiest to leverage Qt framework: • Remember to delete textures! QImageimg(path); unsigned intid; id = view.bindTexture(img, GL_TEXTURE_2D, GL_RGBA,QGLContext::MipMapBindOption|QGLContext::LinearFilteringBindOption);
Texture loading • If you’d rather use straight GL calls: QImageimg(path); img = QGLWidget::convertToGLFormat(img); unsigned intid; glGenTextures(1, &id); glBindTexture(GL_TEXTURE_2D, id); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, img.width(), img.height(),0, GL_RGBA, GL_UNSIGNED_BYTE, img.bits());
Drawing geometry • For this week, you can just use immediate mode: glBindTexture(GL_TEXTURE_2D, id); glEnable(GL_TEXTURE_2D); glBegin(GL_QUADS); glTexCoord2f(0,0); glVertex3f(0,0,0); // remember winding order! glTexCoord2f(1,0); glVertex3f(1,0,0); glTexCoord2f(1,1); glVertex3f(1,1,0); glTexCoord2f(0,1); glVertex3f(0,1,0); glEnd(); glDisable(GL_TEXTURE_2D);
C++ tip of the week • Helpful Qt data structures! • classQList<T> • Like std::vector but much easier to use and usually faster, overrides += and << for quick manipulations • classQHash<K,V> • Useful, general hashtable implementation. Overload the global qHash() function to return int hash for new key types • classQPair<A,B> • A tuple of two types, comes in handy for hash table keys.
C++ tip of the week • Qtforeach loop macro: #include <QtGlobal> QList<int> ints; ints << 1 << 2 << 3; foreach (inti, ints) { cout << i << endl; // Value is a copy } foreach (constint &i, ints) { cout << i << endl; // Value is a reference }