chapter 13 polygonal meshes and animation © 2008 cengage learning emea

26
CHAPTER 13 CHAPTER 13 Polygonal Meshes and Polygonal Meshes and Animation Animation © 2008 Cengage Learning EM

Upload: baldric-dickerson

Post on 27-Dec-2015

235 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: CHAPTER 13 Polygonal Meshes and Animation © 2008 Cengage Learning EMEA

CHAPTER 13CHAPTER 13

Polygonal Meshes and AnimationPolygonal Meshes and Animation

© 2008 Cengage Learning EMEA

Page 2: CHAPTER 13 Polygonal Meshes and Animation © 2008 Cengage Learning EMEA

LEARNING OBJECTIVESLEARNING OBJECTIVES In this chapter you will learn about:

– Polygonal meshes– Representing a mesh– Connecting rigid parts of objects using joints– Computer animation techniques– The animation of rigid bodies– The animation of particles– Animation via the laws of physics– Animation of articulated objects– The behavioural animation of objects– Loading and rendering meshes in Direct3D 10

Page 3: CHAPTER 13 Polygonal Meshes and Animation © 2008 Cengage Learning EMEA

POLYGONAL MESHESPOLYGONAL MESHES

We have so far created geometry by defining each vertex constituting an object manually. – For instance, when defining a triangle we had to

hard-code its vertex coordinates as part of our application’s source code.

– This method is very rudimentary and becomes impractical when representing anything more complex than a cube or pyramid.

– As such, game artists and animators use high-end 3D modeling packages to visually create complex meshes for import into games.

Page 4: CHAPTER 13 Polygonal Meshes and Animation © 2008 Cengage Learning EMEA

POLYGONAL MESHESPOLYGONAL MESHES

A polygon mesh, or 3D model, is a set of vertices connected in such a way as to define a polyhedral object.

A polyhedron, shown in Figure 13-1, is an arbitrary geometric object consisting of flat faces and straight lines.

Page 5: CHAPTER 13 Polygonal Meshes and Animation © 2008 Cengage Learning EMEA

POLYGONAL MESHESPOLYGONAL MESHES Meshes are usually constructed using a

number of triangles or quadrilaterals. Using these polygon types simplifies the

model’s data structure storage requirements as well as the implementation of LOD algorithms.

Common applications for polygonal meshes in gaming include the modeling of complex architecture such as arches, buildings and bridges, vehicles, in-game characters, items, and weapons to name but a few.

Page 6: CHAPTER 13 Polygonal Meshes and Animation © 2008 Cengage Learning EMEA

POLYGONAL MESHESPOLYGONAL MESHES

Apart from consisting of a set of interconnected vertices, meshes almost always contain additional data generated using the modeling software such as:– surface normals– material properties– pixel color information– Texture coordinates.

Page 7: CHAPTER 13 Polygonal Meshes and Animation © 2008 Cengage Learning EMEA

Representing a MeshRepresenting a Mesh Two issues become apparent when

attempting to create a structure for the storage of a geometric mesh.

The first issue relates to the internal representation of the model itself with the second issue pertaining to the representation of models in three-dimensional space.

Neither OpenGL nor Direct3D place any limitations on the construction of more complex objects via the interconnection of numerous primitives – the constraint being only hardware-based (the

higher the number of polygons, the greater the strain on the GPU and memory).

Page 8: CHAPTER 13 Polygonal Meshes and Animation © 2008 Cengage Learning EMEA

Representing a MeshRepresenting a Mesh The simplest way of representing a mesh in 3D

space is to view it as an entity. We can thus define a scene as a set of entities,

for example, each object constituting the scene shown in Figure 13-3 and Figure 13-4 exist independently from each other.

Page 9: CHAPTER 13 Polygonal Meshes and Animation © 2008 Cengage Learning EMEA

Representing a MeshRepresenting a Mesh

All the objects shown in the previous two images have a certain spatial position and orientation – the cylinders and cubes are, for example, all rotated parallel to the y-axis.

Rotating an entity at a specific angle, for instance, results in an orientation change for that object without the rest of the scene being affected or keeping track of this change.

Page 10: CHAPTER 13 Polygonal Meshes and Animation © 2008 Cengage Learning EMEA

Representing a MeshRepresenting a Mesh

Hierarchical models can be used as an alternative to entities when representing meshes.

Hierarchical models are similar to entity-based models and are also defined using a collection of parts; however, hierarchical models feature an added relationship among these parts.

Page 11: CHAPTER 13 Polygonal Meshes and Animation © 2008 Cengage Learning EMEA

