PhysicsScene Class Reference

Physics2D simulation base scene. More...

List of all members.

Public Types

enum  BroadOpType { Or, And }
 

Switch the combination of collisionFilter and groupFilter.

More...
enum  SleepAlgorithmType { BroadphaseBase, NarrowphaseBase }
 

Switch the algorithm of checking sleep status.

More...

Public Member Functions

bool RaycastHit (ref RayHit ray)
 Raycast check.
bool RaycastHit (ref RayHit ray, uint collisionFilter, uint groupFilter)
 Raycast check.
 PhysicsScene ()
 Default Constructor.
void Simulate ()
 Simulate.
void Simulate (int click_index, Vector2 click_pos, Vector2 diff_pos)
 Simulate.
PhysicsShape AddSphereShape (float radius)
 Add sphere shape to the scene.
PhysicsShape AddBoxShape (Vector2 width)
 Add box shape to the scene.
PhysicsShape AddConvexShape (Vector2[] pos, int num)
 Add convex shape to the scene.
PhysicsShape AddConvexHullShape (Vector2[] pos, int num)
 Add convex hull shape comoposed of random points to the scene.
PhysicsShape AddLineChainShape (Vector2[] pos, int num)
 Add chain of line segments to the scene.
PhysicsBody AddBody (int shapeIndex, float mass)
 Add Rigid Body.
PhysicsBody AddBody (PhysicsShape shape, float mass)
 Add Rigid Body.
Vector2 MergeCompound (PhysicsBody[] bodyList, int num, bool flag=true)
 Merge of rigid body.
PhysicsJoint AddJoint (int bodyIndex1, int bodyIndex2, Vector2 anchorPos)
 Add joint.
PhysicsJoint AddJoint (PhysicsBody body1, PhysicsBody body2, Vector2 anchorPos)
 Add joint.
PhysicsSpring AddSpring (int bodyIndex1, int bodyIndex2, Vector2 anchorPos1, Vector2 anchorPos2)
 Add joint.
PhysicsSpring AddSpring (PhysicsBody body1, PhysicsBody body2, Vector2 anchorPos1, Vector2 anchorPos2)
 Add spring.
int DeleteJoint (int index)
 DeleteJoint.
int DeleteJoint (PhysicsJoint joint)
 DeleteJoint.
int DeleteSpring (int index)
 DeleteSpring.
int DeleteSpring (PhysicsSpring spring)
 DeleteSpring.
int DeleteBody (int index)
 DeleteBody.
int DeleteBody (PhysicsBody body)
 DeleteBody.
bool QueryContact (uint index1, uint index2)
 Check whether there is a collision between index1 and index2.
bool QueryContact (PhysicsBody body1, PhysicsBody body2)
 Check whether there is a collision between index1 and index2.
int QueryContactTrigger (uint index, uint[] indexlist)
 Check whether there is a collision between trigger rigid body and others.
int GetShapeIndex (PhysicsShape shape)
 Get index of collision shape.
int GetBodyIndex (PhysicsBody body)
 Get index of rigid body.
int GetJointIndex (PhysicsJoint joint)
 Get index of joint.
int GetSpringIndex (PhysicsSpring spring)
 Get index of spring.
PhysicsShape GetShape (int index)
 Get collilsion shape.
PhysicsBody GetBody (int index)
 Get rigid body.
PhysicsJoint GetJoint (int index)
 Get joint.
PhysicsSpring GetSpring (int index)
 Get spring.
void AddIgnorePair (uint index1, uint index2)
 Add the pair to ignore list.
void AddIgnorePair (PhysicsBody body1, PhysicsBody body2)
 Add the pair to ignore list.
void RemoveIgnorePair (uint index1, uint index2)
 Remove the pair from ignore list.
void RemoveIgnorePair (PhysicsBody body1, PhysicsBody body2)
 Remove the pair from ignore list.
bool CheckOutOfBound (PhysicsBody body)
 if outside of the main area, object will not be considered to take care
int CheckPicking (ref Vector2 click_pos, ref Vector2 diff_pos, bool rigorous_check)
 check whether any rigid body is under touch point
int CheckForcePicking (ref Vector2 click_pos, ref Vector2 diff_pos, bool rigorous_check)
 check whether any rigid body is under touch point
virtual void InitScene ()
 Clear numbers of properties of scene.
virtual void ReleaseScene ()
 user should define that all resources are released including debug rendering objects
virtual void KeyboardFunc (GamePadButtons ePad)
 user should define Game pad handling
virtual void UpdateFuncAfterSim ()
 Post simulation, user update based on contact points...
virtual void UpdateFuncBeforeSim ()
 Pre simulation, user update to force positions changes...
virtual void DrawAllBody (ref GraphicsContext graphics, ref ShaderProgram program, Matrix4 rendering_scale, int click_index)
 User can define how to render rigid body.
virtual void DrawAdditionalInfo (ref GraphicsContext graphics, ref ShaderProgram program, Matrix4 rendering_scale)
 User can define additional debug rendering.

Public Attributes

int numBody = 0
 number of rigid sceneBodies in the scene
int numJoint = 0
 number of joints in the scene
int numSpring = 0
 number of springs in the scene
int numShape = 0
 number of shapes in the scene
int numBroadPair = 0
 number of broad phase collision pairs
int numPhysicsSolverPair = 0
 number of narrow phase collision pairs
int numOldPhysicsSolverPair = 0
 number of old narrow phase collision pairs
PhysicsBody[] sceneBodies = new PhysicsBody[maxBody]
 array of rigid sceneBodies in the scene
PhysicsShape[] sceneShapes = new PhysicsShape[maxShape]
 array of shapes in the scene
uint[] broadPair = new uint[maxContacts]
 array of broad phase collision pairs in the scene
PhysicsSolverPair[] solverPair = new PhysicsSolverPair[maxContacts]
 array of solver pairs in the scene
PhysicsJoint[] sceneJoints = new PhysicsJoint[maxJoint]
 array of joints in the scene
PhysicsSpring[] sceneSprings = new PhysicsSpring[maxSpring]
 array of springs in the scene
uint[] compoundMap = new uint[maxBody]
 compound map in the scene
float simDt = 1.0f/60.0f
 simulation time step in the scene
Vector2 gravity = new Vector2(0, -9.8f)
 gravity in the scene
Vector2 sceneMin = new Vector2(-1000.0f, -1000.0f)
 minimum value of bounding box of simulation area
Vector2 sceneMax = new Vector2(1000.0f, 1000.0f)
 maximum value of bounding box of simulation area
ulong sceneFrame = 0
 scene frame number of this simulation
string sceneName = "Scene made by Physics2DEngine"
 scene name of this simulation
int numIgnorePair = 0
 number of ignore pairs in the scene
uint[] ignorePair = new uint[maxIgnore]
 array of ignore pairs in the scene
bool printPerf = false
 print out performance of each simulation phase
bool uniqueProperty = true
 whether use unique value for the scene
float penetrationRepulse = 0.2f
 repulse acceleration for penetration
float penetLimit = 0.03f
 penetration limitation
float tangentFriction = 0.3f
 tangent friction for repulse
float restitutionCoeff = 0.0f
 restitution coefficient for repulse
SleepAlgorithmType sleepAlgorithm = SleepAlgorithmType.BroadphaseBase
 sleep algorithm based on broadphase or narrow phase
BroadOpType filterOp
 filterOp

Properties

int NumBody [get, set]
 setter and getter of numBody
int NumJoint [get, set]
 setter and getter of numJoint
int NumSpring [get, set]
 setter and getter of numSpring
int NumShape [get, set]
 setter and getter of numShape
int NumBroadPair [get, set]
 setter and getter of numBroadPair
int NumPhysicsSolverPair [get, set]
 setter and getter of numPhysicsSolverPair
int NumOldPhysicsSolverPair [get, set]
 setter and getter of numOldPhysicsSolverPair
PhysicsBody[] SceneBodies [get, set]
 setter and getter of sceneBodies
PhysicsShape[] SceneShapes [get, set]
 setter and getter of sceneShapes
PhysicsJoint[] SceneJoints [get, set]
 setter and getter of sceneJoints
PhysicsSpring[] SceneSprings [get, set]
 setter and getter of sceneSprings
float SimDt [get, set]
 setter and getter of simDt
Vector2 Gravity [get, set]
 setter and getter of gravity
Vector2 SceneMin [get, set]
 setter and getter of sceneMin
Vector2 SceneMax [get, set]
 setter and getter of sceneMax
ulong SceneFrame [get, set]
 setter and getter of sceneFrame
string SceneName [get, set]
 setter and getter of sceneName
int NumIgnorePair [get, set]
 setter and getter of numIgnorePair
uint[] IgnorePair [get, set]
 setter and getter of ignorePair
bool PrintPerf [get, set]
 setter and getter of printPerf
bool UniqueProperty [get, set]
 setter and getter of uniqueProperty
float PenetrationRepulse [get, set]
 setter and getter of penetrationRepulse
float PenetLimit [get, set]
 setter and getter of penetLimit
float TangentFriction [get, set]
 setter and getter of tangentFriction
float RestitutionCoeff [get, set]
 setter and getter of restitutionCoeff
BroadOpType FilterOp [get, set]
 setter and getter of filterOp
uint[] CompoundMap [get, set]
 setter and getter of compoundMap
PhysicsSolverPair[] SolverPair [get]
 getter of solverPair
uint[] BroadPair [get]
 getter of broadPair
SleepAlgorithmType SleepAlgorithm [get, set]
 setter and getter of sleepAlgorithm

Detailed Description

Physics2D simulation base scene.


Member Enumeration Documentation

Switch the combination of collisionFilter and groupFilter.

Enumerator:
Or 

OR operation.

And 

AND operation.

Switch the algorithm of checking sleep status.

Enumerator:
BroadphaseBase 

Based on broadphase collision.

NarrowphaseBase 

Based on narrowphase collision.


Member Function Documentation

PhysicsBody AddBody ( int  shapeIndex,
float  mass 
)

Add Rigid Body.

Parameters:
shapeIndexindex of collision shape
massmass of rigid body
Returns:
reference to this rigid body

increment numBody automatically by this function

PhysicsBody AddBody ( PhysicsShape  shape,
float  mass 
)

Add Rigid Body.

Parameters:
shapereference to collision shape
massmass of rigid body
Returns:
reference to this rigid body

increment numBody automatically by this function

PhysicsShape AddBoxShape ( Vector2  width)

Add box shape to the scene.

Parameters:
widthhalf width of box

width param is half width of box
increment numShape automatically by this function

PhysicsShape AddConvexHullShape ( Vector2[]  pos,
int  num 
)

Add convex hull shape comoposed of random points to the scene.

Parameters:
numrandom point set
numnumber of random point set

the limitation of number of point list containd by convex shape is 30
increment numShape automatically by this function

PhysicsShape AddConvexShape ( Vector2[]  pos,
int  num 
)

Add convex shape to the scene.

Parameters:
pospoint list for convex shape
numnum of point list for convex shape

the limitation of number of point list containd by convex shape is 30
increment numShape automatically by this function

void AddIgnorePair ( uint  index1,
uint  index2 
)

Add the pair to ignore list.

Parameters:
index1one of the pair
index2the other of the pair
void AddIgnorePair ( PhysicsBody  body1,
PhysicsBody  body2 
)

Add the pair to ignore list.

Parameters:
body1one of the pair
body2the other of the pair
PhysicsJoint AddJoint ( int  bodyIndex1,
int  bodyIndex2,
Vector2  anchorPos 
)

Add joint.

Parameters:
bodyIndex1index of one of rigid body pair
bodyIndex2index of the other of rigid body pair
anchorPosanchor position of joint
Returns:
reference to this joint

increment numJoint automatically by this function

PhysicsJoint AddJoint ( PhysicsBody  body1,
PhysicsBody  body2,
Vector2  anchorPos 
)

Add joint.

Parameters:
body1reference to one of rigid body pair
body2reference to the other of rigid body pair
anchorPosanchor position of joint
Returns:
reference to this joint

increment numJoint automatically by this function

PhysicsShape AddLineChainShape ( Vector2[]  pos,
int  num 
)

Add chain of line segments to the scene.

Parameters:
pospoint list for line shape
numnum of point list for convex shape

