Applied ODE - PowerPoint PPT Presentation

1 / 23
About This Presentation
Title:

Applied ODE

Description:

Set the mass of the rigid body. Set the shape of the rigid body (the geom) ... The collision engine is given information about the shape of each body. ... – PowerPoint PPT presentation

Number of Views:120
Avg rating:3.0/5.0
Slides: 24
Provided by: bdug1
Category:
Tags: ode | applied

less

Transcript and Presenter's Notes

Title: Applied ODE


1
Applied ODE
  • Bryan Duggan

2
Overview!
  • Car
  • Gravity Gun

3
Car Algorithm
  • Create the mesh for the chassis (a box)
  • Create the RigidBody (a box)
  • Set the mass of the rigid body
  • Set the shape of the rigid body (the geom)
  • Create 4 wheels at the appropriate positions
  • Create a cylinder mesh
  • Create the rigid body
  • Set the mass of the rigid body
  • Set the shape of the rigid body (the geom)

4
Car Algorithm continued
  • Create 4 hinges so that the wheels can rotate
  • Create the hinge
  • Join the hinge to the chassis using the hinge
  • Set the axis of the hinge to be the positive Z
    axis
  • Set the anchor of the hinge to be the centre
    point of the wheel

5
Car Algorithm
  • At each step,
  • Step forward the simulation (INTEGRATION)
  • Get the position of the rigid body
  • Get the quaternion
  • Create a transform matrix
  • Use it to draw the mesh
  • What about collisions??

6
(No Transcript)
7
ODE
  • ODE Consists of
  • A physics engine
  • A collision detection engine

8
Collision detection
  • The collision engine is given information about
    the shape of each body.
  • At each time step it figures out which bodies
    bounding boxes intersect (broad phase).
  • The user in turn checks to see if the objects
    themselves intersect (narrow phase)
  • It then creates contact joints between bodies

9
Collision detection
  • You have to register a callback function with ODE
    to handle collisions.
  • Call dSpaceCollide in your update function and
    register the callback
  • Your function will get called once for each pair
    of bounding boxes that intersectdSpaceCollide(_s
    pace, this, nearCallback)

10
  • void nearCallback(void data, dGeomID o0, dGeomID
    o1)
  • reinterpret_castltWorldgt(data)-gthandleCollisionBe
    tween(o0,o1)

11
  • Your callback function can call a member function
    on a class
  • void WorldhandleCollisionBetween(dGeomID o1,
    dGeomID o2)

12
  • Its job is to go through each pair of bounding
    boxes (passed in as parameters) and call dCollide
    with the 2 bounding boxes
  • It returns the number of contact points generated
    by the collison (which may be 0)

13
  • const int N 30
  • dContact contactN
  • n dCollide (o1,o2,N,contact0.geom,sizeof(dCon
    tact))
  • if (n gt 0)
  • \\ process the collisions

14
Typically,
  • Generate a contact joint for each pair of
    collisions that push the objects apart based on
    the depth of penetration
  • for (i0 iltn i)
  • contacti.surface.mode dContactSlip1
    dContactSlip2 dContactSoftERP dContactSoftCFM
    dContactApprox1
  • contacti.surface.mu dInfinity
  • contacti.surface.slip1 0.1f
  • contacti.surface.slip2 0.1f
  • contacti.surface.soft_erp 0.5f
  • contacti.surface.soft_cfm 0.3f
  • dJointID c dJointCreateContact
    (_dWorldID,_contactgroup,contacti)
  • dJointAttach (c,dGeomGetBody(contacti.geom.g1
    ),dGeomGetBody(contacti.geom.g2))

15
Gravity Gun!
  • Using the collision detection API, we can make a
    gravity gun

16
(No Transcript)
17
  • When the user presses the mouse button
  • IF they are not already holding something
  • Create a ray from the camera origin and look and
    add it to the space
  • A ray is a geom with no body
  • Else
  • Calculate the holding position (some units in
    front of the camera, say 10) camera pos camera
    look units
  • Calculate a velocity vector to move the held
    object to the hold point
  • Take hold point held object position
  • Multiply by power factor of the gun (a scalar)
  • If its greater than the max velocity scale it so
    its at the max velocity
  • Set the held objects linear velocity

18
  • if (pickedUp NULL)
  • ray dCreateRay(_space, 100)
  • D3DXVECTOR3 origin _camera-gtgetPosition()
  • D3DXVECTOR3 look _camera-gtgetLook()
  • D3DXVec3Normalize( look, look)
  • dGeomRaySet(ray, origin.x, origin.y, origin.z,
    look.x, look.y, look.z)
  • else
  • float powerfactor 100
  • float maxVel 50
  • float fdistance 10
  • D3DXVECTOR3 holdpos _camera-gtgetPosition()
    _camera-gtgetLook() fdistance
  • D3DXVECTOR3 v holdpos - pickedUp-gtgetPosition(
    )
  • v powerfactor // powerfactor of the
    GravityGun
  • if ( D3DXVec3length(v) gt maxVel )
  • v maxVel

19
In the collision detection callback
  • Check to see if one of the geoms is a ray, if so
    its a ray trace and handle it differently
  • Instead of calculating the contact points, set
    the other geom to be the picked up object

20
In code
  • if (o1 ray)
  • if ((dGeomGetClass(o2) ! dPlaneClass) (o2
    ! _camera-gtgetGeom()))
  • RigidBodyODE pu (RigidBodyODE )
    dGeomGetData(o2)
  • if (pu ! NULL)
  • pickedUp pu
  • return

21
Things to watch out for!
  • Check the collision inside the narrow phase
    collision test, not the broad phase collision
    test.
  • ODE uses bounding boxes even for rays!
  • You may need to swap the order of the geom
    parameters to simplify your code

22
Factory design pattern
  • The factory method pattern is an object-oriented
    design pattern.
  • It deals with the problem of creating objects
    (products) without specifying the exact class of
    object that will be created.
  • The factory method design pattern handles this
    problem by defining a separate method for
    creating the objects, which subclasses can then
    override to specify the derived type of product
    that will be created.
  • More generally, the term factory method is often
    used to refer to any method whose main purpose is
    creation of objects.

23
Spawning new objects
  • You can use a factory object to spawn new
    objects
  • class Spawner
  • private
  • World _world
  • IDirect3DDevice9 _device
  • public
  • RigidBodyODE createCube(float x, float y,
    float z)
  • RigidBodyODE createWheel(float radius, float
    x, float y, float z)
  • ...
  • ...
Write a Comment
User Comments (0)
About PowerShow.com