Exemplo n.º 1
0
/*****************************************************************
* GetNearbyObjects(CBounds*)				Returns all objects that could/do
*											collide with the specified bounds
*
* Ins:					cBounds - The bounds of the object.
*
* Outs:					None
*
* Returns:				vector<IObject*>
*
* Mod. Date:		    08/12/2015
* Mod. Initials:	    MZ
*****************************************************************/
std::vector<IObject*>CQuadTree::GetNearbyObjects(CBounds* cBounds)
{
	Bounds::eBoundsType eType = cBounds->GetType();

	float xMin = 0.0f, zMin = 0.0f, xMax = 0.0f, zMax = 0.0f;

	if (eType == Bounds::AABB)
	{
		xMin = ((CAABB *)cBounds)->Min().x;
		zMin = ((CAABB *)cBounds)->Min().z;
		xMax = ((CAABB *)cBounds)->Max().x;
		zMax = ((CAABB *)cBounds)->Max().z;
	}
	else if (eType == Bounds::Capsule)
	{
		float fRadius = ((CCapsule*)cBounds)->GetRadius();
		xMin = ((CCapsule*)cBounds)->GetStart().x - fRadius;
		zMin = ((CCapsule*)cBounds)->GetStart().z - fRadius;
		xMax = ((CCapsule*)cBounds)->GetStart().x + fRadius;
		zMax = ((CCapsule*)cBounds)->GetStart().z + fRadius;

		float testXMin = ((CCapsule*)cBounds)->GetEnd().x - fRadius;
		float testZMin = ((CCapsule*)cBounds)->GetEnd().z - fRadius;
		float testXMax = ((CCapsule*)cBounds)->GetEnd().x + fRadius;
		float testZMax = ((CCapsule*)cBounds)->GetEnd().z + fRadius;
		
		if (testXMin < xMin)
		{
			xMin = testXMin;
		}
		if (testZMin < zMin)
		{
			zMin = testZMin;
		}
		if (testXMax > xMax)
		{
			xMax = testXMax;
		}
		if (testZMax > zMax)
		{
			zMax = testZMax;
		}
	}
	else if (eType == Bounds::Plane)
	{
		xMin = ((CPlane *)cBounds)->Min().x;
		zMin = ((CPlane *)cBounds)->Min().z;
		xMax = ((CPlane *)cBounds)->Max().x;
		zMax = ((CPlane *)cBounds)->Max().z;
	}
	else
	{
		assert(0 && "Type Not Supported.  Let Matt Know About This Please.");
	}

	return GetNearbyObjects(xMin,zMin,xMax,zMax);
}
Exemplo n.º 2
0
void World::PhysicsUpdate(Vec<double,3> pos, double radius, double dt){
  std::list<GameObjectBase> golist = GetNearbyObjects(pos,radius);
  
  double gravity = 0.1;//9.8;

  std::list<AABBMass> masses;
  for(GameObjectBase gob : golist){
    if(gob.Get()->GravityBound){
      gob.Get()->aabb.mass.ApplyImpulse(vec(0.0,-gravity,0.0));
    }
    masses.push_back(gob.Get()->aabb);
  }
  
  AABBListPhysics physicsHandler;
  PhysicsIterationResult result = physicsHandler.PhysicsIteration2(masses,dt);
  masses = result.NewMasses;
  for(AABBMass aabb : masses){
    (*(golist.begin())).Get()->aabb = aabb;
    golist.pop_front();
  }
  
}