CS 480/680: GAME ENGINE PROGRAMMING ANIMATION 2/21/2013 Santiago - - PowerPoint PPT Presentation

cs 480 680 game engine programming animation
SMART_READER_LITE
LIVE PREVIEW

CS 480/680: GAME ENGINE PROGRAMMING ANIMATION 2/21/2013 Santiago - - PowerPoint PPT Presentation

CS 480/680: GAME ENGINE PROGRAMMING ANIMATION 2/21/2013 Santiago Ontan santi@cs.drexel.edu https://www.cs.drexel.edu/~santi/teaching/2013/CS480-680/intro.html Game AI in Educational Game A CS RA @ 20 hrs/week for two-terms in the Digital


slide-1
SLIDE 1

CS 480/680: GAME ENGINE PROGRAMMING ANIMATION

2/21/2013 Santiago Ontañón santi@cs.drexel.edu https://www.cs.drexel.edu/~santi/teaching/2013/CS480-680/intro.html

slide-2
SLIDE 2

Game AI in Educational Game

A CS RA @ 20 hrs/week for two-terms in the Digital Media program. Experience Management for educational games Skills: * basic knowledge in AI * C# and/or JavaScript * Unity 3D experience is a plus If you are interested, contact me.

slide-3
SLIDE 3

Outline

  • Student Presentations
  • Cel Animation
  • Skeletal Animation
  • Skinning
  • Project Discussion
slide-4
SLIDE 4

Outline

  • Student Presentations
  • Cel Animation
  • Skeletal Animation
  • Skinning
  • Project Discussion
slide-5
SLIDE 5

Student Presentations

  • Steven Bauer:
  • “Real-time Shadows on Complex Objects”
  • Christopher Miller:
  • “Real-Time Strategy Network Protocol”
  • Joseph Muoio:
  • “Search-based Procedural Content Generation”
  • James Rodgers
  • “Terrain Analysis in an RTS – The Hidden Giant”
  • Justin Weaver:
  • “Coping with Friction in Dynamic Simulations”
slide-6
SLIDE 6

Outline

  • Student Presentations
  • Cel Animation
  • Skeletal Animation
  • Skinning
  • Project Discussion
slide-7
SLIDE 7

Game Engine Architecture

HARDWARE DRIVERS OS SDKs Platform Independence Layer Utility Layer Resource Management Game Engine Functionalities Game Specific Game Engine Dependencies

slide-8
SLIDE 8

Game Engine Architecture

Rendering Engine Animation Engine Collisions Physics Audio Subsystem Online Multiplayer Profiling & Debugging Gameplay Foundations (Game Loop) Artificial Intelligence Scripting

slide-9
SLIDE 9

Game Engine Architecture

Rendering Engine Animation Engine Collisions Physics Audio Subsystem Online Multiplayer Profiling & Debugging Gameplay Foundations (Game Loop) Artificial Intelligence Scripting

slide-10
SLIDE 10

Animation

  • Mostly for characters, but used for any animated object in

the game

  • Animation is DIFFERENT from “movement”:
  • Movement refers to game objects changing location and orientation

in the game world

  • Animation refers to game objects changing shape, or appearance

while potentially not changing location nor orientation.

slide-11
SLIDE 11

Animation Types

  • Cel Animation (applicable to bitmap graphics)
  • Skeletal Animation (applicable to all kind of graphics)
  • Per-Vertex Animation (applicable to vector-based

representations)

  • Skinned Animation (applicable to vector-based

representations)

slide-12
SLIDE 12

Cel Animation Examples

  • Classic pixel-art 2d animations:
  • Graphic artist draws different frames (“cels”) for each

animation, which the game engine displays in sequence

  • http://www.youtube.com/watch?v=ePJsX2YdqAs
slide-13
SLIDE 13

