[ODE] Simple player representation

Andrzej Szombierski qq at kuku.eu.org
Tue Jul 27 20:03:26 MST 2004


I've also been thinking about a reasonable player representation in ODE 
world. Some assumptions:

- the player should be able to move around and push some (lighter) 
  objects and collide with heavier objects and static environment.
- the player should be able to stand on anything (not only static 
  environment)
- moving objects, if heavy enough, should push the player.
- the player should be able to rotate only around one axis (Z in my case)

I've found a simple solution which "looks right":

1. Take the Plane2D joint (can be found in ODE mailing list archives).
2. Cut off the part which enforces z=0.
3. (optional) Modify the linear motors so their axes are player-relative.
4. Give the player a geom (sphere in my case, but ccylinder should work 
   well, or possibly implement an ellipsoid geom (as Chrome authors have 
   done)), and a body.
5. Attach the body to static environement with the new joint.

The player can be moved by setting vel/FMax on the two linear motors. If 
they are player-relative, it's as simple as setting FMax to some constant 
value, and vel to positive/negative value when up/down arrow is 
pressed.

The orientation can be controlled either by using the angular motor 
(haven't tried) or simply resetting the rotation with dBodySetRotation 
each frame (works fine for me).

These are the modified functions from plane2d joint: (renamed to 
"controller")
================================================================================
static void     controllerGetInfo1 (dxJointController *j, dxJoint::Info1 *info)
{
  info->nub = 2;
  info->m = 2;

  if (j->motor_x.fmax > 0)
      j->row_motor_x = info->m ++;
  if (j->motor_y.fmax > 0)
      j->row_motor_y = info->m ++;
  if (j->motor_angle.fmax > 0)
      j->row_motor_angle = info->m ++;
}

static void     controllerGetInfo2 (dxJointController *joint, dxJoint::Info2 *info)
{
    int         r0 = 0,
                r1 = info->rowskip;
    dReal       eps = info->fps * info->erp;

    VoXYZ (&info->J1l[r0], =, 0, 0, 0);
    VoXYZ (&info->J1l[r1], =, 0, 0, 0);

    VoXYZ (&info->J1a[r0], =, 1, 0, 0);
    VoXYZ (&info->J1a[r1], =, 0, 1, 0);

    dVector3 ax1 = {
	    joint->node[0].body->R[0],
	    joint->node[0].body->R[4],
	    joint->node[0].body->R[8] };
    dVector3 ax2 = {
	    joint->node[0].body->R[1],
	    joint->node[0].body->R[5],
	    joint->node[0].body->R[9] };

    if (joint->row_motor_x > 0)
        joint->motor_x.addLimot (
            joint, info, joint->row_motor_x, ax1, 0);

    if (joint->row_motor_y > 0)
        joint->motor_y.addLimot (
            joint, info, joint->row_motor_y, ax2, 0);

    if (joint->row_motor_angle > 0)
        joint->motor_angle.addLimot (
            joint, info, joint->row_motor_angle, Midentity[2], 1);
}

================================================================================

The joint can also be thought of an AMotor with X and Y rotation "locked" 
and two linear motors on these axes.

-- 
:: Andrzej Szombierski :: qq at kuku.eu.org :: http://kuku.eu.org ::
:: anszom at bezkitu.com  :: radio bez kitu :: http://bezkitu.com ::



More information about the ODE mailing list