ClanLib
2.3.7
|
Collision detection outline. More...
#include <collision_outline.h>
Public Member Functions | |
Construction | |
CL_CollisionOutline () | |
Construct a collision outline. More... | |
CL_CollisionOutline (const CL_PixelBuffer &pbuf, int alpha_limit=128, CL_OutlineAccuracy accuracy=accuracy_medium) | |
Construct a collision outline. More... | |
CL_CollisionOutline (const CL_StringRef &fullname, int alpha_limit=128, CL_OutlineAccuracy accuracy=accuracy_medium, bool get_insides=true) | |
Construct a collision outline. More... | |
CL_CollisionOutline (CL_IODevice &file, const CL_String &file_extension, int alpha_limit=128, CL_OutlineAccuracy accuracy=accuracy_medium, bool get_insides=true) | |
Constructs a CollisionOutline. More... | |
CL_CollisionOutline (const CL_StringRef &filename, const CL_VirtualDirectory &directory, int alpha_limit=128, CL_OutlineAccuracy accuracy=accuracy_medium, bool get_insides=true) | |
Constructs a CollisionOutline. More... | |
CL_CollisionOutline (const CL_StringRef &resource_id, CL_ResourceManager *manager) | |
Construct a collision outline. More... | |
CL_CollisionOutline (std::vector< CL_Contour > contours, int width, int height) | |
Construct a collision outline. More... | |
~CL_CollisionOutline () | |
Attributes | |
CL_Resource | resource |
Resource owning this outline, if any. More... | |
const CL_Contour & | get_object_bounding_box () const |
Returns the contour used as an object bounding box. (an rotated rectangle) More... | |
CL_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< CL_Contour > & | get_contours () |
Returns the contours in the outline. More... | |
const std::vector< CL_Contour > & | get_contours () const |
CL_Pointf | get_translation () const |
Returns the position of the outline. More... | |
CL_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 (CL_Origin &origin, float &x, float &y) const |
Get the translation origin and hotspot of the outline. More... | |
void | get_rotation_hotspot (CL_Origin &origin, float &x, float &y) const |
Get the rotation hotspot of the outline. More... | |
const std::vector < CL_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... | |
Operations | |
void | load (const CL_StringRef &fullname) |
Load the outline from file replacing the current data. More... | |
void | load (const CL_StringRef &filename, const CL_VirtualDirectory &directory) |
Load. More... | |
void | load (CL_IODevice &file) |
Load. More... | |
CL_CollisionOutline & | copy (const CL_CollisionOutline &other) |
Copy. This function is de-appreciated and is removed in ClanLib 2.4. Use clone() instead. More... | |
CL_CollisionOutline | clone () const |
Makes a copy of the current collision outline. More... | |
void | optimize (unsigned char check_distance=3, float corner_angle=CL_PI/5.0) |
Optimize the outline by removing redundant points. More... | |
void | draw (float x, float y, const CL_Colorf &color, CL_GraphicContext &gc) |
Draw outline on graphic context. More... | |
void | draw_sub_circles (float x, float y, const CL_Colorf &color, CL_GraphicContext &gc) |
Draw the subcircles surrounding the linesegments on graphic context. More... | |
void | draw_smallest_enclosing_disc (float x, float y, const CL_Colorf &color, CL_GraphicContext &gc) |
Draw the disc enclosing the entire outline. More... | |
void | set_alignment (CL_Origin origin, float x=0, float y=0) |
Set the translation hotspot of the outline. More... | |
void | set_rotation_hotspot (CL_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 CL_Angle &angle) |
Set the angle (in degrees) of the outline. More... | |
void | rotate (const CL_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< CL_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 CL_StringRef &fullname) const |
Write the outline to a file. More... | |
void | save (const CL_StringRef &filename, CL_VirtualDirectory &directory) const |
Save. More... | |
void | save (CL_IODevice &file) const |
Save. More... | |
bool | collide (const CL_CollisionOutline &outline, bool remove_old_collision_info=true) |
Returns true if outlines overlap. More... | |
bool | point_inside (const CL_Pointf &point) const |
Returns true if a point is inside the outline. More... | |
static void | calculate_penetration_depth (std::vector< CL_CollidingContours > &collision_info) |
Will calculate the penetration_depth and penetration_normal for all colliding contours. More... | |
Collision detection outline.
A collision outline is used in collision detection
CL_CollisionOutline::CL_CollisionOutline | ( | ) |
Construct a collision outline.
CL_CollisionOutline::CL_CollisionOutline | ( | const CL_PixelBuffer & | pbuf, |
int | alpha_limit = 128 , |
||
CL_OutlineAccuracy | accuracy = accuracy_medium |
||
) |
Construct a collision outline.
pbuf | = Find alpha outline from a pixel buffer |
alpha_limit | = Alpha limit for pixels considered solid (collidable) |
accuracy | = Amount of optimization of the outline (default medium) |
CL_CollisionOutline::CL_CollisionOutline | ( | const CL_StringRef & | fullname, |
int | alpha_limit = 128 , |
||
CL_OutlineAccuracy | accuracy = accuracy_medium , |
||
bool | get_insides = true |
||
) |
Construct a collision outline.
fullname | = Full name |
alpha_limit | = value |
accuracy | = Outline Accuracy |
get_insides | = bool |
CL_CollisionOutline::CL_CollisionOutline | ( | CL_IODevice & | file, |
const CL_String & | file_extension, | ||
int | alpha_limit = 128 , |
||
CL_OutlineAccuracy | accuracy = accuracy_medium , |
||
bool | get_insides = true |
||
) |
Constructs a CollisionOutline.
file | = IODevice |
file_extension | = String |
alpha_limit | = value |
accuracy | = Outline Accuracy |
get_insides | = bool |
CL_CollisionOutline::CL_CollisionOutline | ( | const CL_StringRef & | filename, |
const CL_VirtualDirectory & | directory, | ||
int | alpha_limit = 128 , |
||
CL_OutlineAccuracy | accuracy = accuracy_medium , |
||
bool | get_insides = true |
||
) |
Constructs a CollisionOutline.
filename | = String Ref |
directory | = Virtual Directory |
alpha_limit | = value |
accuracy | = Outline Accuracy |
get_insides | = bool |
CL_CollisionOutline::CL_CollisionOutline | ( | const CL_StringRef & | resource_id, |
CL_ResourceManager * | manager | ||
) |
Construct a collision outline.
resource_id | = The resource id |
manager | = The resource manager |
CL_CollisionOutline::CL_CollisionOutline | ( | std::vector< CL_Contour > | contours, |
int | width, | ||
int | height | ||
) |
Construct a collision outline.
contours | = The contours |
width | = The width |
height | = The height |
CL_CollisionOutline::~CL_CollisionOutline | ( | ) |
void CL_CollisionOutline::calculate_convex_hulls | ( | ) |
(Re)calculate the convex hull for every contour in the outline
|
static |
Will calculate the penetration_depth and penetration_normal for all colliding contours.
void CL_CollisionOutline::calculate_radius | ( | ) |
(Re)calculate the radius of the outline.
void CL_CollisionOutline::calculate_smallest_enclosing_discs | ( | ) |
(Re)calculate the smallest circles enclosing every contour in the outline.
void CL_CollisionOutline::calculate_sub_circles | ( | float | radius_multiplier = 3.5 ) |
(Re)calculate the subcircle segmentation of the outline.
void CL_CollisionOutline::clean_collision_info | ( | ) |
This will empty the collision-info vector.
CL_CollisionOutline CL_CollisionOutline::clone | ( | ) | const |
Makes a copy of the current collision outline.
bool CL_CollisionOutline::collide | ( | const CL_CollisionOutline & | outline, |
bool | remove_old_collision_info = true |
||
) |
Returns true if outlines overlap.
outline | = Outline to test against. |
remove_old_collision_info | = set to true to remove old collision info |
CL_CollisionOutline& CL_CollisionOutline::copy | ( | const CL_CollisionOutline & | other) |
Copy. This function is de-appreciated and is removed in ClanLib 2.4. Use clone() instead.
void CL_CollisionOutline::draw | ( | float | x, |
float | y, | ||
const CL_Colorf & | color, | ||
CL_GraphicContext & | gc | ||
) |
Draw outline on graphic context.
Actual rendering position depends on the anchor and the alignment mode.
x | = Anchor position of where to render sprite. |
y | = Anchor y position |
color | = The color |
gc | = Graphic context on which to render upon. |
void CL_CollisionOutline::draw_smallest_enclosing_disc | ( | float | x, |
float | y, | ||
const CL_Colorf & | color, | ||
CL_GraphicContext & | gc | ||
) |
Draw the disc enclosing the entire outline.
Actual rendering position depends on the anchor and the alignment mode.
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 CL_CollisionOutline::draw_sub_circles | ( | float | x, |
float | y, | ||
const CL_Colorf & | color, | ||
CL_GraphicContext & | gc | ||
) |
Draw the subcircles surrounding the linesegments on graphic context.
Actual rendering position depends on the anchor and the alignment mode.
x | = Anchor position of where to render cirles. |
y | = Anchor y position |
color | = The color |
gc | = Graphic context on which to render upon. |
void CL_CollisionOutline::enable_collision_info | ( | bool | points = true , |
bool | normals = false , |
||
bool | metadata = false , |
||
bool | pen_depth = false |
||
) |
Enable collision info gathering.
void CL_CollisionOutline::get_alignment | ( | CL_Origin & | origin, |
float & | x, | ||
float & | y | ||
) | const |
Get the translation origin and hotspot of the outline.
float CL_CollisionOutline::get_angle | ( | ) | const |
Returns the rotation angle.
const std::vector<CL_CollidingContours>& CL_CollisionOutline::get_collision_info | ( | ) | const |
Return the info about the collisions. (collision points, normals, pointers to contours, and indexes to lines that intersected)
void CL_CollisionOutline::get_collision_info_state | ( | bool & | points, |
bool & | normals, | ||
bool & | metadata, | ||
bool & | pendepth | ||
) | const |
Fetch the state of the collision testing variables.
std::vector<CL_Contour>& CL_CollisionOutline::get_contours | ( | ) |
Returns the contours in the outline.
const std::vector<CL_Contour>& CL_CollisionOutline::get_contours | ( | ) | const |
unsigned int CL_CollisionOutline::get_height | ( | ) | const |
Returns the height of the image this outline was created from.
bool CL_CollisionOutline::get_inside_test | ( | ) | const |
Returns true if completely-inside test is used.
CL_Circlef CL_CollisionOutline::get_minimum_enclosing_disc | ( | ) | const |
Returns the radius of the outline.
float get_radius() const;
const CL_Contour& CL_CollisionOutline::get_object_bounding_box | ( | ) | const |
Returns the contour used as an object bounding box. (an rotated rectangle)
void CL_CollisionOutline::get_rotation_hotspot | ( | CL_Origin & | origin, |
float & | x, | ||
float & | y | ||
) | const |
Get the rotation hotspot of the outline.
CL_Pointf CL_CollisionOutline::get_scale | ( | ) | const |
Returns the scaling factor.
CL_Pointf CL_CollisionOutline::get_translation | ( | ) | const |
Returns the position of the outline.
unsigned int CL_CollisionOutline::get_width | ( | ) | const |
Returns the width of the image this outline was created from.
void CL_CollisionOutline::load | ( | const CL_StringRef & | fullname) |
Load the outline from file replacing the current data.
Loads precompiled outlines
void CL_CollisionOutline::load | ( | const CL_StringRef & | filename, |
const CL_VirtualDirectory & | directory | ||
) |
Load.
filename | = The filename |
directory | = Virtual Directory |
void CL_CollisionOutline::load | ( | CL_IODevice & | file) |
Load.
file | = The file |
void CL_CollisionOutline::optimize | ( | unsigned char | check_distance = 3 , |
float | corner_angle = CL_PI/5.0 |
||
) |
Optimize the outline by removing redundant points.
check_distance | = the distance of points compared on the outline |
corner_angle | = angle for a corner |
bool CL_CollisionOutline::point_inside | ( | const CL_Pointf & | point) | const |
Returns true if a point is inside the outline.
point | = the point to test. |
void CL_CollisionOutline::rotate | ( | const CL_Angle & | angle) |
Rotate the outline by angle (in degrees).
void CL_CollisionOutline::save | ( | const CL_StringRef & | fullname) | const |
Write the outline to a file.
fullname | = Name of file. |
void CL_CollisionOutline::save | ( | const CL_StringRef & | filename, |
CL_VirtualDirectory & | directory | ||
) | const |
Save.
filename | = The filename |
directory | = Virtual Directory |
void CL_CollisionOutline::save | ( | CL_IODevice & | file) | const |
Save.
file | = The file |
void CL_CollisionOutline::set_alignment | ( | CL_Origin | origin, |
float | x = 0 , |
||
float | y = 0 |
||
) |
Set the translation hotspot of the outline.
void CL_CollisionOutline::set_angle | ( | const CL_Angle & | angle) |
Set the angle (in degrees) of the outline.
void CL_CollisionOutline::set_collision_info | ( | const std::vector< CL_CollidingContours > & | colinfo) |
This will set the collision info of the outline.
void CL_CollisionOutline::set_inside_test | ( | bool | value) |
Set to true if completely-inside test should be done.
void CL_CollisionOutline::set_rotation_hotspot | ( | CL_Origin | origin, |
float | x = 0 , |
||
float | y = 0 |
||
) |
Set the rotation hotspot of the outline.
void CL_CollisionOutline::set_scale | ( | float | x, |
float | y | ||
) |
Set the scale of the outline.
void CL_CollisionOutline::set_translation | ( | float | x, |
float | y | ||
) |
Set the position of the outline.
CL_Resource CL_CollisionOutline::resource |
Resource owning this outline, if any.