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

Arc shape. More...

#include <Arc.h>

Inheritance diagram for CArc:
CCircle CShape CShapeCommon CKinematicArc

Public Member Functions

 CArc (CArcDesc &)
 Constructor. More...
 
bool PreCollide (CContactDesc &)
 Collision detection. More...
 
bool PtInSector (const Vector2 &)
 Point in sector test. More...
 
void GetEndPts (Vector2 &, Vector2 &)
 Get end points. More...
 
void GetTangents (Vector2 &, Vector2 &)
 Get tangents. More...
 
- Public Member Functions inherited from CCircle
 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 Member Functions

void Update ()
 Update from angles and radius. More...
 
float PtToAngle (const Vector2 &)
 Point to angle.
 

Protected Attributes

Vector2 m_vPt0
 Point 0.
 
Vector2 m_vPt1
 Point 1.
 
float m_fAngle0
 Angle from center to point 0.
 
float m_fAngle1
 Angle from center to point 1.
 
Vector2 m_vTangent0
 Tangent at point 0.
 
Vector2 m_vTangent1
 Tangent at point 1.
 
- Protected Attributes inherited from CCircle
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

An arc represents a portion of the circumference of a circle bounded by a pair of angles. If the first angle is smaller than the second angle, then the arc extends from the first angle to the second angle in a counterclockwise direction. If the first angle is greater than the second angle, then the arc extends from the first angle to the second angle in a clockwise direction. If the first angle is the same as the second angle, then you are an idiot.

Constructor & Destructor Documentation

◆ CArc()

CArc::CArc ( CArcDesc r)

Constructs an arc described by an arc descriptor.

Parameters
rArc descriptor.

Member Function Documentation

◆ GetEndPts()

void CArc::GetEndPts ( Vector2 &  p0,
Vector2 &  p1 
)

Reader function for the end points.

Parameters
p0[out] First end point.
p1[out] Second end point.

◆ GetTangents()

void CArc::GetTangents ( Vector2 &  v0,
Vector2 &  v1 
)

Reader function for the tangents. Tangents are returned in the same order as GetEndPoints().

Parameters
v0[out] Tangent at fist end point.
v1[out] Tangent at second end point.

◆ PreCollide()

bool CArc::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.

◆ PtInSector()

bool CArc::PtInSector ( const Vector2 &  p)

Draw imaginary lines from the center of this arc (meaning the center of the circle containing it) to its end points and continue them on infinitely. A point is said to be inside the sector if it is between those two lines.

Parameters
pA point.
Returns
true if p is inside the sector defined by this arc.

◆ Update()

void CArc::Update ( )
protected

Update the arc properties from its center, radius, and angles. The end points, tangents, and AABB are recomputed.