08_게임 물리 프로그래밍 가이드

Post on 13-Jan-2015

2.215 views 1 download

description

 

Transcript of 08_게임 물리 프로그래밍 가이드

김성익김성익((noerror@hitel.netnoerror@hitel.net))2008/06/222008/06/22

물리물리 엔진엔진 사용을사용을 위한위한

게임게임 물리물리 프로그래밍프로그래밍 가이드가이드

Overview

•• 물리물리 엔진엔진 사용을사용을 위한위한 백그라운드백그라운드 정보정보

–– 개념들개념들 소개소개//정리정리

–– 구현을구현을 다루지다루지 않음않음

–– Box2D Box2D 소개소개

•• PhysXPhysX 소개소개

Box2D

•• Erin Erin CattoCatto씨씨 개인개인 프로젝트프로젝트

•• 2D 2D 오픈오픈 소스소스 물리물리 엔진엔진

•• 사용한사용한 프로젝트프로젝트 : : Crayon PhysicsCrayon Physics

•• http://www.box2d.orghttp://www.box2d.org

•• 최적의최적의 물리물리 처리처리 레퍼런스레퍼런스

Kinematics

•• Newtonian PhysicsNewtonian Physics

–– F = maF = ma

•• Spring (F=Spring (F=--kxkx))

•• Drag Force (F=Drag Force (F=--mpvmpv))

•• GravityGravity

–– F = F = dp/dtdp/dt, P = , P = mvmv

–– a = a = dV/dtdV/dt

–– V = V = dX/dtdX/dt

Calculus

•• PositionPosition

•• VelocityVelocity

•• AccelerationAcceleration

Solution

•• Analytic SolutionAnalytic Solution

•• Numeric SolutionNumeric Solution

–– Euler MethodEuler MethodEuler MethodEuler MethodEuler MethodEuler MethodEuler MethodEuler Method

–– Midpoint MethodMidpoint Method

–– RungeRunge KuttaKutta

–– Implicit MethodImplicit Method

–– VerletVerlet

Solution

•• Analytic SolutionAnalytic Solution

•• Numeric SolutionNumeric Solution

–– Euler MethodEuler Method

–– Midpoint MethodMidpoint MethodMidpoint MethodMidpoint MethodMidpoint MethodMidpoint MethodMidpoint MethodMidpoint Method

–– RungeRunge KuttaKutta

–– Implicit MethodImplicit Method

–– VerletVerlet

Solution

•• Analytic SolutionAnalytic Solution

•• Numeric SolutionNumeric Solution

–– Euler MethodEuler Method

–– Midpoint MethodMidpoint Method

–– RungeRungeRungeRungeRungeRungeRungeRunge KuttaKuttaKuttaKuttaKuttaKuttaKuttaKutta

–– Implicit MethodImplicit Method

–– VerletVerlet

Solution

•• Analytic SolutionAnalytic Solution

•• Numeric SolutionNumeric Solution

–– Euler MethodEuler Method

–– Midpoint MethodMidpoint Method

–– RungeRunge KuttaKutta

–– Implicit MethodImplicit MethodImplicit MethodImplicit MethodImplicit MethodImplicit MethodImplicit MethodImplicit Method

–– VerletVerlet

Solution

•• Analytic SolutionAnalytic Solution

•• Numeric SolutionNumeric Solution

–– Euler MethodEuler Method

–– Midpoint MethodMidpoint Method

–– RungeRunge KuttaKutta

–– Implicit MethodImplicit Method

–– VerletVerletVerletVerletVerletVerletVerletVerlet

Rotational Dynamics

•• Center of MassCenter of Mass

•• Linear Linear vsvs AngularAngular

–– Force Force vsvs TorqueTorque

–– Mass Mass vsvs Moment of inertiaMoment of inertia

–– Momentum Momentum vsvs Angular MomentumAngular Momentum

–– Velocity Velocity vsvs Angular VelocityAngular Velocity

–– Position Position vsvs OrientationOrientation

Box2d CodeReview(1)

•• Simulation iteration stepSimulation iteration step

–– broadphasebroadphase

•• 충돌검사충돌검사 ((충돌정보충돌정보 Arbiter Arbiter 개체로개체로 저장저장))

–– force force 적용적용

•• forceforce-->velocity>velocity

•• torquetorque-->angular velocity>angular velocity

–– prestepprestep

