Princípios de Implementação de Jogos com Modelos 3D em C++ Marcelo Johann II Semana de Tecnologia Departamento de Tecnologia da UNIJUÍ Outline for Introduction Introduction - how games evolved? Motivation - why teaching games? Goals - what to get from the course? Methodology - what’s gonna happen here? Background - what are you expected to know? Infrastructure - HW and SW that we need… Interaction - Keep questioning me… Contents… UNIJUÍ 2004 - Marcelo Johann – Mini Curso de Games : 2 Introduction • Back to the 80’s… Galaga Moon Patrol http://spacemul.emufrance.com/screen.php3?id=13&lettre= G&lang=eng http://www.mobygames.com/game/shots/gameId,575/ UNIJUÍ 2004 - Marcelo Johann – Mini Curso de Games : 3 Introduction • 1986: first 3D games appearing… Alien 8 http://spacemul.emu-france.com/screen2.php3?id2=14687&lang=eng UNIJUÍ 2004 - Marcelo Johann – Mini Curso de Games : 4 Introduction • And today… Half Life 2 http://www.rottentomatoes.com/g/pc_games/half_life_2/images.php UNIJUÍ 2004 - Marcelo Johann – Mini Curso de Games : 5 Introduction Mobil 1 British Rally Championship http://www.mobygames.com/game/shots/p,3/gameId,3758/ UNIJUÍ 2004 - Marcelo Johann – Mini Curso de Games : 6 Introduction • Evolution of computer games From 1D, 2D to complex 3D universe • Needs: hardware, software, artwork • Trends: Continuous hardware evolution Engines - higher abstraction levels Professional programming techniques Extensive visual work -> $$$ UNIJUÍ 2004 - Marcelo Johann – Mini Curso de Games : 7 Motivation • Computing requires Programming • Learning how to program is not simple • Difficulty to begin and to be professional time, interaction, experience • Need for problems that justify complex programming languages and techniques Games: lot of fun and learning potential UNIJUÍ 2004 - Marcelo Johann – Mini Curso de Games : 8 Goals • Learning and Practicing Object-Oriented Programming – Professional C++, modular, O-O • Learning technologies for the development of games that use 3D models – Engines, 3D modeling – Game architecture and timing – Game techniques with many other applications UNIJUÍ 2004 - Marcelo Johann – Mini Curso de Games : 9 Methodology • Hands-on • based on step-by-step examples Test/Ask about everything • At the beginning: – No class definitions! – Avoid using complex C++ constructions; – Emphasis on productivity • Complexity is introduced when required UNIJUÍ 2004 - Marcelo Johann – Mini Curso de Games : 10 Background • Structured programming • C language • Basic data structures Not necessary: – experience on C++ programming – advanced computer graphics Ask about people’s background Should ask anything that you don’t know! UNIJUÍ 2004 - Marcelo Johann – Mini Curso de Games : 11 Infrastructure • Fast computer with: OpenGL, “Accelerated” graphic card Linux with gcc, g++, make (Mac OS X now) • Gizmo3D http://www.tooltech-software.com/ • Crystal Space http://sourceforge.net/projects/crystal • Open Dynamics Engine http://ode.org UNIJUÍ 2004 - Marcelo Johann – Mini Curso de Games : 12 Outline for Contents Introduction Main engine - Gizmo3D structure and start up 3D modeling - from triangles to transforms Events - how to read keyboard input Logic - game actions and control Simulation loop - structure, moves, timing Terrains and LODs - levels of detail Animation / levels - frame, skeleton concepts Collision and Physics - world behavior Things that we did not consider… UNIJUÍ 2004 - Marcelo Johann – Mini Curso de Games : 13 Main Engine Gizmo3D • Features • Tutorial slides: * skip gzApplication methods and task * skip gzGeometry and gzTransform * stop at the Expanding Scene • start with exe00 • Essential constructions of O-O – Just Object *pt = new Object(...); – And result = pt -> method(...); UNIJUÍ 2004 - Marcelo Johann – Mini Curso de Games : 14 3D Modeling Surfaces • Triangles - the easiest way * exe01 • Material • Lighting * http://www.xmission.com/~nate/tutors.html * exe02 and exe03 * slides Gizmo Material UNIJUÍ 2004 - Marcelo Johann – Mini Curso de Games : 15 3D Modeling • Texture * gizmo databases * exe04 to exe11 (0,1) (1,1) (0,0) (1,0) UNIJUÍ 2004 - Marcelo Johann – Mini Curso de Games : 16 3D Modeling • Transformations * gizmo slides 66 to 76 * exe12 to exe14 • Cloning * exe15 • Groups * exe17 a exe19 • Billboard * gizmo’s billboard and my tests UNIJUÍ 2004 - Marcelo Johann – Mini Curso de Games : 17 Control Events •O-O * exe20 to exe21 • app->run and onTick * gizmo slides 29 a 36 * exe22 •app->run and onIdle onTick and onIdle have to call refreshWindow UNIJUÍ 2004 - Marcelo Johann – Mini Curso de Games : 18 Logic of the Game Logic Model may be different from 3D • First City * exe25 • Estoque: “Sokoban” * estoque • Network * show socketControl in drive44 UNIJUÍ 2004 - Marcelo Johann – Mini Curso de Games : 19 Simulation Loop void MyApp::onIdle() { if(m_win->m_key_left_is_down) car1->changeDirection(-1,m_win->getFrameRate()); if(m_win->m_key_right_is_down) car1->changeDirection(1,m_win->getFrameRate()); if(m_win->m_key_up_is_down) car1->speedup(1.3f); if(m_win->m_key_down_is_down) car1->slowdown(1.3f); car1->move( 1, m_win->getFrameRate()); car2->move(m_win->getFrameRate()); car3->move(m_win->getFrameRate()); cam->move(m_win->getFrameRate()); m_win->refreshWindow(); Drive exe44 } UNIJUÍ 2004 - Marcelo Johann – Mini Curso de Games : 20 Playing with Models Take drive44 Take models from: www.3dtotal.com * sofa.3ds * speedboat.3ds * chevi_camaro.3DS * tiebomber.3ds UNIJUÍ 2004 - Marcelo Johann – Mini Curso de Games : 21 Terrain and LOD terrain.txt of the drive44 • Window * gizmo’s window shows LOD Other example is broken (62) UNIJUÍ 2004 - Marcelo Johann – Mini Curso de Games : 22 Animation and Levels • Frame Animation Map file of Crystal Space Flying Brick (exe57) Crystal Space map file UNIJUÍ 2004 - Marcelo Johann – Mini Curso de Games : 23 Skeleton Animation Types of Joints Open Dynamics Engine UNIJUÍ 2004 - Marcelo Johann – Mini Curso de Games : 24 Animation Character Lara Croft http://www.3dkingdom.org UNIJUÍ 2004 - Marcelo Johann – Mini Curso de Games : 25 Animation Control Frame sequences Pony Tail with a math model UNIJUÍ 2004 - Marcelo Johann – Mini Curso de Games : 26 Collision • gzIntersector • intersect(stuff,…) • getResults NO! OK UNIJUÍ 2004 - Marcelo Johann – Mini Curso de Games : 27 Collision • Car corners • Simple Geometry UNIJUÍ 2004 - Marcelo Johann – Mini Curso de Games : 28 Collision • To collide is hard • To know what to do next is even harder UNIJUÍ 2004 - Marcelo Johann – Mini Curso de Games : 29 Collision • stairs and floor • vertical versus horizontal UNIJUÍ 2004 - Marcelo Johann – Mini Curso de Games : 30 Physics • How about collision with other objects? • This is very hard to handle… Model what happens in a physical system * example odetest - from ODE’s test_buggy UNIJUÍ 2004 - Marcelo Johann – Mini Curso de Games : 31 Missing • Sound • Animation Control • Explosions, particles • Artificial intelligence Other Engines and Game Resources: www.3dlinks.com UNIJUÍ 2004 - Marcelo Johann – Mini Curso de Games : 32 Thanks to • PUCRS - Uruguaiana Marcus Kindel ([email protected]) Cintya Bortolazzo • UFRGS - Computação Gráfica Luciana Nelel (www.inf.ufrgs.br/~nedel) [email protected], pelo ODE • Gizmo3D & game community Anders Modén ([email protected]) Esteban G. Clua ([email protected]) UNIJUÍ 2004 - Marcelo Johann – Mini Curso de Games : 33 Princípios de Implementação de Jogos com Modelos 3D em C++ Marcelo Johann [email protected] www.inf.ufrgs.br/~johann II Semana de Tecnologia Departamento de Tecnologia da UNIJUÍ