images

Index

A

Acceleration

angular, 123124

definition, 117

formulas, 469

gravity, 121122

layman's definition, 117

on one axis, 117119

on two axes, 119121

ship controls, 126129

spaceship, 124126

Animation, 69, 131, 225, 247, 291, 343

animation loops, 1619

frame-by-frame animation, 9, 16

JavaScript timer, 19

rendering and displaying frames, 17

rules, 17

using requestAnimationFrame, 1920

while loop, 18

dragging an object

around canvas, 158

with motion code, 160

dynamic animation, 67

easing, 170

frames

as records, 6

definition, 5

programmed frames, 6

rendering and displaying frames, 16

JavaScript, 934

motion, 45

nontemperal media, 4

pressing and releasing an object

mouse events, 153

using touch events, 156

scripted animation, 17

springing, 180

static animation, 7

temporal media, 4

throwing

definition, 162

drawFrame function, 163

setting velocity, 162

trackVelocity function, 163

time, 4

trigonometry

angles, 3641

circles and ellipses, 5861

circular movement, 5860

definition, 36

distance between two points, 62

elliptical movement, 6061

formulas, 6667, 467

Pythagorean theorem, 6165

right-angle triangle, 36

rotation, 4750

sine waves, 5052

cosine waves, 5860

Array.splice method, 133

B

Backface culling, 414418

Billiard ball physics

conservation of momentum, 249273

mass, 248

momentum, 248

Bouncing off angles, 232

code optimization, 238239

coordinate rotation, 234238

multiple angles, 243246

not falling off the edge problem, 240

getBounds method, 240241

hit testing, 240

under the line problem, 241243

Bounding rectangle method, 203

C

Canvas drawing API

commands, 76

drawing context, 77

drawing curves

through control point, 8182

with quadraticCurveTo method, 8081

Canvas element coordinate system, 3840

Collision detection

between irregular shaped objects, 211

distance-based collision detection, 212

collision-based springing, 216218

formula, 224

simple collision detection, 212216

geometric hit testing methods, 202

between object and point, 209211

two objects, 202209

multiple-object collision detection, 218

basic collision detection, 219220

multiple-object springing, 221224

with circle's bounding box, 209

with rectangle's bounding box, 208

Combining colors, bitwise operators, 7273

Conservation of momentum, 249

formulas

in JavaScript, 473

in mathematics, 473

in JavaScript, 273

in mathematics, 273

on one axis, 250

code optimization, 254255

placing the objects, 253254

on two axis, 255

angle of collision, 256

checkCollision function, 258

one-dimensional collision, 256

plug-and-play momentum formula, 258

two-dimensional collision, 256

Coordinate rotation

advanced coordinate rotation

multiple objects, 230232

rotation angle, 228

single objects, 229230

formulas, 472

in third dimension, 371

simple coordinate rotation

angle and radius calculation, 227

positioning the object, 226

3D basics

bouncing

multiple object, 354357

single object, 352354

Z-sorting, 357358

collision detection, 378381

coordinate rotation, 371378

easing, 368370

gravity, 359361

perspectives

formula, 346347

in JavaScript, 347

techniques, 346

springing, 370371

velocity and acceleration, 350352

wrapping, 361368

z axis

left-hand coordinate system, 345

right-hand coordinate system, 344

D

Distance-based collision detection

formulas, 472

3D lighting

clamping, 419

lightMag, 422

3D solid, backface culling and depth

sorting, 427

triangle constructor method, 419

vectors

cross product, 421

dot product, 421

3D lines and fills

modeling 3D solids, 401

cylinder, 407409

extruded letter A, 405407

pyramid, 404405

spinning cube, 401404

moving 3D solids, 409411

points and lines, 383389

Point3D class, 387

point definition, 383

schematic representation, 386

with invisible points, 386

shapes

3D spinning letter E, 393

3D spinning square, 392

plotting points, graph paper, 392

square, 389

using triangles

advantages, 395

benefits, 396

complex polygon, 395

definition, 397

surface normal, 395

Drawframe function, 57

E

Easing

advanced easing, 179

formulas, 471

proportional motion, 170

simple easing

alpha component, 179

calculations, 173

formulas, 199200

illusion of motion, 170

moving targets, 177178

on colors, 179

schematic representation, 171

strategies, 171

target rotation, 178

turning off easing, 174177

verbose syntaxes, 172

Enhanced depth sorting, 417418

Environmental boundaries, 132

bouncing, 141146

steps, 142

strategies, 141

vs. screen wrapping, 141

formulas, 470471

regenerating objects, 137139

removing objects, 133137

screen wrapping, 139141

setting up boundaries, 132133

F

Forward kinematics (FK)

process automation, 301308

walk cycle, 302

programming

moving single segment, 293298

moving two segments, 298301

Frame-by-frame animation, 9, 16

Friction

angular velocity, 147

definition, 146

scaled-back velocity code, 147

spaceship simulation, 149150

velocity multiplication, 148149

G

Geometric hit testing methods, 202

