#include <windows.h>
#include <GL/glut.h>
GLint width=300,height=300;
static GLdouble angle,displace,scale=1,rPace,tPace;
GLdouble rAcc=0.0001d,tAcc=0.0000001d,state=1;
GLint interval=4096;
void triangle(GLfloat x1,GLfloat y1,GLfloat z1,GLfloat x2,GLfloat y2,GLfloat z2,GLfloat x3,GLfloat y3,GLfloat z3)
{
glBegin(GL_TRIANGLES);
glVertex3f(x1,y1,z1);
glVertex3f(x2,y2,z2);
glVertex3f(x3,y3,z3);
glEnd();
}
void init(void)
{
glClearColor(1,1,1,1);
glEnable(GL_DEPTH_TEST);
}
void reshape(GLint w,GLint h)
{
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(0,(GLfloat)w/(GLfloat)h,1,30);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glRotatef(-45,1,0,0);
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(0,displace,0);
glRotatef(angle,0,1,0);
glScalef(scale,scale,scale);
// a(0,0.12,0) b(-0.5,-0.7,-0.29) c(0.5,-0.7,-0.29) d(0,-0.7,0.58)
glColor3f(1,0,0); // abc
triangle(0,0.12,0,-0.5,-0.7,-0.29,0.5,-0.7,-0.29);
glColor3f(0,1,0); // abd
triangle(0,0.12,0,-0.5,-0.7,-0.29,0,-0.7,0.58);
glColor3f(0,0,1); // acd
triangle(0,0.12,0,0.5,-0.7,-0.29,0,-0.7,0.58);
glColor3f(0.5,0.5,0.5); // bcd
triangle(-0.5,-0.7,-0.29,0.5,-0.7,-0.29,0,-0.7,0.58);
glPopMatrix();
glFlush();
}
void idle()
{
if (state>2*interval)
state=1;
if (state++<=interval)
{
angle+=rPace;
displace+=tPace;
scale-=0.8/interval;
rPace+=rAcc;
tPace+=tAcc;
}
else
{
angle+=rPace;
displace-=tPace;
scale+=0.8/interval;
rPace-=rAcc;
tPace-=tAcc;
}
glutPostRedisplay();
}
int main()
{
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(width,height);
glutCreateWindow("Tetrahedron");
glutIdleFunc(idle);
init();
glutReshapeFunc(reshape);
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
OpenGL 旋轉的正三棱錐
最后編輯于 :
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。
- 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事。” “怎么了?”我有些...
- 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發上,一...
- 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側響起,我...
推薦閱讀更多精彩內容
- 沒有多少人知道印度著名演員Vishal Malhotra(維沙爾)與已故的老將Pran有關,Pran是維沙爾妻子拉...