KS.Reactor.ksBasePhysics Class Referenceabstract

Base physics class available on client and server. More...

Inheritance diagram for KS.Reactor.ksBasePhysics:
KS.Reactor.Client.Unity.ksPhysicsAdaptor KS.Reactor.Server.ksBaseServerPhysics

Public Member Functions

delegate bool DepenetrateCallback (ksICollider collider, ref ksVector3 direction, ref float distance)
 Depenetration callback for Depenetrate(ksOverlapParams, out ksVector3, DepenetrateCallback, float) More...
 
virtual void SyncAll ()
 Apply all transform and rigidbody changes to the physics simulation now rather than waiting for the next simulation step. More...
 
virtual void SyncTransforms ()
 Apply entity transform updates to the physics simulation now rather than waiting for the next simulation step. More...
 
abstract bool RaycastAny (ksRaycastParams args)
 Raycast query that checks if anything was hit. More...
 
abstract bool RaycastNearest (ksRaycastParams args, out ksRaycastResult hit)
 Raycast query that finds the nearest hit. More...
 
abstract ksQueryHitResults< ksRaycastResultRaycast (ksRaycastParams args)
 Raycast query that returns the nearest blocking hit and any touching hits before the blocking hit. More...
 
abstract bool SweepAny (ksSweepParams args)
 Sweep query that checks if anything was hit. More...
 
abstract bool SweepNearest (ksSweepParams args, out ksSweepResult hit)
 Sweep query that finds the nearest hit. More...
 
abstract ksQueryHitResults< ksSweepResultSweep (ksSweepParams arg)
 Sweep query that returns the nearest blocking hit and any touching hits before the blocking hit. More...
 
abstract bool OverlapAny (ksOverlapParams args)
 Overlap query that checks for any overlap. More...
 
abstract List< ksOverlapResultOverlap (ksOverlapParams args)
 Overlap query. More...
 
List< ksRaycastResultRaycast (ksVector3 origin, ksVector3 direction, float distance, bool includeOverlaps=false, ksQueryFlags flags=ksQueryFlags.DEFAULT, uint groupMask=0xffffffff, uint maxResults=255)
 Raycast. More...
 
List< ksSweepResultSweep (ksShape shape, ksVector3 origin, ksQuaternion rotation, ksVector3 direction, float distance, bool includeOverlaps=false, ksQueryFlags flags=ksQueryFlags.DEFAULT, uint groupMask=0xffffffff, uint maxResults=255)
 Shape sweep. More...
 
List< ksSweepResultSweep (ksIEntity entity, ksVector3 direction, float distance, bool includeOverlaps=false, ksQueryFlags flags=ksQueryFlags.DEFAULT, uint groupMask=0xffffffff, uint maxResults=255)
 Entity sweep using the current position and rotation as starting points. More...
 
List< ksSweepResultSweep (ksIEntity entity, ksVector3 origin, ksQuaternion rotation, ksVector3 direction, float distance, bool excludeSelf=true, bool includeOverlaps=false, ksQueryFlags flags=ksQueryFlags.DEFAULT, uint groupMask=0xffffffff, uint maxResults=255)
 Entity sweep. More...
 
List< ksOverlapResultOverlap (ksShape shape, ksVector3 origin, ksQuaternion rotation, ksQueryFlags flags=ksQueryFlags.DEFAULT, uint groupMask=0xffffffff, uint maxResults=255)
 Shape overlap. More...
 
List< ksOverlapResultOverlap (ksIEntity entity, ksVector3 origin, ksQuaternion rotation, bool excludeSelf=true, ksQueryFlags flags=ksQueryFlags.DEFAULT, uint groupMask=0xffffffff, uint maxResults=255)
 Entity overlap. More...
 
abstract bool ComputePenetration (ksICollider collider0, ksVector3 position0, ksQuaternion rotation0, ksICollider collider1, ksVector3 position1, ksQuaternion rotation1, out ksVector3 direction, out float distance)
 Compute the minimal translation required to separate the given colliders apart at specified poses. More...
 
abstract ksVector3 GetClosestPoint (ksVector3 point, ksICollider collider)
 Get the closest point on a collider to another point. More...
 
abstract ksVector3 GetClosestPoint (ksVector3 point, ksICollider collider, ksVector3 position, ksQuaternion rotation)
 Get the closest point on a collider to another point. More...
 
ksSweepSlideParams CreateSimulationQueryParams (ksIEntity entity, bool excludeTouches=true)
 Creates ksSweepSlideParams for an entity configured to use simulation rules. More...
 
bool Depenetrate (ksOverlapParams args, out ksVector3 delta, DepenetrateCallback callback=null, float separationOffset=.0001f)
 Does an overlap query and calcuates a depenetration delta to attempt to depenetrate from overlapping geometry. More...
 
bool SweepAndSlide (ksSweepSlideParams args, out ksVector3 position)
 Does sweep-and-slide movement. More...
 

Protected Attributes

ksVector3 m_gravity
 

Properties

bool AutoSync [get, set]
 If true, transform changes are synced with the physics system and stale inertia tensors and centers of mass are recalculated automatically before any physics queries. More...
 
ksVector3 Gravity [get]
 Gets the current gravity in the scene. More...
 

Detailed Description

Base physics class available on client and server.

Member Function Documentation

◆ ComputePenetration()

abstract bool KS.Reactor.ksBasePhysics.ComputePenetration ( ksICollider  collider0,
ksVector3  position0,
ksQuaternion  rotation0,
ksICollider  collider1,
ksVector3  position1,
ksQuaternion  rotation1,
out ksVector3  direction,
out float  distance 
)
pure virtual

Compute the minimal translation required to separate the given colliders apart at specified poses.

Parameters
collider0First collider to test.
position0Position of collider 0.
rotation0Rotation of collider 0.
collider1Secoond collider to test.
position1Position of collider 1.
rotation1Rotation of collider 1.
directionDirection along which the translation required to separate collider0 from collider1 is minimal.
distanceThe distance along the direction that is required to separate collider0 from collider1 .
Returns
True if the colliders were overlapping.

Implemented in KS.Reactor.Client.Unity.ksPhysicsAdaptor.

◆ CreateSimulationQueryParams()

ksSweepSlideParams KS.Reactor.ksBasePhysics.CreateSimulationQueryParams ( ksIEntity  entity,
bool  excludeTouches = true 
)

Creates ksSweepSlideParams for an entity configured to use simulation rules.

Anything the entity would collide with are blocking hits and optionally anything it would receive overlap events with are touching hits. This sets the ksBaseQueryParams.Filter and ksOverlapParams.EntityColliderFilter to a ksSimulationFilter, and sets the ksBaseQueryParams.ExcludeEntity to the entity .

Parameters
entityQuery entity
excludeTouchesIf true, sets the ksQueryFlags.EXCLUDE_TOUCHES flag.
Returns
Overlap params using simulation rules.

◆ Depenetrate()

bool KS.Reactor.ksBasePhysics.Depenetrate ( ksOverlapParams  args,
out ksVector3  delta,
DepenetrateCallback  callback = null,
float  separationOffset = .0001f 
)

Does an overlap query and calcuates a depenetration delta to attempt to depenetrate from overlapping geometry.

If the overlap query returns multiple results the depenetration vector from the previous overlap will be added to the position when computing the depenetration vector for the next overlap. This may result in pushing the object back into the first overlapping geometry. Geometry that the object gets pushed into by the depenetration vector that was not initially overlapping will not be considered.

Parameters
argsOverlap query parameters. The query object cannot be a shape.
deltaDepenetration delta
callbackCallback to call for each overlapping collider. Can be used to alter the depenetration vector for each collider, or to cancel the entire depenetration by returning false.
separationOffsetAmount to add to the depenetration distance for each overlapping collider. Helps prevent penetrations when sweeping.
Returns
True if there was a penetration.

◆ DepenetrateCallback()

delegate bool KS.Reactor.ksBasePhysics.DepenetrateCallback ( ksICollider  collider,
ref ksVector3  direction,
ref float  distance 
)

Depenetration callback for Depenetrate(ksOverlapParams, out ksVector3, DepenetrateCallback, float)

Parameters
colliderCollider being penetrated.
directionMinimum depenetration movement direction. Can be changed to alter movement direction.
distanceMinimum depenetration movement distance. Can be changed to alter the movement distance. Set to zero to ignore the penetration.
Returns
False to cancel all depenetrations.

◆ GetClosestPoint() [1/2]

abstract ksVector3 KS.Reactor.ksBasePhysics.GetClosestPoint ( ksVector3  point,
ksICollider  collider 
)
pure virtual

Get the closest point on a collider to another point.

Currently supported colliders: box, sphere, capsule, convexmesh.

Parameters
pointPoint to measure from.
colliderCollider to get the closest point from.
Returns
Closest point on the collider.

Implemented in KS.Reactor.Client.Unity.ksPhysicsAdaptor.

◆ GetClosestPoint() [2/2]

abstract ksVector3 KS.Reactor.ksBasePhysics.GetClosestPoint ( ksVector3  point,
ksICollider  collider,
ksVector3  position,
ksQuaternion  rotation 
)
pure virtual

