コード例 #1
0
//------------------------------------------------------------------------
void CVehiclePartAnimated::SetDrivingProxy(bool bDrive)
{
	IVehicleMovement* pMovement = m_pVehicle->GetMovement();
	if (!(pMovement && pMovement->UseDrivingProxy()))
		return;

	if (0 == m_hullMatId[bDrive]) // 0 means, nothin to do
		return;

	if (!m_pCharInstance)
		return;

	ISkeletonPose* pSkeletonPose = m_pCharInstance->GetISkeletonPose();
	if (!pSkeletonPose)
		return;
	IDefaultSkeleton &rIDefaultSkeleton = m_pCharInstance->GetIDefaultSkeleton();
	IPhysicalEntity*  pPhysics          = m_pVehicle->GetEntity()->GetPhysics();
	if (!pPhysics)
		return;

	int id = rIDefaultSkeleton.GetJointIDByName("hull_proxy");

	if (id < 0)
	{
		m_hullMatId[0] = m_hullMatId[1] = 0;
		return;
	}

	int partid = pSkeletonPose->GetPhysIdOnJoint(id);

	if (partid == -1)
		return;

	pe_params_part params;
	params.partid = partid;
	params.ipart  = -1;
	if (!pPhysics->GetParams(&params) || !params.nMats)
		return;

	phys_geometry* pGeom = params.pPhysGeom;
	if (pGeom && pGeom->surface_idx < pGeom->nMats)
	{
		ISurfaceTypeManager* pSurfaceMan = gEnv->p3DEngine->GetMaterialManager()->GetSurfaceTypeManager();

		// initialize once
		if (m_hullMatId[0] < 0)
		{
			int         idDriving = 0;
			int         idOrig    = pGeom->pMatMapping[pGeom->surface_idx];
			const char* matOrig   = pSurfaceMan->GetSurfaceType(idOrig)->GetName();

			if (strstr(matOrig, "mat_metal"))
				idDriving = pSurfaceMan->GetSurfaceTypeByName("mat_metal_nofric")->GetId();
			else
			{
				string mat(matOrig);
				mat.append("_nofric");

				idDriving = pSurfaceMan->GetSurfaceTypeByName(mat.c_str(), NULL, false)->GetId();
			}

			//if (pDebug->GetIVal())
			//CryLog("%s looking up driving surface replacement for %s (id %i) -> got id %i", m_pVehicle->GetEntity()->GetName(), matOrig, idOrig, idDriving);

			if (idDriving > 0)
			{
				// store old and new id
				m_hullMatId[0] = idOrig;
				m_hullMatId[1] = idDriving;

				/*if (pDebug->GetIVal())
				   {
				   const char* matDriving = pSurfaceMan->GetSurfaceType(idDriving)->GetName();
				   CryLog("%s storing hull matId for swapping: %i (%s) -> %i (%s)", m_pVehicle->GetEntity()->GetName(), m_hullMatId[0], matOrig, m_hullMatId[1], matDriving);
				   }*/
			}
			else
				m_hullMatId[0] = m_hullMatId[1] = 0;
		}

		// only swap if materials available
		if (m_hullMatId[bDrive] > 0)
		{
#if ENABLE_VEHICLE_DEBUG
			if (VehicleCVars().v_debugdraw == eVDB_Parts)
				CryLog("%s swapping hull proxy from %i (%s) to matId %i (%s)", m_pVehicle->GetEntity()->GetName(), m_hullMatId[bDrive ^ 1], pSurfaceMan->GetSurfaceType(m_hullMatId[bDrive ^ 1])->GetName(), m_hullMatId[bDrive], pSurfaceMan->GetSurfaceType(m_hullMatId[bDrive])->GetName());
#endif

			for (int n = 0; n < pGeom->nMats; ++n)
			{
				pGeom->pMatMapping[n] = m_hullMatId[bDrive];
			}
		}
	}
}
コード例 #2
0
//--------------------------------------------------------------------------------------------------
// Name: BreakGlassObject
// Desc: Replaces a physical StatObj with a glass node where supported
// Note: We're currently duplicating some work done in CryAction, so should be reading that in.
//			 Similarly, we should also be accepting the SProcessImpactIn struct instead of the event
//--------------------------------------------------------------------------------------------------
bool CBreakableGlassSystem::BreakGlassObject(const EventPhysCollision& physEvent, const bool forceGlassBreak)
{
	bool bSuccess = false;
	SBreakableGlassInitParams initParams;

	// Get surface type's breaking effect
	ISurfaceTypeManager* pSurfaceTypeManager = gEnv->p3DEngine->GetMaterialManager()->GetSurfaceTypeManager();
	initParams.surfaceTypeId = physEvent.idmat[PHYSEVENT_COLLIDEE];

	if (ISurfaceType* pMat = pSurfaceTypeManager->GetSurfaceType(initParams.surfaceTypeId))
	{
		if (ISurfaceType::SBreakable2DParams* pBreakableParams = pMat->GetBreakable2DParams())
		{
			initParams.pShatterEffect = pBreakableParams->full_fracture_fx ? gEnv->pParticleManager->FindEffect(pBreakableParams->full_fracture_fx) : NULL;
		}
	}

	// Calculate glass data
	SBreakableGlassPhysData physData;

	if (ExtractPhysDataFromEvent(physEvent, physData, initParams) &&
			ValidateExtractedOutline(physData, initParams))
	{
		Vec3 size;
		Matrix34 transMat;

		CalculateGlassBounds(physData.pPhysGeom, size, transMat);

		// Update initialisation parameters
		if (!physData.defaultFrag.empty())
		{
			initParams.pInitialFrag = physData.defaultFrag.begin();
			initParams.numInitialFragPts = physData.defaultFrag.size();
		}
		else
		{
			initParams.pInitialFrag = NULL;
			initParams.numInitialFragPts = 0;
		}

		initParams.size.set(size.x, size.y);
		initParams.thickness = size.z;

		// Fix-up mesh and calculate anchors
		CalculateGlassAnchors(physData, initParams);

		// Calculate UV coords at axis-aligned points
		Vec2 origin = InterpolateUVCoords(physData.uvBasis[0], physData.uvBasis[1], physData.uvBasis[2], Vec2Constants<f32>::fVec2_Zero);
		Vec2 xAxisPt = InterpolateUVCoords(physData.uvBasis[0], physData.uvBasis[1], physData.uvBasis[2], Vec2Constants<f32>::fVec2_OneX);
		Vec2 yAxisPt = InterpolateUVCoords(physData.uvBasis[0], physData.uvBasis[1], physData.uvBasis[2], Vec2Constants<f32>::fVec2_OneY);

		// Convert the UV basis to X and Y axes w/ an offset
		initParams.uvOrigin = origin;
		initParams.uvXAxis = xAxisPt - origin;
		initParams.uvYAxis = yAxisPt - origin;

		// Create a replacement glass node
		IBreakableGlassRenderNode* pRenderNode = InitGlassNode(physData, initParams, transMat);
		
		// Duplicate the collision event and patch it up for the new node
		EventPhysCollision dupeEvent = physEvent;	

		dupeEvent.pEntity[PHYSEVENT_COLLIDEE] = pRenderNode->GetPhysics();
		dupeEvent.pForeignData[PHYSEVENT_COLLIDEE] = (void*)pRenderNode;
		dupeEvent.iForeignData[PHYSEVENT_COLLIDEE] = PHYS_FOREIGN_ID_BREAKABLE_GLASS;

		pe_params_part partParams;
		if (dupeEvent.pEntity[PHYSEVENT_COLLIDEE]->GetParams(&partParams) && partParams.nMats > 0)
		{
			dupeEvent.idmat[PHYSEVENT_COLLIDEE] = partParams.pMatMapping[0];
		}

		if (forceGlassBreak)
		{
			ModifyEventToForceBreak(&dupeEvent);			
		}

		// Send it directly to the new node
		PassImpactToNode(pRenderNode, &dupeEvent);

		bSuccess = true;
	}

	return bSuccess;
}//-------------------------------------------------------------------------------------------------