Cell-Animation Engine

  • Basic concepts:
  • Sprite: (recall from the “rendering lecture”):
  • Bitmap
  • Hotspot
  • Clip:
  • A scripted sequence of sprites that represents a specific animation
  • For example: “walking right”, or “crouching”
  • The animation engine allows the game engine to assign a

“clip” to a game object. The clip determines the sprite to be drawn at each game cycle.

slide-14
SLIDE 14

Cell-Animation Engine

  • Example code

Class Sprite { Bitmap bm; int hot_x; int hot_y; Void draw(int x, int y); } Class Clip { List<Sprite> sprites; List<Integer> times; int local_time; Boolean looping; Sprite update(); }

These lists define the animation sequence A clip keeps an internal clock, that is incremented each time the “update” function is called. Update advances the clock, checks which is the sprite that should be displayed at the current time, and returns it.

slide-15
SLIDE 15

Cell-Animation Engine

  • Example code

Class Sprite { Bitmap bm; int hot_x; int hot_y; Void draw(int x, int y); } Class Clip { List<Sprite> sprites; List<Integer> times; int local_time; Boolean looping; Sprite update(); }

times = [ 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30 ] bitmaps= [ ]

slide-16
SLIDE 16

Cell-Animation Engine

  • Example code

Class Sprite { Bitmap bm; int hot_x; int hot_y; Void draw(int x, int y); } Class Clip { List<Sprite> sprites; List<Integer> times; int local_time; Boolean looping; Sprite update(); }

times = [ 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30 ] bitmaps= [ ] This is oversimplistic. More expressive ways to define clips (allowing randomness, etc.) can be defined.

slide-17
SLIDE 17

Cell-Animation Engine

  • As part of your “AI” or “Scripting” code, each game object

will have an “update” function.

  • Such update function is responsible for assigning “clips” to

each game object

  • The rendering module calls the clips to determine which

sprite to draw.

slide-18
SLIDE 18

Outline

  • Student Presentations
  • Cel Animation
  • Skeletal Animation
  • Skinning
  • Project Discussion
slide-19
SLIDE 19

Skeletal Animation

  • Characters made up of rigid parts combined together

using a hierarchical “skeleton”

  • This can be done in either 2D or 3D:
  • 2D: http://www.youtube.com/watch?v=5_wzNRwyGD0
  • 3D: http://www.youtube.com/watch?v=Vb3L7Odrcdo
slide-20
SLIDE 20

Skeleton

  • Hierarchy of “rigid pieces” known as bones.
  • Example for a human character:

Pelvis LowerSpine UpperSpine RightArm RightForearm RightHand LeftArm LeftForearm LeftHand RightThigh RightLeg RightFoot LeftThigh LeftLeg LeftFoot

slide-21
SLIDE 21

Skeleton

  • In code, a skeleton can be represented as:

Class Skeleton { List<Bone> bones; } Class Bone{ Pose defaultPose; String name; int parent; List<int> children; }

Id: 0, Name: Pelvis, parent: -1, children: [1,9,12] Id: 1, Name: LowerSpine, parent: 0, children: [2] Id: 2, Name: UpperSpine, parent: 1, children: [3,6] Id: 3, Name: RightArm, parent: 2, children: [4] Id: 4, Name: RightForearm, parent: 3, children: [5] Id: 5, Name: RightHand, parent: 4, children: [] Id: 6, Name: LeftArm, parent: 2, children: [7] Id: 7, Name: LeftForearm, parent: 6, children: [8] Id: 8, Name: LeftHand, parent: 7, children: [] Id: 9, Name: RightThigh, parent: 1, children: [10] Id: 10, Name: RightLeg, parent: 9, children: [11] Id: 11, Name: RightFoot, parent: 10, children: [] Id: 12, Name: LeftThigh, parent: 1, children: [13] Id: 13, Name: LeftLeg, parent: 12, children: [14] Id: 14, Name: LeftFoot, parent: 13, children: []

slide-22
SLIDE 22

Skeleton

  • In code, a skeleton can be represented as:

