Colliding Shapes
Ian Parberry's "Introduction to Game Physics"
Public Member Functions | Protected Attributes | List of all members
CCircle Class Reference

Circle shape. More...

#include <Circle.h>

Inheritance diagram for CCircle:
CShape CShapeCommon CArc CDynamicCircle CKinematicCircle CKinematicArc

Public Member Functions

 CCircle (const CCircleDesc &)
 Constructor. More...
 
bool PreCollide (CContactDesc &)
 Collision detection. More...
 
bool PtInCircle (const Vector2 &)
 Point in circle test. More...
 
Vector2 ClosestPt (const Vector2 &)
 Closest point on circle. More...
 
bool Tangents (const Vector2 &, Vector2 &, Vector2 &)
 Tangents through external point. More...
 
bool Tangents (CCircle *, CLineSegDesc &, CLineSegDesc &)
 Common tangents. More...
 
bool Tangent (CCircle *, CLineSegDesc &)
 Common tangent. More...
 
float GetRadius ()
 Get radius. More...
 
- Public Member Functions inherited from CShape
 CShape (const CShapeDesc &)
 Constructor. More...
 
virtual ~CShape ()
 Destructor. More...
 
const eShape GetShapeType () const
 Get shape type. More...
 
const eMotion GetMotionType () const
 Get motion type. More...
 
const CAabb2DGetAABB () const
 Get AABB. More...
 
const bool GetSensor () const
 Is this shape a sensor? More...
 
const Vector2 & GetPos () const
 Get position. More...
 
void SetPos (const Vector2 &)
 Set position. More...
 
void SetAABBPoint (const Vector2 &)
 Set AABB point. More...
 
void AddAABBPoint (const Vector2 &)
 Add AABB point. More...
 
void SetCanCollide (bool=true)
 Turn collisions on or off. More...
 
const bool GetCanCollide () const
 Get whether shape can collide. More...
 
virtual void Rotate (const Vector2 &, float)
 Rotate. More...
 
virtual void Reset ()
 Reset orientation. More...
 
virtual void move ()
 Translate. More...
 
const bool GetRotating () const
 Get whether rotating. More...
 
void SetRotating (bool)
 Start or stop rotating. More...
 
const float GetOrientation () const
 Get orientation. More...
 
const float GetRotSpeed () const
 Get rotation speed. More...
 
const Vector2 & GetRotCenter () const
 Get rotation speed. More...
 
const float GetElasticity () const
 Get elasticity. More...
 
void SetOrientation (float)
 Set orientation. More...
 
void SetRotSpeed (float)
 Set rotation speed. More...
 
void SetRotCenter (const Vector2 &)
 Set center of rotation. More...
 
void * GetUserPtr () const
 Get user pointer. More...
 
void SetUserPtr (void *)
 Set user pointer. More...
 

Protected Attributes

float m_fRadius = 0.0f
 Radius.
 
float m_fRadiusSq = 0.0f
 Radius squared, used for faster distance calculations.
 
- Protected Attributes inherited from CShape
eShape m_eShapeType = eShape::Unknown
 Type of shape.
 
eMotion m_eMotionType = eMotion::Static
 How shape moves.
 
float m_fElasticity = 1.0f
 Elasticity, aka restitution, bounciness.
 
bool m_bIsSensor = false
 Sensor only, no rebound on collision.
 
CAabb2D m_cAABB
 Axially aligned bounding box in World Space.
 
bool m_bCanCollide = true
 Can collide with other shapes.
 
float m_fOrientation = 0.0f
 Orientation angle.
 
void * m_pUser
 Spare pointer for user in case they might need one.
 
Vector2 m_vRotCenter
 Center of rotation.
 
float m_fRotSpeed = 0.0f
 Rotation speed.
 
bool m_bRotating = false
 Whether rotating.
 

Additional Inherited Members

- Static Protected Attributes inherited from CShapeCommon
static float m_fGravity = 0.0f
 Gravitational constant.
 
static float m_fTimeStep = 0.0f
 Time step per animation frame (fictional).
 

Detailed Description

A circle is represented by the position of its center and its radius.

Constructor & Destructor Documentation

◆ CCircle()

CCircle::CCircle ( const CCircleDesc r)

Constructs a circle described by a circle descriptor.

Parameters
rCircle descriptor.

Member Function Documentation

◆ ClosestPt()

Vector2 CCircle::ClosestPt ( const Vector2 &  p)

Find the point on the perimeter of this circle that is closest to a given point.

Parameters
pA point.
Returns
The closest point to p that is on the perimeter.

◆ GetRadius()

float CCircle::GetRadius ( )

Reader function for the radius.

Returns
The radius.

◆ PreCollide()

bool CCircle::PreCollide ( CContactDesc c)
virtual

Collision detection with a dynamic circle.

Parameters
c[in, out] Contact descriptor for this collision.
Returns
true is there was a collision.

Reimplemented from CShape.

◆ PtInCircle()

bool CCircle::PtInCircle ( const Vector2 &  p)

Determine whether a given point is strictly inside this circle, that is, if the point's distance to the center of this circle is strictly less that its radius.

Parameters
pA point.
Returns
true if p is in this circle.

◆ Tangent()

bool CCircle::Tangent ( CCircle pCirc,
CLineSegDesc t 
)

Compute the common tangent with another circle that is counterclockwise from the vector pointing from this circle to that one.

Parameters
pCircPointer to another circle.
[out]tLine segment descriptor for common tangent.
Returns
true if tangent exists.

◆ Tangents() [1/2]

bool CCircle::Tangents ( const Vector2 &  p,
Vector2 &  p0,
Vector2 &  p1 
)

Compute the points of intersection of tangents passing through a point. Note that there are two possible tangents to a circle that pass through a given point outside the circle. If the point is inside the circle, then the tangents don't exist.

Parameters
pPoint that must lie on the tangents.
[out]p0Intersection point with first tangent.
[out]p1Intersection point with second tangent.
Returns
true if the tangents exist.

◆ Tangents() [2/2]

bool CCircle::Tangents ( CCircle pCirc,
CLineSegDesc t0,
CLineSegDesc t1 
)

A line tangent to circles at centers \(p_0\) and \(p_1\) of radii \(r_0\) and \(r_1 < r_0\) is constructed by constructing the tangent to a single circle of radius \(r_0 - r_1\) centered at \(p_0\) and through \(p_1\), then translating this line segment along the radius through \(p_0\) a distance \(r_1\). See J. Casey, "A sequel to the First Six Books of the Elements of Euclid", pp. 31-32, 1888.

Parameters
pCircPointer to another circle.
[out]t0Line segment descriptor for first common tangent.
[out]t1Line segment descriptor for second common tangent.
Returns
true if tangents exist.