Get the closest point on a collider to another point.

Currently supported colliders: box, sphere, capsule, convexmesh.

Parameters
pointPoint to measure from.
colliderCollider to get the closest point from.
positionCollider position
rotationCollider rotation
Returns
Closest point on the collider.

Implemented in KS.Reactor.Client.Unity.ksPhysicsAdaptor.

◆ Overlap() [1/3]

List<ksOverlapResult> KS.Reactor.ksBasePhysics.Overlap ( ksIEntity  entity,
ksVector3  origin,
ksQuaternion  rotation,
bool  excludeSelf = true,
ksQueryFlags  flags = ksQueryFlags.DEFAULT,
uint  groupMask = 0xffffffff,
uint  maxResults = 255 
)

Entity overlap.

Parameters
entityEntity.
originEntity point.
rotationEntity orientation.
excludeSelfExclude this entity in the returned results.
flagsBit flags for filtering static, dynamic, and first hit.
groupMaskBit mask of collsion groups.
maxResultsUnused
Returns
List of overlap results.

◆ Overlap() [2/3]

abstract List<ksOverlapResult> KS.Reactor.ksBasePhysics.Overlap ( ksOverlapParams  args)
pure virtual

Overlap query.

Parameters
argsOverlap parameters
Returns
List of overlap results.

Implemented in KS.Reactor.Client.Unity.ksPhysicsAdaptor.

◆ Overlap() [3/3]

List<ksOverlapResult> KS.Reactor.ksBasePhysics.Overlap ( ksShape  shape,
ksVector3  origin,
ksQuaternion  rotation,
ksQueryFlags  flags = ksQueryFlags.DEFAULT,
uint  groupMask = 0xffffffff,
uint  maxResults = 255 
)

Shape overlap.

Parameters
shapePrimitive or convex shape.
originOrigin point.
rotationShape orientation.
flagsBit flags for filtering static, dynamic, and first hit.
groupMaskBit mask of collsion groups.
maxResultsUnused
Returns
List of overlap results.

◆ OverlapAny()

abstract bool KS.Reactor.ksBasePhysics.OverlapAny ( ksOverlapParams  args)
pure virtual

Overlap query that checks for any overlap.

Parameters
argsOverlap parameters
Returns
True if anything was overlapping.

Implemented in KS.Reactor.Client.Unity.ksPhysicsAdaptor.

◆ Raycast() [1/2]

abstract ksQueryHitResults<ksRaycastResult> KS.Reactor.ksBasePhysics.Raycast ( ksRaycastParams  args)
pure virtual

Raycast query that returns the nearest blocking hit and any touching hits before the blocking hit.

Parameters
argsRaycast parameters
Returns
Raycast results

Implemented in KS.Reactor.Client.Unity.ksPhysicsAdaptor.

◆ Raycast() [2/2]

List<ksRaycastResult> KS.Reactor.ksBasePhysics.Raycast ( ksVector3  origin,
ksVector3  direction,
float  distance,
bool  includeOverlaps = false,
ksQueryFlags  flags = ksQueryFlags.DEFAULT,
uint  groupMask = 0xffffffff,
uint  maxResults = 255 
)

Raycast.

Parameters
originOrigin point.
directionDirection vector.
distanceRay distance.
groupMaskBit mask of collsion groups.
includeOverlapsInclude entities that overlap the origin.
flagsBit flags for filtering static, dynamic, and first hit.
maxResultsUnused
Returns

◆ RaycastAny()

abstract bool KS.Reactor.ksBasePhysics.RaycastAny ( ksRaycastParams  args)
pure virtual

Raycast query that checks if anything was hit.

Parameters
argsRaycast parameters
Returns
True if the raycast hit anything.

Implemented in KS.Reactor.Client.Unity.ksPhysicsAdaptor.

◆ RaycastNearest()

abstract bool KS.Reactor.ksBasePhysics.RaycastNearest ( ksRaycastParams  args,
out ksRaycastResult  hit 
)
pure virtual

Raycast query that finds the nearest hit.

Parameters
argsRaycast parameters
hitSet to the nearest hit.
Returns
True if the raycast hit anything.

Implemented in KS.Reactor.Client.Unity.ksPhysicsAdaptor.

◆ Sweep() [1/4]

List<ksSweepResult> KS.Reactor.ksBasePhysics.Sweep ( ksIEntity  entity,
ksVector3  direction,
float  distance,
bool  includeOverlaps = false,
ksQueryFlags  flags = ksQueryFlags.DEFAULT,
uint  groupMask = 0xffffffff,
uint  maxResults = 255 
)

Entity sweep using the current position and rotation as starting points.

Parameters
entityEntity.
directionDirection vector.
distanceRay distance.
includeOverlapsInclude entities that overlap at the origin.
flagsBit flags for filtering static, dynamic, and first hit.
groupMaskBit mask of collsion groups.
maxResultsUnused
Returns

◆ Sweep() [2/4]

List<ksSweepResult> KS.Reactor.ksBasePhysics.Sweep ( ksIEntity  entity,
ksVector3  origin,
ksQuaternion  rotation,
ksVector3  direction,
float  distance,
bool  excludeSelf = true,
bool  includeOverlaps = false,
ksQueryFlags  flags = ksQueryFlags.DEFAULT,
uint  groupMask = 0xffffffff,
uint  maxResults = 255 
)

Entity sweep.

Parameters
entityEntity.
originOrigin point.
rotationEntity orientation.
directionDirection vector.
distanceSweep distance.
excludeSelfExclude this entity in the returned results.
includeOverlapsInclude entities that overlap at the origin.
flagsBit flags for filtering static, dynamic, and first hit.
groupMaskBit mask of collsion groups.
maxResultsUnused
Returns
List of sweep results.

◆ Sweep() [3/4]

List<ksSweepResult> KS.Reactor.ksBasePhysics.Sweep ( ksShape  shape,
ksVector3  origin,
ksQuaternion  rotation,
ksVector3  direction,
float  distance,
bool  includeOverlaps = false,
ksQueryFlags  flags = ksQueryFlags.DEFAULT,
uint  groupMask = 0xffffffff,
uint  maxResults = 255 
)

Shape sweep.

Parameters
shapePrimitive or convex shape.
originOrigin point.
rotationShape orientation.
directionDirection vector.
distanceSweep distance.
includeOverlapsInclude entities that overlap at the origin.
flagsBit flags for filtering static, dynamic, and first hit.
groupMaskBit mask of collsion groups.
maxResultsUnused
Returns
List of sweep results.

◆ Sweep() [4/4]

abstract ksQueryHitResults<ksSweepResult> KS.Reactor.ksBasePhysics.Sweep ( ksSweepParams  arg)
pure virtual

Sweep query that returns the nearest blocking hit and any touching hits before the blocking hit.

Parameters
argsSweep parameters
Returns
Sweep results

Implemented in KS.Reactor.Client.Unity.ksPhysicsAdaptor.

◆ SweepAndSlide()

bool KS.Reactor.ksBasePhysics.SweepAndSlide ( ksSweepSlideParams  args,
out ksVector3  position 
)

Does sweep-and-slide movement.

When a sweep hits something, the remaining movement vector is projected onto the plane perpendicuar to the surface normal to get a new movement vector which is used to sweep recursively.

Parameters
argsSweep parameters
positionPosition at the end of the sweep-and-slide movement.
Returns
True if the sweep and slide hit anything.

◆ SweepAny()

abstract bool KS.Reactor.ksBasePhysics.SweepAny ( ksSweepParams  args)
pure virtual

Sweep query that checks if anything was hit.

Parameters
argsSweep arguments
Returns
True if the sweep hit anything.

Implemented in KS.Reactor.Client.Unity.ksPhysicsAdaptor.

◆ SweepNearest()

abstract bool KS.Reactor.ksBasePhysics.SweepNearest ( ksSweepParams  args,
out ksSweepResult  hit 
)
pure virtual

Sweep query that finds the nearest hit.

Parameters
argsSweep arguments
hitSet to the nearest hit.
Returns
True if the sweep hit anything.

Implemented in KS.Reactor.Client.Unity.ksPhysicsAdaptor.

◆ SyncAll()

virtual void KS.Reactor.ksBasePhysics.SyncAll ( )
virtual

Apply all transform and rigidbody changes to the physics simulation now rather than waiting for the next simulation step.

Reimplemented in KS.Reactor.Client.Unity.ksPhysicsAdaptor.

◆ SyncTransforms()

virtual void KS.Reactor.ksBasePhysics.SyncTransforms ( )
virtual

Apply entity transform updates to the physics simulation now rather than waiting for the next simulation step.

Reimplemented in KS.Reactor.Client.Unity.ksPhysicsAdaptor.

Property Documentation

◆ AutoSync

bool KS.Reactor.ksBasePhysics.AutoSync
getset

If true, transform changes are synced with the physics system and stale inertia tensors and centers of mass are recalculated automatically before any physics queries.

If this is false, changes are only synced during the simulation step, and you are responsible for calling Sync if you want to sync changes sooner.

◆ Gravity

ksVector3 KS.Reactor.ksBasePhysics.Gravity
get

Gets the current gravity in the scene.