Ch 15: Collision and Simple Physics

Preview:

Citation preview

Ch 15: Collision and Simple Physics

Quiz # 5 Discussion

Collision Detection Resources:

http://sharky.bluecog.co.nz/?p=108

Collision: Bounding Box

ò  Circle or sphere around the object

ò  Collision detection is:

   

 If  (d2  <=  (r2  +r1)2)    

 collision  =  true;  else  collision  =  false;  

x,y r

d r1 r2

Collision: Bounding Box (AABB) [XNA]

ò  Axis-Aligned Bounding Box (AABB)

ò  Collision detection is: If  (  (object1.max.x  <  object2.min.x)  ||        (object1.min.x  >  object2.max.x)  )  

 return  false;  if  (    (object1.max.y  <  object2.min.y)  ||  

 (object1.min.y  >  object2.max.y)  )    return  false;  

if  (    (object1.max.z  <  object2.min.z)  ||    (object1.min.z  >  object2.max.z)  )    return  false;  

return  true;  

min (x, y, z)

max(x, y, z)

min (x, y, z)

max(x, y, z)

Collision: Bounding Box (OBB)

ò  Oriented Bounding Box (OBB)

Collision: Others

ò  Convex Hull

ò  Divide model meshes – sphere around each mesh separately

Processing and Efficiency

1.  Sphere

2.  AABB  

3.  OBB  

4.  Convex  Hull  

Decrease in efficiency

Using XNA AABB Make sure to rotate and scale and translate the bounding box

BoundingBox  boxbox  =  new  BoundingBox(new  Vector3(0,  0,  0),  new  Vector3(125,  100,  75));  

BoundingBox  playerbox  =  new  BoundingBox(  new  Vector3(modelpos.X  -­‐  50,  -­‐50,  modelpos.Z  -­‐  50),  new  Vector3(modelpos.X  +  50,  50,  modelpos.Z  +  50));  

 if  (playerbox.Intersects(boxbox))    

{  

         System.Console.WriteLine("there  is  a  collision");  

 }  

Try it

ò  Get your assignment # 2

ò  Add another object

ò  Move the object closer to the character

ò  Just print out a message when a collision happens

More resources on Collision

ò  Gottschalk, Stephan, Ming Lin and Dinesh Manocha, “OBB-Tree: A Hierarchical Structure for Rapid Interference Detection,” SIGGRAPH ‘96.

ò  Ericson, Christer, Real-Time Collision Detection, Morgan Kaufmann, San Francisco, 2004.

ò  Van den Bergen, Gino, Collision Detection in Interactive 3D Environments, Morgan Kaufmann, San Francisco, 2003.

ò  Van Verth, James M. Essential Mathematics for Games and Interactive Applications A Programmer’s Guide, Morgan Kaufmann, San Francisco, 2004

For Physics

ò  Physics and Collision:

ò  Raycast: can be good for AI vision

ò  Shapecast

ò  Procedural Animation and Rag Doll physics: turned on at death or other events

ò  Use a Physics engine. You can integrate:

ò  Bullet: http://bulletphysics.org/wordpress/

ò  ODE: http://www.ode.org/

Ray Casting

ò  Shoot a ray from object to another:

ò  Given Position, direction (use parametric line equation)

ò  Check for collision along the way (object intersections)

Parametric line Equation

xy

!

"##

$

%&&=

xp0 + t(xp1 − xp0 )

yp0 + t(yp1 − yp0 )

(

)

**

+

,

-- p0

p1

For Physics

ò  Physics and Collision:

ò  Raycast: can be good for AI vision

ò  Shapecast

ò  Procedural Animation and Rag Doll physics: turned on at death or other events

ò  Use a Physics engine. You can integrate:

ò  Bullet: http://bulletphysics.org/wordpress/

ò  ODE: http://www.ode.org/

Inverse Kinematics

1.  Set goal configuration of end effector 2.  calculate interior joint angles

Analytic approach – when linkage is simple enough, directly calculate joint angles in configuration that satisfies goal

Numeric approach – complex linkages At each time slice, determine joint movements that take you in direction of goal position (and orientation)

From Rick Parent’s slides

Forward Kinematics - review

Pose – linkage is a specific configuration

Pose Vector – vector of joint angles for linkage

Degrees of Freedom (DoF) – of joint or of whole figure

Articulated linkage – hierarchy of joint-link pairs

Types of joints: revolute, prismatic

Tree structure – arcs & nodes Recursive traversal – concatenate arc matrices Push current matrix leaving node downward Pop current matrix traversing back up to node

Goal

End Effector

θ1

θ2 θ3 L1

L2 L3

Inverse Kinematics

Animation

ò  Procedural animation disadvantages:

ò  Too expensive

ò  Doesn’t look good – not controlled by the artist

ò  Most games now use a mix of both

ò  Alternative Smartbody by USC (blend of both with constraint system)

Animation & Control (the need for Physics)

GDC Vault

Recommended