0ad/source/simulation/Collision.h

51 lines
2.1 KiB
C
Raw Normal View History

// Collision.h
//
// Collision detection functions
//
// Usage: Fairly trivial; GetCollisionObject( CEntity* entity ) will return the first entity colliding with the given entity.
// The version with (x, y) parameters is just a helper; it temporarily moves the entity's collision bounds to the given
// position before transferring to the other function.
// Notes: GetCollisionObject will only return the /first/ entity it finds in collision. This /may/ need a rethink when
// multiple-entity (pileup) collisions become possible, I don't know.
//
// Mark Thompson mot20@cam.ac.uk / mark@wildfiregames.com
#ifndef INCLUDED_COLLISION
#define INCLUDED_COLLISION
#include "BoundingObjects.h"
class CEntity;
class CPlayer;
class CStrW;
#include "EntityHandles.h"
struct rayIntersectionResults
{
CEntity* Entity;
CBoundingObject* boundingObject;
CVector2D position;
float closestApproach;
float distance;
};
// maximum radius at which we check for entities (if some entity is much bigger than this, that's bad)
# Housekeeping and pathfinder enhancements / optimization when dealing with ranged actions. - Modified Xeromyces to no longer automatically convert element and attribute names to lowercase, so that we can have camelCase names. We should now be able to convert all the multi-word entity properties, like pass_through_allies, to camelCase, like passThroughAllies, which is more consistent with the rest of our JavaScript naming conventions. To support the existing code that assumes lowercase element names, I made the getElementID and getAttributeID methods (used in the EL and AT macros) ignore case, and I changed any code that directly accessed element names to use the right case. CEntityTemplate now converts Names_LikeThis to names_likeThis (changing each separate "word" in the name to camelCase). Changed the version letter in XMB filenames from A to B to support this without requiring people to delete old XMBs. - Enhanced the pathfinder's handling of contact paths, resulting in a very large speedup for actions like attacking, construction, etc. The problem was that the pathfinder used to not count a given state as the goal unless it was exactly coincident with the target location. This is fine when you order a unit to go exactly to a certain spot, but if you're ordering a unit to build, gather or attack something, then the target tile is impassable (because your target is there) and therefore the pathfinder never declares a state final. As a result, the pathfinder tries hundreds of extra tiles in case there is a long path that gets to the goal, and after failing to find any path that reaches the goal, it gives you one to the closest point it got to. To fix it, I made the pathfinder take into account a radius around the goal in which it's OK to be, which depends on the size of the target unit and the range of your action. This was SVN commit r4186.
2006-08-01 05:41:21 +02:00
#define COLLISION_RANGE 20
typedef std::vector<CEntity*> RayIntersects;
HEntity GetCollisionObject( CEntity* entity, bool enablePassThroughAllies=true );
HEntity GetCollisionObject( CEntity* entity, float x, float y );
CBoundingObject* GetCollisionObject( CBoundingObject* bounds, CPlayer* player=0, const CStrW* ignoreClass=0 );
CEntity* GetCollisionEntity( CBoundingObject* bounds, CPlayer* player=0, const CStrW* ignoreClass=0 );
CBoundingObject* GetContainingObject( const CVector2D& point );
CEntity* GetCollisionObject( float x, float y ); // Point collision
bool GetRayIntersection( const CVector2D& source, const CVector2D& forward, const CVector2D& right, float length, float maxDistance, CBoundingObject* destinationCollisionObject, rayIntersectionResults* results );
// Assumes zero width, also includes moving units (other one doesn't).
void GetProjectileIntersection( const CVector2D& position, const CVector2D& axis, float length, RayIntersects& results );
// Stores results in shared area
RayIntersects& GetProjectileIntersection( const CVector2D& position, const CVector2D& axis, float length );
#endif