Esempio n. 1
0
File: spr2d.cpp Progetto: garinh/cs
void csSprite2DMeshObject::UpdateLighting (
	const csSafeCopyArray<csLightInfluence>& lights,
	const csReversibleTransform& transform)
{
  csVector3 new_pos = transform.This2Other (part_pos);
  UpdateLighting (lights, new_pos);
}
Esempio n. 2
0
void psWorld::BuildWarpCache()
{
    int sectorCount = engine->GetSectors()->GetCount();
    Debug2(LOG_STARTUP,0,"Building warp cache for %d sectors...",sectorCount);

    /// Clear existing entries
    transarray.Empty();

    transarray.SetSize(sectorCount);

    for(int i=0; i<sectorCount; i++)
    {
        const csSet<csPtrKey<iMeshWrapper> > &portals = engine->GetSectors()->Get(i)->GetPortalMeshes();
        Debug3(LOG_STARTUP,0," %zu portal meshes for %s",portals.GetSize(),
               engine->GetSectors()->Get(i)->QueryObject()->GetName());

        csSet<csPtrKey<iMeshWrapper> >::GlobalIterator it = portals.GetIterator();
        while(it.HasNext())
        {
            iMeshWrapper* portal_mesh = it.Next();
            iPortalContainer* pc = portal_mesh->GetPortalContainer();
            for(int j = 0 ; j < pc->GetPortalCount() ; j++)
            {
                iPortal* portal = pc->GetPortal(j);
                if(portal->CompleteSector(0))
                {
                    if(engine->GetSectors()->Find(portal->GetSector()) != -1)
                    {
                        const csReversibleTransform warp = portal->GetWarp();

                        // Check the values and issue warning for strange values.
                        csVector3 v_o2t = warp.GetO2TTranslation();
                        if(fabs(v_o2t.x) > 1.0e+10 || fabs(v_o2t.y) > 1.0e+10 || fabs(v_o2t.z) > 1.0e+10)
                        {
                            Error3("Warpspace with very large o2t translation:  %s: %s",
                                   portal->GetName(),warp.Description().GetData());
                        }

                        // Apply the warp to the chache
                        transarray[i].Set(portal->GetSector(), warp);
                    }
                }
            }
        }
    }
}
Esempio n. 3
0
csReversibleTransform WalkTestLights::FlashlightShift (const csReversibleTransform& tf)
{
  csReversibleTransform newTF (tf);
  // Tilt flashlight a bit down
  csMatrix3 newmat (tf.GetT2O());
  newmat *= csXRotMatrix3 (float ((10.0/180.0)*PI));
  newTF.SetT2O (newmat);
  return newTF;
}
Esempio n. 4
0
void csPortalContainer::WorldToCamera (iCamera*,
	const csReversibleTransform& camtrans)
{
  camera_vertices.SetSize (world_vertices.GetSize ());
  size_t i;
  for (i = 0 ; i < world_vertices.GetSize () ; i++)
    camera_vertices[i] = camtrans.Other2This (world_vertices[i]);
  camera_planes.Empty ();
  for (i = 0 ; i < portals.GetSize () ; i++)
  {
    csPortal* prt = portals[i];
    csPlane3 p;
    csVector3& cam_vec = camera_vertices[portals[i]->GetVertexIndices ()[0]];
    camtrans.Other2This (prt->GetIntWorldPlane (), cam_vec, p);
    p.Normalize ();
    camera_planes.Push (p);
  }
}
Esempio n. 5
0
/**
 * Modify the slave transform so that it is nicely aligned to the master
 * transform (horizontally) but with the smallest possible rotation.
 */
static void FindBestAlignedTransform (const csReversibleTransform& masterTrans,
    csReversibleTransform& slaveTrans)
{
  csReversibleTransform masterCopy = masterTrans;
  int i = 4;
  while (i > 0)
  {
    csVector3 front = masterCopy.GetFront ();
    csVector3 fr = slaveTrans.GetFront ();
    float angle = GetAngle (front.x, front.z, fr.x, fr.z);
    if (fabs (angle) <= (PI / 4.0))
    {
      slaveTrans.SetO2T (masterCopy.GetO2T ());
      return;
    }
    i--;
    masterCopy.RotateOther (csVector3 (0, 1, 0), PI/2.0);
  }
}
Esempio n. 6
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 ();
}
Esempio n. 7
0
void csPortalContainer::HardTransform (const csReversibleTransform& t)
{
  size_t i;
  world_vertices.SetSize (vertices.GetSize ());
  for (i = 0 ; i < vertices.GetSize () ; i++)
  {
    vertices[i] = t.This2Other (vertices[i]);
    world_vertices[i] = vertices[i];
  }
  for (i = 0 ; i < portals.GetSize () ; i++)
  {
    csPortal* prt = portals[i];
    csPlane3 new_plane;
    csDirtyAccessArray<int>& vidx = prt->GetVertexIndices ();
    t.This2Other (prt->GetIntObjectPlane (), vertices[vidx[0]], new_plane);
    prt->SetObjectPlane (new_plane);
    prt->SetWorldPlane (new_plane);
    if (prt->flags.Check (CS_PORTAL_WARP))
      prt->ObjectToWorld (t, prt->warp_obj);
  }
  movable_nr--;	// Make sure object to world will be recalculated.
  prepared = false;
}
bool psEffectObjDecal::Update(csTicks elapsed)
{
    if (!anchor || !anchor->IsReady()) // wait for anchor to be ready
        return true;

    if (!psEffectObj::Update(elapsed))
        return false;

    float heightScale = 1.0f;
    if (keyFrames->GetSize() > 0)
      heightScale = LERP_KEY(KA_HEIGHT,LERP_FACTOR);

    const csReversibleTransform t = mesh->GetMovable()->GetFullTransform();
    const csVector3 newPos = t.GetOrigin();
    const csVector3 newUp = t.GetFront();
    const csVector3 newNormal = t.GetUp();
    const float newWidth = baseScale;
    const float newHeight = baseScale * heightScale;
    if (!decal
        || newPos != pos
        || newUp != up
        || newNormal != normal
        || newWidth != width
        || newHeight != height)
    {
        decal = decalMgr->CreateDecal(decalTemplate, mesh->GetMovable()->GetSectors()->Get(0), newPos, newUp, 
                newNormal, newWidth, newHeight, decal);

        pos = newPos;
        up = newUp;
        normal = newNormal;
        width = newWidth;
        height = newHeight;
    }

    return true;
}
Esempio n. 9
0
void csPortalContainer::ObjectToWorld (const csMovable& movable,
	const csReversibleTransform& movtrans)
{
  movable_nr = movable.GetUpdateNumber ();
  movable_identity = movable.IsFullTransformIdentity ();
  size_t i;
  world_vertices.SetSize (vertices.GetSize ());
  if (movable_identity)
  {
    world_vertices = vertices;
    for (i = 0 ; i < portals.GetSize () ; i++)
    {
      csPortal* prt = portals[i];
      csPlane3 wp (prt->GetIntObjectPlane ());
      prt->SetWorldPlane (wp);
      prt->world_sphere = prt->object_sphere;
    }
  }
  else
  {
    for (i = 0 ; i < vertices.GetSize () ; i++)
      world_vertices[i] = movtrans.This2Other (vertices[i]);
    for (i = 0 ; i < portals.GetSize () ; i++)
    {
      csPortal* prt = portals[i];
      csPlane3 p;
      csVector3& world_vec = world_vertices[portals[i]->GetVertexIndices ()[0]];
      movtrans.This2Other (prt->GetIntObjectPlane (), world_vec, p);
      p.Normalize ();
      prt->SetWorldPlane (p);
      prt->world_sphere = csSphere (
	  movtrans.This2Other (prt->object_sphere.GetCenter ()),
	  prt->object_sphere.GetRadius ());
    }
  }
}
Esempio n. 10
0
  ProxyLight::ProxyLight (Sector* owner, Light* parentLight, const csFrustum& frustum,
    const csReversibleTransform& transform, const csPlane3& portalPlane)
    : Light (owner, parentLight->IsDeltaLight ()), parent (parentLight),
    proxyTransform (transform), portalPlane (portalPlane)
  {
    realLight = false;

    SetPDLight (parent->IsPDLight ());
    SetColor (parent->GetColor ());
    SetLightID ((const char*)parent->GetLightID ().data);
    SetName (parent->GetName ());
    lightFrustum = frustum;
    boundingSphere = transform.Other2This (parentLight->GetBoundingSphere ());

    csPlane3 bp (portalPlane);
    bp.DD += bp.norm * lightFrustum.GetOrigin ();
    bp.Invert ();
    lightFrustum.SetBackPlane (bp);
  }
