Can anyone help me to penetrate a cylinder in the cube(made up of Quads)?
code is here.
#include <GL/glut.h>
#include <GL/gl.h>
float angle;
float length, width, height, constx,consty, constz;
double xLocation, yLocation, zLocation,x,y,z;
void display()
{angle=100;
length=0.5; //x
width=0.5; //y
height=0.5; //z
constx=length;
consty=width;
constz=height;
xLocation=0.0; yLocation=0.0; zLocation=0.0;
x=0; y=0; z=-0.2;
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
glLoadIdentity();
glTranslated(xLocation, yLocation, zLocation);
glRotatef(angle, 0.5, 0.5, 0.0f);
glBegin(GL_QUADS);
// glTranslated(xLocation, yLocation, zLocation);
// FACE ONE!!
glColor4f(1.0f, 1.0f, 1.0f, 0.0f);
glVertex3f(length+x, consty+y, 0.0+z);
glVertex3f(0.0+x, consty+y, 0.0+z);
glVertex3f(0.0+x, consty+y, height+z);
glVertex3f(length+x, consty+y, height+z);
//glTranslated(xLocation, yLocation, zLocation);
// FACE TWO!!
glColor4f(1.0f, 0.0f, 1.0f, 1.0f);//glColor4f(0.0f, 1.0f, 0.0f, 1.0f);
glVertex3f(constx+x, width+y, 0.0+z);
glVertex3f(constx+x, width+y, height+z);
glVertex3f(constx+x, 0.0+y, height+z);
glVertex3f(constx+x, 0.0+y, 0.0+z);
// glTranslated(xLocation, yLocation, zLocation);
// FACE THREE!!
glColor4f(0.0f, 0.0f, 0.0f, 1.0f);//glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
glVertex3f(length+x, width+y, constz+z);
glVertex3f(0.0+x, width+y, constz+z);
glVertex3f(0.0+x, 0.0+y, constz+z);
glVertex3f(length+x, 0.0+y, constz+z);
// glTranslated(xLocation, yLocation, zLocation);
// FACE FOUR!!
glColor4f(1.0f, 1.0f, 0.0f, 1.0f);//glColor4f(0.0f, 0.0f, 1.0f, 1.0f); yellow =facefour
glVertex3f(length+x, width+y, 0.0+z);
glVertex3f(0.0+x, width+y, 0.0+z);
glVertex3f(0.0+x, 0.0+y, 0.0+z);
glVertex3f(length+x, 0.0+y, 0.0+z);
// glTranslated(xLocation, yLocation, zLocation);
// FACE FIVE!!
glColor4f(0.0f, 1.0f, 0.0f, 1.0f);//glColor4f(1.0f, 1.0f, 0.0f, 1.0f); green=face five
glVertex3f(constx+x, width+y, 0.0+z);
glVertex3f(constx+x, width+y, height+z);
glVertex3f(constx+x, 0.0+y, height+z);
glVertex3f(constx+x, 0.0+y, 0.0+z);
// glTranslated(xLocation, yLocation, zLocation);
// FACE SIX!!
glColor4f(0.0f, 0.0f, 0.0f, 1.0f);//glColor4f(0.0f, 1.0f, 1.0f, 1.0f); balck=face six
glVertex3f(length+x, 0.0+y, 0.0+z);
glVertex3f(0.0+x, 0.0+y, 0.0+z);
glVertex3f(0.0+x, 0.0+y, height+z);
glVertex3f(length+x, 0.0+y, height+z);
glEnd();
glutSwapBuffers();
}
void rotation(int timer)
{
angle += 0.5f;
glutTimerFunc(1000 / 50, rotation, timer);
}
void framerate(int timer)
{
glutPostRedisplay();
glutTimerFunc(1000 / 100, framerate, timer);
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_RGBA | GLUT_DOUBLE);
glutInitWindowPosition(0, 0);
glutInitWindowSize(600, 600);
glutCreateWindow("dimension3");
glEnable(GL_BLEND);
glutDisplayFunc(display);
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
//glutTimerFunc(1000 / 100, framerate, 1);
//glutTimerFunc(1000 / 50, rotation, 2);
glutMainLoop();
return 0;
}