Collision Detection: What Am I Doing Wrong?

This is a discussion on Collision Detection: What Am I Doing Wrong? within the Game Programming forums, part of the General Programming Boards category; I've almost got this thing working. You're supposed to be able to push up against the other quad and move ...

  1. #1
    Registered User Wiser's Avatar
    Join Date
    Feb 2003
    Posts
    8

    Collision Detection: What Am I Doing Wrong?

    I've almost got this thing working. You're supposed to be able to push up against the other quad and move it, but it works a little differently.
    Code:
    void hitTesting();
    
    GLfloat xpos=-1.5f;
    GLfloat ypos=0.0f;
    
    GLfloat xpos2=0.0f;
    
    GLfloat left=-1.0f;
    GLfloat right=1.0f;
    GLfloat left2=-1.0f;
    GLfloat right2=1.0f;
    int DrawGLScene(GLvoid)
    {
    	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    	glLoadIdentity();
    	glTranslatef(xpos,ypos,-6.0f);	
    	
    	glColor3f(1.0f,1.0f,1.0f);
    	glBegin(GL_QUADS);
    		glVertex3f(left, 1.0f, 0.0f);
    		glVertex3f(right, 1.0f, 0.0f);
    		glVertex3f( right,-1.0f, 0.0f);
    		glVertex3f(left,-1.0f, 0.0f);
    	glEnd();
    
    	glLoadIdentity();
    	glColor3f(0.6f,0.0f,0.0f);
    	glTranslatef(xpos2,0.0f,-6.0f);
    		
    	glBegin(GL_QUADS);
    		glVertex3f( left2, 1.0f, 0.0f);
    		glVertex3f( right2, 1.0f, 0.0f);
    		glVertex3f( right2,-1.0f, 0.0f);
    		glVertex3f(left2,-1.0f, 0.0f);
    	glEnd();
    
    	hitTesting();
    	return TRUE;
    }
    
    void hitTesting()
    {
    	if (xpos>left2)
    		xpos2+=0.2f;
    	if (xpos<right2)
    		xpos2-=0.2f;
    }
    
    void KeyControl()
    {
    	if (keys[VK_UP])
    ypos+= 0.2f;
    	if (keys[VK_DOWN])
    ypos-= 0.2f;
    	if (keys[VK_RIGHT])
    xpos+= 0.2f;
    	if (keys[VK_LEFT])
    xpos-= 0.2f;
    }
    What am I doing wrong?

  2. #2
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020
    I think you got the directions the other way round. Try revert them all.

  3. #3
    Banned
    Join Date
    Jan 2003
    Posts
    1,708
    wiser = krak

  4. #4
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    thanks for the heads up Silver. He's been added to my ignore list.
    Away.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple 2-D Collision Detection
    By Tonto in forum Game Programming
    Replies: 4
    Last Post: 10-14-2006, 06:54 PM
  2. Collision Detection
    By cboard_member in forum Game Programming
    Replies: 2
    Last Post: 08-06-2005, 12:14 PM
  3. tile collision detection help needed...
    By werdy666 in forum Game Programming
    Replies: 0
    Last Post: 01-01-2003, 01:57 AM
  4. Bounding box collision detection?
    By Crossbow in forum Game Programming
    Replies: 5
    Last Post: 07-13-2002, 05:20 PM
  5. bounding box collision detection
    By DavidP in forum Game Programming
    Replies: 7
    Last Post: 07-07-2002, 11:43 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21