Esempio n. 11
0
static csVector3 FindBiggestHorizontalMovement (
    const csBox3& box1, const csReversibleTransform& trans1,
    const csBox3& box2, const csReversibleTransform& trans2)
{
  // The origin of the second box in the 3D space of the first box.
  csVector3 o2Tr = trans1.Other2This (trans2.GetOrigin ());
  // Transformed bounding box.
  csBox3 box2Tr;
  box2Tr.StartBoundingBox (trans1.Other2ThisRelative (trans2.This2OtherRelative (box2.GetCorner (0))));
  box2Tr.AddBoundingVertexSmart (trans1.Other2ThisRelative (trans2.This2OtherRelative (box2.GetCorner (1))));
  box2Tr.AddBoundingVertexSmart (trans1.Other2ThisRelative (trans2.This2OtherRelative (box2.GetCorner (2))));
  box2Tr.AddBoundingVertexSmart (trans1.Other2ThisRelative (trans2.This2OtherRelative (box2.GetCorner (3))));
  box2Tr.AddBoundingVertexSmart (trans1.Other2ThisRelative (trans2.This2OtherRelative (box2.GetCorner (4))));
  box2Tr.AddBoundingVertexSmart (trans1.Other2ThisRelative (trans2.This2OtherRelative (box2.GetCorner (5))));
  box2Tr.AddBoundingVertexSmart (trans1.Other2ThisRelative (trans2.This2OtherRelative (box2.GetCorner (6))));
  box2Tr.AddBoundingVertexSmart (trans1.Other2ThisRelative (trans2.This2OtherRelative (box2.GetCorner (7))));

  float xr = o2Tr.x - box1.MaxX () + box2Tr.MinX ();
  float xl = box1.MinX () - o2Tr.x - box2Tr.MaxX ();
  float zr = o2Tr.z - box1.MaxZ () + box2Tr.MinZ ();
  float zl = box1.MinZ () - o2Tr.z - box2Tr.MaxZ ();
  csVector3 newpos = trans2.GetOrigin ();
  if (xr >= xl && xr >= zr && xr >= zl)
    newpos = trans1.This2Other (o2Tr + csVector3 (-xr, 0, -o2Tr.z));
  else if (xl >= xr && xl >= zr && xl >= zl)
    newpos = trans1.This2Other (o2Tr + csVector3 (xl, 0, -o2Tr.z));
  else if (zr >= xl && zr >= xr && zr >= zl)
    newpos = trans1.This2Other (o2Tr + csVector3 (-o2Tr.x, 0, -zr));
  else if (zl >= xl && zl >= xr && zl >= zr)
    newpos = trans1.This2Other (o2Tr + csVector3 (-o2Tr.x, 0, zl));
  return newpos;
}
Esempio n. 12
0
csBox3 operator/ (const csBox3 &p, const csReversibleTransform &t)
{
  return t.This2Other (p);
}
Esempio n. 13
0
csSphere operator/ (const csSphere &p, const csReversibleTransform &t)
{
  return t.This2Other (p);
}
Esempio n. 14
0
csVector3 operator/ (const csVector3 &v, const csReversibleTransform &t)
{
  return t.This2Other (v);
}