2018年3月12日 星期一

Week 03 滑鼠鍵盤應用

                                                     上課剛開始先複習GLUT範例程式,熟悉基本


                                                                           #include <GL/glut.h>
                                                                           void display()
                                                                                      {

                                                                                      }

                                                                        int main(int argc, char**argv)
                                                                                     {

                                                                                     }


利用滑鼠點擊 找出圖形座標
#include <stdio.h>
void mouse(int button,int state,int x,int y)
{
                                                  if(state==GLUT_DOWN) printf("glvertex2f(%f,%f);\n",(x-150)/150.0,-(y-150)/150.0);
}
加入Motion 滑動功能
float teapotX=0,teapotY=0;
void motion(int x, int y)
{
    teapotX=(x-150)/150.0;teapotY=-(y-150)/150.0;
    printf("%d %d\n",x,y);
    glutPostRedisplay();
}

沒有留言:

張貼留言