PDA

View Full Version : Multiple CL_CollisionOutline Objects and another minor question



0000000100
08-01-2011, 07:49 PM
Hello, I am new to ClanLib SDK, and I have some questions about CollsionDetection System, and if someone could be so kind to help me :)

1. If I have 100 objects of the same type, I don't think it's a good idea to create for everyone a CL_CollisionObject for every object ? It will be just a waste of memory... I was to thinking to use just one CL_CollisionObject for every type of object, but there is a problem then I need to check collision between two objects of the same type ( collision will always return true ). Some advice about this ?

2. About CL_CollisionOutline constuctor:
CL_CollisionOutline (const CL_StringRef &resource_id, CL_ResourceManager *manager) , can't find more about this, does this mean that we can store *.out files inside a resource file ? If yes, what are the tags for this?

And one more question, what "Apple OpenGL ES 2.0 initial support" from "ClanLib 2.3.0 Release Notes" means ? will we be able to compile our code for iOS devices ? :)

Tnx everyone who can help me a bit with these questions :)

rombust
08-03-2011, 07:37 PM
I think ClanLib requires some better examples using CL_Collision.

1) A moving object colliding with a static background (which can be extrapolated to 2 objects moving - since A+a_delta == B + b_delta - is the same as A + a_delta - b_delta == B)
This can be tricky to the programmer, since if the object is fast (eg 8 pixels), it may pass through the collision area (eg 7 pixels width)

2) Basic collision using multiple objects

3) Collision using animated CL_Sprites

Until then (if someone creates some examples)

See - http://clanlib.org/wiki/MainDocs:Collision_Detection
Also Tests/Displays/Collision (in the source package)

Ref iOS devices, see http://www.rtsoft.com/forums/showthread.php?3883-Methane-V1.5.1-Release

A developer got it to work, the modifications were merged in. But I don't know if it currently works. (if he is reading this, i'm sure he'll reply)

0000000100
08-04-2011, 05:58 PM
So what about collisionOutline constructor ? Can I create a outline from xml resource file? Or it is used to take a png file from resource?

rombust
08-04-2011, 06:42 PM
Sorry, I don't know. I have never used CL_Collision in my own code.

Have a look inside CL_Collision code.

Unless someone else can help

sphair
08-04-2011, 07:05 PM
Use the source, Luke!


CL_CollisionOutline::CL_CollisionOutline(const CL_StringRef &resource_id, CL_ResourceManager *manager)
{
resource = manager->get_resource(resource_id);
if (resource.get_type() != "collisionoutline")
throw CL_Exception(cl_format("Resource '%1' is not of type 'collisionoutline'", resource_id));


so, first thing we notice is that the resource type has to be collisionoutline.


data = CL_SharedPtr<CL_ResourceData_CollisionOutline>(new CL_ResourceData_CollisionOutline(resource));


secondly, the rest of the interesting code is separated into a class called CL_ResourceData_CollisionOutline.


CL_ResourceData_CollisionOutline::CL_ResourceData_ CollisionOutline(CL_Resource &resource)
{
CL_String filename = resource.get_element().get_attribute("file");
int alpha_limit = CL_StringHelp::text_to_int( (resource.get_element().get_attribute("alpha_value", "128")));
CL_String accuracy_str = resource.get_element().get_attribute("accuracy", "medium");
CL_OutlineAccuracy accuracy;

if(accuracy_str == "high")
accuracy = accuracy_high;
else if(accuracy_str == "medium")
accuracy = accuracy_medium;
else if(accuracy_str == "low")
accuracy = accuracy_low;
else if(accuracy_str == "poor")
accuracy = accuracy_poor;
else
accuracy = accuracy_raw;

CL_CollisionOutline_Generic *outline;

if (filename.length() >= 3 && filename.substr(filename.length()-3, 3) == "out" )
{
outline = new CL_CollisionOutline_Generic(
new CL_OutlineProviderFile(filename, resource.get_manager().get_directory(resource)), accuracy_raw);
}
else
{
CL_PixelBuffer pbuf = CL_ImageProviderFactory::load(filename, resource.get_manager().get_directory(resource), "");
outline = new CL_CollisionOutline_Generic(
new CL_OutlineProviderBitmap(pbuf, alpha_limit), accuracy );
}

CL_CollisionOutline *collision_outline_tmp =
new CL_CollisionOutline(outline->contours, outline->width, outline->height);

....
}


We can now easily read what kind of structure it expects from the xml:

file = filename, which can be a .out file, or an image.
alpha_limit = alpha limit used for extracting if its an image.
accuracy = high, medium, low, poor or raw accuracy if its an image.

Examples:
<collisionoutline file="mysprite.col"/>
<collisionoutline file="mysprite.png" accuracy="medium" alpha_limit="128"/>