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?