Пример #1
0
    bool csBulletCollider::CreateSphereGeometry (const csSphere& sphere)
    {
        // TODO: the body won't be set if one create a body, then AttachCollider,
        //       then CreateGeometry on the collider

        delete shape;
        shape = 0;
        delete[] vertices;
        vertices = 0;
        delete[] indices;
        indices = 0;

        shape = new btSphereShape (sphere.GetRadius () * dynSys->internalScale);
        geomType = SPHERE_COLLIDER_GEOMETRY;

        if (isStaticBody)
        {
            // TODO: add local transform?
            localTransform.Identity ();
            if (!(sphere.GetCenter () < 0.0001f))
                localTransform.SetOrigin (sphere.GetCenter ());

            body->compoundChanged = true;
            body->RebuildBody ();
        }

        return true;
    }
Пример #2
0
    bool csBulletCollider::GetSphereGeometry (csSphere& sphere)
    {
        if (geomType != SPHERE_COLLIDER_GEOMETRY)
            return false;

        btSphereShape* geometry = static_cast<btSphereShape*> (shape);
        sphere.SetCenter (localTransform.GetOrigin ());
        sphere.SetRadius (geometry->getRadius () * dynSys->inverseInternalScale);

        return true;
    }
Пример #3
0
csSphere csReversibleTransform::This2Other (const csSphere &s) const
{
  csSphere news;
  news.SetCenter (This2Other (s.GetCenter ()));

  // @@@ It would be nice if we could quickly detect if a given
  // transformation is orthonormal. In that case we don't need to transform
  // the radius.
  // To transform the radius we transform a vector with the radius
  // relative to the transform.
  csVector3 v_radius (s.GetRadius ());
  v_radius = This2OtherRelative (v_radius);

  float radius = (float)fabs (v_radius.x);
  if (radius < (float)fabs (v_radius.y)) radius = (float)fabs (v_radius.y);
  if (radius < (float)fabs (v_radius.z)) radius = (float)fabs (v_radius.z);
  news.SetRadius (radius);
  return news;
}
Пример #4
0
  csRef<iMeshWrapper> DynamicsDebugger::CreateSphereMesh (csSphere sphere,
                                iMaterialWrapper* material, iSector* sector)
  {
    // Find the pointer to the engine plugin
    csRef<iEngine> engine = csQueryRegistry<iEngine> (manager->object_reg);
    if (!engine)
    {
      manager->Report (CS_REPORTER_SEVERITY_ERROR,
		       "No iEngine plugin!");
      return 0;
    }

    // Create the sphere mesh factory.
    csRef<iMeshFactoryWrapper> sphereFact =
      engine->CreateMeshFactory ("crystalspace.mesh.object.genmesh",
				 "sphereFact");
    if (sphereFact == 0)
    {
      manager->Report (CS_REPORTER_SEVERITY_ERROR,
		       "Error creating sphere mesh factory!");
      return 0;
    }
 
    // Generate the sphere topology
    csRef<iGeneralFactoryState> gmstate = scfQueryInterface<iGeneralFactoryState>
      (sphereFact->GetMeshObjectFactory ());
    csVector3 radius (sphere.GetRadius ());
    csEllipsoid ellips (sphere.GetCenter (), radius);
    gmstate->GenerateSphere (ellips, 16);

    // Create the mesh.
    csRef<iMeshWrapper> mesh (engine->CreateMeshWrapper (sphereFact, "sphere", sector));
    mesh->GetMeshObject ()->SetMaterialWrapper (material);

    return mesh;
  }
Пример #5
0
void csPortalContainer::GetBoundingSpheres (iRenderView* rview, 
                                            csReversibleTransform* tr_o2c,
					    csVector3* camera_origin, 
					    csSphere& world_sphere, 
					    csSphere& cam_sphere)
{
  iCamera* camera = rview->GetCamera ();
  const csReversibleTransform& camtrans = camera->GetTransform ();
  const csMovable& cmovable = meshwrapper->GetCsMovable ();
  if (movable_nr != cmovable.GetUpdateNumber ())
  {
    const csReversibleTransform movtrans = cmovable.GetFullTransform ();
    ObjectToWorld (cmovable, movtrans);
  }

  csSphere sphere;
  sphere.SetCenter (object_bbox.GetCenter ());
  sphere.SetRadius (object_radius);

  uint8 local_t2c[sizeof(csReversibleTransform)];
  if (tr_o2c == 0) 
  {
#include "csutil/custom_new_disable.h"
    tr_o2c = new (local_t2c) csReversibleTransform;
#include "csutil/custom_new_enable.h"
  }
  *tr_o2c = camtrans;
  if (!movable_identity)
  {
    const csReversibleTransform movtrans = cmovable.GetFullTransform ();
    *tr_o2c /= movtrans;
    world_sphere = movtrans.This2Other (sphere);
  }
  else
  {
    world_sphere = sphere;
  }
  cam_sphere = tr_o2c->Other2This (sphere);
  if (camera_origin) *camera_origin = cam_sphere.GetCenter ();
}