Class Skeleton { List<Bone> bones; } Class Bone{ Pose defaultPose; String name; int parent; List<int> children; }

Id: 0, Name: Pelvis, parent: -1, children: [1,9,12] Id: 1, Name: LowerSpine, parent: 0, children: [2] Id: 2, Name: UpperSpine, parent: 1, children: [3,6] Id: 3, Name: RightArm, parent: 2, children: [4] Id: 4, Name: RightForearm, parent: 3, children: [5] Id: 5, Name: RightHand, parent: 4, children: [] Id: 6, Name: LeftArm, parent: 2, children: [7] Id: 7, Name: LeftForearm, parent: 6, children: [8] Id: 8, Name: LeftHand, parent: 7, children: [] Id: 9, Name: RightThigh, parent: 1, children: [10] Id: 10, Name: RightLeg, parent: 9, children: [11] Id: 11, Name: RightFoot, parent: 10, children: [] Id: 12, Name: LeftThigh, parent: 1, children: [13] Id: 13, Name: LeftLeg, parent: 12, children: [14] Id: 14, Name: LeftFoot, parent: 13, children: []

“defaultPose” sometimes called the “bindPose”

slide-23
SLIDE 23

Skeleton Poses

  • The pose of a bone is defined by (relative to the parent

bone):

  • Location
  • Orientation
  • Scale
  • Typically represented as a SQT structure: Scale (1

number, or a vector), rotation (1 Quaternion), Translation (1 vector)

  • The SQT structure is preferred to the typical 4x4 matrix used for

rendering, since it’s better for “blending” purposes (more on this later)

slide-24
SLIDE 24

Skeleton Poses

  • The pose of a bone is defined by (relative to the parent

bone):

  • Location
  • Orientation
  • Scale
  • Typically represented as a SQT structure: Scale (1

number, or a vector), rotation (1 Quaternion), Translation (1 vector)

  • The SQT structure is preferred to the typical 4x4 matrix used for

rendering, since it’s better for “blending” purposes (more on this later)

Class Pose { Quaternion r; Vector t; double s; }

slide-25
SLIDE 25

Key Poses

  • Remember: in “cel animation” the animation was defined

by different bitmaps, annotated with the times at which we need to change from one bitmap to another

  • In Skeletal animation, the idea is the same:
  • We define “key poses” (analogous to the bitmaps in cel animation)
  • We define the times at which the character should be in each key

pose

  • A key pose: list of poses for each bone (translation,

rotation, scale)

slide-26
SLIDE 26

Pose Interpolation

  • Clip: sequence of key poses at times t1, t2, …, tn
  • For each time t such that ti < t < tj
  • The animation engine can interpolate between the poses defined at

ti and tj

  • Interpolation generates intermediate poses
  • Since we can interpolate poses, we can play animations

at any speed, or even in reverse:

  • Game Time: time as maintained by the game loop
  • Animation Time: time as maintained internally by the clip
slide-27
SLIDE 27

Pose Interpolation

  • Notice that each pose is basically 10 numbers:
  • 3 for translation
  • 4 for rotation
  • 3 for scaling
  • A clip can be seen as the definition of 10 functions over time:
  • 2
  • 1

1 2 3 4 5 2 4 6 8 10 12 14 16 18 Tx Ty Tz Qx Qy Qz Qw Sx Sy Sz

slide-28
SLIDE 28

Pose Interpolation

  • Notice that each pose is basically 10 numbers:
  • 3 for translation
  • 4 for rotation
  • 3 for scaling
  • A clip can be seen as the definition of 10 functions over time:
  • 2
  • 1

1 2 3 4 5 2 4 6 8 10 12 14 16 18 Tx Ty Tz Qx Qy Qz Qw Sx Sy Sz

Interpolation typically just means linearly interpolating between the values specified in the key poses.

slide-29
SLIDE 29

Clip

  • Example clip classes:

Class JointPose { List<Pose> poses; } Class Clip{ List<JointPose> keyPoses; List<Double> times; double globalTimeAtStart; double localTime; double timeSpeed; JointPose update(double t); }

A Clip maintains an internal clock and animation speed. In this way, it can properly perform interpolation.

slide-30
SLIDE 30

Clip

  • Example clip classes:

Class JointPose { List<Pose> poses; Event event; } Class Clip{ List<JointPose> keyPoses; List<Double> times; double globalTimeAtStart; double localTime; double timeSpeed; JointPose update(double t); }

Additionally, we might want to annotated key poses with events. Like “footstep”, to trigger any game event we might need (such as playing some sound). Or we could even add color changes, etc.

slide-31
SLIDE 31

Outline

  • Student Presentations
  • Cel Animation
  • Skeletal Animation
  • Skinning
  • Project Discussion
slide-32
SLIDE 32

Per-Vertex Animation

  • Modifying the vertexes and triangles of a mesh

(deforming) to create realistic animations

  • Typically used for facial animations:
  • http://www.youtube.com/watch?v=IgRia5mRsWU (3:30)
slide-33
SLIDE 33

Skinned Animation

  • Hybrid between per-vertex animation and skeletal
  • animation. Consists on having a skeleton plus a

deformable skin around it (skeleton is not rendered)

  • Used typically for skin and cloth:
  • Oblivion: http://www.youtube.com/watch?v=n3Lje6CQzKA
  • Spore: http://www.youtube.com/watch?v=FQIF2_gxgUg
slide-34
SLIDE 34

Skinning

  • The skin is just a triangle mesh assigned to a skeleton
  • Each skin mesh has:
  • A list of bones to which the skin is bound
  • For each vertex in the mesh:
  • A weight for each of the bones: how much influence each bone has on

this vertex Bones Skin

slide-35
SLIDE 35

Skinning

  • Vertex coordinates of the skin defined in coordinates

relative to the bone

y x

slide-36
SLIDE 36

Skinning

  • We first obtain the transformation matrix of the bone, and

then use it on each of the vertexes of the skin for rendering.

y x

~ p Mb

slide-37
SLIDE 37

Skinning

  • We first obtain the transformation matrix of the bone, and

then use it on each of the vertexes of the skin for rendering.

y x

~ p Mb ~ pw = Mb~ p

slide-38
SLIDE 38

Skinning

  • In general, vertexes in the skin can be bound to more than
  • ne bone

y x

~ p1

x y

~ p2

slide-39
SLIDE 39

Skinning

  • In general, vertexes in the skin can be bound to more than
  • ne bone

y x

~ p1

x y

~ p2 ~ pw = w1M1~ p1 + w2M2~ p2

slide-40
SLIDE 40

Skinning

  • In general, vertexes in the skin can be bound to more than
  • ne bone

y x

~ p1

x y

~ p2 ~ pw = w1M1~ p1 + w2M2~ p2

In order to prevent having to store the coordinates of each vertex relative to each bone, the game engine just stores the vertexes

  • nce, and also a transformation

matrix per skin piece and bone, to map skin coordinates to bone coordinates.

slide-41
SLIDE 41

Skinning

  • In general, vertexes in the skin can be bound to more than
  • ne bone

[0, 1] [0.5, 0.5] [1, 0] Binding weights, vary gradually

  • ver the skin, to obtain the

desired “skin” effect: [0.8, 0.2] [0.9, 0.1]

slide-42
SLIDE 42

Skinning

  • In general, vertexes in the skin can be bound to more than
  • ne bone

[0, 1] [0.5, 0.5] [0.8, 0.2] [0.9, 0.1] [1, 0]

slide-43
SLIDE 43

Skinning

  • In general, vertexes in the skin can be bound to more than
  • ne bone

[0, 1] [0.5, 0.5] [0.8, 0.2] [0.9, 0.1] [1, 0]

slide-44
SLIDE 44

Skinning

  • In general, vertexes in the skin can be bound to more than
  • ne bone
  • This is how it would look like with another skin piece
  • Notice the smooth transition at the elbow
