Step1:茶壺會動
1. 畫茶壺
#include <GL/glut.h>
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutSolidTeapot(0.3);
glutSwapBuffers();
}
int main(int argc,char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("08160130");
glutDisplayFunc(display);
glutMainLoop();
}
2.加滑鼠程式
#include <GL/glut.h>
#include <stdio.h>
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutSolidTeapot(0.3);
glutSwapBuffers();
}
void mouse(int button,int state,int x,int y)
{
printf("button:%d state:%d x:%d y:%d\n",button,state,x,y);
}
int main(int argc,char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("08160130");
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMainLoop();
}
3. 用GL印出程式碼
#include <GL/glut.h>
#include <stdio.h>
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutSolidTeapot(0.3);
glutSwapBuffers();
}
void mouse(int button,int state,int x,int y)
{
if(state==GLUT_DOWN)
{
printf("glVertex3f((%d-150)/150.0,-(%d-150)/150.0,0);\n",x,y);
}
}
int main(int argc,char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("08160130");
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMainLoop();
}
4. 將黑窗的程式碼複製到codeblocks 就會顯示茶壺
5. 將程式碼更改成簡單的版本 讓茶壺移動更快速
#include <GL/glut.h>
#include <stdio.h>
float teapotX=0,teapotY=0; ///茶壺的座標
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix(); ///矩陣備份
glTranslatef(teapotX,teapotY,0); ///照著座標移動
glutSolidTeapot(0.3);
glPopMatrix(); ///矩陣還原
glEnd();
glutSwapBuffers();
}
void motion(int x, int y)
{
teapotX=(x-150)/150.0; ///換算座標
teapotY=-(y-150)/150.0;
display(); ///清除歷史
}
int main(int argc,char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("08160130");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}
Step2: 搞懂旋轉軸
glTranslatef ( 0.00 , 0.00 , 0.00 ) ; 移動( x , y , z )
glRotatef (0.0 , 0.00 , 1.00 , 0.00 ) ; 旋轉( 角度 , x , y , z )
glScalef (1.00 , 1.00 , 1.00 ) ; 縮放( x , y , z )
glBegin( .... );
Step3: Github
1. 前面的##後面加1個空格,會變標題
2. 前面的#後面加1個空格,會變大大的標題
2. 程式要加```才可以顯示
3. 超連結 [名字](網址)
4. 把網頁main改成gh-pages
5. 選主題
6. 網頁出現
沒有留言:
張貼留言