clan::CollisionOutline Class Reference

Collision detection outline. More...

#include <collision_outline.h>

Public Member Functions

Construction
 CollisionOutline ()
 Construct a collision outline. More...
 
 CollisionOutline (const PixelBuffer &pbuf, int alpha_limit=128, OutlineAccuracy accuracy=accuracy_medium)
 Construct a collision outline. More...
 
 CollisionOutline (const std::string &fullname, int alpha_limit=128, OutlineAccuracy accuracy=accuracy_medium, bool get_insides=true)
 Construct a collision outline. More...
 
 CollisionOutline (IODevice &file, const std::string &file_extension, int alpha_limit=128, OutlineAccuracy accuracy=accuracy_medium, bool get_insides=true)
 Constructs a CollisionOutline. More...
 
 CollisionOutline (const std::string &filename, const FileSystem &file_system, int alpha_limit=128, OutlineAccuracy accuracy=accuracy_medium, bool get_insides=true)
 Constructs a CollisionOutline. More...
 
 CollisionOutline (const std::vector< Contour > &contours, const Size &size, OutlineAccuracy accuracy)
 Construct a collision outline. More...
 
 ~CollisionOutline ()
 
Attributes
const Contourget_object_bounding_box () const
 Returns the contour used as an object bounding box. (an rotated rectangle) More...
 
Circlef get_minimum_enclosing_disc () const
 Returns the radius of the outline. More...
 
bool get_inside_test () const
 Returns true if completely-inside test is used. More...
 
std::vector< Contour > & get_contours ()
 Returns the contours in the outline. More...
 
const std::vector< Contour > & get_contours () const
 
Pointf get_translation () const
 Returns the position of the outline. More...
 
Pointf get_scale () const
 Returns the scaling factor. More...
 
float get_angle () const
 Returns the rotation angle. More...
 
unsigned int get_width () const
 Returns the width of the image this outline was created from. More...
 
unsigned int get_height () const
 Returns the height of the image this outline was created from. More...
 
void get_alignment (Origin &origin, float &x, float &y) const
 Get the translation origin and hotspot of the outline. More...
 
void get_rotation_hotspot (Origin &origin, float &x, float &y) const
 Get the rotation hotspot of the outline. More...
 
const std::vector< CollidingContours > & get_collision_info () const
 Return the info about the collisions. (collision points, normals, pointers to contours, and indexes to lines that intersected) More...
 
void get_collision_info_state (bool &points, bool &normals, bool &metadata, bool &pendepth) const
 Fetch the state of the collision testing variables. More...
 

Static Public Member Functions

Resources
static Resource< CollisionOutlineresource (const std::string &id, const ResourceManager &resources)
 Retrieves a CollisionOutline from the resource manager. More...
 
static CollisionOutline load (const std::string &id, const XMLResourceDocument &doc)
 Loads a CollisionOutline from a XML resource definition. More...
 

Operations

CollisionOutline clone () const
 Makes a copy of the current collision outline. More...
 
void optimize (unsigned char check_distance=3, float corner_angle=PI/5.0)
 Optimize the outline by removing redundant points. More...
 
void draw (float x, float y, const Colorf &color, Canvas &canvas)
 Draw outline on graphic context. More...
 
void draw_sub_circles (float x, float y, const Colorf &color, Canvas &canvas)
 Draw the subcircles surrounding the linesegments on graphic context. More...
 
void draw_smallest_enclosing_disc (float x, float y, const Colorf &color, Canvas &canvas)
 Draw the disc enclosing the entire outline. More...
 
void set_alignment (Origin origin, float x=0, float y=0)
 Set the translation hotspot of the outline. More...
 
void set_rotation_hotspot (Origin origin, float x=0, float y=0)
 Set the rotation hotspot of the outline. More...
 
void set_translation (float x, float y)
 Set the position of the outline. More...
 
void set_scale (float x, float y)
 Set the scale of the outline. More...
 
void set_angle (const Angle &angle)
 Set the angle (in degrees) of the outline. More...
 
void rotate (const Angle &angle)
 Rotate the outline by angle (in degrees). More...
 
void set_inside_test (bool value)
 Set to true if completely-inside test should be done. More...
 