slide-45
SLIDE 45

Skinning

  • In general, vertexes in the skin can be bound to more than
  • ne bone
  • This is how it would look without skinning
  • Notice the abrupt transition at the elbow
slide-46
SLIDE 46

Skinning

  • It can be used both in 3D and 2D
  • It can be used for body parts, but also for facial

expressions (face bones)

slide-47
SLIDE 47

Animation Blending

  • Given two animations, blend them into one
  • Uses:
  • Smooth transitions between animations (blend the end of one with

the beginning of the other)

  • Gradual effects: if we have a walking animation, and an “injured

walking” animation, we can produce different blends, for intermediate degrees of injury.

slide-48
SLIDE 48

Animation Blending

  • Most common method: Linear interpolation (LERP)
  • Compute the poses for both animations at the current time

frame, and interpolate between them (like we did for pose animation).

  • We just need a weight w, which initially is set to 1, and

gradually goes down to 0, to transition from one animation to the other.

slide-49
SLIDE 49

The Animation Engine

Rendering Engine Animation Engine Collisions Physics Audio Subsystem Online Multiplayer Profiling & Debugging Gameplay Foundations (Game Loop) Artificial Intelligence Scripting Game State

slide-50
SLIDE 50

The Animation Engine

Rendering Engine Animation Engine Collisions Physics Audio Subsystem Online Multiplayer Profiling & Debugging Gameplay Foundations (Game Loop) Artificial Intelligence Scripting Scripting or AI modules set the current animation clip (of clip blends) to be played to a particular game object. Game State

slide-51
SLIDE 51

Game State

The Animation Engine

Rendering Engine Animation Engine Collisions Physics Audio Subsystem Online Multiplayer Profiling & Debugging Gameplay Foundations (Game Loop) Artificial Intelligence Scripting Animation engine plays the clips, determines the poses, and skins the objects. The output is a set of transformation matrices that the rendering engine can take for rendering each object/skin

slide-52
SLIDE 52

Game State

The Animation Engine

Rendering Engine Animation Engine The 3 main steps for in the animation pipeline: 1) Run clips 2) Determine poses 3) Skinning The output is the transformation matrices for each bone (and a set

  • f matrices plus weights

for each skin vertex) Run the clips, and get the key poses Key pose blending, obtain the global pose Skinning, obtain the correct transformations for each vertex

slide-53
SLIDE 53

Links to Interesting Game Videos

  • Gish:
  • http://www.youtube.com/watch?v=5WzGQQOIcp8
  • Locoroco:
  • http://www.youtube.com/watch?v=QfGrX0zzVp0
  • Aquaria:
  • http://www.youtube.com/watch?v=YqY9mDOw-UI
  • Non-rigid physics demo:
  • http://www.youtube.com/watch?v=KppTmsNFneg
slide-54
SLIDE 54

Outline

  • Student Presentations
  • Cel Animation
  • Skeletal Animation
  • Skinning
  • Project Discussion
slide-55
SLIDE 55

Remember that next week:

  • Third Project Deliverable:
  • First Demo of your Game Engine:
  • If you are a in-class student, you’ll show it to the class. If you are an on-line group,

you’ll send me a short video and I’ll play it in class.

  • Main functionalities should be there (it’s fine if it has bugs, crashes, etc., but I need to

see that most of the code is there)

  • It needs to run and be playable (even if gameplay is very simple)
  • Do not worry if the GUI is terrible, or if there is no GUI. I care about the engine, not the

GUI J

  • Source Code
  • Document:
  • Updated Game Engine diagram (shortened version of Deliverables 1 and 2)
  • Explain how each team member is addressing their part (one section per team

members.

  • Submission procedure:
  • Email to (copy both):
  • Santiago Ontañón santi@cs.drexel.edu
  • Stephen Lombardi sal64@drexel.edu
  • Subject: CS480-680 Project Deliverable 3 Group #