#include <stdio.h>
#include <math.h>
#include <GL/gl.h>
#include <GL/glut.h>
#include <time.h>
#define maxWD 640
#define maxHT 480
#define thetaSpeed 0.05
void delay(unsigned int mseconds)
{
clock_t goal=mseconds+clock();
while(goal>clock());
}
void myInit(void)
{
glClearColor(0.0,0.0,0.0,0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,maxWD,0.0,maxHT);
glClear(GL_COLOR_BUFFER_BIT);
glFlush();
}
void drawPoint(int x, int y)
{
glPointSize(7.0);
glColor3f(0.0f,1.0f,0.0f);
glBegin(GL_POINTS);
glVertex2i(x,y);
glEnd();
}
void rotateAroundPt(int px, int py, int cx, int cy)
{
float theta=0.0;
while(1)
{
glClear(GL_COLOR_BUFFER_BIT);
int xf, yf;
#include <math.h>
#include <GL/gl.h>
#include <GL/glut.h>
#include <time.h>
#define maxWD 640
#define maxHT 480
#define thetaSpeed 0.05
void delay(unsigned int mseconds)
{
clock_t goal=mseconds+clock();
while(goal>clock());
}
void myInit(void)
{
glClearColor(0.0,0.0,0.0,0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,maxWD,0.0,maxHT);
glClear(GL_COLOR_BUFFER_BIT);
glFlush();
}
void drawPoint(int x, int y)
{
glPointSize(7.0);
glColor3f(0.0f,1.0f,0.0f);
glBegin(GL_POINTS);
glVertex2i(x,y);
glEnd();
}
void rotateAroundPt(int px, int py, int cx, int cy)
{
float theta=0.0;
while(1)
{
glClear(GL_COLOR_BUFFER_BIT);
int xf, yf;
theta=theta+thetaSpeed;
if(theta>=(2.0*3.14159))
theta=theta-(2.0*3.14159);
xf=cx+(int)((float)(px-cx)*cos(theta))-((float)(py-cy)*sin(theta));
yf=cy+(int)((float)(px-cx)*sin(theta))+((float)(py-cy)*cos(theta));
drawPoint(cx,cy);
drawPoint(xf,yf);
glFlush();
delay(500);
}
}
void translatePoint(int px, int py, int tx, int ty)
{
int fx=px, fy=py;
glClear(GL_COLOR_BUFFER_BIT);
px=px+tx;
py=py+ty;
drawPoint(px,py);
glFlush();
}
void scalePoint(int px,int py, int sx, int sy)
{
int fx, fy;
glClear(GL_COLOR_BUFFER_BIT);
drawPoint(px,py);
fx=px*sx;
fy=py*sy;
drawPoint(fx,fy);
}
void myDisplay(void)
{
int opt;
printf("*\nEnter\n\t<1> for translation"
"\n\t<2> for roatation"
"\n\t<3> for scaling\n\t:");
scanf("%d",&opt);
printf("\nGo to the window...");
if(theta>=(2.0*3.14159))
theta=theta-(2.0*3.14159);
xf=cx+(int)((float)(px-cx)*cos(theta))-((float)(py-cy)*sin(theta));
yf=cy+(int)((float)(px-cx)*sin(theta))+((float)(py-cy)*cos(theta));
drawPoint(cx,cy);
drawPoint(xf,yf);
glFlush();
delay(500);
}
}
void translatePoint(int px, int py, int tx, int ty)
{
int fx=px, fy=py;
glClear(GL_COLOR_BUFFER_BIT);
px=px+tx;
py=py+ty;
drawPoint(px,py);
glFlush();
}
void scalePoint(int px,int py, int sx, int sy)
{
int fx, fy;
glClear(GL_COLOR_BUFFER_BIT);
drawPoint(px,py);
fx=px*sx;
fy=py*sy;
drawPoint(fx,fy);
}
void myDisplay(void)
{
int opt;
printf("*\nEnter\n\t<1> for translation"
"\n\t<2> for roatation"
"\n\t<3> for scaling\n\t:");
scanf("%d",&opt);
printf("\nGo to the window...");
switch(opt)
{
case 1:
translatePoint(100,200,1,5);
break;
case 2:
rotateAroundPt(200,200,maxWD/2, maxHT/2);
break;
case 3:
scalePoint(10,20,2,3);
break;
}
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(maxWD,maxHT);
glutInitWindowPosition(100,150);
glutCreateWindow("Transforming Point");
glutDisplayFunc(myDisplay);
myInit();
glutMainLoop();
return 0;
}
{
case 1:
translatePoint(100,200,1,5);
break;
case 2:
rotateAroundPt(200,200,maxWD/2, maxHT/2);
break;
case 3:
scalePoint(10,20,2,3);
break;
}
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(maxWD,maxHT);
glutInitWindowPosition(100,150);
glutCreateWindow("Transforming Point");
glutDisplayFunc(myDisplay);
myInit();
glutMainLoop();
return 0;
}

Comments
Post a Comment