•• 충돌충돌 포인트에포인트에 대해서대해서 massnormalmassnormal, , masstangentmasstangent, bias , bias 계산계산

Box2d CodeReview(2)

–– 충돌에충돌에 의한의한 impulseimpulse

•• 충돌체에충돌체에 impulseimpulse

–– velocity, angular velocity velocity, angular velocity 적용적용

•• Joint Joint 에에 의한의한 impulseimpulse

–– 양양 jointjoint에에 충돌체에충돌체에 impulseimpulse

–– 위치위치 및및 회전에회전에 적용적용

•• velocity => positionvelocity => position

•• Angular velocity => rotationAngular velocity => rotation

PhysX(1)

•• NVidiaNVidia ((http://http://www.ageia.comwww.ageia.com))

•• 무료무료 ((일부일부 플렛폼플렛폼 및및 소스코드소스코드 라이센스는라이센스는유료유료))

•• 충실한충실한 튜터리얼튜터리얼 셈플셈플 제공제공

•• 메인스트림메인스트림 물리물리 엔진엔진

•• 사용사용 프로젝트프로젝트 : : 언리얼언리얼3, 3, 외외 다수다수

PhysX(2)

•• 기능기능

–– 복잡한복잡한 강체강체 물리물리 시스템시스템

–– 캐릭터캐릭터 컨트롤컨트롤

–– 탈탈 것것 다이나믹스다이나믹스

–– 멀티쓰레드멀티쓰레드//멀티멀티 플렛폼플렛폼/PPU/PPU지원지원

–– 유체유체 시뮬레이션시뮬레이션

–– 옷옷, , 깃발등의깃발등의 천천 시뮬레이션시뮬레이션

–– 소프트소프트 바디바디

–– 역장역장((forcefieldforcefield) ) 시뮬레이션시뮬레이션

PhysX–architecture diagram

Shape

•• ShapeShape

–– SphereSphere

–– CapsuleCapsule

–– BoundBoxBoundBox

•• AABB AABB (Axis Aligned Bound Box)(Axis Aligned Bound Box)

•• OBB OBB (Object Oriented Box)(Object Oriented Box)

–– ConvexConvex

–– (height field)(height field)

PhysX-Shape

•• SphereSphere•• BoxBox•• CapsuleCapsule

•• PlanePlane•• Height fieldHeight field•• Convex meshesConvex meshes•• Triangle meshesTriangle meshes

PhysX-Actor

Collision Detection(1)

•• Distance TestDistance Test

–– PointPoint--point distancepoint distance

–– LineLine--point distancepoint distance

–– LineLine--line distanceline distance

–– SegmentSegment--segment distancesegment distance

•• Rough BoundingRough Bounding

–– Sweep and pruneSweep and prune

Collision Detection(1)

•• Distance TestDistance Test

–– PointPoint--point distancepoint distance

–– LineLine--point distancepoint distance

–– LineLine--line distanceline distance

–– SegmentSegment--segment distancesegment distance

•• Rough BoundingRough Bounding

–– Sweep and pruneSweep and pruneSweep and pruneSweep and pruneSweep and pruneSweep and pruneSweep and pruneSweep and prune

Collision Detection(2)

•• SAT(separationSAT(separation axis test)axis test)

•• Lin CannyLin Canny

•• MinkowskiMinkowski DiffrenceDiffrence

Collision Detection(2)

•• SAT(separationSAT(separation axis test)axis test)

•• Lin CannyLin Canny

•• MinkowskiMinkowski DiffrenceDiffrence

Collision Detection(2)

•• SAT(separationSAT(separation axis test)axis test)

•• Lin CannyLin Canny

•• MinkowskiMinkowski Sum/Sum/DiffrenceDiffrence

Collistion Detection(3)

•• Determine Collision TimeDetermine Collision Time

–– Time of impactTime of impact

•• TunnellingTunnelling (CCD)(CCD)

Collistion Detection(3)

•• Determine Collision TimeDetermine Collision Time

–– Time of impactTime of impact

•• TunnellingTunnelling

PhysX - CCD

•• Continuous Collision DetectionContinuous Collision Detection

Collision Detection(4)

•• Spatial SubdivisionSpatial Subdivision

–– BspBsp, , kk--dd treetree

–– PortalPortal

–– Quad tree / Quad tree / octreeoctree

•• GroupingGrouping

–– SleepingSleeping

Collision Detection(4)

•• Spatial SubdivisionSpatial Subdivision

–– BspBsp, , kk--dd treetree

–– PortalPortal

–– Quad tree / Quad tree / octreeoctree

•• GroupingGrouping

–– SleepingSleeping

Collision Detection(4)

•• Spatial SubdivisionSpatial Subdivision

–– BspBsp, , kk--dd treetree

–– PortalPortal

–– Quad tree / Quad tree / octreeoctree

•• GroupingGrouping

–– SleepingSleeping

Collision Detection(4)

•• Spatial SubdivisionSpatial Subdivision

–– BspBsp, , kk--dd treetree

–– PortalPortal

–– Quad tree / Quad tree / octreeoctree

•• GroupingGrouping

–– SleepingSleeping

Collision Detection(4)

•• Spatial SubdivisionSpatial Subdivision

–– BspBsp, , kk--dd treetree

–– PortalPortal

–– Quad tree / Quad tree / octreeoctree

•• GroupingGrouping

–– SleepingSleeping

PhysX-Collision Detection

•• Contact FilteringContact Filtering•• TriggersTriggers•• CCDCCD•• Dominance Dominance GrioupGrioup•• Overlap TestingOverlap Testing

Collision Response(1)

•• Contact PointContact Point

–– EE (EdgeEE (Edge--Edge)Edge)

–– FV (FaceFV (Face--Vertex)Vertex)

–– GJKGJK

•• NormalNormal

•• PenetrationPenetration

Collision Response(1)

•• Contact PointContact Point

–– EE (EdgeEE (Edge--Edge)Edge)

–– FV (FaceFV (Face--Vertex)Vertex)

–– GJKGJK

•• NormalNormal

•• PentrationPentration

Collision Response(2)

•• CollidingColliding

–– BouncingBouncing

•• RestingResting

–– RollingRolling

–– SlidingSliding

Collision Response(2)

•• CollidingColliding

–– BouncingBouncing

•• RestingResting

–– RollingRolling

–– SlidingSliding

Constraint

•• JointJoint

–– Pin JointsPin Joints

–– HingeHinge

•• Angular ConstraintsAngular Constraints

•• Distance Constraints, ...Distance Constraints, ...

PhysX-Joint

•• spherical jointspherical joint•• revolute jointrevolute joint•• prismatic jointprismatic joint•• cylindrical jointcylindrical joint•• fixed jointfixed joint•• distance jointdistance joint•• point in plane joint / point on line jointpoint in plane joint / point on line joint•• pulley jointpulley joint•• d6d6

PhysX-Joint

•• spherical jointspherical joint•• revolute jointrevolute joint•• prismatic jointprismatic joint•• cylindrical jointcylindrical joint•• fixed jointfixed joint•• distance jointdistance joint•• point in plane joint / point on line jointpoint in plane joint / point on line joint•• pulley jointpulley joint•• d6d6

PhysX-Joint

•• spherical jointspherical joint•• revolute jointrevolute joint•• prismatic jointprismatic joint•• cylindrical jointcylindrical joint•• fixed jointfixed joint•• distance jointdistance joint•• point in plane joint / point on line jointpoint in plane joint / point on line joint•• pulley jointpulley joint•• d6d6

PhysX-Example Review

•• 예제예제 : : SampleBoxesSampleBoxes

•• InitNxInitNx–– Initialize Initialize PhysicsScenePhysicsScene => => gPhysicsSDKgPhysicsSDK–– CreateSceneCreateScene => => gScenegScene–– Create Ground Create Ground => => gScenegScene-->>createActorcreateActor

•• RenderCallbackRenderCallback–– SimulateSimulate–– GetResultGetResult/Render All actors => actor/Render All actors => actor-->>getGlobalPosgetGlobalPos–– FetchSimulationFetchSimulation => => flushScreamflushScream, , fetchResultfetchResult

•• CreateCubeCreateCube–– shapes.pushBackshapes.pushBack–– gScenegScene-->>createActorcreateActor

More

•• BreakingBreaking

•• Force FieldForce Field

•• Character ControllerCharacter Controller

•• Raycast/SweepTestRaycast/SweepTest

•• Multithreading ModelMultithreading Model

Reference

•• http://http://www.essentialmath.comwww.essentialmath.com

•• 게임물리바이블게임물리바이블,David H ,David H EverlyEverly, , 사이텍미디어사이텍미디어