void enable_collision_info (bool points=true, bool normals=false, bool metadata=false, bool pen_depth=false)
 Enable collision info gathering. More...
 
void set_collision_info (const std::vector< CollidingContours > &colinfo)
 This will set the collision info of the outline. More...
 
void clean_collision_info ()
 This will empty the collision-info vector. More...
 
void calculate_radius ()
 (Re)calculate the radius of the outline. More...
 
void calculate_sub_circles (float radius_multiplier=3.5)
 (Re)calculate the subcircle segmentation of the outline. More...
 
void calculate_smallest_enclosing_discs ()
 (Re)calculate the smallest circles enclosing every contour in the outline. More...
 
void calculate_convex_hulls ()
 (Re)calculate the convex hull for every contour in the outline More...
 
void save (const std::string &fullname) const
 Write the outline to a file. More...
 
void save (const std::string &filename, FileSystem &file_system) const
 Save. More...
 
void save (IODevice &file) const
 Save. More...
 
bool collide (const CollisionOutline &outline, bool remove_old_collision_info=true)
 Returns true if outlines overlap. More...
 
bool point_inside (const Pointf &point) const
 Returns true if a point is inside the outline. More...
 
static void calculate_penetration_depth (std::vector< CollidingContours > &collision_info)
 Will calculate the penetration_depth and penetration_normal for all colliding contours. More...
 

Detailed Description

Collision detection outline.

A collision outline is used in collision detection

Member Function Documentation

◆ calculate_convex_hulls()

void clan::CollisionOutline::calculate_convex_hulls ( )

(Re)calculate the convex hull for every contour in the outline

◆ calculate_penetration_depth()

static void clan::CollisionOutline::calculate_penetration_depth ( std::vector< CollidingContours > &  collision_info)
static

Will calculate the penetration_depth and penetration_normal for all colliding contours.

◆ calculate_radius()

void clan::CollisionOutline::calculate_radius ( )

(Re)calculate the radius of the outline.

◆ calculate_smallest_enclosing_discs()

void clan::CollisionOutline::calculate_smallest_enclosing_discs ( )

(Re)calculate the smallest circles enclosing every contour in the outline.

◆ calculate_sub_circles()

void clan::CollisionOutline::calculate_sub_circles ( float  radius_multiplier = 3.5)

(Re)calculate the subcircle segmentation of the outline.

◆ clean_collision_info()

void clan::CollisionOutline::clean_collision_info ( )

This will empty the collision-info vector.

◆ clone()

CollisionOutline clan::CollisionOutline::clone ( ) const

Makes a copy of the current collision outline.

◆ collide()

bool clan::CollisionOutline::collide ( const CollisionOutline outline,
bool  remove_old_collision_info = true 
)

Returns true if outlines overlap.

Parameters
outline= Outline to test against.
remove_old_collision_info= set to true to remove old collision info

◆ draw()

void clan::CollisionOutline::draw ( float  x,
float  y,
const Colorf color,
Canvas canvas 
)

Draw outline on graphic context.

Actual rendering position depends on the anchor and the alignment mode.

Parameters
x= Anchor position of where to render sprite.
y= Anchor y position
color= The color
gc= Graphic context on which to render upon.

◆ draw_smallest_enclosing_disc()

void clan::CollisionOutline::draw_smallest_enclosing_disc ( float  x,
float  y,
const Colorf color,
Canvas canvas 
)

Draw the disc enclosing the entire outline.

Actual rendering position depends on the anchor and the alignment mode.

Parameters
x= Anchor position of where to render the cirle.
y= Anchor y position
color= The color
gc= Graphic context on which to render upon.

◆ draw_sub_circles()

void clan::CollisionOutline::draw_sub_circles ( float  x,
float  y,
const Colorf color,
Canvas canvas 
)

Draw the subcircles surrounding the linesegments on graphic context.

Actual rendering position depends on the anchor and the alignment mode.

Parameters
x= Anchor position of where to render cirles.
y= Anchor y position
color= The color
gc= Graphic context on which to render upon.

◆ enable_collision_info()

void clan::CollisionOutline::enable_collision_info ( bool  points = true,
bool  normals = false,
bool  metadata = false,
bool  pen_depth = false 
)

Enable collision info gathering.

◆ get_alignment()

