Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <GL/glut.h>
- #include<stdio.h>
- #include<math.h>
- #include<algorithm>
- double x=0, y=0, d = .3, z = 0, r, g, b, n1=1, n2=1, n3=1, t1=0,t2=0,t3=0;
- bool fiQ, sQ, tQ, fQ;
- void drawRectangle(){
- glBegin(GL_QUADS);
- glVertex3f(x+d,y+d,z);
- glVertex3f(x+d,y-d,z);
- glVertex3f(x-d,y-d,z);
- glVertex3f(x-d,y+d,z);
- glEnd();
- }
- void changeColor(){
- if(fiQ) glColor3f(1,1,0);
- if(sQ) glColor3f(1,0,1);
- if(tQ) glColor3f(0,1,1);
- if(fQ) glColor3f(.7,.3,.2);
- }
- void display (void) {
- glClearColor (0.0,0.0,0.0,1.0);
- glClear (GL_COLOR_BUFFER_BIT);
- glLoadIdentity();
- gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
- glScalef(n1,n2,n3);
- glTranslatef(t1,t2,t3);
- changeColor();
- drawRectangle();
- glFlush();
- glutSwapBuffers();
- }
- void reshape (int w, int h) {
- glViewport (0, 0, (GLsizei)w, (GLsizei)h);
- glMatrixMode (GL_PROJECTION);
- glLoadIdentity ();
- gluPerspective (30, 1, 1.0, 100.0);
- glMatrixMode (GL_MODELVIEW);
- }
- void keyboard(unsigned char key, int x, int y){
- if(key=='R'||key=='r'){
- glColor3f(1,0,0);
- }
- if(key=='G'||key=='g'){
- glColor3f(0,1,0);
- }
- if(key=='B'||key=='b'){
- glColor3f(0,0,1);
- }
- if(key=='E'||key=='e'){
- n1 += .1;
- n2 += .1;
- if(n1>2) n1=2;
- if(n2>2) n2 = 2;
- }
- if(key=='S'||key=='s'){
- n1 -= .1;
- n2 -= .1;
- if(n1<0) n1 = 0;
- if(n2<0) n2 = 0;
- }
- //glutPostRedisplay();
- }
- void specialKeyboard(int key, int x, int y){
- if(key==GLUT_KEY_UP){
- t2+=.1;
- if(t2>2)t2=2;
- }
- if(key==GLUT_KEY_DOWN){
- t2-=.1;
- if(t2<-2)t2=-2;
- }
- if(key==GLUT_KEY_LEFT){
- t1-=.1;
- if(t1<-2)t1=-2;
- }
- if(key==GLUT_KEY_RIGHT){
- t1+=.1;
- if(t1>2)t1=2;
- }
- fiQ=sQ=tQ=fQ=false;
- if(x<=400){
- if(y<=400){
- sQ=true;
- }
- else tQ=true;
- }
- else{
- if(y<=400) fiQ=true;
- else fQ=true;
- }
- printf("%d %d\n",x,y);
- }
- void main (int argc, char **argv)
- {
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_SINGLE);
- glutInitWindowSize(800,800);
- glutInitWindowPosition(250,30);
- glutCreateWindow("Rotation");
- glutDisplayFunc(display);
- glutReshapeFunc(reshape);
- glutIdleFunc(display);
- glutKeyboardFunc(keyboard);
- glutSpecialFunc(specialKeyboard);
- glutMainLoop();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement