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

void clan::CollisionOutline::calculate_convex_hulls ( )

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

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.

void clan::CollisionOutline::calculate_radius ( )

(Re)calculate the radius of the outline.

void clan::CollisionOutline::calculate_smallest_enclosing_discs ( )

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

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

(Re)calculate the subcircle segmentation of the outline.

void clan::CollisionOutline::clean_collision_info ( )

This will empty the collision-info vector.

CollisionOutline clan::CollisionOutline::clone ( ) const

Makes a copy of the current collision outline.

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
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.
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.
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.
void clan::CollisionOutline::enable_collision_info ( bool  points = true,
bool  normals = false,
bool  metadata = false,
bool  pen_depth = false 
)

Enable collision info gathering.

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

Get the translation origin and hotspot of the outline.

float clan::CollisionOutline::get_angle ( ) const

Returns the rotation angle.

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)

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

Fetch the state of the collision testing variables.

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

Returns the contours in the outline.

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

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

bool clan::CollisionOutline::get_inside_test ( ) const

Returns true if completely-inside test is used.

Circlef clan::CollisionOutline::get_minimum_enclosing_disc ( ) const

Returns the radius of the outline.

float get_radius() const;

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

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

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

Get the rotation hotspot of the outline.

Pointf clan::CollisionOutline::get_scale ( ) const

Returns the scaling factor.

Pointf clan::CollisionOutline::get_translation ( ) const

Returns the position of the outline.

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

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

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
bool clan::CollisionOutline::point_inside ( const Pointf point) const

Returns true if a point is inside the outline.

Parameters
point= the point to test.
void clan::CollisionOutline::rotate ( const Angle angle)

Rotate the outline by angle (in degrees).

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

Write the outline to a file.

Parameters
fullname= Name of file.
void clan::CollisionOutline::save ( const std::string &  filename,
FileSystem file_system 
) const

Save.

Parameters
filename= The filename
directory= Virtual Directory
void clan::CollisionOutline::save ( IODevice file) const

Save.

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

Set the translation hotspot of the outline.

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

Set the angle (in degrees) of the outline.

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

This will set the collision info of the outline.

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

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

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

Set the rotation hotspot of the outline.

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

Set the scale of the outline.

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: