Where was this used? Ragdoll prerequisites  Animation system needs to be capable of procedural animation  (ideal) employ callbacks that allow manipulation

  • View
    213

  • Download
    0

Embed Size (px)

Transcript

  • Slide 1

Slide 2 Slide 3 Where was this used? Slide 4 Ragdoll prerequisites Animation system needs to be capable of procedural animation (ideal) employ callbacks that allow manipulation on a per bone basis (less-ideal) Ragdoll system hijacks the skeleton entirely NITROSystem has an animation system that employs per bone callbacks Collision detection system Slide 5 A Simple Particle System Nodes points that get updated by physics Constraints apply further modification to the position of a node (or nodes) (particle system demo)particle system demo Slide 6 What is the basic idea? Use a particle system to represent the skeleton Apply appropriate constraints to ensure valid skeleton configurations Derive rotation and translation info from the configuration of the nodes Procedurally animate Slide 7 Nodes struct Node { Vecposition; VeclastPos; Vecaccel; floatinvMass; }; Slide 8 Updating Nodes Accumulate Forces void AccumulateForce(Node* n, Vec* F) { n->accel += Scale(F, n->invMass); } void ApplyGlobalAcceleration(Vec* a) { (loop over all nodes n) { n->accel += *a; } } Slide 9 Updating Nodes Use the Verlet Integration formula to update nodes X n+1 = 2X n X n-1 + A n t 2 X n+1 = X n + (1-f)(X n X n-1 ) + A n t 2 This formula has several advantages Numerically stable Easy to apply constraints Slide 10 Updating Nodes void Integrate(float t2, float f) { (loop over all nodes n) { Vec tmp = n->position; n->position += (1.0-f)*(n->position-n->lastPos); n->position += n->accel*t2; n->lastPos = tmp; n->accel = 0; } } Slide 11 Applying Constraints Always apply constraints after updating the nodes The underlying strategy for applying a constraint is Determine where a node needs to be Put it there Verlet Integration takes care of the rest Slide 12 Constraints Preventing floor penetration is an example of a global constraint void FloorConstraint(float height) { (loop over all nodes n) { if(n->position.y position.y = height; } } } Slide 13 Constraints Examples of local constraints are enum ConstraintTypes { ANCHOR, STICK, LINE, PLANE, SPLINE, }; Slide 14 Constraints struct Constraint { inttype; Node*n1; Node*n2; Vec*anchor; floatmaxLength; floatminLength; } Slide 15 Constraints void ApplyAnchor(Constraint* c) { c->n1->position = *c->anchor; } Code for applying a stick constraint is included in the handout Note: Applying 2 constraints to the same node generally results in one of the constraints being violated Slide 16 Constraints void ApplyConstraints(int iterations) { for(int i=0; i type) { case ANCHOR: ApplyAnchor(c); break; case STICK: ApplyStick(c); break; } } //apply global constraints FloorConstraint(0.0f); } } Slide 17 Constraints Some types of constraints require a change in velocity, i.e. Bounce To change the velocity of the particle you can: Modify the value of the lastPos (instantaneous impulse) Accumulate a force on the particle that will change its velocity on the next frame (penalty force) Slide 18 The Verlet System The Verlet System is a set of Nodes and Constraints structVerletConfig { Vec gravAccel; int iterations; float airFriction; }; Slide 19 Updating the Verlet System void UpdateVerlet(VerletConfig* conf, float t) { float t2 = t*t; //Accumulate Forces ApplyGlobalAcceleration(&conf->gravAccel); (Accumulate local forces) //Integrate Integrate(t2, conf->airFriction); //Apply Constraints ApplyConstraints(conf->iterations); } Slide 20 Animation Primer Slide 21 What do we need in order to create an animation? We need to calculate a model space representation of each bone of the animation Translation information is carried by the position of the node Rotation information can be derived by the positions of nearby nodes Slide 22 Future mechanism for obtaining information about rotations Allow a Verlet Node to carry information about its orientation in the form of a quaternion struct Node { Quatrotation; QuatlastRot; QuatangularAccel; }; Update the quaternions using the Non-Abelian Verlet formula R n+1 = (W t (R n (R n-1 ) -1 ) 1/t ) t Rn Slide 23 Brads A structure that contains all of the information necessary to calculate a full bone matrix from a set of 4 Verlet Nodes A Brad is a brass fastener that attaches several sheets of paper together Brad Moss is a designer that made a suggestion that motivated the idea of this object Slide 24 Brads struct Brad { Node*a; Node*b; Node*c1; Node*c2; Mtx43*bone; intbAxis; //0-X, 1-Y, 2-Z intcAxis; }; Slide 25 Brads Brads Node A Node B B Axis Node Ca Node Cb C Axis Slide 26 Revised Update Routine void UpdateVerlet(VerletConfig* conf, float t) { float t2 = t*t; //Accumulate Forces ApplyGlobalAcceleration(&conf->gravAccel); (Accumulate local forces) //Integrate Integrate(t2, conf->airFriction); //Apply Constraints ApplyConstraints(conf->iterations); //Update All Brads UpdateAllBrads(); } Slide 27 Articulate Collision We used a standard swept sphere collision for each node Note: Node positions were in world space The spheres were so small that the swept sphere routine would fail due to imprecission Slide 28 Fixed Point math primer Fixed Point math primer 5.7 1.2 114 570 6.84 0.3 0.3 9 0 0.09 Slide 29 FX32 FX32 is a 32 bit Fixed Point data type with 12 bits of decimal precision As a mnemonic device we will create a unit called FX =4096 A decimal number like 5.7 can be represented in FX32 format as 5.7FX = 23347.2 -> 23347 Every time you multiplying 2 FX32 numbers you accumulate an extra power of FX Therefore you must divide by FX whenever you multiply Basically, if ab=c then (aFX*bFX)/FX = cFX Slide 30 Sample multiplication routine fx32 FX_MUL(fx32 a, fx32 b) { return (a*b)>>12; } Slide 31 FX32 The range of FX32 is about +/-500000 The smallest number is 1/FX = 0.00024 The smallest FX32 number that can be multiplied by itself and get a non-zero result is 0.015FX = 64 If you let 1FX represent 1 meter, then the precision limit is a few centimeters Slide 32 Sphere Intersection Test BOOL SphereIntersection(VecFx32* center, fx32 radius, VecFx32* point) { fx32 r2, d2; VecFx32 diff; r2 = FX_MUL(radius, radius); VEC_Subtract(center, point, &diff); d2 = VEC_DotProduct(&diff, &diff); return (d2 < r2); } Radius > 1 Meter Good results Radius < 1 Meter Not so good Radius < 0.5 Meters Pretty crappy Slide 33 How do we get around this? Create a new fixed point data type with higher precision Fx32e has 27 bits of precision Uncertainty of multiplication is on the order of microns rather than centimeters (a micron is 1000 times smaller than a millimeter) Use a regular integer multiplication if you can get away with it (dont divide by FX after you multiply) Slide 34 Example: We start with 4 numbers that are related by ab > cd If we try to evaluate this comparison using FX32 multiplication we have (aFX*bFX)/FX > (cFX*dFX)/FX Truncation error might cause this comparison to evaluate incorrectly If we try to evaluate this comparison using integer multiplication we have aFX*bFX > cFX*dFX There is still truncation error, but it is significantly smaller. On the order of millimeters rather than ten centimeters Slide 35 A Better Sphere Intersection Test BOOL SphereIntersection(VecFx32* center, fx32 radius, VecFx32* point) { fx32 r2, d2; VecFx32 diff; r2 = radius*radius; VEC_Subtract(center, point, &diff); d2 = diff.x*diff.x + diff.y*diff.y + diff.z*diff.z; return (d2 < r2); } Radius > 1mm Good results Radius < 1mm Not so good Radius < 0.5mm Pretty crappy Slide 36 More than 2 Mults If you are going to perform more than 2 FX32 mults, you can get some extra mileage out of integer multiplies If you want to multiply three numbers abc using FX32 multiplication you have ( ( aFX*bFX)/FX ) *cFX)/FX Instead use integer mults and divide by FX2 at the end This is (aFX*bFX*cFX)/(FX*FX) Slide 37 Sample 3 mult Routine fx32 FX_MUL3(fx32 a, fx32 b, fx32 c) { return (a*b*c)>>24; } Slide 38 Philosophy of using integer multipy fx32 numbers accumulate a power of FX for every integer multiply An fx32 can endure 2 powers of FX before overflowing An fx64 can endure 5 powers of FX before overflowing Perform as many integer multiplies as possible before dividing out the powers of FX If you are comparing two numbers that have accumulated the same powers of FX (homogeneous), perform the comparison without dividing out the powers of FX If the numbers you are comparing are not homogeneous, multiply by FX until the powers are equal, then perform the comparison Try not to overflow Slide 39 Rotation Math In order for a matrix M to represent a rotation it must be OrthoNormal. This means that its inverse is equal to its transpose. One direct result of a matrix being OrthoNormal is that det(M) = +/- 1 If det(M) = 1 then the matrix represents a rotation If det(M) = -1 then the matrix represents a reflection. Slide 40 Reflections and Rotations If you multiply two OrthoNormal reflection matrices S 1, S 2, then the product is also OrthoNormal The determinant of this product is: det(S 1 S 2 ) = det(S 1 )det(S 2 ) = (-1)(-1) = 1 The short story? 2 consecutive reflections form a rotation. Slide 41 Reflection Rotations Rotations are unique (almost) If the result of 2 reflections places a vector where it needs to be, then the reflections are equivalent to the corresponding rotation Goal: find a reflection algorithm to replace a rotation algorithm Slide 42 Find 2 Reflections Slide 43 Reflect about a line that bisects the initial and final vectors Reflect about the final vector Slide 44 Reflection about a line The component of the vector that is parallel to the line does not get reflected Split the vector into 2 components V = V line + V reflect The reflected vector is V = V line - V reflect To find V line you need the normal n in the direction of