230 likes | 412 Views
Game Programming :Programming Lab 2. 2008/9/24 Kim, HyungSeok. Part I: Framework 1. Windows creation 2. Renderer 3. Lights and Objects/Model loading 4. GUI design/Input system/Sound. Part II: Simulation 5. Math libs 6. Collision detection 7. Basic scripting 8. Model animation
E N D
Game Programming:Programming Lab 2 2008/9/24 Kim, HyungSeok
Part I: Framework 1. Windows creation 2. Renderer 3. Lights and Objects/Model loading 4. GUI design/Input system/Sound Part II: Simulation 5. Math libs 6. Collision detection 7. Basic scripting 8. Model animation Part III: Advanced rendering 9. Special effects 10. Textures Part IV: Final 11. Game final Programming Labs HyungSeok Kim, Konkuk University
Game Engine • Rendering • Video • Audio • Haptic, … • Simulation • AI • Math calculation • User interface • Input • Scene graph HyungSeok Kim, Konkuk University
What we have done in Lab #1 • Create a frame for an engine • Game Engine • Main loop • Class Renderer • Class Simulator • … HyungSeok Kim, Konkuk University
Lab #2 • Create a basic scene graph structures • Which object to create? • Which structure to hold? • Create a basic renderer • How to put renderer into the framework? • Which functionality the renderer will have? HyungSeok Kim, Konkuk University
Scene Definition • Task 1: Following the last Homework • Create a scene database • How? • Requirement analysis • Specification • Implementation HyungSeok Kim, Konkuk University
Scene Definition • Common properties of objects • Position • Orientation • Transform matrix • Shape • Mesh • … and more HyungSeok Kim, Konkuk University
Scene Definition • Scene structure • Why? • How? • Array? • Tree? • Any others? • Your proposition • Pros and cons HyungSeok Kim, Konkuk University
Scene Definition • Scene Graph • Tree-like approach HyungSeok Kim, Konkuk University
Scene Definition • 1. Class hierarchy definition • 2. Data definition • Position/Orientation? • Shape? HyungSeok Kim, Konkuk University
Transform Matrix • Transform Matrix • Matrix for specifying position and orientation • Translation • Rotation • Matrix concatenation and storage HyungSeok Kim, Konkuk University
Hierarchical Transform • Hierarchical transform • World matrix stack • Why stack? HyungSeok Kim, Konkuk University
Exemplar Code in D3D ID3DXMatrixStack* pMatrixStack; D3DXCreateMatrixStack(0,&pMatrixStack); pMatrixStack->LoadMatrix(<Hand matrix>); <Draw Hand> For childrens • pMatrixStack->Push(); • pMatrixStack->MultMatrix(<Finger 1 matrix>); • <Draw Finger 1> • For childrens if any • … • pMatrixStack->Pop(); HyungSeok Kim, Konkuk University
Exemplar Code in OpenGL glLoadMatrix(<Hand matrix>); <Draw Hand> For childrens • glPushMatrix(); • glMultMatrix(<Finger 1 matrix>); • <Draw Finger 1> • For childrens if any • … • glPopMatrix(); HyungSeok Kim, Konkuk University
What to Store? • Matrix • Translation (x,y,z) • Rotation • How? • Quaternion HyungSeok Kim, Konkuk University
D3D functions • Mesh • Container for a shape • Shape-wise representation: an object • Use a container instead of separated elements • Easy representation and control of multiple shapes • Store/load of a shape • OpenGL: vertex array, index array, … • D3D: class ID3DXMesh; HyungSeok Kim, Konkuk University
Displaying a Mesh • D3D • HRESULT ID3DXBaseMesh::DrawSubset(DWORD AttribId ); • Subset • A group of triangles which has the same material and states • OpenGL • glDrawPrimitives, glDrawElements, … HyungSeok Kim, Konkuk University
Scene Definition • class Scene { … }; • Singleton • Access scene definition • Array case: able to get array • Tree case: able to get tree root • … HyungSeok Kim, Konkuk University
Lab #2 – Task 1 • Create Box or Sphere and add it to your scene • OpenGL • GLUquadricObj* gluNewQuadric( void ); • void gluSphere( GLUquadricObj *qobj,GLdouble radius,GLint slices,GLint stacks); • D3D • HRESULT D3DXCreateBox(LPDIRECT3DDEVICE9 pDevice, FLOAT width, FLOAT height, FLOAT depth, LPD3DXMESH *ppMesh, LPD3DXBUFFER *ppAdjacency); • Draw HyungSeok Kim, Konkuk University
Renderer • Render scene periodically • Should be called in main loop • Event-based update vs. Continuous update HyungSeok Kim, Konkuk University
Renderer • Functions • Traverse scene database • Scene graph • Scene array? • … • Render each object • Optimization HyungSeok Kim, Konkuk University
Lab #2 – Task 2 • Add another box or sphere to the scene graph • Render all HyungSeok Kim, Konkuk University
Conclusion HyungSeok Kim, Konkuk University