Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSE 381 – Advanced Game Programming Animation Systems Jack Skellington, from The Nightmare Before Christmas.

Similar presentations


Presentation on theme: "CSE 381 – Advanced Game Programming Animation Systems Jack Skellington, from The Nightmare Before Christmas."— Presentation transcript:

1 CSE 381 – Advanced Game Programming Animation Systems Jack Skellington, from The Nightmare Before Christmas

2 Static objects are boring Look at your diamonds –they just sit there –we can give them velocities, but they’re still boring What about more complicated shapes? –living things –vehicles –etc. These things are all made up of separate moving parts that are still part of the whole object –where I go, my arms go with me

3 Player Animation States Think about an FPS What game states does the player have? –running forward –running backwards –running sideways –jumping –falling –landing –dying (in all sorts of ways) –etc.

4 Typical Role of Artist Create a mesh for a game shape/character/vehicle –geometry –texturing –materials Create animation sequences for different game states for that entity NOTE: exported data can be tricky

5 5 11-5 Keyframe Animation  In traditional hand-drawn animation:  the senior key artist would draw the keyframes, and  the junior artist would fill the in-between frames.  We can use a similar approach  For a 30-fps animation, < 30 frames are defined per second: 1.The key data are assigned to the keyframes 2.In-between frames are interpolated

6 Morph Targets Keyframe Animation –i.e. per-vertex animation Morph Targets –pre-set poses for vertices –at runtime, interpolate Good for face animation –requires huge numbers of morph targets

7 The MD2 Model Format Created by id for Quake 2 The Good: –easy to parse and animate –support with many free modeling tools –plenty of free models available TurboSquid, 3DCafe, 3DTotal The not so good: –older format –inefficiently stores keyframe info –not good for realistic animations –time consuming for artists to animate

8 The MD2 File Layout MD2 Header Skin Data Texture Coords Triangles GL Commands Keyframes Skin Offset Texture Coord Offset Triangle Offset GL Command Offset Keyframe Offset File End Offset Data

9 The MD2 Header struct MD2Header { char ident[4]; int version; int skinWidth; int skinHeight; int frameSize; int numSkins; int numVertices; int numTextureCoords; int numTriangles; int numGLCmds; int numFrames; int skinOffset; int texCoordOffset; int triangleOffset; int frameOffset; int GLCmdOffset; int eofOffset; }; Let’s look at Ogro Invasion’s md2model.h

10 Some More Details Data stored in struct chunks struct TexCoord { short s; short t; }; struct KeyFrame{ float scale[3]; float translate[3] char name[16]; Vertex vertices[numVertices]; }; struct Vertex{ unsigned char v[3]; unsigned char lightNormalIndex; }; struct Triangle { short vertexIndex[3]; short texCoordIndex[3]; };

11 Again, the positions between frames? Must be interpolated (linear interpolation used) Assume a time from 0.0 to 1.0 –from one keyframe to next –m_interpolation variable in MD2Model class –other important variables to note: m_startFrame, m_endFrame, m_currentFrame, m_nextFrame v i = v 1 + t * (v 2 – v 1 )

12 Alternative Approaches For better results we could use other techniques –more efficient –more realistic Frame Hierarchies Bone (Joint) Hierarchies Skinning Quaternions

13 Frame Hierarchy A means for organizing a mesh into structures that may be moved separately –meshes can consist of other child meshes This provides a means for fluid object animation –when artists create meshes, they establish hierarchy

14 Frame Hold the actual hierarchy data –each Frame can contain zero to many child Frames –each Frame can contain zero to many sibling Frames Important Properties of a frame –Name –Transformation Matrix –Adjacency data –And others All other Frames can be accessed through the root

15 Example: A Tank Gun Turret should be able to rotate Gun Barrel should be able to move up and down The wheels should be able to spin

16

17

18

19 What would be the Tank Hierarchy? Tank hull – central parent section –Wheels – children of the hull and siblings to each other –Gun Turret – child of the hull Gun Barrel – child of the Gun Turret Sub-meshes –wheels vertices would be a sub-mesh of the hull –where the hull goes, the wheels go –when the hull rotates, the wheels rotate

20 What do you think a combined Matrix is? Our tank will have a location –we translate according to that location, by building a matrix Remember, the sub-meshes may move and rotate additionally, relative to the tank, but independently of the hull Combined matrices combine the two –move, scale, and rotate the mesh (along with entire object) –move, scale, and rotate the sub-mesh relative to the parent mesh

21 What is skinning? Provides a means to animate a model while reducing the "folding" and "creasing" of polygons as the model animates Sometimes called skeletal animation A model is represented in two parts: –skin –skeleton

22 How is skinning implemented? Define a bone hierarchy in a model –separate from the mesh (triangle) data –is linked to the model's mesh, so that animating the bone hierarchy animates the mesh's vertices Multiple bones affect each vertex in the skin mesh Each bone has a weighting value to determine how much influence it has in proportion to the others