void clan::CollisionOutline::get_alignment ( Origin origin,
float &  x,
float &  y 
) const

Get the translation origin and hotspot of the outline.

◆ get_angle()

float clan::CollisionOutline::get_angle ( ) const

Returns the rotation angle.

◆ get_collision_info()

const std::vector<CollidingContours>& clan::CollisionOutline::get_collision_info ( ) const

Return the info about the collisions. (collision points, normals, pointers to contours, and indexes to lines that intersected)

◆ get_collision_info_state()

void clan::CollisionOutline::get_collision_info_state ( bool &  points,
bool &  normals,
bool &  metadata,
bool &  pendepth 
) const

Fetch the state of the collision testing variables.

◆ get_contours() [1/2]

std::vector<Contour>& clan::CollisionOutline::get_contours ( )

Returns the contours in the outline.

◆ get_contours() [2/2]

const std::vector<Contour>& clan::CollisionOutline::get_contours ( ) const

◆ get_height()

unsigned int clan::CollisionOutline::get_height ( ) const

Returns the height of the image this outline was created from.

◆ get_inside_test()

bool clan::CollisionOutline::get_inside_test ( ) const

Returns true if completely-inside test is used.

◆ get_minimum_enclosing_disc()

Circlef clan::CollisionOutline::get_minimum_enclosing_disc ( ) const

Returns the radius of the outline.

float get_radius() const;

◆ get_object_bounding_box()

const Contour& clan::CollisionOutline::get_object_bounding_box ( ) const

Returns the contour used as an object bounding box. (an rotated rectangle)

◆ get_rotation_hotspot()

void clan::CollisionOutline::get_rotation_hotspot ( Origin origin,
float &  x,
float &  y 
) const

Get the rotation hotspot of the outline.

◆ get_scale()

Pointf clan::CollisionOutline::get_scale ( ) const

Returns the scaling factor.

◆ get_translation()

Pointf clan::CollisionOutline::get_translation ( ) const

Returns the position of the outline.

◆ get_width()

unsigned int clan::CollisionOutline::get_width ( ) const

Returns the width of the image this outline was created from.

◆ optimize()

void clan::CollisionOutline::optimize ( unsigned char  check_distance = 3,
float  corner_angle = PI/5.0 
)

Optimize the outline by removing redundant points.

Parameters
check_distance= the distance of points compared on the outline
corner_angle= angle for a corner

◆ point_inside()

bool clan::CollisionOutline::point_inside ( const Pointf point) const

Returns true if a point is inside the outline.

Parameters
point= the point to test.

◆ rotate()

void clan::CollisionOutline::rotate ( const Angle angle)

Rotate the outline by angle (in degrees).

◆ save() [1/3]

void clan::CollisionOutline::save ( const std::string &  fullname) const

Write the outline to a file.

Parameters
fullname= Name of file.

◆ save() [2/3]

void clan::CollisionOutline::save ( const std::string &  filename,
FileSystem file_system 
) const

Save.

Parameters
filename= The filename
directory= Virtual Directory

◆ save() [3/3]

void clan::CollisionOutline::save ( IODevice file) const

Save.

Parameters
file= The file

◆ set_alignment()

void clan::CollisionOutline::set_alignment ( Origin  origin,
float  x = 0,
float  y = 0 
)

Set the translation hotspot of the outline.

◆ set_angle()

void clan::CollisionOutline::set_angle ( const Angle angle)

Set the angle (in degrees) of the outline.

◆ set_collision_info()

void clan::CollisionOutline::set_collision_info ( const std::vector< CollidingContours > &  colinfo)

This will set the collision info of the outline.

◆ set_inside_test()

void clan::CollisionOutline::set_inside_test ( bool  value)

Set to true if completely-inside test should be done.

◆ set_rotation_hotspot()

void clan::CollisionOutline::set_rotation_hotspot ( Origin  origin,
float  x = 0,
float  y = 0 
)

Set the rotation hotspot of the outline.

◆ set_scale()

void clan::CollisionOutline::set_scale ( float  x,
float  y 
)

Set the scale of the outline.

◆ set_translation()

void clan::CollisionOutline::set_translation ( float  x,
float  y 
)

Set the position of the outline.


The documentation for this class was generated from the following file: