Hi
I have created a class(.h&.cpp) and I used the following code.Here the problem is both the object are moving but I want make the cube which is created by the function “glutWireCube(5);” should move inside that room which made by glBegin&glEnd(QUAD).
Here I’m giving the code which I made,can any one plz help me on this issue
void MFCOpenGL::Display(void)
{
glDrawBuffer(GL_FRONT_LEFT);
//glColor3f(1, 1, 1);
glClearColor(1,1,1,1);//set the background color to black
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
//Image Starts
glBegin(GL_QUADS);
glColor3d(1.0, 0.0, 0.0);
glVertex2d(0.0, 0.0);
glVertex2d(10.4, -1.4);
glVertex2d(10.45, 10.5);
glVertex2d(0.0, 10.7);
glEnd();
glBegin(GL_QUADS);
glColor3d(0.0, 1.0, 0.0);
glVertex2d(-10.5, -1.4);
glVertex2d(0.0, 0.0);
glVertex2d(10.0, 10.7);
glVertex2d(-10.5, 10.5);
glEnd();
glBegin(GL_QUADS);
glColor3d(0.0, 0.0,0.0);
glVertex2d(-10.5, -1.4);
glVertex2d(10.4, -1.4);
glVertex2d(0.0, 0.0);
glVertex2d(0.0,-8.45);
glEnd();
glPushMatrix();
glTranslatef(-10, 10, -10);
glColor3f(1.0f, 0.0f, 0.0f); //set cube color
glutWireCube(5); //use the premade glut function to draw
//a wire cube
glPopMatrix();
glutPostRedisplay();
glutSwapBuffers();
}
void MFCOpenGL::Resize(int width,int height)
{
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0, (float)width / (float)height, 0.1, 1000.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// Set the viewing position and orientation
gluLookAt(
0.0, 0.0, 200.0, // eye location
0.0, 0.0, 0.0, // center location
0.0, 1.0, 0.0); // up vector
}
void MFCOpenGL::keyboard(int key, int x, int y)
{
switch (key)
{
case ‘a’:
case ‘A’:
glTranslatef(-10.0, 0.0, 0.0);
break;
case ‘d’:
case ‘D’:
glTranslatef(10.0, 0.0, 0.0);
break;
case ‘w’:
case ‘W’:
glTranslatef(0.0, 0.0, 10.0);
break;
case ‘s’:
case ‘S’:
glTranslatef(0.0, 0.0, -10.0);
break;
}
}
Thanks in advance