Results 1 to 8 of 8

Thread: Simple collision detection problem

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2009
    Posts
    11

    Simple collision detection problem

    Suppose we have a moving quad.

    How can we detect collision of the quad with the borders of a window?

  2. #2
    Senior Member Frequent Contributor scratt's Avatar
    Join Date
    May 2008
    Location
    Thailand
    Posts
    555

    Re: Simple collision detection problem

    Are you working in 2D or 3D?

    If it's 2D and you have an Ortho view then it could be as simple as an x,y range check.

    If it's 3D then you the solution is somewhat different..

  3. #3
    Junior Member Newbie
    Join Date
    Dec 2009
    Posts
    2

    Re: Simple collision detection problem

    ok in 3d?

  4. #4
    Junior Member Newbie
    Join Date
    Dec 2009
    Posts
    2

    Re: Simple collision detection problem

    Ok if it is in 3d?

  5. #5
    Junior Member Newbie
    Join Date
    Dec 2009
    Posts
    11

    Re: Simple collision detection problem

    Its just a simple 2d square. I'd like to see some code if possible.

  6. #6
    Senior Member Regular Contributor
    Join Date
    Mar 2003
    Location
    Los Angeles
    Posts
    374

    Re: Simple collision detection problem

    You'd get a more enthusiastic response if you posted your code and asked for help. That way we'd know that you've put some effort into solving the problem. Also you could post a screen capture. What does your program do now? Does it generate a static square on the screen? Forgetting about collision detection for a moment, can you move the square using a clock function, or interactively via the keyboard? If you can do all that, solving the collision detection problem would be trivial. If you can't do it, then you have much more basic problems than collision detection.
    Am I doing your homework for you?

  7. #7
    Senior Member Regular Contributor
    Join Date
    Jul 2005
    Location
    Pennsylvannia
    Posts
    103

    Re: Simple collision detection problem

    is it a 2d square in a 2d world? or a 2d square in a 3d world?

    either way.. you would need to consider both your modelview transformation matrix, and your perspective transformation matrix.
    Striving for proficiency...

  8. #8
    Junior Member Newbie
    Join Date
    Jul 2010
    Posts
    4

    Re: Simple collision detection problem

    #ifdef COLLISION
    float tmp_dx, tmp_dy;
    for(int k=0; k<BNUM-1; k++){
    for (int l=k+1; l<BNUM; l++){
    if((ball[k].x+BSIZE > ball[l].x-BSIZE &amp;&amp; ball[k].x-BSIZE < ball[l].x+BSIZE)&amp;&amp;
    (ball[k].y+BSIZE > ball[l].x-BSIZE &amp;&amp; ball[k].y-BSIZE < ball[l].y+BSIZE)){
    if(ball[k].x - ball[l].x > ball[k].y - ball[l].y){
    if(ball[l].x > ball[k].x){
    ball[l].x=ball[k].x+2*BSIZE;
    }else{
    ball[l].x=ball[k].x-2*BSIZE;
    }
    tmp_dx=ball[l].dx;
    ball[l].dx=ball[k].dx*PERCENT_AFTER_BOUNCE;
    ball[k].dx=tmp_dx*PERCENT_AFTER_BOUNCE;
    }else{
    if(ball[l].y > ball[k].y){
    ball[l].y=ball[k].y+2*BSIZE;
    }else{
    ball[l].y=ball[k].y-2*BSIZE;
    }
    tmp_dy=ball[l].dy;
    ball[l].dy=ball[k].dy*PERCENT_AFTER_BOUNCE;
    ball[k].dy=tmp_dy*PERCENT_AFTER_BOUNCE;
    }
    num_bounce++;
    ball[k].collided=1;
    ball[l].collided=1;
    break;
    }
    }
    }
    #endif

Similar Threads

  1. Replies: 3
    Last Post: 07-14-2012, 02:14 PM
  2. Collision Detection Problem
    By tjames221188 in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 03-10-2011, 08:38 AM
  3. Simple particle collision detection in shader.
    By imported_rocketmagnet in forum OpenGL: GLSL
    Replies: 1
    Last Post: 08-02-2009, 06:33 AM
  4. Simple Collision Detection Problem
    By in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 10-06-2003, 07:58 AM
  5. collision-detection problem
    By martinzwigl in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 08-30-2001, 08:51 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean