Physics2D simulation base scene. More...
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 |
Physics2D simulation base scene.
enum BroadOpType |
enum SleepAlgorithmType |
PhysicsBody AddBody | ( | int | shapeIndex, |
float | mass | ||
) |
Add Rigid Body.
shapeIndex | index of collision shape |
mass | mass of rigid body |
increment numBody automatically by this function
PhysicsBody AddBody | ( | PhysicsShape | shape, |
float | mass | ||
) |
Add Rigid Body.
shape | reference to collision shape |
mass | mass of rigid body |
increment numBody automatically by this function
PhysicsShape AddBoxShape | ( | Vector2 | width | ) |
Add box shape to the scene.
width | half 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.
num | random point set |
num | number 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.
pos | point list for convex shape |
num | num 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.
index1 | one of the pair |
index2 | the other of the pair |
void AddIgnorePair | ( | PhysicsBody | body1, |
PhysicsBody | body2 | ||
) |
Add the pair to ignore list.
body1 | one of the pair |
body2 | the other of the pair |
PhysicsJoint AddJoint | ( | int | bodyIndex1, |
int | bodyIndex2, | ||
Vector2 | anchorPos | ||
) |
Add joint.
bodyIndex1 | index of one of rigid body pair |
bodyIndex2 | index of the other of rigid body pair |
anchorPos | anchor position of joint |
increment numJoint automatically by this function
PhysicsJoint AddJoint | ( | PhysicsBody | body1, |
PhysicsBody | body2, | ||
Vector2 | anchorPos | ||
) |
Add joint.
body1 | reference to one of rigid body pair |
body2 | reference to the other of rigid body pair |
anchorPos | anchor position of joint |
increment numJoint automatically by this function
PhysicsShape AddLineChainShape | ( | Vector2[] | pos, |
int | num | ||
) |
Add chain of line segments to the scene.
pos | point list for line shape |
num | num 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.
radius | radius of sphere |
increment numShape automatically by this function
PhysicsSpring AddSpring | ( | PhysicsBody | body1, |
PhysicsBody | body2, | ||
Vector2 | anchorPos1, | ||
Vector2 | anchorPos2 | ||
) |
Add spring.
body1 | reference to one of rigid body pair |
body2 | reference to the other of rigid body pair |
anchorPos1 | one of anchor position of joint |
anchorPos2 | the other of anchor positions of spring |
increment numSpring automatically by this function
PhysicsSpring AddSpring | ( | int | bodyIndex1, |
int | bodyIndex2, | ||
Vector2 | anchorPos1, | ||
Vector2 | anchorPos2 | ||
) |
Add joint.
bodyIndex1 | index of one of rigid body pair |
bodyIndex2 | index of the other of rigid body pair |
anchorPos | anchor position of joint |
increment numJoint automatically by this function
check whether any rigid body is under touch point
click_pos | given touch point |
diff_pos | difference between touch point and center of rigid body |
rigorous_check | whether rigorous check is done |
bool CheckOutOfBound | ( | PhysicsBody | body | ) |
if outside of the main area, object will not be considered to take care
body | give rigid body |
check whether any rigid body is under touch point
click_pos | given touch point |
diff_pos | difference between touch point and center of rigid body |
rigorous_check | whether rigorous check is done |
int DeleteBody | ( | int | index | ) |
DeleteBody.
index | index of rigid body |
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.
body | reference to rigid body |
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.
index1 | index of joint |
int DeleteJoint | ( | PhysicsJoint | joint | ) |
DeleteJoint.
joint | reference to joint |
int DeleteSpring | ( | PhysicsSpring | spring | ) |
DeleteSpring.
spring | reference to spring |
int DeleteSpring | ( | int | index | ) |
DeleteSpring.
index | index of spring |
virtual void DrawAdditionalInfo | ( | ref GraphicsContext | graphics, |
ref ShaderProgram | program, | ||
Matrix4 | rendering_scale | ||
) | [virtual] |
User can define additional debug rendering.
graphics | given graphics context |
program | given shader program |
rendering_scale | given 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.
graphics | given graphics context |
program | given shader program |
rendering_scale | given rendering scale |
click_index | given touch point index |
PhysicsBody GetBody | ( | int | index | ) |
Get rigid body.
index | index of rigid body |
int GetBodyIndex | ( | PhysicsBody | body | ) |
Get index of rigid body.
body | rigid body |
PhysicsJoint GetJoint | ( | int | index | ) |
Get joint.
index | index of joint |
int GetJointIndex | ( | PhysicsJoint | joint | ) |
Get index of joint.
joint | joint |
PhysicsShape GetShape | ( | int | index | ) |
Get collilsion shape.
index | index of shape |
int GetShapeIndex | ( | PhysicsShape | shape | ) |
Get index of collision shape.
shape | collision shape |
PhysicsSpring GetSpring | ( | int | index | ) |
Get spring.
index | index of spring |
int GetSpringIndex | ( | PhysicsSpring | spring | ) |
Get index of spring.
spring | spring |
virtual void KeyboardFunc | ( | GamePadButtons | ePad | ) | [virtual] |
user should define Game pad handling
ePad | game 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
bodyList | given rigid body list of the scene |
num | given number of rigid sceneBodies to be attached |
flag | whether rearrange the position of merged rigid body |
bool QueryContact | ( | uint | index1, |
uint | index2 | ||
) |
Check whether there is a collision between index1 and index2.
index1 | one of rigid body pair |
index2 | the other of rigid body pair |
bool QueryContact | ( | PhysicsBody | body1, |
PhysicsBody | body2 | ||
) |
Check whether there is a collision between index1 and index2.
body1 | one of rigid body pair |
body2 | the other of rigid body pair |
int QueryContactTrigger | ( | uint | index, |
uint[] | indexlist | ||
) |
Check whether there is a collision between trigger rigid body and others.
index | index of trigger rigid body |
indexlist | index list which contact with the trigger will be saved |
bool RaycastHit | ( | ref RayHit | ray, |
uint | collisionFilter, | ||
uint | groupFilter | ||
) |
Raycast check.
ray | Ray information for raycast  |
collisionFilter | collision filter as usual collision  |
groupFilter | group filter as usual collision |
bool RaycastHit | ( | ref RayHit | ray | ) |
Raycast check.
ray | Ray information for raycast  |
void RemoveIgnorePair | ( | PhysicsBody | body1, |
PhysicsBody | body2 | ||
) |
Remove the pair from ignore list.
body1 | one of the pair |
body2 | the other of the pair |
void RemoveIgnorePair | ( | uint | index1, |
uint | index2 | ||
) |
Remove the pair from ignore list.
index1 | one of the pair |
index2 | the other of the pair |
Simulate.
click_index | one of rigid body pair |
click_pos | the other of rigid body pair |
diff_pos | sceneShapes 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
uint [] compoundMap = new uint[maxBody] |
compound map in the scene
internal use only
filterOp
OR / AND switch for collision and group filter combination
uint [] BroadPair [get] |
getter of broadPair
setter is not provided
PhysicsSolverPair [] SolverPair [get] |
getter of solverPair
setter is not provided