Physics engines Wolfgang Knecht Institute of Computer Graphics and - - PowerPoint PPT Presentation

physics engines
SMART_READER_LITE
LIVE PREVIEW

Physics engines Wolfgang Knecht Institute of Computer Graphics and - - PowerPoint PPT Presentation

Physics engines Wolfgang Knecht Institute of Computer Graphics and Algorithms Vienna University of Technology Topics for today What is a physics engine? Available engines How to use NVIDIA PhysX Create Scene Actors Actors Shapes Dynamic,


slide-1
SLIDE 1

Physics engines

Wolfgang Knecht

Institute of Computer Graphics and Algorithms Vienna University of Technology

slide-2
SLIDE 2

Topics for today What is a physics engine?

Available engines

How to use NVIDIA PhysX

Create Scene Actors

1

Actors

Shapes Dynamic, static and kinematic actors

Joints Simulation Debugging

Institute of Computer Graphics and Algorithms

slide-3
SLIDE 3

What is a physics engine? Handles collision detection Physical simulation Independent form what you see

Low resolution approximation of scene

2 Institute of Computer Graphics and Algorithms

Graphical representation Approximation for physical simulation

slide-4
SLIDE 4

Available engines PhysX Havok Bullet

OpenSource

ODE ODE

OpenSource

Institute of Computer Graphics and Algorithms 3

slide-5
SLIDE 5

PhysX by NVIDIA

Institute of Computer Graphics and Algorithms 4

slide-6
SLIDE 6

Get the PhysX SDK Download form NVIDIA Developer website [1]

free, but you have to register (takes some time)

Also get the PhysX SystemSoftware

Hardware acceleration on all GeForce 8- Hardware acceleration on all GeForce 8- series, 9-series and 200-series

Institute of Computer Graphics and Algorithms 5

slide-7
SLIDE 7

Prepare your project to use the SDK Specify include directories

'SDKs\Physics\include‘ 'SDKs\Foundation\include‘ 'SDKs\PhysXLoader\include‘ 'SDKs\Cooking\include' (optional) 'SDKs\Cooking\include' (optional) 'SDKs\NxCharacter\include' (optional)

Identify Library

'SDKs\lib\win32\PhysXLoader.lib‚

PhysXLoader.dll

Institute of Computer Graphics and Algorithms 6

slide-8
SLIDE 8

Init the SDK

#include "NxPhysics.h" NxPhysicsSDK *gPhysicsSDK = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION, &myAllocator, &myOutputStream);

Institute of Computer Graphics and Algorithms 7

if(!gPhysicsSDK) Error("Wrong SDK DLL version?"); ... gPhysicsSDK->release();

slide-9
SLIDE 9

The scene and it‘s actors

Scene Static objects

  • Levelgeometry

Dynamic objects

  • Boxes

Kinematic objects

  • Elevators

Institute of Computer Graphics and Algorithms 8

  • Levelgeometry
  • Walls
  • Stairs
  • Boxes
  • Barrels
  • Elevators
  • Doors
  • Platforms

Actors

slide-10
SLIDE 10

Create a physics scene

NxScene NxSceneDesc sceneDesc; sceneDesc.gravity.set(0,-9.8f,0); NxScene *gScene = gPhysicsSDK->createScene(sceneDesc); if (!gScene) Error("Can't create scene!");

Institute of Computer Graphics and Algorithms 9

slide-11
SLIDE 11

Actors

NxScene NxActor NxActor NxActorDesc actorDesc; actorDesc.globalPose = ...; // initial modelmatrix

Institute of Computer Graphics and Algorithms 10

gScene->createActor(actorDesc);

slide-12
SLIDE 12

Actors contain shapes

NxScene NxActor NxActor NxActorDesc actorDesc; actorDesc.globalPose = ...; // initial modelmatrix NxSphereShapeDesc shapeDesc; shapeDesc.radius = 2.0; shapeDesc.localPose = ...; // Pose of the shape

Institute of Computer Graphics and Algorithms 11

NxShape NxShape NxShape actorDesc.shapes.pushBack(&shapeDesc); gScene->createActor(actorDesc);

slide-13
SLIDE 13

Actors contain shapes

NxScene NxActor NxActor NxActorDesc actorDesc; actorDesc.globalPose = ...; // initial modelmatrix NxSphereShapeDesc shapeDesc; shapeDesc.radius = 2.0; shapeDesc.localPose = ...; // Pose of the shape

Institute of Computer Graphics and Algorithms 12

NxShape NxShape NxShape actorDesc.shapes.pushBack(&shapeDesc); gScene->createActor(actorDesc);

slide-14
SLIDE 14

Actors contain shapes

NxScene NxActor NxActor NxActorDesc actorDesc; actorDesc.globalPose = ...; // initial modelmatrix NxSphereShapeDesc shapeDesc; shapeDesc.radius = 2.0; shapeDesc.localPose = ...; // Pose of the shape

Institute of Computer Graphics and Algorithms 13

NxShape NxShape NxShape actorDesc.shapes.pushBack(&shapeDesc); gScene->createActor(actorDesc);

slide-15
SLIDE 15

Shapes have materials

NxScene NxActor NxActor NxActorDesc actorDesc; actorDesc.globalPose = ...; // initial modelmatrix NxSphereShapeDesc shapeDesc; shapeDesc.radius = 2.0; shapeDesc.localPose = ...; // Pose of the shape NxMaterialDesc materialDesc; materialDesc.restitution = 0.7f; materialDesc.staticFriction = 0.5f;

Institute of Computer Graphics and Algorithms 14

