/////////////////////////////////////////////////////////////////////// // // The physical body of an object. // Based on the sample engine written by Chris Peters // // Jonathan Rust // // All Content © 2011 DigiPen (USA) Corporation, all rights reserved. //////////////////////////////////////////////////////////////////////// #include "Precompiled.h" #include "Body.h" #include "Physics\PhysicsSystem.h" #include "ComponentManager.h" #include "VectorMath.h" #include "Gravity.h" #include "Mesh.h" #include "DebugDraw.h" #include "Clamp.h" //--------------------------------- // MORE STUFF USUALLY GOES HERE //--------------------------------- Vector2 Body::CalcGravitationalPull(Vector2 pos) { //Only calculate gravitational pull for objects that move if (isStatic || gravityEffect == 0.0f) { return Vector2(0,0); } else { Vector2 gravPull(0,0); IntrusiveLinkedList::iterator gravityIt = PHYSICS->gravityList.begin(); //loop through all objects with a gravity field, and apply their fields to this body for (; gravityIt!=PHYSICS->gravityList.end(); ++gravityIt) { Vector2 dirVec = gravityIt->body->position - position; float distSq = LenSquared(position - gravityIt->body->position); //this equation is based on the actual calculation of gravity in the real world, //although obviously in the real world it would apply in three dimensions if( distSq > 0.0f ) { Normalize(dirVec); gravPull += dirVec * (PHYSICS->gravConst * mass * gravityIt->body->mass / distSq); } } gravPull *= invMass; return gravPull; } } //--------------------------------- // MORE STUFF USUALLY GOES HERE //---------------------------------