2018年3月16日 星期五

Week03 蔡育維

今天教了
(1)  GL_TRIANGLE_STRIP、GL_QUAD_STRIP......等

GL_QUAD_STRIP

QUAD是用四邊形畫出圖形

GL_TRIANGLE_STRIP 

TRIANGLE是用三角形來畫圖

(2) OpenGL
 1.mouse的按下、移動函數
 2.以滑鼠拖曳移動圖形
程式碼如下

#include <stdio.h>
#include <GL/glut.h>


void display();
void mouse(int,int,int,int);
void motion(int,int);

float potx=0,poty=0,oldx,oldy;
///oldx為用來記住原本滑鼠座標


int main(int argc,char **argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("Week03 Mouse");

    glutDisplayFunc(display);
    glutMouseFunc(mouse);///滑鼠按下相關函式
    glutMotionFunc(motion);///滑鼠移動相關
函式


    glutMainLoop();
}
void display()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glPushMatrix();///備份矩陣
        glTranslatef(potx,poty,0);///移動的參數
        glutSolidTeapot(0.3);
    glPopMatrix();///還原矩陣


    glutSwapBuffers();
}
void mouse(int button,int state,int x,int y)
{
///butten為按鈕類型,0為左鍵、1為右鍵、2為中鍵(滾輪)
///state為是否按下,0為按下、1為放開

///x、y為滑鼠座標 
   oldx=x;
    oldy=y;
}
void motion(int x,int y)
{
    potx=(x-oldx)/150.0;///新得數值等於變化量
    poty=(oldy-y)/150.0;
    glutPostRedisplay();///重畫畫面
}

沒有留言:

張貼留言