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

Line shape. More...

#include <Line.h>

Inheritance diagram for CLine:
CShape CShapeCommon CLineSeg CKinematicLineSeg

Public Member Functions

 CLine (const Vector2 &, float)
 Constructor. 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 bool PreCollide (CContactDesc &)
 Collision detection. 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

Vector2 Intersect (const CLine &)
 Get intersection point with line. More...
 
Vector2 ClosestPt (const Vector2 &)
 Get closest point on line. More...
 

Protected Attributes

float m_fGradient = 0.0f
 Gradient.
 
float m_fInverseGradient = 0.0f
 Inverse gradient.
 
float m_fYIntercept = 0.0f
 Intercept with Y axis.
 
float m_fXIntercept = 0.0f
 Intercept with X axis.
 
- 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 line is infinite in both directions. It consists of its gradient \(m\) and \(y\)-incercept \(c\), that is, it has the equation \(y = mx + c\). The gradient can be infinite, in that case it has the equation \(x = b\), where \(b\) is its \(x\)-intercept. Note that there is no line descriptor class CLineDesc. That is to discourage the use of lines outside this project. If you are thinking of using one, I recommend that you use a line segment instead.

Constructor & Destructor Documentation

◆ CLine()

CLine::CLine ( const Vector2 &  p,
float  m 
)

Given a point and a gradient, construct the unique line through that point with that gradient.

Parameters
pPoint.
mGradient.

Member Function Documentation

◆ ClosestPt()

Vector2 CLine::ClosestPt ( const Vector2 &  p)
protected

Given a point, find the point on this line that is closest to it. This is done by intersecting this line with a line through p perpendicular to it.

Parameters
pA point.
Returns
The point on this line that is closest to it.

◆ Intersect()

Vector2 CLine::Intersect ( const CLine Line)
protected

Given another line, find the unique point that is on both lines if they are not parallel, otherwise fail. We have to careful whem one or both of the lines are vertical because vertical lines have infinite gradient.

Parameters
LineA line to intersect with.
Returns
Point of intersection of this line with that one, if there is one.