-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscaling.cpp
executable file
·86 lines (83 loc) · 2.03 KB
/
scaling.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <GL/glut.h>
#include<math.h>
#include<stdio.h>
void scaling(float , float);
typedef struct Point
{
float x, y;
};
Point p[3]={ {50, 50}, {150, 50}, {100, 125}};
void drawTriangle(Point p[3])
{
glColor3f(0.0, 0.0, 0.0);
glBegin(GL_LINE_LOOP);
glVertex2i(p[0].x, p[0].y);
glVertex2i(p[1].x, p[1].y);
glVertex2i(p[2].x, p[2].y);
glEnd();
glFlush();
}
void display()
{
int opt;
float sx, sy;
glClearColor(1.0, 1.0, 1.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
drawTriangle(p);
printf("************ Traingle Scaling ***************");
printf("\n1. Scale along x-axis \n 2. Scale along y-axis \n 3. Scale along both x-axis and y-axis \n");
printf("Enter your option:");
scanf("%d", & opt);
switch(opt)
{
case 1: printf("\n Enter value for sx: ");
scanf("%f", &sx);
scaling(sx, 0);
break;
case 2: printf("\n Enter value for sy: ");
scanf("%f", &sy);
scaling(0, sy);
break;
case 3: printf("\n Enter value for sx : ");
scanf("%f", &sx);
printf("\n Enter value for sy : ");
scanf("%f", &sy);
scaling(sx, sy);
break;
default: return;
}
glFlush();
}
void scaling(float sx, float sy)
{ int i;
Point new_p[3];
for(i=0;i<3;i++)
{
if(sx !=0)
new_p[i].x = p[i].x * sx;
else
new_p[i].x=p[i].x;
if(sy!=0)
new_p[i].y = p[i].y * sy;
else
new_p[i].y=p[i].y;
}
drawTriangle(new_p);
}
void init(void)
{
glClearColor(1.0,1.0,1.0,0.0);
glMatrixMode(GL_PROJECTION);
gluOrtho2D(0.0,400.0,0.0,400.0);
}
int main(int argc, char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(400,400);
glutInitWindowPosition(500,100);
glutCreateWindow("2d Scaling");
init();
glutDisplayFunc(display);
glutMainLoop();
}