- //#include<windows.h>
- #include<stdio.h>
- #include<stdlib.h>
- #include<string.h>
- #include<math.h>
- #include<GL/gl.h>
- #include<GL/glu.h>
- #include<GL/glut.h>
- #include<iostream>
- using namespace std;
- #define WIDTH 800
- #define HEIGHT 600
- #define radius 5
- int pp,qq;
- int fflag=0;
- double dx, dy, dz, Q, zp;
- struct h{
- int xpos;
- int ypos;
- } sampleH, obj;
- void reshape(int width, int height){
- glViewport(0, 0, width, height);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- // glOrtho(-WIDTH/2,WIDTH/2-1,-HEIGHT/2,HEIGHT/2-1,-1,1);
- glOrtho(0,WIDTH,0,HEIGHT,0,1);
- // glOrtho(0,WIDTH,HEIGHT,0,0,1);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- }
- void init(void){
- glClearColor(0.0,0.0,0.0,1.0);
- }
- struct h make2DD(int x, int y, int z){
- zp = -200; Q = 100000; dx = .1; dy = .15;
- dz = sqrt(1 - pow(dx, 2) - pow(dy, 2));
- double down = ((zp - z) / (Q * dz)) + 1;
- sampleH.xpos= (x - (z * dx / dz) + (zp * dx / dz)) / down;
- sampleH.ypos = (y - (z * dy / dz) + (zp * dy / dz)) / down;
- return sampleH;
- }
- void mousehandle(int button,int status,int x0,int y0){
- pp=x0;
- qq=y0;
- int i,x,y,n,k,tempx,tempy,tempr;
- if(status==GLUT_DOWN){
- printf("x0: %d y0: %d\n",x0,y0);
- fflag=1;
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glColor4f(1.0,1.0,1.0,1.0);
- int i,j,k,l,m,n;
- glBegin(GL_POINTS);
- //0 0 0 --- 0 1 1
- for(i = 0; i < 256; i++){
- glColor3ub(0, i, i);
- obj = make2DD(0, i, i);
- glVertex2i(obj.xpos, obj.ypos);
- }
- // 0 1 1 -- 1 1 1
- for(k=0;k<256;k++){
- n=k;
- for(i = 0; i < 256; i++){
- glColor3ub(i, 255-n, 255-n);
- obj = make2DD(i, 255-n, 255-n);
- tempx=obj.xpos;
- tempy=obj.ypos;
- tempr=sqrt((pp-tempx)*(pp-tempx)+(qq-tempy)*(qq-tempy));
- if(tempr<=30){
- glColor3ub(1-i,1-(255-n),1-(255-n));
- glVertex2i(tempx,tempy);
- }
- }
- }
- //111 --------- 100
- for(i = 0; i < 256; i++){
- glColor3ub(255, i, i);
- obj = make2DD(255, i, i);
- glVertex2i(obj.xpos, obj.ypos);
- }
- }
- glEnd();
- glFlush();
- }
- void display(void){
- int tempx,tempy,tempr;
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glColor4f(1.0,1.0,1.0,1.0);
- glBegin(GL_POINTS);
- int i,j,k;
- //0 0 0 --- 0 1 1
- for(i = 0; i < 256; i++){
- glColor3ub(0, i, i);
- obj = make2DD(0, i, i);
- glVertex2i(obj.xpos, obj.ypos);
- }
- // 0 1 1 -- 1 1 1
- //111 --------- 100
- for(i = 0; i < 256; i++){
- glColor3ub(255, i, i);
- obj = make2DD(255, i, i);
- glVertex2i(obj.xpos, obj.ypos);
- }
- glEnd();
- glFlush();
- }
- void Timer(int pp){
- glutPostRedisplay();
- glutTimerFunc(20, Timer, 0);
- }
- void idle(void){
- /*...*/
- }
- int main(int argc, char **argv){
- glutInit(&argc,argv);
- glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA | GLUT_DEPTH);
- glutInitWindowPosition(0,0);
- glutInitWindowSize(WIDTH, HEIGHT);
- glutCreateWindow(argv[0]);
- init();
- glutIdleFunc(idle);
- glutReshapeFunc(reshape);
- glutDisplayFunc(display);
- glutMouseFunc(mousehandle);
- //glutTimerFunc(0, Timer, 0);
- glutMainLoop();
- return(1);
- }
