Thread: Having trouble with planar collision detection

  1. #1
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    968

    Having trouble with planar collision detection

    Right now I'm using this function:
    Code:
    	bool planeCollision2d(vector2 plane1, vector2 plane2)
    	{
    		vector2 vec;
    		vec = plane1 - plane2;
    		if(vec.dot_product(normalized(plane1)) > 1)
    		{
    			return false;
    		}
    		else return true;
    	}
    In this way:
    Code:
    	void check_paddle_collision()
    	{	
    		if (planeCollision2d(border.topLeft, player1->paddle->getMaximum()))
    		{
    			player1->paddle->getLocation().y = 70;
    		}
    		else if(planeCollision2d(border.bottomLeft, player1->paddle->getMinimum()))
    		{
    			player1->paddle->getLocation().y = -70;
    		}
    		if (planeCollision2d(border.topRight, player2->paddle->getMaximum()))
    		{
    			player2->paddle->getLocation().y = 70;
    		}
    		else if(planeCollision2d(border.bottomRight, player2->paddle->getMinimum()))
    		{
    			player2->paddle->getLocation().y = -70;
    		}	
    	}
    And everything appears to be working.

    Is there anything wrong with what I'm doing?
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

  2. #2
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    On a side note -
    Code:
    		if(vec.dot_product(normalized(plane1)) > 1)
    		{
    			return false;
    		}
    		else return true;
    is the same as
    Code:
    return vec.dot_product(normalized(plane1)) <= 1;

  3. #3
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    968
    Okay actually it doesn't appear to be working.

    It seems to work fine when I do this:
    Code:
    	void check_paddle_collision()
    	{	
    		if (planeCollision2d(border.topLeft, player1->paddle->getMaximum()))
    		{
    			player1->paddle->getLocation().y = 70;
    		}
    		else if(planeCollision2d(border.bottomLeft, player1->paddle->getMinimum()))
    		{
    			player1->paddle->getLocation().y = -70;
    		}
    		if (planeCollision2d(border.topRight, player2->paddle->getMaximum()))
    		{
    			player2->paddle->getLocation().y = 70;
    		}
    		else if(planeCollision2d(border.bottomRight, player2->paddle->getMinimum()))
    		{
    			player2->paddle->getLocation().y = -70;
    		}	
    	}
    But not when I do this:

    Code:
    		if(ball->getVelocity().y > 0)
    		{
    			if (planeCollision2d(border.topRight, ball->getMaximum()))
    			{
    				reverse_y_velocity(ball->getVelocity());
    			}
    		}
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Collision Detection Problems
    By Dark_Phoenix in forum Game Programming
    Replies: 1
    Last Post: 12-17-2006, 03:25 PM
  2. Collision Detection
    By Grantyt3 in forum C++ Programming
    Replies: 3
    Last Post: 09-30-2005, 03:21 PM
  3. trouble understanding collision detection code
    By silk.odyssey in forum Game Programming
    Replies: 5
    Last Post: 06-16-2004, 02:27 PM
  4. bounding box collision detection
    By DavidP in forum Game Programming
    Replies: 7
    Last Post: 07-07-2002, 11:43 PM
  5. Replies: 4
    Last Post: 05-03-2002, 09:40 PM