Exemplo n.º 1
0
void vHavokTerrain::Init(const VTerrainSector &terrainSector)
{
  // Init may only be called once
  VVERIFY_OR_RET(m_bInitialized == false);
  m_bInitialized = true;

  m_terrainSector = &terrainSector;

  // Build the Havok shape
  CreateHkRigidBody();
}
Exemplo n.º 2
0
void vHavokStaticMesh::Init(VisStaticMeshInstance_cl &meshInstance)
{
  // Init may only be called once
  VVERIFY_OR_RET(m_bInitialized == false);

  // Add the static mesh instance
  m_staticMeshes.Append(&meshInstance);
  meshInstance.SetPhysicsObject(this);
  m_iNumValidStaticMeshes = 1;
  m_bInitialized = true;

  // Build the Havok shape
  CreateHkRigidBody();
}
Exemplo n.º 3
0
void vHavokStaticMesh::Init(VisStaticMeshInstCollection &meshInstances)
{
  // Init may only be called once
  VVERIFY_OR_RET(m_bInitialized == false);

  // Add the static mesh instances
  int iCount = meshInstances.GetLength();
  for (int i = 0; i < iCount; i++)
  {
    m_staticMeshes.Append(meshInstances[i]);
    meshInstances[i]->SetPhysicsObject(this);
    m_iNumValidStaticMeshes++;
  }

  m_bInitialized = true;

  CreateHkRigidBody();
}
Exemplo n.º 4
0
void vHavokStaticMesh::UpdateVision2Havok()
{
  VVERIFY_OR_RET(m_staticMeshes.GetLength() >= 1 && m_pRigidBody);

  int iCount = m_staticMeshes.GetLength();
  for (int i=0;i<iCount;i++)
  {
    // since collision mesh does not provide a bounding box, use bounding box of render mesh as approximation
    const hkvAlignedBBox& bbox = m_staticMeshes[i]->GetBoundingBox();
	hkVector4 bbox_min; vHavokConversionUtils::VisVecToPhysVec_noscale(bbox.m_vMin, bbox_min);
	hkVector4 bbox_max; vHavokConversionUtils::VisVecToPhysVec_noscale(bbox.m_vMax, bbox_max);
	hkVector4 bbox_extent; bbox_extent.setSub(bbox_max,bbox_min); bbox_extent.mul(vHavokConversionUtils::GetVision2HavokScaleSIMD());

	hkVector4 meshTol; meshTol.setAll(hkReal(HKVIS_MESH_SHAPE_TOLERANCE));
	hkVector4Comparison::Mask largeEnough = bbox_extent.greaterEqual(meshTol).getMask<hkVector4ComparisonMask::MASK_XYZ>();
	if (hkMath::countBitsSet(largeEnough) < 2)
    {
      Vision::Error.Warning("Attempted to create a vHavokStaticMesh with undersized extents (%.4f, %4f, %.4f)", 
							bbox_extent(0), bbox_extent(1), bbox_extent(2));
      return;
    }
  }

  // We use the first static mesh instance as origin reference
  VisStaticMeshInstance_cl *pMeshInstance = m_staticMeshes[0];

  // Get the static mesh instance position and rotation
  hkMatrix4 mTransform;
  vHavokConversionUtils::VisMatrixToHkMatrix(pMeshInstance->GetTransform(), mTransform, false, false, true);

  // Split the rotation into scale and normal matrix
  hkRotation mRotation; 
  mRotation.setCols(mTransform.getColumn<0>(),mTransform.getColumn<1>(),mTransform.getColumn<2>());
  hkVector4 vScale;
  vScale.set(mRotation.getColumn<0>().normalizeWithLength<3>(),
			 mRotation.getColumn<1>().normalizeWithLength<3>(),
			 mRotation.getColumn<2>().normalizeWithLength<3>(),
			 hkSimdReal_1);
  
  bool bUpdateDebugRendering = false;

  //Check here if we need to recalculate the precomputed collision mesh
  //should only happen inside the editor
  //if((vScale.x != m_vScale.x || vScale.y != m_vScale.y || vScale.z != m_vScale.z) && m_pRigidBody != NULL)
  hkVector4 mvScale; vHavokConversionUtils::VisVecToPhysVec_noscale(m_vScale,mvScale);
  if (!vScale.allEqual<3>(mvScale, hkSimdReal::fromFloat(HKVMATH_LARGE_EPSILON)) && (m_pRigidBody != NULL))
  {
    // Keep our object alive
    VSmartPtr<vHavokStaticMesh> keepAlive = this;

    RemoveHkRigidBody(); //Remove the old collision object
    CreateHkRigidBody(); //Create a new one (because the scale changed)
    VASSERT_MSG(m_pRigidBody != NULL, "Creating new rigid body failed");
	vHavokConversionUtils::PhysVecToVisVec_noscale(vScale, m_vScale);

    bUpdateDebugRendering = true;
  }

  // Set the transformation in Havok
  hkTransform hkTfOut;
  hkTfOut.setRotation(mRotation);
  hkTfOut.getTranslation().setMul(mTransform.getColumn<3>(),vHavokConversionUtils::GetVision2HavokScaleSIMD());
  m_pRigidBody->setTransform(hkTfOut);

  if (bUpdateDebugRendering)
  {
    SetDebugRendering (false);
  }
}