C# Class Nez.Physics

Show file Open project: prime31/Nez

Public Properties

Property Type Description
gravity Microsoft.Xna.Framework.Vector2
raycastsHitTriggers bool
raycastsStartInColliders bool
spatialHashCellSize int

Public Methods

Method Description
addCollider ( Collider collider ) : void

adds the collider to the physics system

boxcastBroadphase ( RectangleF rect, int layerMask = allLayers ) : IEnumerable

returns all colliders with bounds that are intersected by collider.bounds. Note that this is a broadphase check so it only checks bounds and does not do individual Collider-to-Collider checks!

boxcastBroadphaseExcludingSelf ( Collider collider, RectangleF &rect, int layerMask = allLayers ) : IEnumerable

returns all colliders that are intersected by bounds excluding the passed-in collider (self). this method is useful if you want to create the swept bounds on your own for other queries

boxcastBroadphaseExcludingSelf ( Collider collider, float deltaX, float deltaY, int layerMask = allLayers ) : IEnumerable

returns all colliders that are intersected by collider.bounds expanded to incorporate deltaX/deltaY excluding the passed-in collider (self)

boxcastBroadphaseExcludingSelf ( Collider collider, int layerMask = allLayers ) : IEnumerable

returns all colliders with bounds that are intersected by collider.bounds excluding the passed-in collider (self)

clear ( ) : void

removes all colliders from the SpatialHash

getAllColliders ( ) : IEnumerable

gets all the Colliders managed by the SpatialHash

linecast ( Vector2 start, Vector2 end, int layerMask = allLayers ) : RaycastHit

casts a line from start to end and returns the first hit of a collider that matches layerMask

linecastAll ( Vector2 start, Vector2 end, RaycastHit hits, int layerMask = allLayers ) : int

casts a line through the spatial hash and fills the hits array up with any colliders that the line hits

overlapCircle ( Vector2 center, float radius, int layerMask = allLayers ) : Collider

check if any collider falls within a circular area. Returns the first Collider encountered.

overlapCircleAll ( Vector2 center, float radius, Collider results, int layerMask = allLayers ) : int

gets all the colliders that fall within the specified circle

overlapRectangle ( RectangleF rect, int layerMask = allLayers ) : Collider

check if any collider falls within a rectangular area

overlapRectangleAll ( RectangleF &rect, Collider results, int layerMask = allLayers ) : int

gets all the colliders that fall within the specified rect

removeCollider ( Collider collider ) : void

removes the collider from the physics system

reset ( ) : void
updateCollider ( Collider collider ) : void

updates the colliders position in the physics system. This essentially just removes then re-adds the Collider with its new bounds

Private Methods

Method Description
debugDraw ( float secondsToDisplay ) : void

debug draws the contents of the spatial hash. Note that Core.debugRenderEnabled must be true or nothing will be displayed.

Method Details

addCollider() public static method

adds the collider to the physics system
public static addCollider ( Collider collider ) : void
collider Collider Collider.
return void

boxcastBroadphase() public static method

returns all colliders with bounds that are intersected by collider.bounds. Note that this is a broadphase check so it only checks bounds and does not do individual Collider-to-Collider checks!
public static boxcastBroadphase ( RectangleF rect, int layerMask = allLayers ) : IEnumerable
rect RectangleF
layerMask int Layer mask.
return IEnumerable

boxcastBroadphaseExcludingSelf() public static method

returns all colliders that are intersected by bounds excluding the passed-in collider (self). this method is useful if you want to create the swept bounds on your own for other queries
public static boxcastBroadphaseExcludingSelf ( Collider collider, RectangleF &rect, int layerMask = allLayers ) : IEnumerable
collider Collider Collider.
rect RectangleF
layerMask int
return IEnumerable

boxcastBroadphaseExcludingSelf() public static method

returns all colliders that are intersected by collider.bounds expanded to incorporate deltaX/deltaY excluding the passed-in collider (self)
public static boxcastBroadphaseExcludingSelf ( Collider collider, float deltaX, float deltaY, int layerMask = allLayers ) : IEnumerable
collider Collider Collider.
deltaX float
deltaY float
layerMask int
return IEnumerable

boxcastBroadphaseExcludingSelf() public static method

returns all colliders with bounds that are intersected by collider.bounds excluding the passed-in collider (self)
public static boxcastBroadphaseExcludingSelf ( Collider collider, int layerMask = allLayers ) : IEnumerable
collider Collider Collider.
layerMask int
return IEnumerable

clear() public static method

removes all colliders from the SpatialHash
public static clear ( ) : void
return void

getAllColliders() public static method

gets all the Colliders managed by the SpatialHash
public static getAllColliders ( ) : IEnumerable
return IEnumerable

linecast() public static method

casts a line from start to end and returns the first hit of a collider that matches layerMask
public static linecast ( Vector2 start, Vector2 end, int layerMask = allLayers ) : RaycastHit
start Microsoft.Xna.Framework.Vector2 Start.
end Microsoft.Xna.Framework.Vector2 End.
layerMask int Layer mask.
return RaycastHit

linecastAll() public static method

casts a line through the spatial hash and fills the hits array up with any colliders that the line hits
public static linecastAll ( Vector2 start, Vector2 end, RaycastHit hits, int layerMask = allLayers ) : int
start Microsoft.Xna.Framework.Vector2 Start.
end Microsoft.Xna.Framework.Vector2 End.
hits RaycastHit Hits.
layerMask int Layer mask.
return int

overlapCircle() public static method

check if any collider falls within a circular area. Returns the first Collider encountered.
public static overlapCircle ( Vector2 center, float radius, int layerMask = allLayers ) : Collider
center Microsoft.Xna.Framework.Vector2 Center.
radius float Radius.
layerMask int Layer mask.
return Collider

overlapCircleAll() public static method

gets all the colliders that fall within the specified circle
public static overlapCircleAll ( Vector2 center, float radius, Collider results, int layerMask = allLayers ) : int
center Microsoft.Xna.Framework.Vector2 Center.
radius float Radius.
results Collider Results.
layerMask int Layer mask.
return int

overlapRectangle() public static method

check if any collider falls within a rectangular area
public static overlapRectangle ( RectangleF rect, int layerMask = allLayers ) : Collider
rect RectangleF Rect.
layerMask int Layer mask.
return Collider

overlapRectangleAll() public static method

gets all the colliders that fall within the specified rect
public static overlapRectangleAll ( RectangleF &rect, Collider results, int layerMask = allLayers ) : int
rect RectangleF Rect.
results Collider Results.
layerMask int Layer mask.
return int

removeCollider() public static method

removes the collider from the physics system
public static removeCollider ( Collider collider ) : void
collider Collider Collider.
return void

reset() public static method

public static reset ( ) : void
return void

updateCollider() public static method

updates the colliders position in the physics system. This essentially just removes then re-adds the Collider with its new bounds
public static updateCollider ( Collider collider ) : void
collider Collider Collider.
return void

Property Details

gravity public static property

convenience field for storing a gravity value globally
public static Vector2,Microsoft.Xna.Framework gravity
return Microsoft.Xna.Framework.Vector2

raycastsHitTriggers public static property

Do raycasts detect Colliders configured as triggers?
public static bool raycastsHitTriggers
return bool

raycastsStartInColliders public static property

Do ray/line casts that start inside a collider detect those colliders?
public static bool raycastsStartInColliders
return bool

spatialHashCellSize public static property

cell size used when reset is called and a new SpatialHash is created
public static int spatialHashCellSize
return int