Implementation of an Outdoor Shooting Game - PowerPoint PPT Presentation

About This Presentation
Title:

Implementation of an Outdoor Shooting Game

Description:

Game objects are different (heterogeneous collection) Parent-child relationships (owner-weapon) ... return (hx1 yd * (hx2 - hx1)); Sky. Image that is textured ... – PowerPoint PPT presentation

Number of Views:34
Avg rating:3.0/5.0
Slides: 56
Provided by: infUs
Category:

less

Transcript and Presenter's Notes

Title: Implementation of an Outdoor Shooting Game


1
Implementation of an Outdoor Shooting Game
  • Szirmay-Kalos László
  • Budapest University of Technology
  • email szirmay_at_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
1.
2.
?
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_TRIAN
GLES) 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
Games
ControlIt(dt), InteractIt()
AnimateIt(dt), DrawIt()
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, checks
    collisions
  • 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 -gt ProcessInput( ) world
-gt Control( dt ) world -gt Animate( dt )
glClearColor(0, 0, 0, 0) glClear(GL_COLOR_BUF
FER_BIT GL_DEPTH_BUFFER_BIT)
avatar -gt SetCameraTransform() world -gt 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 BW 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) gt 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_fieldY w X
wheight float h2 height_fieldY w X1
wheight float h3 height_field(Y1) w
X wheight float h4 height_field(Y1)
w X1 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 ?v
u,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
  • Newtons 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 lt 4 Avatar_angle lt 40
Dont Care
Escape
Dist gt 6
Avatar_angle lt 20
Dist lt 4 Avatar_angle gt 60
Dist lt 1
Chase
Attack
Dist gt 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
tdt
velocity
t
force, acceleration
acceleration (0, 0, -g) velocity
acceleration dt position velocity dt
41
The bullet is flying Animate, Draw
void BulletAnimateIt( float dt )
acceleration Vector(0,0,-g) speed
acceleration dt position speed
dt void BulletDrawIt( ) 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() lt min) Collision!
43
Bullet collision detection
BulletInteractIt( GameObject obj ) if
(obj-gtGetType() TERRAIN) Mountain
terrain (Mountain )obj if
(terrain-gtHeight(position.x, position.y)gt
position.z) KillIt()
world -gt Join(new Explosion(position))
if ( obj-gtGetType() AVATAR
obj-gtGetType() ENEMY )
if (bounding spheres overlap)
KillIt() obj -gt KillIt( ) world -gt
Join(new Explosion(position))
44
Collision detection with fast objects
ray-tracing
position
rel_velocity velocity - vel2 ray position
rel_velocityt If (ray intersects bounding
sphere first AND tintersect lt dt)
Collision!
vel2
velocity
hit_object world-gtIntersect(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 gt
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
51
Keyboard control
KeyboardFunc SpecialFunc
input
IsSpace, IsLeft, IsRight, IsUp, IsDown
IdleFunc GameLoop
virtual world
52
Game engine
GLUTWindow
GameObject position, velocity, acceleration Contro
lIt(float dt ) AnimateIt(float dt) InteractIt(
GameObject o) DrawIt( ) IntersectIt(Ray r,
float t)
GameEngine DisplayFunc IdleFunc KeyPress
500 C lines
Texture Load( char fname)
world
Member Control, Animate, Draw Interact,
Intersect, Join
next
Particle
avatar
ParticleSystem Emit(int n)
Avatar ProcessInput() SetCameraTransform()
TexturedObject
BillBoard DrawIt()
53
Shooting game
GameEngine
Avatar
TexturedObject
ParticleSystem
Self ProcessInput ControlIt InteractIt
Explosion ControlIt
Enemy DrawIt InteractIt ControlIt
Terrain DrawIt AnimateIt
Sky DrawIt
SpaceGame
350 C lines
54
Indoor games?
  • No terrain
  • Building
  • Cannot be represented by a height field
  • Textured triangle mesh
  • Collision without checking all triangles
  • Fast visibility quickly eliminating the
    potentially invisible objects

55
Thanks for your audience
Write a Comment
User Comments (0)
About PowerShow.com