#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <GL\glut.h>
#include <iostream.h>
class Wcpt2d
{
public:
GLfloat x,y;
};
void display(void)
{
Wcpt2d P1,P2,P3;
Wcpt2d Pa,Pb;
GLint i,n;
GLfloat t,inc;
n=200;
inc=(GLfloat)1/n;
t=0;
P1.x=0;
P1.y=180;
P2.x=80;
P2.y=-160;
P3.x=160;
P3.y=180;
Pa=P1;
glClear (GL_COLOR_BUFFER_BIT);
glColor3f (1.0, 0.0, 0.0);
for(i=1;i<n;i++)
{
t+=inc;
Pb.x=(P3.x-2*P2.x+P1.x)*t*t+2*(P2.x-P1.x)*t+P1.x;
Pb.y=(P3.y-2*P2.y+P1.y)*t*t+2*(P2.y-P1.y)*t+P1.y;
glBegin(GL_LINES);
glVertex2f(Pa.x, Pa.y);
glVertex2f(Pb.x, Pb.y);
glEnd();
Pa=Pb;
}
glFlush();
}
void init(void)
{
glClearColor (1.0, 1.0, 1.0, 0.0);
glLoadIdentity();
glShadeModel (GL_PROJECTION);
gluOrtho2D(0.0,200.,0.,150.);
}
void main(int argc, char** argv){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE| GLUT_RGB);
glutInitWindowSize (500, 400);
glutInitWindowPosition (30, 30);
glutCreateWindow("实验1_2");
init();
glutDisplayFunc(display);
glutMainLoop();
}
评论0