1. 旋轉
1. 滑鼠右鍵,Swap translate / rotate
2. 公轉,自轉
glScalef (1.00 , 1.00 , 1.00 ) ; 縮放( x , y , z )
glBegin( .... );
.......
glBegin( .... );
.......
!!!!! 繞著世界轉最重要
3. 從下往上看程式碼才對
自轉:
glTranslatef ( 0.45 , 0.00 , 0.00 ) ; 有一個胖胖的旋轉25度移動到右邊的車子
glRotatef ( 51.0 , 0.00 , 1.00 , 0.00 ) ; 有一個胖胖的旋轉51度的車子
glScalef (1.79 , 1.00 , 1.00 ) ; 有一個變胖的車子
glBegin( .... ); 有一個車子
.......
公轉:
glRotatef ( 68.0 , 0.00 , 1.00 , 0.00 ) ; 有一個變胖移動到右邊旋轉1度的車子
glTranslatef ( 0.41 , 0.00 , 0.00 ) ; 有一個變胖移動到右邊的車子
glScalef (1.20 , 1.00 , 1.00 ) ; 有一個變胖的車子
glBegin( .... ); 有一個車子
.......
2. 自製
1. 下載github
2. 開GLUT檔
3. 新增程式碼
#include <GL/glut.h>
#include <stdio.h>
float vx[2000],vy[2000]; ///準備很多頂點
int N=0; ///有N個頂點
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f(1,1,0); ///加顏色
glBegin(GL_LINE_LOOP); ///也可以是GL_TRIANGLE_FAN 就可以有其他形狀
for(int i=0;i<N;i++)
{
glVertex2f(vx[i],vy[i]);
}
glEnd();
glutSwapBuffers();
}
void mouse(int buttin,int state,int x,int y)
{
}
void motion(int x,int y)
{
printf("%d %d\n",x,y); ///把頂點記下來
vx[N] = (x-150)/150.0;
vy[N] = -(y-150)/150.0;
N++;
display();
}
int main(int argc,char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH );
glutCreateWindow("Week05 drawing");
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutMainLoop();
}



沒有留言:
張貼留言