Representing a MeshRepresenting a Mesh

This hierarchical model can be animated by noting the interrelationship between its various parts – i.e. we can define the animation of our model in such a way so that the front wheel turns whenever the handlebar is rotated.

Also, when the hierarchical model’s front wheel is translated in an upwards direction, for example, the rest of the model will follow.

When modeling a complex mesh via a set of entities, we can construct and animate it using a series of function calls, each generating and transforming a part of the model.

Page 12: CHAPTER 13 Polygonal Meshes and Animation © 2008 Cengage Learning EMEA

Representing a MeshRepresenting a Meshvoid AnimateHierarchicalBike(spatialPosition, distanceTravelled, void AnimateHierarchicalBike(spatialPosition, distanceTravelled,

handlebarRotation, wheelRotation)handlebarRotation, wheelRotation){{

float spatialPosition_ = spatialPosition;float spatialPosition_ = spatialPosition;float distanceTravelled_ = distanceTravelled;float distanceTravelled_ = distanceTravelled;float handlebarRotation_ = handlebarRotation;float handlebarRotation_ = handlebarRotation;float wheelRotation_ = wheelRotation;float wheelRotation_ = wheelRotation;

/* construct and animate the mesh *//* construct and animate the mesh */RenderFrontWheel(spatialPosition_, wheelRotation_);RenderFrontWheel(spatialPosition_, wheelRotation_);RenderRearWheel(spatialPosition_, wheelRotation_);RenderRearWheel(spatialPosition_, wheelRotation_);RenderBikeFrame(spatialPosition_ + distanceTravelled_);RenderBikeFrame(spatialPosition_ + distanceTravelled_);RenderBikeSaddle(spatialPosition_ + distanceTravelled_);RenderBikeSaddle(spatialPosition_ + distanceTravelled_);RenderHandlebars(spatialPosition_ + distanceTravelled_, RenderHandlebars(spatialPosition_ + distanceTravelled_, handlebarRotation_);handlebarRotation_);RenderPedals(spatialPosition_ + distanceTravelled_, RenderPedals(spatialPosition_ + distanceTravelled_, wheelRotation_);wheelRotation_);

}}

Page 13: CHAPTER 13 Polygonal Meshes and Animation © 2008 Cengage Learning EMEA

Representing a MeshRepresenting a Mesh

Page 14: CHAPTER 13 Polygonal Meshes and Animation © 2008 Cengage Learning EMEA

Representing a MeshRepresenting a Mesh The elements stored in the above given tree can be

accessed or traversed in one of three ways. The first method of traversal, pre-order traversal,

starts at the root node, subsequently visiting each higher-level node before visiting its children.

Pre-order traversal for the above given tree will visit the nodes in the following order: 1–2–3–8–9–7–4–5–6.

This traversal method is most commonly encountered in computer gaming and is also used in skeletal animation.

Post-order traversal is the exact opposite of the previous technique. It starts at the leaf nodes followed by the higher-level nodes: 8–9–7–3–5–6–2–4–1.

The third traversal technique called level-order traversal, starts at the root node, visiting all its child nodes, then the nodes below them and so forth: 1–2–4–3–5–6–8–9–7. [see the textbook for an example

and detailed discussion].

Page 15: CHAPTER 13 Polygonal Meshes and Animation © 2008 Cengage Learning EMEA

Connecting Rigid Parts of Connecting Rigid Parts of Objects Using JointsObjects Using Joints

The handlebars–front wheel interconnection presented in the previous section illustrates the need for a relationship among the various parts of a mesh.

This relationship does not only make sense from a logical perspective but is crucial for the realistic and efficient animation of meshes.

One mechanism used to model this relationship is joint angles.

A joint angle determines the manner in which the attached mesh component is positioned with respect to the mesh object at the other end of the joint. – Thus, rotating the bike mesh’s handlebars about its vertical

axis at some specific angle, y, will also cause the attached front wheel to rotate at this exact same angle.

Page 16: CHAPTER 13 Polygonal Meshes and Animation © 2008 Cengage Learning EMEA

Connecting Rigid Parts of Connecting Rigid Parts of Objects Using JointsObjects Using Joints

Page 17: CHAPTER 13 Polygonal Meshes and Animation © 2008 Cengage Learning EMEA

ANIMATIONANIMATION Computer games draw heavily on animation –

simply put, without animation most games will not be worth playing.

Animation in games can include any motion such as flowing water, bubbling lava or a character running across the screen (which is simply a series of polygons or triangles manipulated and translated in real-time, as discussed in the previous section).

Despite offering the possibility of user interaction, all our programs have so far been static.

