-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtest.cpp
executable file
·71 lines (68 loc) · 1.36 KB
/
test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <GL/glu.h>
#include <GL/freeglut.h>
#include <iostream>
#include <math.h>
#include<stdlib.h>
#include<stdio.h>
using namespace std;
#define ROUND(x) ((int)(x+0.5))
int xa,xb,ya,yb;
void display (void)
{
int dx=xb-xa,dy=yb-ya,steps,k;
float xIncrement,yIncrement,x=xa,y=ya;
glClear (GL_COLOR_BUFFER_BIT);
glColor3f (1.0, 0.0, 0.0);
if(abs(dx)>abs(dy))
steps=abs(dx);
else steps=abs(dy);
xIncrement=dx/(float)steps;
yIncrement=dy/(float)steps;
glBegin(GL_POINTS);
glVertex2s(ROUND(x),ROUND(y));
for(k=0;k<steps;k++)
{
x+=xIncrement;
y+=yIncrement;
glVertex2s(ROUND(x),ROUND(y));
printf("%lf %lf\n",x,y);
}
glColor3f (1.0, 1.0, 1.0);
for(int i=-100 ; i<=100 ; i++)
{
glVertex2s(i,0);
glVertex2s(0,i);
}
for(int i=-2; i<=2 ; i++)
{
glVertex2s(95+i,4+i);
glVertex2s(95-i,4+i);
}
for(int i=0; i<=2 ; i++)
{
glVertex2s(4+i,95+i);
glVertex2s(4-i,95+i);
glVertex2s(4,95-i);
}
glEnd();
glFlush();
}
void init(void)
{
glClearColor (0.0, 0.0, 0.0, 0.0);
glOrtho(-100.0, 100.0, -100.0, 100.0, -1.0, 1.0);
}
int main(int argc, char** argv)
{
printf("Enter the points\n");
scanf("%d %d %d %d",&xa,&ya,&xb,&yb);
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (500, 500);
glutInitWindowPosition (100, 100);
glutCreateWindow ("Simple DDA ");
init ();
glutDisplayFunc(display);
glutMainLoop();
return 0;
}