Results 1 to 4 of 4

Thread: Collision...

  1. #1
    Lesser Wizard
    Join Date
    Jun 2007
    Posts
    109

    Default Collision...

    Basically, I don't need much more than basic bounding box testing for my project, however, I do want the ability to rotate rects.

    Quads do pretty much exactly that, but their API is fairly limited. They do have the ability to fetch the containing rect of their rotation, but it's not precise (just an unrotated rect that encompasses the size of the rotation).

    I thought it might be smart to generate a collision outline from a quad using the points, but running into API road blocks again. Is there anyway to do this?

    I would use collision outlines but they seemingly only have the ability to scale -- I can't set the individual point data easily. At least, I can't figure out how.

    Anyone able to nudge me in the right direction? Again, rects/quads are as complex as I need, but detecting collisions within a quad is not naturally supported by ClanLib, and I can't figure out how to use my quad data to generate a collision outline on the fly.

    Thanks all,
    -Dan

  2. #2
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    Quote Originally Posted by catch22 View Post
    Basically, I don't need much more than basic bounding box testing for my project, however, I do want the ability to rotate rects.

    Quads do pretty much exactly that, but their API is fairly limited. They do have the ability to fetch the containing rect of their rotation, but it's not precise (just an unrotated rect that encompasses the size of the rotation).
    [snip]
    I am not sure that I understand.

    CL_Quad - Integer based
    CL_Quadf - Float based
    CL_Quadd - Double based

    These classes have public member variables: p, q, r, s for the 4 corners of the quad.

    For example:
    Code:
    CL_Quad
    quad.p = CL_Vec2i(-10, -10);
    quad.q = CL_Vec2i(10, -10);
    quad.r = CL_Vec2i(10, 10);
    quad.s = CL_Vec2i(-10, 10);
    quad.rotate(CL_Vec2i(0,0), CL_Angle(45, cl_degrees));
    quad.p, quad.q, quad.r, quad.s contains the rotated points.

    Note - For floats, and double quads:
    - These constructers are missing
    Code:
    	CL_Quadf(const CL_Rectf &rect) : CL_Quadx<float>(rect) {}
    	CL_Quadd(const CL_Rectd &rect) : CL_Quadx<float>(rect) {}
    They currently only have CL_Rect &rect

  3. #3

    Default

    Quote Originally Posted by catch22 View Post
    I thought it might be smart to generate a collision outline from a quad using the points, but running into API road blocks again. Is there anyway to do this?
    In the collision overview documentation there's the following code example (under the topic internal operation):

    Code:
    	CL_SurfaceOutline outline;
    
    	CL_Contour contour;
    	contour.points.push_back( CL_Pointf(0.0f,0.0f) );
    	contour.points.push_back( CL_Pointf(0.0f,100.0f) );
    	outline.get_contours().push_back(contour);
    	outline.calculate_radius();
    	outline.calculate_sub_circles();
    Should you want to do a specialized quad-quad overlap checker then that's fairly simple using CL_Line2f::get_intersection and CL_Triangle:: point_inside. First intersect all the quad line segments using CL_Line. If that doesn't give you a positive you need to check if one quad is completely inside the other. To do that you use CL_Triangle:: point_inside to check if one of the quad vertices is inside either of the triangles the other quad consists of.

    I'm sure there's also some mathematically elegant way to do this...

  4. #4
    Lesser Wizard
    Join Date
    Jun 2007
    Posts
    109

    Default

    Thanks Harry! Can't believe I missed that in the docs... Whoops.

Similar Threads

  1. Collision thingy
    By attle in forum Novashell Game Creation System
    Replies: 2
    Last Post: 04-29-2009, 11:25 PM
  2. vista bug and collision request
    By attle in forum Novashell Game Creation System
    Replies: 2
    Last Post: 06-19-2008, 03:27 AM
  3. help with weird collision bug...
    By harrio in forum Novashell Game Creation System
    Replies: 2
    Last Post: 03-24-2008, 12:59 PM
  4. Collision Detection in SpriteRTS Example
    By manicmark in forum Official ClanLib SDK Forums
    Replies: 0
    Last Post: 09-23-2007, 12:51 AM
  5. Collision bug in latest build
    By whisperstorm in forum Novashell Game Creation System
    Replies: 1
    Last Post: 01-28-2007, 01:29 AM

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •