-下載windows裡的Transformation
-對軸轉動練習的網址:https://120.125.80.50/GL/opengl_TRT_demo.html
-點擊ToDraw即可開始畫圖
-將myDrawObject(0);移動到下面glTranslatef(0,0,0);
-滑鼠點擊右上角的angle,並按下空白鍵,圖形就會進行旋轉
-將myDrawObject(0);移動到glTranslatef(0,0,0);
-點擊glTranslatef(0,0,0);就可以拖曳移動圖形位置
會旋轉的茶壺
#include <GL/glut.h>
float angle=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef(angle , 0, 0, 1);
glTranslatef(0.4,-0.07,0);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
angle+=0.1;
}
int main(int argc,char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("week12 TRT");
glutIdleFunc(display);
glutDisplayFunc(display);
glutMainLoop();
}
-改程式碼,增加一個茶壺
程式碼:
#include <GL/glut.h>
float angle=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f(1,1,1);
glutSolidTeapot(0.3);
glPushMatrix();
glTranslatef(0.3,0,0);
glRotatef( angle,0,0,1);
glTranslatef(0.2,0,0);
glColor3f(1,0,0);
glutSolidTeapot(0.2);
glPopMatrix();
glutSwapBuffers();
angle+=0.1;
}
int main(int argc,char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week12 TRT");
glutIdleFunc(display);
glutDisplayFunc(display);
glutMainLoop();
}
程式碼:
#include <GL/glut.h>
float angle=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f(1,1,1);
glutSolidTeapot(0.3);
glPushMatrix();
glTranslatef(0.3,0,0);
glRotatef( angle,0,0,1);
glTranslatef(0.2,0,0);
glColor3f(1,0,0);
glutSolidTeapot(0.2);
glPushMatrix();
glTranslatef(0.2,0,0);
glRotatef( angle,0,0,1);
glTranslatef(0.2,0,0);
glColor3f(1,0,0);
glutSolidTeapot(0.2);
glPopMatrix();
glPopMatrix();
glutSwapBuffers();
angle+=0.1;
}
int main(int argc,char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week12 TRT");
glutIdleFunc(display);
glutDisplayFunc(display);
glutMainLoop();
}



沒有留言:
張貼留言