2009-04-18 10:00:33 -07:00
|
|
|
/* Copyright (C) 2009 Wildfire Games.
|
|
|
|
|
* This file is part of 0 A.D.
|
|
|
|
|
*
|
|
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
2004-05-25 20:14:33 -07:00
|
|
|
// BoundingObjects.h
|
|
|
|
|
//
|
|
|
|
|
// Bounding circle and object-aligned bounding box. 2D, for simulation code.
|
|
|
|
|
//
|
|
|
|
|
// Note: object-aligned bounding boxes are often referred to as oriented bounding boxes (OBBs)
|
|
|
|
|
|
2007-05-07 09:33:24 -07:00
|
|
|
#ifndef INCLUDED_BOUNDINGOBJECTS
|
|
|
|
|
#define INCLUDED_BOUNDINGOBJECTS
|
2004-05-25 20:14:33 -07:00
|
|
|
|
2006-06-01 19:10:27 -07:00
|
|
|
#include "ps/Vector2D.h"
|
2004-05-25 20:14:33 -07:00
|
|
|
|
|
|
|
|
class CBoundingBox;
|
|
|
|
|
class CBoundingCircle;
|
|
|
|
|
|
|
|
|
|
class CBoundingObject
|
|
|
|
|
{
|
|
|
|
|
public:
|
2004-07-23 03:56:52 -07:00
|
|
|
CBoundingObject() {}
|
2004-05-26 13:57:25 -07:00
|
|
|
enum EBoundingType
|
2004-05-25 20:14:33 -07:00
|
|
|
{
|
2004-10-07 12:23:35 -07:00
|
|
|
BOUND_NONE,
|
2004-05-25 20:14:33 -07:00
|
|
|
BOUND_CIRCLE,
|
|
|
|
|
BOUND_OABB
|
|
|
|
|
};
|
2004-05-26 13:57:25 -07:00
|
|
|
EBoundingType m_type;
|
|
|
|
|
CVector2D m_pos;
|
|
|
|
|
float m_radius;
|
2005-05-10 00:13:25 -07:00
|
|
|
float m_height;
|
|
|
|
|
|
2007-05-02 05:07:08 -07:00
|
|
|
void SetPosition( float x, float y );
|
|
|
|
|
void SetHeight( float height );
|
|
|
|
|
bool Intersects( CBoundingObject* obj );
|
|
|
|
|
bool Contains( const CVector2D& point );
|
|
|
|
|
virtual bool LooselyIntersects( CBoundingObject* obj, const CVector2D& delta ) = 0;
|
|
|
|
|
virtual bool LooselyContains( const CVector2D& point, const CVector2D& delta ) = 0;
|
|
|
|
|
virtual void Render( float height ) = 0; // Temporary
|
2004-05-25 20:14:33 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class CBoundingCircle : public CBoundingObject
|
|
|
|
|
{
|
|
|
|
|
public:
|
2004-05-26 13:57:25 -07:00
|
|
|
CBoundingCircle() { m_type = BOUND_OABB; }
|
2005-05-10 00:13:25 -07:00
|
|
|
CBoundingCircle( float x, float y, float radius, float height );
|
2004-05-26 13:57:25 -07:00
|
|
|
CBoundingCircle( float x, float y, CBoundingCircle* copy );
|
2007-05-02 05:07:08 -07:00
|
|
|
void SetRadius( float radius );
|
|
|
|
|
bool LooselyIntersects( CBoundingObject* obj, const CVector2D& delta );
|
|
|
|
|
bool LooselyContains( const CVector2D& point, const CVector2D& delta );
|
|
|
|
|
void Render( float height ); // Temporary
|
2004-05-25 20:14:33 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class CBoundingBox : public CBoundingObject
|
|
|
|
|
{
|
|
|
|
|
public:
|
2004-05-26 13:57:25 -07:00
|
|
|
CBoundingBox() { m_type = BOUND_OABB; }
|
2005-05-10 00:13:25 -07:00
|
|
|
CVector2D m_u; // Unit vector along the direction of this box's depth.
|
2004-05-26 13:57:25 -07:00
|
|
|
CVector2D m_v; // Unit vector along the direction of this box's width.
|
2005-05-10 00:13:25 -07:00
|
|
|
float m_d; // Half this box's depth.
|
2004-05-26 13:57:25 -07:00
|
|
|
float m_w; // Half this box's width.
|
2005-05-10 00:13:25 -07:00
|
|
|
CBoundingBox( float x, float y, float orientation, float width, float depth, float height );
|
|
|
|
|
CBoundingBox( float x, float y, const CVector2D& orientation, float width, float depth, float height );
|
2004-06-02 19:20:48 -07:00
|
|
|
CBoundingBox( float x, float y, float orientation, CBoundingBox* copy );
|
2004-05-26 13:57:25 -07:00
|
|
|
CBoundingBox( float x, float y, const CVector2D& orientation, CBoundingBox* copy );
|
2007-05-02 05:07:08 -07:00
|
|
|
void SetDimensions( float width, float depth );
|
|
|
|
|
void SetOrientation( float orientation );
|
|
|
|
|
void SetOrientation( const CVector2D& orientation );
|
|
|
|
|
float GetWidth() const { return( 2.0f * m_w ); };
|
|
|
|
|
float GetDepth() const { return( 2.0f * m_d ); };
|
|
|
|
|
bool LooselyIntersects( CBoundingObject* obj, const CVector2D& delta );
|
|
|
|
|
bool LooselyContains( const CVector2D& point, const CVector2D& delta );
|
|
|
|
|
void Render( float height ); // Temporary
|
2004-05-25 20:14:33 -07:00
|
|
|
};
|
|
|
|
|
|
2004-06-02 09:11:32 -07:00
|
|
|
#endif
|