GetBounds method, 202

Gravity

description, 277

formulas, 473

gravitational force

collision detection and reaction, 280281

gravitational constant, 277279

orbiting, 281282

slingshot effect, 279

H

Hit testing, 201

HTML5

canvas element support, 1011

CSS stylessheet, 14

debugging tools, 1516

document, 1213

features, 10

performance, 11

utils.js script, 14

Hypotenuse, 40

I

Inverse kinematics (IK)

dragging method

with multiple segments, 322326

with single segments, 320, 321322

law of cosines, 335

formula, 339

in JavaScript, 339

programming, 336339

reaching method

for an object, 332

for the mouse, 326

interaction, 333

multiple segment reaching, 332334

with single segments, 319, 320321

J

JavaScript

HTML5 (see HTML5)

objects, 20

constructor function, 2122

functional iteration, 2223

name property, 21

prototypes, 22

user interaction, 23

events and event handlers, 2324

listeners and handlers, 2434

K

Kinematics

definition, 291

forward kinematics, 292

inverse kinematics, 292

L

Law of cosines, formula, 474

Linear vertical motion, 5455

LineTo and moveTo method

create multiple curves, 82

closed curves, 87

context.quadraticCurveTo methods, 83

smooth multiple curves, 85

with midpoints, 84

drawing curves

quadraticCurveTo method, 80

through control point, 81

Listeners and handlers

addEventListener method, 24

key code property, 3234

keyboard events, 3132

mouse events, 24, 2627

mousemove, 24

mouseup and mousedown, 25, 26

mouse position, 2729

removeEventListener method, 24

touch events, 29

touch position, 3031

M

Mass, 248

Matrix

addition, 432433

canvas transforms

affine transformation, 437

context.save() and

context.restore() methods, 439

identity matrix, 438

skewing, 439

definition, 431

multiplication, 433

coding with matrices, 436437

coordinate rotation, 435436

scaling, 433435

Momentum, 248

Multiple-object collision detection

formulas, 224, 472

P

Particles, 275277

Pythagorean theorem, 6165

Q

Quadratic Bézier curve, 80

R

Rendering techniques

canvas element

CSS-style strings, 6970

drawing API, 7677

drawing context, 77

clearRect method, 77

line style properties, 78

color, canvas element

bitwise combination, 7273

bitwise extraction, 7374

color utility functions, 7476

combining colors, 7172

extracting component colors, 73

hexadecimal color values, 7071

transparency, 74

formulas, 100101, 468

lineTo and moveTo method, 7880

arc method, 87

arcTo method, 87

bezierCurveTo method, 87

multiple curves creation, 8287

quadraticCurveTo method, 8082

loading and drawing images, 91

context.drawImage method, 92

using image elements, 92

shapes, 8788

gradient fills, 8889

setting gradient color stops, 8991

S

Speeds, and centers, 56

Springing, 282

chained springs, 186189

formulas, 199200, 471

vs. gravity, 282283

line drawing and gravity additions, 185

to a moving target, 184

multiple objects

three objects connected, 196

two objects connected, 193

multiple springs, 189191

nodes

with connections, 286288

with mass, 288289

offsetting the target, 191193

in one dimension, 180182

proportional motion, 170, 180

springy node garden, 283286

in two dimensions, 183184

T

Throwing

definition, 162

drawFrame function, 163

setting velocity, 162

trackVelocity function, 163

Trig functions

arcsine, 45

arctangent, 4547

cosine, 4244

sine, 4142

tangent, 4445

Trigonometry

angles, 3641

canvas coordinate system, 3840

radians and degrees, 3638

context.rotate(angle)method, 37

measurements, 37

triangle sides, 4041

trig functions, 4147

circles and ellipses, 5861

circular movement, 5860

definition, 36

distance between two points, 62

elliptical movement, 6061

formulas, 6667, 467

Pythagorean theorem, 6165

right-angle triangle, 36

rotation, 4750

sine waves, 5052

smooth up and down motion, 5254

waves

cosine waves, 5860

linear vertical motion, 5455

pulsing motion, 5556

with drawing API, 5758

with two angles, 5657

U

User interaction

dragging an object

around canvas, 158159

with motion code, 160162

pressing and releasing an object, 153

mouse events, 154

using touch events, 156158

throwing (see Throwing)

Utils.intersects function, 205

V

Velocity

and vectors, 106

magnitude and direction, 107, 111

negative velocity, 107

angular velocity, 110113

concepts, 105

extended velocity, 115116

formulas, 469

layman's definition, 105

mouse follower, 114115

on one axis, 107109

on two axes, 109110

vector addition, 113114

W,X,Y

Walk cycle

beginnings, 303

calfOffsetSlider, 306

calfRangeSlider, 306

drawFrame function, 304

gravity, 309310

handling collision, 310311

handling reaction, 311312

offset definition, 303

screen wrapping, 313317

speedSlider, 306

thighBaseSlider, 306

thighRangeSlider, 306

Z

Z-sorting, 357358

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.219.220.22