Esempio n. 1
0
int CParachute::AddCel(IPhysicalEntity* pPhysics, int _iID,SWing *_pCel)
{
    IPhysicalWorld *pPhysicalWorld = gEnv->pPhysicalWorld;

    primitives::box geomBox;
    geomBox.Basis = Matrix33::CreateRotationXYZ(Ang3(DEG2RAD(_pCel->fAngleX),DEG2RAD(_pCel->fAngleY),0.0f));
    geomBox.bOriented = 1;
    geomBox.center.Set(0.0f,0.0f,0.0f);
    geomBox.size = _pCel->vSize;
    IGeometry *pGeom = pPhysicalWorld->GetGeomManager()->CreatePrimitive(primitives::box::type,&geomBox);
    phys_geometry *physGeom = pPhysicalWorld->GetGeomManager()->RegisterGeometry(pGeom);
    pGeom->Release();

    pe_geomparams partpos;
    partpos.pos		= _pCel->vPos;
    partpos.mass	= _pCel->fMass;
    int id = pPhysics->AddGeometry(physGeom,&partpos);

    pPhysicalWorld->GetGeomManager()->UnregisterGeometry(physGeom);

    return id;
}
int CScriptBind_Physics::SamplePhysEnvironment(IFunctionHandler *pH)
{
	int nEnts,i,nHits=0,objtypes = ent_static|ent_rigid|ent_sleeping_rigid|ent_sort_by_mass;
	pe_status_nparts snp; 
	pe_status_pos sp;
	IPhysicalEntity **pEnts;
	geom_world_data gwd;
	IGeometry *pSphere;
	primitives::sphere sph;
	intersection_params ip;
	geom_contact *pcontacts;
	IPhysicalWorld *pWorld = m_pSystem->GetIPhysicalWorld();
	IEntity *pEntity;
	SmartScriptTable pObj(m_pSS);
	ip.bStopAtFirstTri=ip.bNoBorder=ip.bNoAreaContacts = true;
	ip.bThreadSafe = true;

	if (!pH->GetParams(sph.center,sph.r))
		return pH->EndFunction();
	if (pH->GetParamCount()>2)
		pH->GetParam(3,objtypes);
	pSphere = pWorld->GetGeomManager()->CreatePrimitive(primitives::sphere::type,&sph);

	nEnts = pWorld->GetEntitiesInBox(sph.center-Vec3(sph.r),sph.center+Vec3(sph.r),pEnts,objtypes);
	for(i=0;i<nEnts;i++) for(sp.ipart=pEnts[i]->GetStatus(&snp)-1;sp.ipart>=0;sp.ipart--)
	{
		sp.partid=-1; pEnts[i]->GetStatus(&sp);
		gwd.offset=sp.pos; gwd.R=Matrix33(sp.q); gwd.scale=sp.scale;
		WriteLockCond lock;
		if ((sp.flagsOR & (geom_colltype0|geom_no_coll_response))==geom_colltype0 && sp.pGeomProxy->IntersectLocked(pSphere,&gwd,0,&ip,pcontacts,lock))
		{
			++nHits;
			if (pEntity = (IEntity*)pEnts[i]->GetForeignData(PHYS_FOREIGN_ID_ENTITY))
				pObj->SetAt(nHits*3-2, pEntity->GetScriptTable());
			else
				pObj->SetNullAt(nHits*3-2);
			pObj->SetAt(nHits*3-1, sp.partid);
			pObj->SetAt(nHits*3, pWorld->GetPhysicalEntityId(pEnts[i]));
			if (pEnts[i]->GetType()!=PE_ARTICULATED)
				break;
		}
	}
	pSphere->Release();

	return pH->EndFunction(*pObj);	
}