23 How are bones moved? Matrices –each bone has a transformation matrix for moving it Moving a joint has what effect? –moves all children joints (and their children, etc.) –transforms corresponding vertices according to weighted results So, to calculate the final position of a vertex: –Each joint transformation is applied to the vertex position, scaled by its corresponding weight

24 24 11-24 Hierarchical Model  Associate joints with vertices

25 25 11-25 Hierarchical Model Example

26 What might be a disadvantage of skinning? Doesn’t provide realistic muscle movement –Ex: a character flexing an arm muscle –historically more important for movies than games –games are starting to use muscle controllers as well attached to bones, mimic muscle movements

27 Skinned Data Necessary data to define relationship between bone hierarchy and the skin: –Number of vertices –Number of joints –Vertex Weights –Vertex Indices –Inverse Matrices Values are extracted from the modeler when loading an animation

28 Inverse Bone Matrices (IBMs) Used to transform from skin space to bone space Describe the transformation matrix from "the root" bone in the hierarchy to "each" bone in the hierarchy

29 Typical Skinning Algorithm 1.Transforms vertex positions from their object space (skin space) into bone space using the IBMs. 1.Performs the key-frame based animation for that frame, which transform the vertex positions back into skin space in its animated pose. 1.The model is then rendered.

30 Problems With Euler Angles Bones are positioned and rotated –pitch, yaw, and roll are Euler angles We need to interpolate interim bone transforms Euler angles are problematic when interpolating –Can produce incorrect results –Gimbal lock

31 Quaternions An extension of complex numbers An alternative for interpolation –don’t suffer from Gimbal Lock A rotation can be represented: –using 3 Euler Angles –using 4 Quaternion Components 1 real (think scalar) 3 imaginary (think vector) Alt representation: 4 num vector (real as w)

32 Quaternion Advantages Interpolation is easy between 2 quaternions Smoother animation Take up less space than matrices Can easily be converted to matrices for rendering

33 But what is a quaternion? A quadruple Q= (q x, q y, q z, q w ) = q x i + q y j + q z k + qw Where i 2 = j 2 = k 2 = -1 Alternatively denoted as [w, x, y, z] Or [s, v] where s is the scalar (w) v is the vector (x,y,z)

34 Quaternion Addition All quaternions for a 3D rotation have unit length Adding and subtracting quaternions is easy Ex: p = [w 1, x 1, y 1, z 1 ] q = [w 2, x 2, y 2, z 2 ] p + q = [w 1 +w 2,x 1 +x 2,y 1 +y 2,z 1 +z 2 ]

35 Quaternion Multiplication Same as multiplying two rotation matrices: –the rotations will be added together p = [s1, v1]q = [s2, v2] p * q = [s 1 s 2 – v 1 ∙v 2, s 1 v 2 + s 2 v 1 + v 1 xv 2 ]

36 Quaternion Conversions What the hell is a quaternion anyway? –Artists can’t relate Plus, OpenGL doesn’t support them So what do we do? –do all interpolation using quaternions –convert results to matrices

37 Conversion Calculations Euler angles to quaternions: Q x = [cos(pitch/2),sin(pitch/2),0,0] Q y = [cos(yaw/2),0,sin(yaw/2),0] Q z = [cos(roll/2), 0, 0, sin(roll/2)] Quaternion to matrix: 1-2y 2 -2z 2 2xy-2wz2xz+2wy 2xy+2wz1-2x 2 -2z 2 2yz-2wx 2xz-2wy2yz+2wx1-2x 2 -2y 2

38 LERPs AND SLERPs 2 Ways of Interpolating Quaternions LERP –Linear Interpolation SLERP –Spherical Linear Interpolation LERP SLERP

39 Interpolating LERP(q 0,q 1,t) = (1-t)q 0 + tq 1 = arccos(q 0 ∙ q 1 ) SLERP (q 0, q 1, t) = (sin((1-t) ))q 0 /(sin) + (sin(t))q 1 /(sin)

40 References UV Mapping a Human Head Mesh Utilizing LSCM –http://bgdm.katorlegaz.com/lscm_tute/lscm_tute.htmhttp://bgdm.katorlegaz.com/lscm_tute/lscm_tute.htm Wikipedia: –http://en.wikipedia.org/wiki/Skeletal_animationhttp://en.wikipedia.org/wiki/Skeletal_animation CADTutor –http://www.cadtutor.net/dd/bryce/anim/anim.htmlhttp://www.cadtutor.net/dd/bryce/anim/anim.html Tom’s Hardware –http://graphics.tomshardware.com/graphic/20000717/i mages/keyframe.gifhttp://graphics.tomshardware.com/graphic/20000717/i mages/keyframe.gif


Download ppt "CSE 381 – Advanced Game Programming Animation Systems Jack Skellington, from The Nightmare Before Christmas."

Similar presentations


Ads by Google