User interaction doesn’t count towards animation because the output does not change until the screen is cleared and redrawn.

[see the textbook and online source code for an example and detailed discussion].

Page 18: CHAPTER 13 Polygonal Meshes and Animation © 2008 Cengage Learning EMEA

Introduction to Computer Introduction to Computer Animation TechniquesAnimation Techniques

A number of computer animation techniques exist, each technique category describing a programming technique and the type of objects best suited for achieving the desired animation:1 Animation of rigid bodies.2 Animation of particles.3 Animation via the laws of physics.4 Animation of articulated objects (bipeds and

quadrupeds).5 Animation of objects according to their behaviour.

Page 19: CHAPTER 13 Polygonal Meshes and Animation © 2008 Cengage Learning EMEA

Animation of Rigid BodiesAnimation of Rigid Bodies

Rigid body animation is the simplest and most frequently encountered form of computer animation.

A common example is simply translating an object from one spatial position to another – in that way creating the illusion of a smoothly moving object.

Page 20: CHAPTER 13 Polygonal Meshes and Animation © 2008 Cengage Learning EMEA

Animation of ParticlesAnimation of Particles Particle animation is based on the scripting and

subsequent translation of a large group of objects – either particles (pixel sized units) or objects (mesh-based units).

Particle scripting controls each of the following properties:1 The particle’s original position (the spatial position the

particle is injected at).2 The particle’s original velocity (each particle is assigned a

speed when injected into the particle stream).3 The particle’s original direction of movement (particles

are injected into the particle stream at a specific angle).4 The physical dimension of the particle (each particle is

generated with a specific size).5 The original shape of the particle (particles can be

deformed based on the application of certain rules).6 The particle’s time to live or the amount of time it is

visible (the particle is destroyed the moment its time to live exceeds some predefined threshold).

Page 21: CHAPTER 13 Polygonal Meshes and Animation © 2008 Cengage Learning EMEA

Animation of ParticlesAnimation of Particles

Page 22: CHAPTER 13 Polygonal Meshes and Animation © 2008 Cengage Learning EMEA

Animation via the Laws of Animation via the Laws of PhysicsPhysics

Computer animation can be scripted to simulate a high degree of realism; however, the simulation of motion without factoring in the effect of object masses, friction, momentum, and forces will always seem what they are – scripted.

By modeling motion through the laws of physics, we can simulatethe movement, interaction and deformation of objects automatically.

Page 23: CHAPTER 13 Polygonal Meshes and Animation © 2008 Cengage Learning EMEA

Animation of Articulated Animation of Articulated ObjectsObjects

The animation of geometric objects representing bipeds and/or quadrupeds, as previously mentioned, is an extremely difficult form of animation due to the great number of complex transformations needed for the simulation of natural movement associated with humans and animals.

These objects are represented using articulated meshes.

An articulated mesh is simply a number of rigid objects connected to each other via a series of joints allowing the different parts to be translated and/or rotated.

Page 24: CHAPTER 13 Polygonal Meshes and Animation © 2008 Cengage Learning EMEA

Animation of Articulated Animation of Articulated ObjectsObjects

Page 25: CHAPTER 13 Polygonal Meshes and Animation © 2008 Cengage Learning EMEA

Behavioural Animation of Behavioural Animation of ObjectsObjects

Objects can be animated by simulating their known behaviour through the definition of a behavioural model, for example, to simulate the flocking of birds, the swarming of bees, or the movement of a school of fish.

The simplest behavioural model will require us to specify a set of rules for each fish or bee in relation to the position of the other fish or bees around it.

The Reynolds behavioural model is based on the following three rules:

1 Avoid collisions with nearby flock/swarm members.

2 Match the speed of nearby flock/swarm members.3 Stay close to nearby flock/swarm members.

Page 26: CHAPTER 13 Polygonal Meshes and Animation © 2008 Cengage Learning EMEA

LOADING AND RENDERING LOADING AND RENDERING MESHES IN DIRECT3D 10MESHES IN DIRECT3D 10

What we have not looked at yet is actually creating a model. – This process basically involves the use of some modeling

application like 3D Studio Max or Maya and saving of the mesh in a format that is readable by our application (commonly referred to as the model format).

Model formats are created by developers to meet their game’s requirements; for example, player models and non-static geometry (like switches, or a door) will normally be saved in the game’s custom model format.

An exporter is commonly written by the development team once the model format has been finalized. – This exporter converts meshes created in Maya, 3D Studio

Max or Blender to a format readable by the game – the game’s custom model format.

[see the textbook and online source code for an example and detailed discussion].