[準備上課囉!]
複習上週的內容Transformation
自轉(自己轉動)
程式碼:
#include <stdio.h>
float vx[2000], vy[2000]; ///準備一堆頂點,等一下要畫!!! 介於 -1 ~ +1
int N=0;///有N個頂點
void display()
{///我就是 等一下
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBegin(GL_LINE_LOOP);
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();
///減一半,再除一半,y加負號
}
int main(int argc, char ** argv)
{
glutInit(&argc, argv); ///(1) GLUT初始設定
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("Week05 drawing");
glutDisplayFunc(display);///第2週
glutMouseFunc(mouse);///第4週 按下去、彈起來
glutMotionFunc(motion);///第4週 mouse motion 在動(拖曳)/在畫
glutMainLoop();
}







沒有留言:
張貼留言