Home

Game Physics

image

Contents

1. Access continuous data in memory e g traversing an array from begin to end produces less cache misses e so less loading time e vectors are faster to traverse than lists L Universiteit Utrecht Game Ph ys ics 40 Optimization techniques e Size does matter To compile arrays of structures the compiler performs a multiplication by the size to create the array indexing e if the structure size is a power of 2 the multiplication is replaced by a shift operation much faster e you can round array sizes aligned to a power of 2 even if you do not use all of it Example ine SOrEBodyNedes 33 7 int softBodyNodes 64 faster allocation L Universiteit Utrecht Game Physics 41 End of Physics engine design and implementation
2. breDeraulecol lisronlont zgnras on 7 col lrsionConrigurallonm new btrDefaultCollisiontontiguration h z Set up the collision dispatcher btCollisionDispatcher dispatcher new brcollisieonDisparcher collisroncontigquration 7 Set Up broad phase methodi btBroadphaselnterface overlappingPairCache new btDbvtBroadphase Set up the constraint solver btSequentiallmpulseConstraintSolver solver btSequentiallmpulseConstraintSolver btDiscreteDynamicsWorld dynamicsWorld new btDiscreteDynamicsWorld dispatcher Over lappingPaircache solver collisionConrtrgurakion p dynamiuesworld setGravity bEVectors 0 9 7 315 0 L Universiteit Utrecht Game P hysics Simulation cor imne i 0 KOY dynamicsWorld gt stepSimulation 1 0f 60 f 10 j print positione of all objeers ror int 7 dynanresworld gemNumeollirsetonOb jects L J gt 0 2 J 1 BECoL Il 1 sronobjeer obj dynemicsWworld gercollisionObjyectArray I birRig1dBody Body btkhigidbody upeast cba if body Es body gt getMotionState brcrransform trang body gt getMotionState gt getWorldTransform trans Dreinck World pos Ep 8 SENA Lloar crans getOrigin getxXx Eloar trans getOrigin NE cei On loar trans getOrigin getz 2 L Universiteit Utrecht Game P hysics Termination remove the rigid bodies from the dynamics world and delete them ter ine i dynamicswWworld gt gerNumCol
3. set to a factor of 0 04 i e expand the shape by 4 cm if unit is meter to still look correct the margin is usually subtracted from the original shape e Itis always highly recommended to use SI units everywhere L Universiteit Utrecht Game P hysics 17 User collision filtering e Bullet provides three ways to filter colliding objects Masks e user defined IDs could be seen as layers in 2D grouping possibly colliding objects together Broadphase filter callbacks e user defined callbacks called at the early broad phase of the collision detection pipeline Nearcallbacks e user defined callbacks called at the late narrow phase of the collision detection pipeline L Universiteit Utrecht Game Physics 18 Rigid body dynamics e The rigid body dynamics is implemented on top of the collision detection e It adds force mass inertia velocity and constraint e Main rigid body object is btRigidBody moving objects have non zero mass and inertia inherits world transform friction and restitution from btCollisionObject adds linear and angular velocity L Universiteit Utrecht Game P hysics 19 Rigid body dynamics e Bullet has 3 types of rigid bodies Dynamic moving bodies e have positive mass position updated at each frame Static non moving bodies e have zero mass cannot move but can collide Kinematic bodies e have zero mass can be animated by the user can push dynamic bodi
4. Bullet Collision Detection can be used on its own as a separate SDK without Bullet Dynamics Discrete and continuous collision detection Swept collision queries Generic convex support using GJK capsule cylinder cone sphere box and non convex triangle meshes Support for dynamic deformation of non convex triangle meshes e Multi physics Library includes Rigid body dynamics including constraint solvers Support for constraint limits and motors Soft body support including cloth and rope L Universiteit Utrecht Game P hys ics Design e The main components are organized as follows Soft Body Dynamics Bullet Multi Threaded Extras Maya Plugin Rigid Body Dynamics etc Collision Detection Linear Math Memory Containers L Universiteit Utrecht Game P hysics Overview e First the high level simulation manager is defined btDiscreteDynamicsWorld Of btSoftRigidDynamicsWorld manages the physics objects and constraints implements the update call to all objects at each frame e Then the objects are created btRigidBody you will need e the mass gt 0 for dynamic objects 0 for static e the collision shape box sphere etc e the material properties friction restitution etc e Finally the simulation is updated at each frame stepSimulation L Universiteit Utrecht Game Physics 8 Initialization 4 Collision contiquration Contains default setup for memory collision setup
5. provides algorithms and structures for collision detection Object with world transformation and collision shape bGrCollisionObj ct Collision shape box sphere etc usually centered around the origin of their local coordinate frame e btCollisionShape Interface for queries e btCollisionWorld e The broad phase quickly rejects pairs of objects that do not collide using a dynamic bounding volume tree based on the AABBs it can be changed to another algorithm L Universiteit Utrecht Game Physics 14 Collision dispatcher e Acollision dispatcher iterates over each pair of possibly colliding objects and calls the collision algorithm corresponding to each configuration e These algorithms return the time of impact the closest points on each object and the penetration depth distance vector iversiteit Utrecht Game P hysics Collision dispatcher boxbox spherebox CONVEX CYLINDER ik CONE g CAPSULE COMPOUND compound TRIANGLE r n MESH concaveconvex L Universiteit Utrecht CONVEX CYLINDER CONE CAPSULE spherebox gjk spheresphere gjk gjk gik compound compound concaveconvex concaveconvex Game Physics COMPOUND compound compound compound compound compound TRIANGLE MESH concaveconvex concaveconvex concaveconvex compound gimpact Collision detection e Bullet uses a small collision margin for collision shapes to improve performance and reliability
6. Game Physics Game and Media Technology Master Program Utrecht University Dr Nicolas Pronost Physics engine design and implementation Physics engine e The physics engine is a component of the game engine e The game engine separates reusable features and specific game logic basically software components physics graphics input network etc e The physics engine handles the simulation of the world physical behavior collisions terrain changes ragdoll and active characters explosions object breaking and destruction liquids and soft bodies L Universiteit Utrecht Game Physics 3 Physics engine e Some SDKs Open Source e Bullet Open Dynamics Engine ODE Tokamak Newton Game Dynamics PhysBam Box2D Closed source e Havok Physics e Nvidia PhysX C Universiteit Utrecht Game Ph ys ics Case study Bullet e Bullet Physics Library is an open source game physics engine http bulletphysics org open source under ZLib license It provides collision detection soft body and rigid body solvers It has been used by many movie and game companies in AAA titles on PC consoles and mobile devices It has a modular extendible C design This is the engine you will use for the practical assignment e have a good look at the user manual and the numerous demos e g CCD Physics Collision and SoftBody Demo L Universiteit Utrecht Game Ph ys ics Features e
7. es but cannot react to them L Universiteit Utrecht Game Physics 20 Rigid body dynamics e The world transform of a body is given for its center of mass if the collision shape is not aligned with COM it can be shifted in a compound shape e Its basis defines the local frame for inertia e The btCollisionShape Class provides a method to automatically calculate the local inertia according to the shape and the mass the inertia can be edited if the collision shape is different from the inertia shape L Universiteit Utrecht Game Physics 21 Rigid body dynamics e Rigid body constraints are defined as btTypedConstraint Bullet includes different constraints such as hinge joint 1 rot DOF and ball and socket joint 3 rot DOF e Constraint limits are given for each DOF Lower limit and upper limit 3 configurations e lower upper means that the DOF is locked e lower gt upper means that the DOF is unlimited e lower lt upper means that the DOF is limited in that range L Universiteit Utrecht Game Physics 22 Soft body dynamics e Bullet provides dynamics for rope cloth and soft body e The main soft body object is btSoftBody that also Inherits from btCollisionObject each node has a dedicated world transform e The container for soft bodies rigid bodies and collision objects IS btSoftRigidDynamicsWorld L Universiteit Utrecht Game Physics 23 Soft body dynamics e Bullet offers the function btSof
8. han to access an array float acc 0 for ingr i 07 i lt 10007 i ace ace i sam x i e instead use simlable x 1 C Universiteit Utrecht Game Physics 37 Optimization techniques e Simplify your math Mathematical operators are not equally fast Complex function gt gt divide gt gt multiply gt gt addition subtraction Try to simplify equations and or tabulate them Try to reduce type conversion Examples double acc 1000000 tor int i 0g i lt 10000 i ace ace 2 05 acc 1000000 for int i 0g i lt 10000 i ace ace 0 5g takes 60 of the execution time of the previous version a b a c as bre gets rid of one multiply b a ey a 1 a b c changes one divide for one multiply esse Er gets rid one divide L Universiteit Utrecht Game Physics 38 Optimization techniques e Store data efficiently chose the right data type with the right precision both code execution and memory footprint are proportional to the number of bytes used Size B char 1 128 127 unsigned char 1 0 255 int 4 2 147 483 648 2 147 483 647 unsigned int 4 0 4 294 967 295 float 4 3 4 10 8 3 4 1028 7 decimal double 8 1 7 10208 1 7 109 8 15 decimal bool 1 true false L Universiteit Utrecht Game Ph ys ics Optimization techniques e Be linear CPUs come with memory caches loaded when accessing data
9. lisionOb ects j l 1520 p im brCollisrenOby ect obj dynmamicsworld gerCollisitonOb ectArray 1 BERILABOdy body btRigrelBocys s upeast 0 gt if body amp amp body gt getMotionState delete body gt getMotionState dynamicsWorld gt removeCollisionObject obj delete obj delete collision shapes cor imne le J lt collisionshapes size st eon btCollisionShape shape collisionShapes j collisionshapes ij 0 delete shape dynamicsWorld solver overlappingPairCache dispatcher eo llisreneonrigurac en L Universiteit Utrecht Game P hysics Rigid Body Physics Pipeline e Data structures used and computation stages performed by a call to stepSimulation Collision Data Dynamics Data Broadphase Collision Narrowphase Forward Dynamics Collision Forward Dynamics Detection Detection L Universiteit Utrecht Game Physics 12 Simulation step e The simulation stepper updates the world transformation for active objects by calling btMotionState setWorldTransform e It uses an internal fixed time step of 60 Hertz when the game frame frequency is smaller game faster it interpolates the world transformation of the objects without performing simulation when the game frame frequency is larger game Slower it will perform multiple simulations e the maximum number of iterations can be specified L Universiteit Utrecht Game Physics 13 Collision detection e Bullet
10. orce is applied will not settle down e We need to come up with two functionalities One for deactivating an object And one for activating an object back L Universiteit Utrecht Game Physics 34 Object de activation e Collision detector still returns contacts with deactivated objects but omitted in velocity resolution algorithm Numerical integration is skipped for deactivated objects so it Saves computation time e The object is deactivated when both linear and angular velocities are below a threshold body specific values Deactivated objects are therefore more stable L Universiteit Utrecht Game Physics 35 Object de activation e The object is activated when it collides with another active object e another threshold can be used for the minimal severity of the collision needed to activate again the object when non constant external forces are applied to the object e In a game every object is initialized in its rest configuration and deactivated At start up it is then very fast even with many objects It is only when interactions occur with the object that it will be simulated until it settles down again L Universiteit Utrecht Game Physics 36 Optimization techniques e Precompute as much as possible Try to tabulate mathematical functions random numbering etc To perform only array access in the physics update Example e sine call takes 5 times longer to be evaluated t
11. ssing power than needed to get a targeted effect Graphics Al and so on need it as well e Simplify the equations depending on the number of dimensions of the simulated world e Use primitive shapes as much as possible for collision detection use low number of vertices in convex hulls performance and stability L Universiteit Utrecht Game Physics 31 Efficiency e Be careful about the ratios sometimes difficult to manage both very small and very big objects need to reduce internal time step same for very different masses e Combine multiple static triangle meshes into one to reduce computations in broad phase L Universiteit Utrecht Game Ph ys ics 32 Efficiency e Neglect unwanted or not important effects you can assume for example that the sum of the gravity the reaction force and the static friction is zero you can neglect or simulate air resistance by a drag coefficient multiplied by the velocity e Run full physics simulation only on relevant objects only visible or near player objects only currently active objects but be careful about the discontinuities when they are simulated again L Universiteit Utrecht Game Physics 33 Object de activation e To save up many useless calculations we do not want to simulate an object which does not move For example sitting on the ground or a spring at rest Because of drag and friction only objects on which a consistent net f
12. tBodyHelpers CreateFromTriMesh to automatically create a soft body from a triangle mesh e Bullet can use either direct nodes triangles collision detection or a more efficient decomposition into convex deformable clusters iversiteit Utrecht Game P hysics Soft body dynamics Forces can be applied either on every node of a body or on an individual node SOrtBody adatoree const bEVECEOT Y TForceVeceror softBody gt addForce const btVector3 amp forceVector int node lt is possible to make nodes immovable softBody gt setMass int node 0501 Or attach nodes to a rigid body SOreBbeody appendAnchor ink node btRigicBody rrqrdbody bool disableCollisionBetweenLinkedBodies false Or attach two soft bodies using constraints L Universiteit Utrecht Game P hysics Demos e Convex e Concave e Convex hull collision collision distance L Universiteit Utrecht Game Ph ys ics 26 Assignment e You will use Bullet in your assignment to control the motion of a creature e The default configuration of the physics world uses A8D axis sweep and prune broad phase A sequential impulse constraint solver Afixed collision object for the ground e The Application creates and Manages a Creature a Scene and the simulation time stepping e The Application takes care of the simulation loop update and render and manages the user inputs e The scene manages the rotation of the mobile platform and the thro
13. wing of the balls L Universiteit Utrecht Game Physics 27 Assignment e To control the motion of the creature you have to use PD controllers at the joints Create a class PDController and add a container for them in the creature 1 per DOF Angular motors have to be enabled for the joints you want to control creature cpp line 69 and 82 PD controller gains have to be tuned to produce natural behavior At each simulation step e The balance corrections are fed to the PD controllers e The PD controllers give back the torques to apply to correct the pose according to the current pose velocity and gains e The torques are given to the joint motors function setMotorTarget L Universiteit Utrecht Game Physics 28 Assignment e The function btCollisionObject getWorldTransform returns a btTransform describing the 3D transformation from the local reference frame of an object to the global world reference frame common to every object e The function btTransform inverse Can be used to get the inverse transformation e The functions getCenterOfMassPosition and getInvMass return respectively the COM and the inverse of the mass of a btRigidBody L Universiteit Utrecht Game P hysics Assignment 0 4 KNEE 0 5 ANKLE 0 24 Eu 0 05 0 2 Game Physics L Universiteit Utrecht L UPPER LEG mass 3 kg LOWER LEG mass 3 kg FOOT mass 5 kg 30 Efficiency e Do not waste time with more proce

Download Pdf Manuals

image

Related Search

Related Contents

Como comunicar resumos circunstanciados de - ECHA  0845 683 8717 - Russell Hobbs  F-FTS Assembly Manual - Australian Fitness Supplies  RHA42GN  取扱説明書  

Copyright © All rights reserved.
Failed to retrieve file