Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Mar 19th, 2010 | Syntax: None | Size: 3.16 KB | Hits: 76 | Expires: Never
This paste has a previous version, view the difference. Copy text to clipboard
  1. //#include<windows.h>
  2. #include<stdio.h>
  3. #include<stdlib.h>
  4. #include<string.h>
  5. #include<math.h>
  6. #include<GL/gl.h>
  7. #include<GL/glu.h>
  8. #include<GL/glut.h>
  9. #include<iostream>
  10. using namespace std;
  11.  
  12. #define WIDTH 800
  13. #define HEIGHT 600
  14.  
  15. #define radius 5
  16. int pp,qq;
  17. int fflag=0;
  18.  
  19. double dx, dy, dz, Q, zp;
  20. struct h{
  21.                 int xpos;
  22.                 int ypos;
  23. } sampleH, obj;
  24.  
  25. void reshape(int width, int height){
  26.                 glViewport(0, 0, width, height);
  27.                 glMatrixMode(GL_PROJECTION);
  28.                 glLoadIdentity();
  29. //      glOrtho(-WIDTH/2,WIDTH/2-1,-HEIGHT/2,HEIGHT/2-1,-1,1);
  30.                 glOrtho(0,WIDTH,0,HEIGHT,0,1);
  31.         //      glOrtho(0,WIDTH,HEIGHT,0,0,1);
  32.                 glMatrixMode(GL_MODELVIEW);
  33.                 glLoadIdentity();
  34. }
  35. void init(void){
  36.                 glClearColor(0.0,0.0,0.0,1.0);
  37. }
  38. struct h make2DD(int x, int y, int z){
  39.                 zp = -200; Q = 100000; dx = .1; dy = .15;
  40.                 dz = sqrt(1 - pow(dx, 2) - pow(dy, 2));
  41.                 double down = ((zp - z) / (Q * dz)) + 1;
  42.                 sampleH.xpos= (x - (z * dx / dz) + (zp * dx / dz)) / down;
  43.                 sampleH.ypos = (y - (z * dy / dz) + (zp * dy / dz)) / down;
  44.                 return sampleH;
  45. }
  46. void mousehandle(int button,int status,int x0,int y0){
  47.                 pp=x0;
  48.                 qq=y0;
  49.                 int i,x,y,n,k,tempx,tempy,tempr;
  50.                 if(status==GLUT_DOWN){
  51.                                 printf("x0: %d y0: %d\n",x0,y0);
  52.                                 fflag=1;
  53.                                 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  54.                                 glColor4f(1.0,1.0,1.0,1.0);    
  55.                                 int i,j,k,l,m,n;
  56.                                 glBegin(GL_POINTS);
  57.  
  58.                                 //0 0 0 --- 0 1 1
  59.                                 for(i = 0; i < 256; i++){
  60.                                                 glColor3ub(0, i, i);
  61.                                                 obj = make2DD(0, i, i);
  62.                                                 glVertex2i(obj.xpos, obj.ypos);
  63.                                 }
  64.                                 //       0 1 1 -- 1 1 1
  65.  
  66.                                 for(k=0;k<256;k++){
  67.                                                 n=k;
  68.                                                 for(i = 0; i < 256; i++){
  69.                                                                 glColor3ub(i, 255-n, 255-n);
  70.                                                                 obj = make2DD(i, 255-n, 255-n);
  71.                                                                 tempx=obj.xpos;
  72.                                                                 tempy=obj.ypos;
  73.                                                                 tempr=sqrt((pp-tempx)*(pp-tempx)+(qq-tempy)*(qq-tempy));
  74.                                                                 if(tempr<=30){
  75.                                                                                 glColor3ub(1-i,1-(255-n),1-(255-n));
  76.                                                                                 glVertex2i(tempx,tempy);
  77.                                                                 }
  78.                                                 }
  79.                                 }
  80.  
  81.                                 //111 ---------  100
  82.                                 for(i = 0; i < 256; i++){
  83.                                                 glColor3ub(255, i, i);
  84.                                                 obj = make2DD(255, i, i);
  85.                                                 glVertex2i(obj.xpos, obj.ypos);
  86.                                 }
  87.                 }
  88. glEnd();
  89. glFlush();
  90. }
  91. void display(void){
  92.                 int tempx,tempy,tempr;
  93.                 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  94.                 glColor4f(1.0,1.0,1.0,1.0);    
  95.                 glBegin(GL_POINTS);
  96.                 int i,j,k;
  97.                 //0 0 0 --- 0 1 1
  98.                 for(i = 0; i < 256; i++){
  99.                                 glColor3ub(0, i, i);
  100.                                 obj = make2DD(0, i, i);
  101.                                 glVertex2i(obj.xpos, obj.ypos);
  102.                 }
  103.                 //       0 1 1 -- 1 1 1
  104.                 //111 ---------  100
  105.                 for(i = 0; i < 256; i++){
  106.                                 glColor3ub(255, i, i);
  107.                                 obj = make2DD(255, i, i);
  108.                                 glVertex2i(obj.xpos, obj.ypos);
  109.                 }
  110.  
  111.         glEnd();
  112.         glFlush();
  113. }
  114.  
  115. void Timer(int pp){
  116.                 glutPostRedisplay();
  117.                 glutTimerFunc(20, Timer, 0);
  118. }
  119.  
  120. void idle(void){
  121.                 /*...*/
  122.  
  123. }
  124.  
  125.  
  126. int main(int argc, char **argv){
  127.                 glutInit(&argc,argv);
  128.                 glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA | GLUT_DEPTH);
  129.                 glutInitWindowPosition(0,0);
  130.                 glutInitWindowSize(WIDTH, HEIGHT);
  131.                 glutCreateWindow(argv[0]);
  132.                 init();
  133.                 glutIdleFunc(idle);
  134.                 glutReshapeFunc(reshape);
  135.                 glutDisplayFunc(display);
  136.                 glutMouseFunc(mousehandle);
  137.                 //glutTimerFunc(0, Timer, 0);
  138.  
  139.                 glutMainLoop();
  140.                 return(1);
  141. }