2016年3月14日 星期一

Week04


左鍵drag綠色數字
右鍵可以換模型








複製完按ENTER 就有了

#include <GL/glut.h>
#include <stdio.h>
void mouse(int button,int state, int x, int y)
{
    //if(state==GLUT_DOWN) printf("%d %d\n", x, y);
    if(state==GLUT_DOWN)printf(" glVertex2f( (%d-150)/150.0,-(%d-150)/150.0);\n", x, y);

}
void display()
{

    glBegin(GL_POLYGON);
    glClear(GL_COLOR_BUFFER_BIT);
    glColor3ub(175 ,193, 81);// glColor3ub(175 ,193, 81,透明度);
    glBegin(GL_POLYGON);
 glVertex2f( (119-150)/150.0,-(82-150)/150.0);
 glVertex2f( (56-150)/150.0,-(105-150)/150.0);
 glVertex2f( (35-150)/150.0,-(136-150)/150.0);
 glVertex2f( (35-150)/150.0,-(187-150)/150.0);
 glVertex2f( (99-150)/150.0,-(234-150)/150.0);
 glVertex2f( (192-150)/150.0,-(225-150)/150.0);
 glVertex2f( (253-150)/150.0,-(189-150)/150.0);
 glVertex2f( (271-150)/150.0,-(134-150)/150.0);
 glVertex2f( (258-150)/150.0,-(87-150)/150.0);
 glVertex2f( (210-150)/150.0,-(75-150)/150.0);
 glVertex2f( (175-150)/150.0,-(69-150)/150.0);
    glEnd();
    glutSwapBuffers();
}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE| GLUT_DEPTH);
    glutCreateWindow("hellow");
    glutDisplayFunc(display);
    glutMouseFunc(mouse);
    glutMainLoop();
}


做圓形



#include <GL/glut.h>
#include <stdio.h>
#include <math.h>
void mouse(int button,int state, int x, int y)
{
    //if(state==GLUT_DOWN) printf("%d %d\n", x, y);
    if(state==GLUT_DOWN)printf(" glVertex2f( (%d-150)/150.0,-(%d-150)/150.0);\n", x, y);

}
void display()
{

    glBegin(GL_POLYGON);
    glClear(GL_COLOR_BUFFER_BIT);
    glColor3ub(175 ,193, 81);// glColor3ub(175 ,193, 81,透明度);

    glPushMatrix();
    glBegin(GL_POLYGON);
    for(float angle=0; angle<3.1415926565*2; angle+= 0.1)//angle+=的數字越小 越圓 越大(0.9)會變有角
    {
        glVertex2f( 0.2*cos(angle), 0.2*sin(angle) );//cos是X軸 sin是Y軸 0.2的位置是圓的大小

    }
    glEnd();
     glPopMatrix();//pop 跟push如果沒有對應到就會當機歐!!!

    glutSwapBuffers();
}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE| GLUT_DEPTH);
    glutCreateWindow("hellow");
    glutDisplayFunc(display);
    glutMouseFunc(mouse);
    glutMainLoop();
}


#include <GL/glut.h>
#include <stdio.h>
#include <math.h>
float nowX=0, nowY=0, now=0;
void mouse(int button,int state, int x, int y)
{
    nowX=(x-150)/150.0;
    nowY=-(y-150)/150.0;
    now+=0.1;

}
void display()
{
    glClearColor(150/255.0 ,170/255.0, 55/255.0,1);

    glClear(GL_COLOR_BUFFER_BIT);
    glColor3ub(175 ,193, 81);// glColor3ub(175 ,193, 81,透明度);

    glPushMatrix();
    glBegin(GL_POLYGON);
    for(float angle=0; angle<3.1415926565*2; angle+= 0.1)
    {
        glVertex2f( nowX+0.3*cos(angle), nowY+0.3*sin(angle) );

    }
    glEnd();
     glPopMatrix();

    glColor3ub(1 ,1,1);
    glPushMatrix();
    glBegin(GL_POLYGON);
    glVertex2f(nowX, nowY);
    for(float angle=0; angle<now; angle+= 0.1)
    {
        glVertex2f(nowX+ 0.3*cos(angle),nowY+ 0.3*sin(angle) );

    }
    glEnd();
     glPopMatrix();


    glutSwapBuffers();
}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE| GLUT_DEPTH);
    glutCreateWindow("hellow");
    glutDisplayFunc(display);
    glutMouseFunc(mouse);
    glutMainLoop();
}

會跟著滑鼠移動的倒數的圓







沒有留言:

張貼留言