CGL_AS7[1]
CGL_AS7[1]
ASSIGNMENT:07
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<windows.h>
#include<GL/glut.h>
using namespace std;
class Point
{
public:
float x,y;
void setxy(float x2,float y2)
{
x=x2;y=y2;
}
const Point & operator=(const Point &rPoint)
{
x=rPoint.x;
y=rPoint.y;
return *this;
}
};
int factorial(int n)
{
if(n<=1)
return(1);
else
n=n*factorial(n-1);
return n;
}
Point abc[20];
int SCREEN_HEIGHT=500;
int points=0;
int clicks=4;
void myInit()
{
glClearColor(0.0,0.0,0.0,0.0);
glColor3f(1.0,1.0,1.0);
glPointSize(3);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,500.0,0.0,500.0);
}
void drawDot(int x,int y)
{
glBegin(GL_POINTS);
glVertex2i(x,y);
glEnd();
glFlush();
}
void drawLine(Point p1,Point p2)
{
glBegin(GL_LINES);
glVertex2f(p1.x,p1.y);
glVertex2f(p2.x,p2.y);
glEnd();
glFlush();
}
Point drawBezier(Point PT[],double t)
{
Point P;
P.x=pow((1-t),3)*PT[0].x+3*t*pow((1-t),2)*PT[1].x+3*(1-t)*pow(t,2)*PT[2].x+pow(t,3)*PT[3].x;
P.y=pow((1-t),3)*PT[0].y+3*t*pow((1-t),2)*PT[1].y+3*(1-t)*pow(t,2)*PT[2].y+pow(t,3)*PT[3].y;
return P;
}
Point drawBezierGeneralized(Point PT[],double t)
{
Point P;
P.x=0;P.y=0;
for (int i=0;i<clicks;i++)
{
P.x=P.x+binomial_coff((float)(clicks-1),(float)i)*pow(t,(double)i)*pow((1-t),(clicks-1-
i))*PT[i].x;
P.y=P.y+binomial_coff((float)(clicks-1),(float)i)*pow(t,(double)i)*pow((1-t),(clicks-1-
i))*PT[i].y;
}
return P;
}
void myDisplay()
{
glClear(GL_COLOR_BUFFER_BIT);
glFlush();
}
OUTPUT: