IPhysicalWorld

#include

Classes

struct SPWIParams
struct SRWIParams

Public Member Functions

virtual void Init ()=0
virtual void Shutdown (int bDeleteGeometries=1)=0
virtual void Release ()=0
destroys the world
virtual IGeomManager * GetGeomManager ()=0
virtual IPhysUtils * GetPhysUtils ()=0
virtual IPhysicalEntity * SetupEntityGrid (int axisz, Vec3 org, int nx, int ny, float stepx, float stepy, int log2PODscale=0, int bCyclic=0, IPhysicalEntity *pHost=nullptr, const QuatT &posInHost=QuatT(IDENTITY))=0
virtual void Cleanup ()=0
virtual void RegisterBBoxInPODGrid (const Vec3 *BBox)=0
RegisterBBoxInPODGrid marks affected sectors as needing on-demand physicalization via IPhysicsStreamer->CreatePhysicalEntitiesInBox.
virtual void UnregisterBBoxInPODGrid (const Vec3 *BBox)=0
virtual void DeactivateOnDemandGrid ()=0
virtual int AddRefEntInPODGrid (IPhysicalEntity *pent, const Vec3 *BBox=0)=0
virtual IPhysicalEntity * SetHeightfieldData (const primitives::heightfield *phf, int *pMatMapping=0, int nMats=0)=0
SetHeightfieldData - sets the global heightfield data. Uses callbacks to get height.
virtual IPhysicalEntity * GetHeightfieldData (primitives::heightfield *phf)=0
virtual void SetHeightfieldMatMapping (int *pMatMapping, int nMats)=0
virtual PhysicsVars * GetPhysVars ()=0
returns a writable structure
virtual IPhysicalEntity * CreatePhysicalEntity (pe_type type, pe_params *params=0, void *pforeigndata=0, int iforeigndata=0, int id=-1, IGeneralMemoryHeap *pHeap=NULL)=0
virtual IPhysicalEntity * CreatePhysicalEntity (pe_type type, float lifeTime, pe_params *params=0, void *pForeignData=0, int iForeignData=0, int id=-1, IPhysicalEntity *pHostPlaceholder=0, IGeneralMemoryHeap *pHeap=NULL)=0
CreatePhysicalEntity - this version is used when creating an a temporary entity (lifeTime) on demand for a placeholder.
virtual IPhysicalEntity * CreatePhysicalPlaceholder (pe_type type, pe_params *params=0, void *pForeignData=0, int iForeignData=0, int id=-1)=0
virtual int DestroyPhysicalEntity (IPhysicalEntity *pent, int mode=0, int bThreadSafe=0)=0
virtual int SetPhysicalEntityId (IPhysicalEntity *pent, int id, int bReplace=1, int bThreadSafe=0)=0
virtual int GetPhysicalEntityId (IPhysicalEntity *pent)=0
special values: NULL : -1, WORLD_ENTITY : -2;
virtual IPhysicalEntity * GetPhysicalEntityById (int id)=0
special values: -1 : terrain, -2 : default (empty) static entity; if bit 30 is set - don't expand placeholders into entities
virtual int SetSurfaceParameters (int surface_idx, float bounciness, float friction, unsigned int flags=0)=0
virtual int GetSurfaceParameters (int surface_idx, float &bounciness, float &friction, unsigned int &flags)=0
virtual int SetSurfaceParameters (int surface_idx, float bounciness, float friction, float damage_reduction, float ric_angle, float ric_dam_reduction, float ric_vel_reduction, unsigned int flags=0)=0
virtual int GetSurfaceParameters (int surface_idx, float &bounciness, float &friction, float &damage_reduction, float &ric_angle, float &ric_dam_reduction, float &ric_vel_reduction, unsigned int &flags)=0
virtual void TimeStep (float time_interval, int flags=ent_all|ent_deleted)=0
virtual float GetPhysicsTime ()=0
virtual int GetiPhysicsTime ()=0
physics time, quantized with PhysVars->timeGranularity
virtual void SetPhysicsTime (float time)=0
virtual void SetiPhysicsTime (int itime)=0
virtual void SetSnapshotTime (float time_snapshot, int iType=0)=0
time corresponding to the current snapshot
virtual void SetiSnapshotTime (int itime_snapshot, int iType=0)=0
virtual int GetEntitiesInBox (Vec3 ptmin, Vec3 ptmax, IPhysicalEntity **&pList, int objtypes, int szListPrealloc=0)=0
virtual int RayWorldIntersection (const SRWIParams &rp, const char *pNameTag=RWI_NAME_TAG, int iCaller=MAX_PHYS_THREADS)=0
virtual int TracePendingRays (int bDoActualTracing=1)=0
virtual void ResetDynamicEntities ()=0
virtual void DestroyDynamicEntities ()=0
virtual void PurgeDeletedEntities ()=0
Forces immediate physical deletion of all entities marked as deleted.
virtual int GetEntityCount (int iEntType)=0
iEntType is of pe_type
virtual int ReserveEntityCount (int nExtraEnts)=0
can prevent excessive internal lists re-allocations
virtual IPhysicalEntityIt * GetEntitiesIterator ()=0
virtual void SimulateExplosion (pe_explosion *pexpl, IPhysicalEntity **pSkipEnts=0, int nSkipEnts=0, int iTypes=ent_rigid|ent_sleeping_rigid|ent_living|ent_independent, int iCaller=MAX_PHYS_THREADS)=0
virtual void RasterizeEntities (const primitives::grid3d &grid, uchar *rbuf, int objtypes, float massThreshold, const Vec3 &offsBBox, const Vec3 &sizeBBox, int flags)=0
virtual int DeformPhysicalEntity (IPhysicalEntity *pent, const Vec3 &ptHit, const Vec3 &dirHit, float r, int flags=0)=0
virtual void UpdateDeformingEntities (float time_interval=0.01f)=0
UpdateDeformingEntities - normally this happens automatically during TimeStep; can be called manually for ex. during loading. More...
virtual float CalculateExplosionExposure (pe_explosion *pexpl, IPhysicalEntity *pient)=0
CalculateExplosionExposure - uses occlusion grid from the last SimulateExplosion to calculate exposure.
virtual float IsAffectedByExplosion (IPhysicalEntity *pent, Vec3 *impulse=0)=0
IsAffectedByExplosion - returns fraction of pent (0..1) that was exposed to the last explosion.
virtual int AddExplosionShape (IGeometry *pGeom, float size, int idmat, float probability=1.0f)=0
virtual void RemoveExplosionShape (int id)=0
virtual void RemoveAllExplosionShapes (void(*OnRemoveGeom)(IGeometry *pGeom)=0)=0
virtual void DrawPhysicsHelperInformation (IPhysRenderer *pRenderer, int iCaller=MAX_PHYS_THREADS)=0
virtual void DrawEntityHelperInformation (IPhysRenderer *pRenderer, int iEntityId, int iDrawHelpers)=0
virtual int CollideEntityWithBeam (IPhysicalEntity *_pent, Vec3 org, Vec3 dir, float r, ray_hit *phit)=0
CollideEntityWithBeam - does a sphere sweep test against an entity.
virtual int CollideEntityWithPrimitive (IPhysicalEntity *_pent, int itype, primitives::primitive *pprim, Vec3 dir, ray_hit *phit, intersection_params *pip=0)=0
CollideEntityWithPrimitive - collides entity with a single primitive; does a sweep check if dir is non-0.
virtual int RayTraceEntity (IPhysicalEntity *pient, Vec3 origin, Vec3 dir, ray_hit *pHit, pe_params_pos *pp=0, unsigned int geomFlagsAny=geom_colltype0|geom_colltype_player)=0
like RWI, but for one entity
virtual float PrimitiveWorldIntersection (const SPWIParams &pp, WriteLockCond *pLockContacts=0, const char *pNameTag=PWI_NAME_TAG)=0
virtual void GetMemoryStatistics (ICrySizer *pSizer)=0
virtual void SetPhysicsStreamer (IPhysicsStreamer *pStreamer)=0
sets the callbacks for on-demand creation
virtual void SetPhysicsEventClient (IPhysicsEventClient *pEventClient)=0
obsolete
virtual float GetLastEntityUpdateTime (IPhysicalEntity *pent)=0
simulation class-based, not actually per-entity
virtual int GetEntityProfileInfo (phys_profile_info *&pList)=0
virtual int GetFuncProfileInfo (phys_profile_info *&pList)=0
virtual int GetGroupProfileInfo (phys_profile_info *&pList)=0
virtual int GetJobProfileInfo (phys_job_info *&pList)=0
virtual void AddEventClient (int type, int(*func)(const EventPhys *), int bLogged, float priority=1.0f)=0
virtual int RemoveEventClient (int type, int(*func)(const EventPhys *), int bLogged)=0
virtual void PumpLoggedEvents ()=0
calls event clients for logged events
virtual uint32 GetPumpLoggedEventsTicks ()=0
virtual void ClearLoggedEvents ()=0
virtual int NotifyEventClients (EventPhys *pEvent, int bLogged)=0
virtual IPhysicalEntity * AddGlobalArea ()=0
virtual IPhysicalEntity * AddArea (Vec3 *pt, int npt, float zmin, float zmax, const Vec3 &pos=Vec3(0, 0, 0), const quaternionf &q=quaternionf(IDENTITY), float scale=1.0f, const Vec3 &normal=Vec3(ZERO), int *pTessIdx=0, int nTessTris=0, Vec3 *pFlows=0)=0
virtual IPhysicalEntity * AddArea (IGeometry *pGeom, const Vec3 &pos, const quaternionf &q, float scale)=0
virtual IPhysicalEntity * AddArea (Vec3 *pt, int npt, float r, const Vec3 &pos=Vec3(0, 0, 0), const quaternionf &q=quaternionf(IDENTITY), float scale=1)=0
AddArea - this adds a 3d-spline area.
virtual IPhysicalEntity * GetNextArea (IPhysicalEntity *pPrevArea=0)=0
GetNextArea: iterates through all registered areas, if prevarea==0 returns the global area.
virtual int CheckAreas (const Vec3 &ptc, Vec3 &gravity, pe_params_buoyancy *pb, int nMaxBuoys=1, int iMedium=-1, const Vec3 &vec=Vec3(ZERO), IPhysicalEntity *pent=0, int iCaller=MAX_PHYS_THREADS)=0
checks areas for a given point (ptc)
virtual void SetWaterMat (int imat)=0
material to use for water hits in RWI with ent_water
virtual int GetWaterMat ()=0
virtual int SetWaterManagerParams (pe_params *params)=0
pe_params_waterman; creates water manager if none is present and nExtraTiles is set
virtual int GetWaterManagerParams (pe_params *params)=0
virtual int GetWatermanStatus (pe_status *status)=0
pe_status_waterman
virtual void DestroyWaterManager ()=0
virtual volatile int * GetInternalLock (int idx)=0
returns one of phys_locks locks
virtual int SerializeWorld (const char *fname, int bSave)=0
saves/loads the world state (without geometries) in a text file
virtual int SerializeGeometries (const char *fname, int bSave)=0
virtual void SerializeGarbageTypedSnapshot (TSerialize ser, int iSnapshotType, int flags)=0
virtual void SavePhysicalEntityPtr (TSerialize ser, IPhysicalEntity *pent)=0
virtual IPhysicalEntity * LoadPhysicalEntityPtr (TSerialize ser)=0
virtual void GetEntityMassAndCom (IPhysicalEntity *pIEnt, float &mass, Vec3 &com)=0
virtual EventPhys * AddDeferredEvent (int type, EventPhys *event)=0
virtual void * GetInternalImplementation (int type, void *object=nullptr)=0
int RayWorldIntersection (const Vec3 &org, const Vec3 &dir, int objtypes, unsigned int flags, ray_hit *hits, int nMaxHits, IPhysicalEntity **pSkipEnts=0, int nSkipEnts=0, void *pForeignData=0, int iForeignData=0, const char *pNameTag=RWI_NAME_TAG, ray_hit_cached *phitLast=0, int iCaller=MAX_PHYS_THREADS)
int RayWorldIntersection (const Vec3 &org, const Vec3 &dir, int objtypes, unsigned int flags, ray_hit *hits, int nMaxHits, IPhysicalEntity *pSkipEnt, IPhysicalEntity *pSkipEntAux=0, void *pForeignData=0, int iForeignData=0)
void SimulateExplosion (Vec3 epicenter, Vec3 epicenterImp, float rmin, float rmax, float r, float impulsivePressureAtR, int nOccRes=0, int nGrow=0, float rminOcc=0.1f, IPhysicalEntity **pSkipEnts=0, int nSkipEnts=0, int iTypes=ent_rigid|ent_sleeping_rigid|ent_living|ent_independent)
float PrimitiveWorldIntersection (int itype, const primitives::primitive *pprim, const Vec3 &sweepDir=Vec3(ZERO), int entTypes=ent_all, geom_contact **ppcontact=0, int geomFlagsAll=0, int geomFlagsAny=geom_colltype0|geom_colltype_player, intersection_params *pip=0, void *pForeignData=0, int iForeignData=0, IPhysicalEntity **pSkipEnts=0, int nSkipEnts=0, WriteLockCond *pLockContacts=0, const char *pNameTag=PWI_NAME_TAG)

Detailed Description

Main interface to the physics implementation

See also
IPhysicalEntity

Member Function Documentation

◆ AddArea() [1/2]

virtual IPhysicalEntity* IPhysicalWorld::AddArea ( Vec3 * pt,
int npt,
float zmin,
float zmax,
const Vec3 & pos = Vec3(0, 0, 0),
const quaternionf & q = quaternionf(IDENTITY),
float scale = 1.0f,
const Vec3 & normal = Vec3(ZERO),
int * pTessIdx = 0,
int nTessTris = 0,
Vec3 * pFlows = 0
)
pure virtual

AddArea - adds a 2d-contour area. Computes the best fitting plane for the points and projects them on it zmin and zmax are the dimensions along this plane's normal if set, pTessIdx is the surface's triangulation (3 idx per tri), used if the points are not close enough to the plane pFlows is per-vertex (0..npt-1) water flow vectors

◆ AddArea() [2/2]

virtual IPhysicalEntity* IPhysicalWorld::AddArea ( IGeometry * pGeom,
const Vec3 & pos,
const quaternionf & q,
float scale
)
pure virtual

AddArea - creates a general geometry area. Typically, primitives work best, but can be a mesh or a heightfield In the latter case, it chages water plane in buoyancy params based on local height perturbation (used for waves)

◆ AddEventClient()

virtual void IPhysicalWorld::AddEventClient ( int type,
int(*)(const EventPhys *) func,
int bLogged,
float priority = 1.0f
)
pure virtual

AddEventClient - adds a phyisics event listener bLogged==1 for a logged event version, 0 for immediate listeners are called in the order of decreasing priorities if a listener returns 0, further event processing stops

◆ AddExplosionShape()

virtual int IPhysicalWorld::AddExplosionShape ( IGeometry * pGeom,
float size,
int idmat,
float probability = 1.0f
)
pure virtual

AddExplosionShape - registers a boolean carving shape for breakable meashes size is the shape's 'characteristic' size; during the actual carving the caller provides a desired size, and the shape is scaled by desired_size/this_size. idmat is the breakability index this shape gets assigned to. if there are several shapes for one index, the ones with the size closest to the requested are selected, and among those one is selected randomly based on relative probability returns shape id, which can be used to unregister the shape later

◆ AddGlobalArea()

virtual IPhysicalEntity* IPhysicalWorld::AddGlobalArea ( )
pure virtual

adds a global phys area or returns an existing one

◆ AddRefEntInPODGrid()

virtual int IPhysicalWorld::AddRefEntInPODGrid ( IPhysicalEntity * pent,
const Vec3 * BBox = 0
)
pure virtual

AddRefEntInPODGrid: makes sure the entity gets an on-demand AddRef for each on-demand sector it touches (needed when manually creating entities outside on-deman callback)

◆ Cleanup()

virtual void IPhysicalWorld::Cleanup ( )
pure virtual

Clean up memory pools after level was unloaded. should only be called when all outside references to physics where deleted.

◆ CreatePhysicalEntity()

virtual IPhysicalEntity* IPhysicalWorld::CreatePhysicalEntity ( pe_type type,
pe_params * params = 0,
void * pforeigndata = 0,
int iforeigndata = 0,
int id = -1,
IGeneralMemoryHeap * pHeap = NULL
)
pure virtual

CreatePhysicalEntity - creates an entity with specified type, sets foreign data and optionally initializes if some pe_params if id is left <0, the physics will assign one (note: internally there's a id->ptr array map, so keep ids wihin some sane range) returns a valid entity pointer even if the physics thread is busy during the call

◆ CreatePhysicalPlaceholder()

virtual IPhysicalEntity* IPhysicalWorld::CreatePhysicalPlaceholder ( pe_type type,
pe_params * params = 0,
void * pForeignData = 0,
int iForeignData = 0,
int id = -1
)
pure virtual

CreatePhysicalPlaceholder - placeholder is a lightweight structure that requests creation of a full entity when needed via IPhysicsStreamer->CreatePhysicalEntity

◆ DeactivateOnDemandGrid()

virtual void IPhysicalWorld::DeactivateOnDemandGrid ( )
pure virtual

deactivates sector-based on-demand physicalization

◆ DeformPhysicalEntity()

virtual int IPhysicalWorld::DeformPhysicalEntity ( IPhysicalEntity * pent,
const Vec3 & ptHit,
const Vec3 & dirHit,
float r,
int flags = 0
)
pure virtual

DeformPhysicalEntity - applies boolean breaking for entity parts that have >=0 breakability index r is used to scale the corresponding explosion (boolean) shape

◆ DestroyDynamicEntities()

virtual void IPhysicalWorld::DestroyDynamicEntities ( )
pure virtual

DestroyDynamicEntities - immediately destroys all physical, living, and detached entities; flushes the deleted entities All subsequent calls to DestroyPhysicalEntity for non-static entities are ignored until the next non-static entity is created

◆ DestroyPhysicalEntity()

virtual int IPhysicalWorld::DestroyPhysicalEntity ( IPhysicalEntity * pent,
int mode = 0,
int bThreadSafe = 0
)
pure virtual

DestroyPhysicalEntity - moves the entity to the to-be-destroyed list (mode 0), destroys areas and placeholders mode 1-suspend the entity (unregister from all physics structures, but don't delete), 2-restore from suspended state mode & 4 - doesn't delete the entity if it is still referenced and returns 0 even if this flag is not set, referenced entities (nRefCount>0) will not be physically deleted until freed request can get queued if the physics thread is busy, unless bThreadSafe is set

◆ GetEntitiesInBox()

virtual int IPhysicalWorld::GetEntitiesInBox ( Vec3 ptmin,
Vec3 ptmax,
IPhysicalEntity **& pList,
int objtypes,
int szListPrealloc = 0
)
pure virtual

GetEntitiesInBox - uses entity grid to query entites in bbox (objtypes - see enum entity_query_flags) unless ent_allocate_list is set, returns pre-alocated internal list for iCaller==MAX_PHYS_THREADS otherwise, tries to use supplied pList up to szListPrealloc, allocates a new one if the size's not enough returns the number of entities

◆ RasterizeEntities()

virtual void IPhysicalWorld::RasterizeEntities ( const primitives::grid3d & grid,
uchar * rbuf,
int objtypes,
float massThreshold,
const Vec3 & offsBBox,
const Vec3 & sizeBBox,
int flags
)
pure virtual

RasterizeEntities - builds a depth map from physical gometries in a box specified by grid; only updates area affected by offsBBox +/- sizeBBox depth is z values, scaled and clamped so that the grid box's -size.z..+size.z is mapped to 0..255

◆ RayWorldIntersection() [1/3]

virtual int IPhysicalWorld::RayWorldIntersection ( const SRWIParams & rp,
const char * pNameTag = RWI_NAME_TAG,
int iCaller = MAX_PHYS_THREADS
)
pure virtual

Performs a raycast through the physical world, returning possible hits into the provided hits structure

#include 
#include 

// Example of how we can cast a ray through the physical world and receive hit information
void RayWorldIntersection()
{
    // Store the half render size, used to calculate a direction that points outwards from the camera
    const float halfRenderWidth = static_cast(gEnv->pRenderer->GetWidth()) * 0.5f;
    const float halfRenderHeight = static_cast(gEnv->pRenderer->GetHeight()) * 0.5f;
    
    // For the sake of this example we will cast the ray 50 meters outwards from the camera
    const float searchRange = 50.f;

    // Calculate the centered position of the near and far planes
    Vec3 cameraCenterNear, cameraCenterFar;
    gEnv->pRenderer->UnProjectFromScreen(halfRenderWidth, halfRenderHeight, 0, &cameraCenterNear.x, &cameraCenterNear.y, &cameraCenterNear.z);
    gEnv->pRenderer->UnProjectFromScreen(halfRenderWidth, halfRenderHeight, 1, &cameraCenterFar.x, &cameraCenterFar.y, &cameraCenterFar.z);

    // Now subtract the far and near positions to get a direction, and multiply by the desired range
    const Vec3 searchDirection = (cameraCenterFar - cameraCenterNear).GetNormalized() * searchRange;

    // The result of RayWorldIntersection will be stored in this array
    // For the sake of this example we will limit to only one hit
    std::array hits;

    // Specify query flags, in this case we will allow any type of entity
    const uint32 queryFlags = ent_all;
    // Specify ray flags, see rwi_flags.
    // Values of 0 - 15 will indicate which surface types the ray will be able to pass through, this depends on the pierceability set in each project's surface types definition.
    // A < check is used, thus lower values are more "durable". For example, pierceability set to 10, and an encountered surface type with pierceability 11 results in the ray passing through. Otherwise, the ray stops at that surface type.
    // A pierceability of 15, or rwi_stop_at_pierceable will mean that the ray does not pierce any surface types.
    // Note that the first ray_hit result is *always* a solid object, thus hits can be reported while the first hit is invalid - this indicates that hits[1] and above were pierced through.
    const uint32 rayFlags = rwi_stop_at_pierceable;

    // Perform the ray intersection, note that this happens on the main thread and can thus be a slow operation
    const int numHits = gEnv->pPhysicalWorld->RayWorldIntersection(cameraCenterNear, searchDirection, queryFlags, rayFlags, hits.data(), hits.max_size());
    if (numHits > 0)
    {
        if (IEntity* pHitEntity = gEnv->pEntitySystem->GetEntityFromPhysics(hits[0].pCollider))
        {
            /* An entity was hit, and we can now use the pHitEntity pointer */
        }
    }
}

◆ RayWorldIntersection() [2/3]

int IPhysicalWorld::RayWorldIntersection ( const Vec3 & org,
const Vec3 & dir,
int objtypes,
unsigned int flags,
ray_hit * hits,
int nMaxHits,
IPhysicalEntity ** pSkipEnts = 0,
int nSkipEnts = 0,
void * pForeignData = 0,
int iForeignData = 0,
const char * pNameTag = RWI_NAME_TAG,
ray_hit_cached * phitLast = 0,
int iCaller = MAX_PHYS_THREADS
)
inline

Performs a raycast through the physical world, returning possible hits into the provided hits structure

#include 
#include 

// Example of how we can cast a ray through the physical world and receive hit information
void RayWorldIntersection()
{
    // Store the half render size, used to calculate a direction that points outwards from the camera
    const float halfRenderWidth = static_cast(gEnv->pRenderer->GetWidth()) * 0.5f;
    const float halfRenderHeight = static_cast(gEnv->pRenderer->GetHeight()) * 0.5f;
    
    // For the sake of this example we will cast the ray 50 meters outwards from the camera
    const float searchRange = 50.f;

    // Calculate the centered position of the near and far planes
    Vec3 cameraCenterNear, cameraCenterFar;
    gEnv->pRenderer->UnProjectFromScreen(halfRenderWidth, halfRenderHeight, 0, &cameraCenterNear.x, &cameraCenterNear.y, &cameraCenterNear.z);
    gEnv->pRenderer->UnProjectFromScreen(halfRenderWidth, halfRenderHeight, 1, &cameraCenterFar.x, &cameraCenterFar.y, &cameraCenterFar.z);

    // Now subtract the far and near positions to get a direction, and multiply by the desired range
    const Vec3 searchDirection = (cameraCenterFar - cameraCenterNear).GetNormalized() * searchRange;

    // The result of RayWorldIntersection will be stored in this array
    // For the sake of this example we will limit to only one hit
    std::array hits;

    // Specify query flags, in this case we will allow any type of entity
    const uint32 queryFlags = ent_all;
    // Specify ray flags, see rwi_flags.
    // Values of 0 - 15 will indicate which surface types the ray will be able to pass through, this depends on the pierceability set in each project's surface types definition.
    // A < check is used, thus lower values are more "durable". For example, pierceability set to 10, and an encountered surface type with pierceability 11 results in the ray passing through. Otherwise, the ray stops at that surface type.
    // A pierceability of 15, or rwi_stop_at_pierceable will mean that the ray does not pierce any surface types.
    // Note that the first ray_hit result is *always* a solid object, thus hits can be reported while the first hit is invalid - this indicates that hits[1] and above were pierced through.
    const uint32 rayFlags = rwi_stop_at_pierceable;

    // Perform the ray intersection, note that this happens on the main thread and can thus be a slow operation
    const int numHits = gEnv->pPhysicalWorld->RayWorldIntersection(cameraCenterNear, searchDirection, queryFlags, rayFlags, hits.data(), hits.max_size());
    if (numHits > 0)
    {
        if (IEntity* pHitEntity = gEnv->pEntitySystem->GetEntityFromPhysics(hits[0].pCollider))
        {
            /* An entity was hit, and we can now use the pHitEntity pointer */
        }
    }
}

◆ RayWorldIntersection() [3/3]

int IPhysicalWorld::RayWorldIntersection ( const Vec3 & org,
const Vec3 & dir,
int objtypes,
unsigned int flags,
ray_hit * hits,
int nMaxHits,
IPhysicalEntity * pSkipEnt,
IPhysicalEntity * pSkipEntAux = 0,
void * pForeignData = 0,
int iForeignData = 0
)
inline

Performs a raycast through the physical world, returning possible hits into the provided hits structure

#include 
#include 

// Example of how we can cast a ray through the physical world and receive hit information
void RayWorldIntersection()
{
    // Store the half render size, used to calculate a direction that points outwards from the camera
    const float halfRenderWidth = static_cast(gEnv->pRenderer->GetWidth()) * 0.5f;
    const float halfRenderHeight = static_cast(gEnv->pRenderer->GetHeight()) * 0.5f;
    
    // For the sake of this example we will cast the ray 50 meters outwards from the camera
    const float searchRange = 50.f;

    // Calculate the centered position of the near and far planes
    Vec3 cameraCenterNear, cameraCenterFar;
    gEnv->pRenderer->UnProjectFromScreen(halfRenderWidth, halfRenderHeight, 0, &cameraCenterNear.x, &cameraCenterNear.y, &cameraCenterNear.z);
    gEnv->pRenderer->UnProjectFromScreen(halfRenderWidth, halfRenderHeight, 1, &cameraCenterFar.x, &cameraCenterFar.y, &cameraCenterFar.z);

    // Now subtract the far and near positions to get a direction, and multiply by the desired range
    const Vec3 searchDirection = (cameraCenterFar - cameraCenterNear).GetNormalized() * searchRange;

    // The result of RayWorldIntersection will be stored in this array
    // For the sake of this example we will limit to only one hit
    std::array hits;

    // Specify query flags, in this case we will allow any type of entity
    const uint32 queryFlags = ent_all;
    // Specify ray flags, see rwi_flags.
    // Values of 0 - 15 will indicate which surface types the ray will be able to pass through, this depends on the pierceability set in each project's surface types definition.
    // A < check is used, thus lower values are more "durable". For example, pierceability set to 10, and an encountered surface type with pierceability 11 results in the ray passing through. Otherwise, the ray stops at that surface type.
    // A pierceability of 15, or rwi_stop_at_pierceable will mean that the ray does not pierce any surface types.
    // Note that the first ray_hit result is *always* a solid object, thus hits can be reported while the first hit is invalid - this indicates that hits[1] and above were pierced through.
    const uint32 rayFlags = rwi_stop_at_pierceable;

    // Perform the ray intersection, note that this happens on the main thread and can thus be a slow operation
    const int numHits = gEnv->pPhysicalWorld->RayWorldIntersection(cameraCenterNear, searchDirection, queryFlags, rayFlags, hits.data(), hits.max_size());
    if (numHits > 0)
    {
        if (IEntity* pHitEntity = gEnv->pEntitySystem->GetEntityFromPhysics(hits[0].pCollider))
        {
            /* An entity was hit, and we can now use the pHitEntity pointer */
        }
    }
}

◆ ResetDynamicEntities()

virtual void IPhysicalWorld::ResetDynamicEntities ( )
pure virtual

Freezes (resets velocities of) all physical, living, and detached entities

◆ SetSurfaceParameters()

virtual int IPhysicalWorld::SetSurfaceParameters ( int surface_idx,
float bounciness,
float friction,
unsigned int flags = 0
)
pure virtual

SetSurfaceParameters: sets parameters for surface_idx (0..511 currently) bounciness - restitution coefficient (for pair of surfaces k = sum of their coefficients, clamped to [0..1] friction - friction coefficient (for pair of surfaces k = sum of their coefficients, clamped to [0..inf) flags - see surface_flags enum

◆ SetupEntityGrid()

virtual IPhysicalEntity* IPhysicalWorld::SetupEntityGrid ( int axisz,
Vec3 org,
int nx,
int ny,
float stepx,
float stepy,
int log2PODscale = 0,
int bCyclic = 0,
IPhysicalEntity * pHost = nullptr,
const QuatT & posInHost = QuatT(IDENTITY)
)
pure virtual

SetupEntityGrid: initializes entity hash grid for broad-phase collision detection and raytracing entity grid partitions the space along x and axes; grid's axisz can be aligned with any world axis (0-x,1-y,2- log2PODscale sets how many grid cells comprise one on-demand physicalization sector (on_demand_sector = 1<

◆ SimulateExplosion()

virtual void IPhysicalWorld::SimulateExplosion ( pe_explosion * pexpl,
IPhysicalEntity ** pSkipEnts = 0,
int nSkipEnts = 0,
int iTypes = ent_rigid|ent_sleeping_rigid|ent_living|ent_independent,
int iCaller = MAX_PHYS_THREADS
)
pure virtual

Simulates an explosion in the world, affecting entities near the epicenter (and within the specified radius)

#include 

// Example of how an explosion can be simulated in the world, affecting entities near the epicenter
void SimulateExplosion()
{
    // The position at which the explosion epicenter is, in world coordinates
    const Vec3 explosionPosition = ZERO;
    // Radius from the epicenter that the explosion will affect
    const float explosionRadius = 10.f;

    // Populate the pe_explosion structure
    pe_explosion explosion;
    // Set the epicenter and epicenter impulse (identical for the sake of this example)
    explosion.epicenter = explosion.epicenterImp = explosionPosition;
    // Set the radius, we keep it uniform for the sake of this example - but can be made to scale downwards further into the radius
    explosion.rmin = explosion.rmax = explosion.r = explosionRadius;

    // Simulate the explosion
    gEnv->pPhysicalWorld->SimulateExplosion(&explosion);
}

◆ TimeStep()

virtual void IPhysicalWorld::TimeStep ( float time_interval,
int flags = ent_all|ent_deleted
)
pure virtual

TimeStep - the main world's function flags - entity types to update (ent_..; ent_deleted to purge deletion physics-on-demand state monitoring)

◆ TracePendingRays()

virtual int IPhysicalWorld::TracePendingRays ( int bDoActualTracing = 1)
pure virtual

Traces ray requests (rwi calls with rwi_queue set); logs and calls EventPhysRWIResult for each returns the number of rays traced

◆ UpdateDeformingEntities()

virtual void IPhysicalWorld::UpdateDeformingEntities ( float time_interval = 0.01f)
pure virtual

UpdateDeformingEntities - normally this happens automatically during TimeStep; can be called manually for ex. during loading.

normally this happens during TimeStep