1 / 55

Implementation of an Outdoor Shooting Game

Implementation of an Outdoor Shooting Game. Szirmay-Kalos László Budapest University of Technology email: szirmay@iit.bme.hu Web: http://www.iit.bme.hu/~szirmay. Demo 1: The objective. Virtual reality. Virtual world. avatar. rendering. interaction. User input. Tasks in games.

arella
Download Presentation

Implementation of an Outdoor Shooting Game

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. Implementation of an Outdoor Shooting Game Szirmay-Kalos László Budapest University of Technology email: szirmay@iit.bme.hu Web: http://www.iit.bme.hu/~szirmay

  2. Demo 1: The objective

  3. Virtual reality Virtual world avatar rendering interaction User input

  4. Tasks in games • Image synthesis from the point of view of the avatar • Control of the avatar through input devices (keyboard, mouse) • Control of the intelligent virtual objects by artificial intelligence algorithms • Simulation of the physical laws (collisions, forces)

  5. I/O libraries simulation Windows + GLUT input Virtual world rendering OpenGL

  6. I/O management initialization callback registration Operating System Windows main GLUT DisplayFunc KeyboadFunc SpecialFunc callbacks IdleFunc OpenGL Graphics hardware application

  7. Rendering with OpenGL Perspective transformation Virtual world Viewing transformation 2. 1.  628 1325 1325 628 clipping visibility: z-buffer display

  8. Geometry definition glBegin(GL_TRIANGLES); glColor3f( 1, 1, 0 ); glVertex3f( x11, y11, z11 ); glVertex3f( x12, y12, z12 ); glVertex3f( x13, y13, z13 ); glColor3f( 0, 1, 0 ); glVertex3f( x21, y21, z21 ); glVertex3f( x22, y22, z22 ); glVertex3f( x23, y23, z23 ); glEnd(); x12,y12,z12 x13,y13,z13 x11,y11,z11 glColor4f(R,G,B,A)

  9. Texturing

  10. Texture mapping (u2, v2) x3,y3,z3 (u1, v1) (u3, v3) x2,y2,z2 x1,y1,z1 glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, texture_id); // which texture glBegin(GL_TRIANGLES); glTexCoord2f(u1, v1); glVertex3f(x1, y1, z1); glTexCoord2f(u2, v2); glVertex3f(x2, y2, z2); glTexCoord2f(u3, v3); glVertex3f(x3, y3, z3); glEnd(); glDisable(GL_TEXTURE_2D);

  11. ControlIt(dt), InteractIt() AnimateIt(dt), DrawIt() Games avatar rendering interaction User input

  12. Game objects • ControlIt: • Interacts, thinks and applies his available controls (e.g. runs, shoots) • InteractIt • Looks at the states of other objects, checkscollisions • AnimateIt: • Moves to its new position according to the elapsed time • DrawIt: • Draws itself onto the screen

  13. Simulation loop (Game loop) dt void IdleFunc( ) { // idle call back float old_time = time; time = glutGet( GLUT_ELAPSED_TIME ); float dt = time - old_time; avatar -> ProcessInput( ); world -> Control( dt ); world -> Animate( dt ); glClearColor(0, 0, 0, 0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); avatar -> SetCameraTransform(); world -> Draw( ); glutSwapBuffers( ); }

  14. Data structure of the virtual world • Game Objects are dynamic (killing) • Game objects are different (heterogeneous collection) • Parent-child relationships (owner-weapon) world avatar Enemy 2 bullet explosion terrain sky Enemy 1 Weapon Join: új elem hozzávétele

  15. Terrain • Complex geometry • Height field • Complex texture • No Control • No Animation • Collision detection, • Lifts objects

  16. Terrain geometry z z y x x,y Height function definition: Discrete samples + linear interpolation z = height(x,y)

  17. Discrete samples = B&W Image Height map Triangle mesh

  18. Reducing the number of triangles: Level of detail

  19. Height-field texturing: projecting the top view y x v u

  20. Terrain improvement: Detail map

  21. Terrain collision detection if (height(x,y) > z) Collision! Walking on the terrain: Position(x, y) = (x, y, height(x,y) + legsize) z x,y

  22. Bi-linear Height field interpolation float Height( float x, float y ) { x += wwidth/2; y += wlength/2; x = x / wwidth * w; y = y / wlength * l; int X = (int)x, Y = (int)y; float h1 = height_field[Y * w + X] * wheight; float h2 = height_field[Y * w + X+1] * wheight; float h3 = height_field[(Y+1) * w + X] * wheight; float h4 = height_field[(Y+1) * w + X+1] * wheight; float xd = x - X; float yd = y - Y; float hx1 = h1 + xd * (h2 - h1); float hx2 = h3 + xd * (h4 - h3); return (hx1 + yd * (hx2 - hx1)); }

  23. Sky • Image that is textured on something: sphere • Sky geometry: dome, sphere • No Control • No Animation • No collision detection

  24. Definition of surfaces as triangle meshes: Tessellation 1. Find a parametric equation of a sphere: x(u,v) = x0 + r cos 2u sin v y(u,v) = y0 + r sin 2u sin v z(u,v) = z0 + r cos vu,v[0,1] 2. Select points in the unit rectangle

  25. GLU Quadrics: Sphere GLUquadricObj * quadric; // definition quadric = gluNewQuadric( ); gluQuadricTexture(quadric, GL_TRUE); // draw glBindTexture(GL_TEXTURE_2D, sky_texture_id); gluSphere(quadric, sky_radius, 32, 20);

  26. Enemy • Animated geometry • Defined by keyframes organized as clips • Stand, run, attack, die, • + mesh animation • Textures (animated) • Artificial intelligence • Collision detection

  27. Keyframe animation: running

  28. Inbetweening: Computation of frames from keyframes Nonlinear interpolation linear interpolation keyframes t

  29. What and how to interpolate • High quality animation: • Newton’s laws: the second derivative of a motion curve is proportional to the force, which acts through an elastic mechanism: interpolation curve is C2 • Even the interpolated frames should meet physical constraints: Bone animation • Games: • Linear interpolation • Interpolate the vertices of the mesh: Mesh deformation

  30. Example for bone animation

  31. Cyclic walk

  32. Mesh morphing: t= 0 Time: t Two neighboring keyframes Linear interpolation for each vertex t= 1 Current vertex positions

  33. Running as mesh morphing + position animation: position += velocity * dt

  34. Motion definition • Keyframes are organized into clips • Keyframes are designed off line and stored in a file: MD2, MD3, etc. file formats • Typical clips in a game: • Run, stand, attack, die, pain, salute, crouch, wave, point, taunt, etc.

  35. Clips Stand 40 keyframes Run 5 keyframes Salute 11 keyframes

  36. Motion control AI machine AI state time: t Keyframes stored in an MD2 file Clip = start, stop keyframe Keyframe animation Vertex positions of a triangle mesh

  37. Artificial Intelligence of an Enemy Dist < 4 && Avatar_angle < 40 Dont Care Escape Dist > 6 Avatar_angle < 20 Dist < 4 && Avatar_angle > 60 Dist < 1 Chase Attack Dist > 1 Collision with the bullet Dying Avatar_angle Avatar

  38. Texturing

  39. Bullet • Geometry: sphere • Textured • Not intelligent • Physical animation

  40. Physical animation of the bullet t+dt velocity t force, acceleration acceleration = (0,0,-g) velocity += acceleration * dt position += velocity * dt

  41. The bullet is flying: Animate, Draw void Bullet::AnimateIt( float dt ) { acceleration = Vector(0,0,-g); speed += acceleration * dt; position += speed * dt; } void Bullet::DrawIt( ) { glPushMatrix( ); glTranslate(position.x, position.y, position.z); glBindTexture(GL_TEXTURE_2D, bullet_texture); gluSphere(quadric, 1.0, 16, 10); glPopMatrix( ); }

  42. Collision detection between two slow objects Problem with fast objects t given t t +  t dist = obj1.position - obj2.position min = obj1.BoundingRadius() + obj2.BoundingRadius() if (dist.Length() < min) Collision!

  43. Bullet collision detection Bullet::InteractIt( GameObject * obj ) { if (obj->GetType() == TERRAIN) { Mountain * terrain = (Mountain *)obj; if (terrain->Height(position.x, position.y)> position.z) { KillIt(); world -> Join(new Explosion(position)); } } if ( obj->GetType() ==AVATAR || obj->GetType() == ENEMY ) { if (“bounding spheres overlap”) { KillIt(); obj -> KillIt( ); world -> Join(new Explosion(position)); } } }

  44. Collision detection with fast objects: ray-tracing position rel_velocity= velocity - vel2 ray: position + rel_velocity·t If (ray intersects bounding sphere first AND tintersect < dt) Collision! vel2 velocity hit_object = world->Intersect(position,velocity,t); world avatar ship1 ship2 space sun bullet explosion

  45. Billboards • Single semi-transparent texture on an oriented quadrilateral pos pos QUAD X Y Z x y z Tmodell Tview Tperspective QUAD position orientation camera position camera orientation

  46. Explosion • Seemingly complex, random structure • Similar look from all directions • Collection of billboards • Particle system

  47. Particle Systems global force field (smoke) position: position += velocity * dt velocity: velocity += acceleration * dt acceleration: acceleration = force / weight lifetime age: age += dt; if (age > lifetime) Kill(); size, dsize: size += dsize * dt; weight, dweight: weight += dweight * dt color, dcolor: color += dcolor * dt random initial values

  48. Explosion settings Rand position = Rand( center, 0.1 ); lifetime = Rand( 2.0, 1.0 ); size = 0.001; dsize = Rand( 1.0, 0.5 ) / lifetime / 2.0; velocity = Rand( CVector(0, 0, 0), 0.4 ); acceleration = Rand( CVector(0, 0, 0), 0.4 ); color = Rand( Color(1, 0.5, 0, 1), Color(0, 0.5, 0, 0) ); dcolor = Color(0, -0.5, 0, -1) / lifetime / 2;

  49. Avatar • Keyboard controls its behavior: • ProcessInput • Its position and orientation will be the camera position and orientation before rendering • SetCameraTransform

  50. Avatar :: SetCameraTransform Avatar :: SetCameraTransform( ) { glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(position.x, position.y,position.z, position.x + head.x, position.y + head.y, position.z + head.z, up.x, up.y, up.z); } eye up = [0, 1, 0] lookat

More Related