the limitation of number of point list containd by convex shape is 30, and this is only for static rigid body
increment numShape automatically by this function

PhysicsShape AddSphereShape ( float  radius)

Add sphere shape to the scene.

Parameters:
radiusradius of sphere

increment numShape automatically by this function

PhysicsSpring AddSpring ( PhysicsBody  body1,
PhysicsBody  body2,
Vector2  anchorPos1,
Vector2  anchorPos2 
)

Add spring.

Parameters:
body1reference to one of rigid body pair
body2reference to the other of rigid body pair
anchorPos1one of anchor position of joint
anchorPos2the other of anchor positions of spring
Returns:
reference to this spring

increment numSpring automatically by this function

PhysicsSpring AddSpring ( int  bodyIndex1,
int  bodyIndex2,
Vector2  anchorPos1,
Vector2  anchorPos2 
)

Add joint.

Parameters:
bodyIndex1index of one of rigid body pair
bodyIndex2index of the other of rigid body pair
anchorPosanchor position of joint
Returns:
reference to this joint

increment numJoint automatically by this function

int CheckForcePicking ( ref Vector2  click_pos,
ref Vector2  diff_pos,
bool  rigorous_check 
)

check whether any rigid body is under touch point

Parameters:
click_posgiven touch point
diff_posdifference between touch point and center of rigid body
rigorous_checkwhether rigorous check is done
Returns:
return index of rigid body which is under touch point, if there are no any rigid sceneBodies, then return -1
This function returns index even if its index is belong to static rigid body
bool CheckOutOfBound ( PhysicsBody  body)

if outside of the main area, object will not be considered to take care

Parameters:
bodygive rigid body
Returns:
whether it exists out side of the main area
int CheckPicking ( ref Vector2  click_pos,
ref Vector2  diff_pos,
bool  rigorous_check 
)

check whether any rigid body is under touch point

Parameters:
click_posgiven touch point
diff_posdifference between touch point and center of rigid body
rigorous_checkwhether rigorous check is done
Returns:
return index of rigid body which is under touch point, if there are no any rigid sceneBodies, then return -1
int DeleteBody ( int  index)

DeleteBody.

Parameters:
indexindex of rigid body
Returns:
total number of joints of scene

This will requires rearrangment of internal cache data used by simulation.
When you want to remove many objects within one frame, you should be careful about the performance, and it is recommended not to remove many objects at once as much as possible and try to consider other ways such that unused objects are put outside the area of simulation
When compound rigid body is given, all rigid bodies related to it are removed.

int DeleteBody ( PhysicsBody  body)

DeleteBody.

Parameters:
bodyreference to rigid body
Returns:
total number of joints of scene

This will requires rearrangment of internal cache data used by simulation.
When you want to remove many objects within one frame, you should be careful about the performance, and it is recommended not to remove many objects at once as much as possible and try to consider other ways such that unused objects are put outside the area of simulation
When compound rigid body is given, all rigid bodies related to it are removed.

int DeleteJoint ( int  index)

DeleteJoint.

Parameters:
index1index of joint
Returns:
total number of joints of scene after removing the joint
int DeleteJoint ( PhysicsJoint  joint)

DeleteJoint.

Parameters:
jointreference to joint
Returns:
total number of joints of scene after removing the joint
int DeleteSpring ( PhysicsSpring  spring)

DeleteSpring.

Parameters:
springreference to spring
Returns:
total number of springs of scene after removing the spring
int DeleteSpring ( int  index)

DeleteSpring.

Parameters:
indexindex of spring
Returns:
total number of springs of scene after removing the spring
virtual void DrawAdditionalInfo ( ref GraphicsContext  graphics,
ref ShaderProgram  program,
Matrix4  rendering_scale 
) [virtual]

User can define additional debug rendering.

Parameters:
graphicsgiven graphics context
programgiven shader program
rendering_scalegiven rendering scale
virtual void DrawAllBody ( ref GraphicsContext  graphics,
ref ShaderProgram  program,
Matrix4  rendering_scale,
int  click_index 
) [virtual]

User can define how to render rigid body.

Parameters:
graphicsgiven graphics context
programgiven shader program
rendering_scalegiven rendering scale
click_indexgiven touch point index
PhysicsBody GetBody ( int  index)

Get rigid body.

Parameters:
indexindex of rigid body
Returns:
if it is not found, null will be returned
int GetBodyIndex ( PhysicsBody  body)

Get index of rigid body.

Parameters:
bodyrigid body
Returns:
if it is not found, -1 will be returned
PhysicsJoint GetJoint ( int  index)

Get joint.

Parameters:
indexindex of joint
Returns:
if it is not found, null will be returned
int GetJointIndex ( PhysicsJoint  joint)

Get index of joint.

Parameters:
jointjoint
Returns:
if it is not found, -1 will be returned
PhysicsShape GetShape ( int  index)

Get collilsion shape.

Parameters:
indexindex of shape
Returns:
if it is not found, null will be returned
int GetShapeIndex ( PhysicsShape  shape)

Get index of collision shape.

Parameters:
shapecollision shape
Returns:
if it is not found, -1 will be returned
PhysicsSpring GetSpring ( int  index)

Get spring.

Parameters:
indexindex of spring
Returns:
if it is not found, null will be returned
int GetSpringIndex ( PhysicsSpring  spring)

Get index of spring.

Parameters:
springspring
Returns:
if it is not found, -1 will be returned
virtual void KeyboardFunc ( GamePadButtons  ePad) [virtual]

user should define Game pad handling

Parameters:
ePadgame pad input
Vector2 MergeCompound ( PhysicsBody[]  bodyList,
int  num,
bool  flag = true 
)

Merge of rigid body.

To merge multiple objects (compound object), bodyList should be given in manner of the ascending order

Parameters:
bodyListgiven rigid body list of the scene
numgiven number of rigid sceneBodies to be attached
flagwhether rearrange the position of merged rigid body
bool QueryContact ( uint  index1,
uint  index2 
)

Check whether there is a collision between index1 and index2.

Parameters:
index1one of rigid body pair
index2the other of rigid body pair
Returns:
the result is true if there is a collision
bool QueryContact ( PhysicsBody  body1,
PhysicsBody  body2 
)

Check whether there is a collision between index1 and index2.

Parameters:
body1one of rigid body pair
body2the other of rigid body pair
Returns:
the result is true if there is a collision
int QueryContactTrigger ( uint  index,
uint[]  indexlist 
)

Check whether there is a collision between trigger rigid body and others.

Parameters:
indexindex of trigger rigid body
indexlistindex list which contact with the trigger will be saved
Returns:
number of rigid bodies which contact with the trigger
bool RaycastHit ( ref RayHit  ray,
uint  collisionFilter,
uint  groupFilter 
)

Raycast check.

Parameters:
rayRay information for raycast 
collisionFiltercollision filter as usual collision 
groupFiltergroup filter as usual collision
Returns:
return wheter ray hit exsists
bool RaycastHit ( ref RayHit  ray)

Raycast check.

Parameters:
rayRay information for raycast 
Returns:
return wheter ray hit exsists
void RemoveIgnorePair ( PhysicsBody  body1,
PhysicsBody  body2 
)

Remove the pair from ignore list.

Parameters:
body1one of the pair
body2the other of the pair
void RemoveIgnorePair ( uint  index1,
uint  index2 
)

Remove the pair from ignore list.

Parameters:
index1one of the pair
index2the other of the pair
void Simulate ( int  click_index,
Vector2  click_pos,
Vector2  diff_pos 
)

Simulate.

Parameters:
click_indexone of rigid body pair
click_posthe other of rigid body pair
diff_possceneShapes of the scene

Simulate function including user-click event manipulation

virtual void UpdateFuncAfterSim ( ) [virtual]

Post simulation, user update based on contact points...

etc

virtual void UpdateFuncBeforeSim ( ) [virtual]

Pre simulation, user update to force positions changes...

etc


Member Data Documentation

uint [] compoundMap = new uint[maxBody]

compound map in the scene

internal use only

filterOp

OR / AND switch for collision and group filter combination


Property Documentation

uint [] BroadPair [get]

getter of broadPair

setter is not provided

PhysicsSolverPair [] SolverPair [get]

getter of solverPair

setter is not provided