NxMaterial NxMaterial NxShape NxShape NxShape materialDesc.staticFriction = 0.5f; materialDesc.dynamicFriction = 0.5f; NxMaterial *newMaterial= gScene->createMaterial(materialDesc); shapeDesc.materialIndex= newMaterial->getMaterialIndex(); actorDesc.shapes.pushBack(&shapeDesc); gScene->createActor(actorDesc);

slide-16
SLIDE 16

Dynamic Actors – Rigid Bodies Actor needs a body User can add forces and torques

NxActorDesc actorDesc; NxBodyDesc bodyDesc; // add some shapes to the actor

Institute of Computer Graphics and Algorithms 15

// add some shapes to the actor bodyDesc.mass=10; actorDesc.body = &bodyDesc; actorDesc.globalPose.t = NxVec3(0.0f,10.0f,0.0f); // set initial position. NxActor *dynamicActor=gScene->createActor(actorDesc);

slide-17
SLIDE 17

Static Actors Set actor‘s body to NULL

NxActorDesc actorDesc; NxBodyDesc bodyDesc; // add some shapes to the actor

Institute of Computer Graphics and Algorithms 16

// add some shapes to the actor bodyDesc.mass=10; actorDesc.body = &bodyDesc; actorDesc.globalPose.t = NxVec3(0.0f,10.0f,0.0f); // set initial position. NxActor *staticActor=gScene->createActor(actorDesc);

slide-18
SLIDE 18

Kinematic Actors Does not move in response to forces, gravity, collision impulses, or if tugged by joints Moving platforms, elevators, …

actor1->raiseBodyFlag(NX_BF_KINEMATIC);

Institute of Computer Graphics and Algorithms 17

actor1->raiseBodyFlag(NX_BF_KINEMATIC); actor1->moveGlobalPose(mat34); actor1->moveGlobalPosition(vec3); actor1->moveGlobalOrientation(mat33); // do NOT use actor1->setGlobal*()

slide-19
SLIDE 19

Joints Connect two actors Several Joint Types Motors, Springs and Special Limits

Institute of Computer Graphics and Algorithms 18

slide-20
SLIDE 20

Controllable kinematic actor Only boxes (NxBoxController) and capsules (NxCapsuleController) are supported

NxControllerManager* gManager = NxCreateControllerManager(myAllocator); NxCapsuleControllerDesc desc;

Character Controller

NxCapsuleControllerDesc desc; desc.radius = 0.5; desc.height = 2.0; desc.stepOffset = 0.5; NxController* c = gManager->createController(scene, desc); ... c->move(disp, 0xffffffff, 0.000001f, collisionFlags, sharpness); ... NxReleaseControllerManager(gManager);

Institute of Computer Graphics and Algorithms 19

slide-21
SLIDE 21

Trigger Very useful to trigger events

Open a door Start an elevator Change background music

Institute of Computer Graphics and Algorithms 20

shapeDesc.shapeFlags |= NX_TRIGGER_ENABLE; // myTriggerCallback: // instance from user defined trigger class // derived from NxUserTriggerReport gScene->setUserTriggerReport(&myTriggerCallback);

slide-22
SLIDE 22

Simulate and fetch results Simulations runs in the background

gScene->setTiming(1.0f/60.f, 8,NX_TIMESTEP_FIXED); simulate()

  • Your calculations
  • Render the scene

fetchResults() Gameloop

Institute of Computer Graphics and Algorithms 21

gScene->setTiming(1.0f/60.f, 8,NX_TIMESTEP_FIXED); // gameloop { gScene->simulate(elapsedTime); gScene->flushStream(); // do your calculations and the rendering gScene->fetchResults(NX_RIGID_BODY_FINISHED, true); // }

slide-23
SLIDE 23

Connect PhysX to the Renderer Create your model matrices using the actor‘s pose

actor1->getGlobalPose(); // returns NXMat34 actor1->getGlobalPosition(); // returns NxVec3

Institute of Computer Graphics and Algorithms 22

actor1->getGlobalOrientation(); // returns NxMat33

slide-24
SLIDE 24

Cleanup Nx…::release… releases Child and all associated objects NxScene::releaseActor releases Actor and all associated shapes and all associated shapes NxPhysicsSDK::releaseScene releases Scene and all actors, joints, materials, … created in the scene gPhysicsSDK->release();

Institute of Computer Graphics and Algorithms 23

slide-25
SLIDE 25

Debugging Debug rendering inside your application

  • r

Visual Debugger [2]

Institute of Computer Graphics and Algorithms 24

slide-26
SLIDE 26

Several more features Fluids Cloth Soft Bodies Force Fields …

Institute of Computer Graphics and Algorithms 25

slide-27
SLIDE 27

Physics engines come with new problems

Finding right parameters is not easy …

Creating vehicle physics „by hand“ can be easier than using a physics engine Do you really need a physics engine? easier than using a physics engine Collision detection for simple objects like spheres or boxes can be done with less effort

E.g. Labyrinth games need no physics engine

Institute of Computer Graphics and Algorithms 26

slide-28
SLIDE 28

References

[1] PhysX Developer Zone, http://developer.nvidia.com/object/physx.html [2] PhysX Visual Debugger, http://developer.nvidia.com/object/pvd_home.html Havok, http://www.havok.com Bullet, http://bulletphysics.org Bullet, http://bulletphysics.org ODE, http://www.ode.org

Institute of Computer Graphics and Algorithms 27

slide-29
SLIDE 29

The End Thanks for your attention! Questions?

Institute of Computer Graphics and Algorithms 28