main.cpp
Dosyayı İndir
#include <GL/glut.h>
#include <stdlib.h>
class vector{
public:
vector(){
vector::vector(0.0, 0.0, 0.0);
}
vector(GLfloat _x, GLfloat _y, GLfloat _z){
x = _x;
y = _y;
z = _z;
}
GLfloat x;
GLfloat y;
GLfloat z;
};
class color{
public:
color(){
vector::vector(1.0, 1.0, 1.0);
}
color(GLfloat _red, GLfloat _green, GLfloat _blue){
red = _red;
green = _green;
blue = _blue;
}
GLfloat red;
GLfloat green;
GLfloat blue;
};
color COLOR_1(0.0, 1.0, 1.0);
color COLOR_2(1.0, 1.0, 0.0);
color COLOR_3(1.0, .0, 1.0);
GLUquadric* quadric;
void draw_system(double width, double height, double depth){
GLdouble radius=0.05;
glPushMatrix();
glColor3f(1.0, 0.0, 0.0);
gluCylinder(quadric, radius, radius, 10, 30, 30);
glRotatef(90,0.0, 1.0, 0.0);
glColor3f(0.0, 1.0, 0.0);
gluCylinder(quadric, radius, radius, 10, 30, 30);
glRotatef(270, 1.0, 0.0, 0.0);
glColor3f(0.0, 0.0, 1.0);
gluCylinder(quadric, radius, radius, 10, 30, 30);
glPopMatrix();
}
void draw_prism(vector& translation, vector& scale,color& color){
glPushMatrix();
glTranslatef(translation.x, translation.y, translation.z);
glScalef(scale.x, scale.y, scale.z);
glColor3f(color.red, color.green, color.blue);
glutSolidCube(1.0);
glColor3f(0.0, 0.0, 1.0);
glutWireCube(1.0);
glPopMatrix();
}
void draw_all(){
gluLookAt(5.0, 5.0, 10.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
draw_system(1, 1, 1);
vector translation1(0, 0, 0);
vector scale1(3, 3, 3);
draw_prism(translation1, scale1,COLOR_1);
vector translation2(0, 0, 3);
vector scale2(2, 2, 2);
draw_prism(translation2, scale2,COLOR_2);
vector translation3(0, 0, 5);
vector scale3(1, 1, 1);
draw_prism(translation3, scale3, COLOR_3);
}
void init(void)
{
quadric = gluNewQuadric();
glClearColor(0.0, 0.0, 0.0, 0.0);
glShadeModel(GL_FLAT);
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
draw_all();
glFlush();
}
void reshape(int w, int h)
{
glViewport(0, 0, (GLsizei)w, (GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-1.0, 1.0, -1.0, 1.0, 1.5, 20.0);
glMatrixMode(GL_MODELVIEW);
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(500, 500);
glutInitWindowPosition(100, 100);
glutCreateWindow(argv[0]);
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}
Dosyayı İndir