Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Integrate forces for each body.
- foreach (RigidBodyBase body in doc.Bodies)
- {
- // Don't move background-anchored bodies.
- if (body.anchored) continue;
- // This is where we will add Each Body's gravitational force
- // to the total force exerted on the object.
- // For each other body, get it's point and it's mass.
- // Find the gravitational force exterted between target body and looped body.
- // Find distance between bodies.
- // vector addition
- // Force = G*mass1*mass2/distance^2
- // Find vector of that force.
- // Add Force to TotalGravityForce
- // loop until there are no more bodies.
- // Add TotalGravityForce to body.totalForce
- }
- foreach( RigidBodyBase body in doc.Bodies)
- foreach ( RigidBodyBase otherBody in doc.Bodies)
- if (!otherBody.Anchored && otherBody != body) // or otherBody.Id != body.Id -- whatever is required...
- // then do the work here
- foreach (RigidBodyBase body in doc.Bodies)
- body.TotalForce += body.GravityForce;
- int l = doc.Bodies.Count;
- for ( int i = 0; i < l; i++ )
- for ( int j = i + 1; j < l; j++ )
- // Do stuff
- foreach (RigidBodyBase body in doc.Bodies)
- {
- Integrateforces(ref body, Bodies);
- }
- ...
- public void Integrateforces(RigidBodyBase out body, RigidBodyBase[] Bodies)
- {
- //Put your integration logic here
- }
Add Comment
Please, Sign In to add comment