資源簡介
適合初學者,賺點積分,計算機圖形學實驗課完全自學,不容易啊QAQ
代碼片段和文件信息
//?random.cpp?:?定義控制臺應用程序的入口點。
//
//?random.cpp?:?定義控制臺應用程序的入口點。
//
#include?“stdafx.h“
#include?
#include?
GLfloat?theta?=?0.0size=20.0xrot=0yrot=300step=0.01R1=0R2R3;?//?全局變量
bool?updownleftright=true;
#define?DEGREES_TO_RADIANS?3.14159/180.0
void?Mouse(int?btnint?stateint?xint?y)
{
//if?(btn==GLUT_LEFT_BUTTON?&&?state?==?GLUT_DOWN)
}
void?MouseMove(int?xmoveint?ymove)
{
}
//畫矩形函數
void?drawrect(int?xstartint?ystartint?xendint?yend)
{
??????glBegin(GL_POLYGON);
?????????glVertex2i(xstartystart);
?????glVertex2i(xstartyend);
?????glVertex2i(xendyend);
?????glVertex2i(xendystart);
?glVertex2i(xstartystart);
?????glEnd();
}
//畫三角形函數
void?drawtriangle(int?xstartint?ystartint?xendint?yend)
{
?glBegin(GL_POLYGON);
?????????glVertex2i(xstartystart);
?????glVertex2i(xendyend);
?glVertex2i(xstartyend);
?????glEnd();
}
void?circle(float?xrot1float?yrot1)
{
?glBegin(GL_POLYGON);
?????glVertex2f(xrot1+size*sin(theta*DEGREES_TO_RADIANS)yrot1+size*cos(theta*DEGREES_TO_RADIANS));
?????glVertex2f(xrot1+size*sin((theta+60)*DEGREES_TO_RADIANS)yrot1+size*cos((theta+60)*DEGREES_TO_RADIANS));
?glVertex2f(xrot1+size*sin((theta+120)*DEGREES_TO_RADIANS)yrot1+size*cos((theta+120)*DEGREES_TO_RADIANS));
?????glVertex2f(xrot1+size*sin((theta+180)*DEGREES_TO_RADIANS)yrot1+size*cos((theta+180)*DEGREES_TO_RADIANS));
?????glVertex2f(xrot1+size*sin((theta+240)*DEGREES_TO_RADIANS)yrot1+size*cos((theta+240)*DEGREES_TO_RADIANS));
?????glVertex2f(xrot1+size*sin((theta+300)*DEGREES_TO_RADIANS)yrot1+size*cos((theta+300)*DEGREES_TO_RADIANS));
???glEnd();
}
void?rect(float?x1float?y1float?x2float?y2float?x3float?y3float?x4float?y4)
{
glBegin(GL_POLYGON);
?????glVertex2f(x1y1);
?glVertex2f(x2y2);
?glVertex2f(x3y3);
?glVertex2f(x4y4);
???glEnd();
}
void?display()
{
float?y1y2xrot1yrot1xrot2yrot2;
int?handmove=0;
int?flag=0;
y1=yrot-50.0;
getchar();
???y2=yrot-100.0;
???glClear(GL_COLOR_BUFFER_BIT);
???glColor3f?(0.0?1.0?0.0);
????rect(xrot-20+R1y2-130xrot-20y2xrot-10y2xrot-10+R1y2-130);
glColor3f?(1.0?1.0?1.0);
???drawrect(xrot-30yrot-30xrot+30yrot+30);???
???
???glBegin(GL_POLYGON);
?????glVertex2f(xrot-50y1-100);
?????glVertex2f(xrot-50y1);
?glVertex2f(xrot+50y1);
?????glVertex2f(xrot+50y1-100);
???glEnd();
???//
???glColor3f?(1.0?0.0?0.0);
???drawrect(xrot-5-handmoveyrot-130xrot+5-handmoveyrot-60);
???drawrect(xrot-5+handmoveyrot-130xrot+5+handmoveyrot-60);
??glColor3f?(0.0?1.0?0.0);
???//drawrect(xrot-20y2-130x
評論
共有 條評論