static inline void DrawCollisionVolume(const CollisionVolume* vol) { static unsigned int listIDs[3] = {0, 0, 0}; switch (vol->GetVolumeType()) { case CollisionVolume::COLVOL_TYPE_FOOTPRINT: // fall through, this is too hard to render correctly so just render sphere :) case CollisionVolume::COLVOL_TYPE_SPHERE: // fall through, sphere is special case of ellipsoid case CollisionVolume::COLVOL_TYPE_ELLIPSOID: { // scaled sphere: radius, slices, stacks glTranslatef(vol->GetOffset(0), vol->GetOffset(1), vol->GetOffset(2)); glScalef(vol->GetHScale(0), vol->GetHScale(1), vol->GetHScale(2)); glWireSphere(&listIDs[0], 20, 20); } break; case CollisionVolume::COLVOL_TYPE_CYLINDER: { // scaled cylinder: base-radius, top-radius, height, slices, stacks // // (cylinder base is drawn at unit center by default so add offset // by half major axis to visually match the mathematical situation, // height of the cylinder equals the unit's full major axis) switch (vol->GetPrimaryAxis()) { case CollisionVolume::COLVOL_AXIS_X: { glTranslatef(-(vol->GetHScale(0)), 0.0f, 0.0f); glTranslatef(vol->GetOffset(0), vol->GetOffset(1), vol->GetOffset(2)); glScalef(vol->GetScale(0), vol->GetHScale(1), vol->GetHScale(2)); glRotatef( 90.0f, 0.0f, 1.0f, 0.0f); } break; case CollisionVolume::COLVOL_AXIS_Y: { glTranslatef(0.0f, -(vol->GetHScale(1)), 0.0f); glTranslatef(vol->GetOffset(0), vol->GetOffset(1), vol->GetOffset(2)); glScalef(vol->GetHScale(0), vol->GetScale(1), vol->GetHScale(2)); glRotatef(-90.0f, 1.0f, 0.0f, 0.0f); } break; case CollisionVolume::COLVOL_AXIS_Z: { glTranslatef(0.0f, 0.0f, -(vol->GetHScale(2))); glTranslatef(vol->GetOffset(0), vol->GetOffset(1), vol->GetOffset(2)); glScalef(vol->GetHScale(0), vol->GetHScale(1), vol->GetScale(2)); } break; } glWireCylinder(&listIDs[1], 20, 1.0f); } break; case CollisionVolume::COLVOL_TYPE_BOX: { // scaled cube: length, width, height glTranslatef(vol->GetOffset(0), vol->GetOffset(1), vol->GetOffset(2)); glScalef(vol->GetScale(0), vol->GetScale(1), vol->GetScale(2)); glWireCube(&listIDs[2]); } break; } }
static inline void DrawCollisionVolume(const CollisionVolume* vol) { glPushMatrix(); switch (vol->GetVolumeType()) { case CollisionVolume::COLVOL_TYPE_ELLIPSOID: case CollisionVolume::COLVOL_TYPE_SPHERE: { // scaled sphere is special case of ellipsoid: radius, slices, stacks glTranslatef(vol->GetOffset(0), vol->GetOffset(1), vol->GetOffset(2)); glScalef(vol->GetHScale(0), vol->GetHScale(1), vol->GetHScale(2)); glWireSphere(&volumeDisplayListIDs[0], 20, 20); } break; case CollisionVolume::COLVOL_TYPE_CYLINDER: { // scaled cylinder: base-radius, top-radius, height, slices, stacks // // (cylinder base is drawn at unit center by default so add offset // by half major axis to visually match the mathematical situation, // height of the cylinder equals the unit's full major axis) switch (vol->GetPrimaryAxis()) { case CollisionVolume::COLVOL_AXIS_X: { glTranslatef(-(vol->GetHScale(0)), 0.0f, 0.0f); glTranslatef(vol->GetOffset(0), vol->GetOffset(1), vol->GetOffset(2)); glScalef(vol->GetScale(0), vol->GetHScale(1), vol->GetHScale(2)); glRotatef( 90.0f, 0.0f, 1.0f, 0.0f); } break; case CollisionVolume::COLVOL_AXIS_Y: { glTranslatef(0.0f, -(vol->GetHScale(1)), 0.0f); glTranslatef(vol->GetOffset(0), vol->GetOffset(1), vol->GetOffset(2)); glScalef(vol->GetHScale(0), vol->GetScale(1), vol->GetHScale(2)); glRotatef(-90.0f, 1.0f, 0.0f, 0.0f); } break; case CollisionVolume::COLVOL_AXIS_Z: { glTranslatef(0.0f, 0.0f, -(vol->GetHScale(2))); glTranslatef(vol->GetOffset(0), vol->GetOffset(1), vol->GetOffset(2)); glScalef(vol->GetHScale(0), vol->GetHScale(1), vol->GetScale(2)); } break; } glWireCylinder(&volumeDisplayListIDs[1], 20, 1.0f); } break; case CollisionVolume::COLVOL_TYPE_BOX: { // scaled cube: length, width, height glTranslatef(vol->GetOffset(0), vol->GetOffset(1), vol->GetOffset(2)); glScalef(vol->GetScale(0), vol->GetScale(1), vol->GetScale(2)); glWireCube(&volumeDisplayListIDs[2]); } break; } glPopMatrix(); }