2016年5月31日 星期二

week 04 鄭玉妮


課堂作業一

旋轉


課堂作業二

印出茶壺

移動


float nowx=0, nowy=0;
void mouse (int button,int state,int x,int y)
{
    nowx= (x-150)/150.0;
    nowy= -(y-150)/150.0;
}
void display()
{
    glClearColor(0,1,0,1);
    glClear(GL_COLOR_BUFFER_BIT);
    glPushMatrix();
        glTranslated(nowx,nowy,0);
        glColor3f (1,0,0);
        glutSolidTeapot(0.3);
    glPopMatrix();
    glutSwapBuffers();

}

int main (int argc,char**argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow ("03161104鄭玉妮");

    glutDisplayFunc (display);
    glutMouseFunc(mouse);
    glutMainLoop ();
}

課堂作業三


#include <GL/glut.h>
#include <stdio.h>
#include <math.h>
float nowx=0, nowy=0;
void mouse (int button,int state,int x,int y)
{
    nowx= (x-150)/150.0;
    nowy= -(y-150)/150.0;
    printf("glTranslatef(%f,%f,0);\n",nowx,nowy);
}
void display()
{
    glClearColor(1,1,0,1);
    glClear(GL_COLOR_BUFFER_BIT);
    glPushMatrix();
        glTranslatef(nowx,nowy,0);
        glColor3f (1,0,0);
        ///glutSolidTeapot(0.3);
        glBegin(GL_POLYGON);
            for(float angle=0;angle<3.14159265358979*2;angle+=0.1){
                glVertex2f (0.2*cos(angle),0.2*sin(angle));
            }
        glEnd();
    glPopMatrix();
    glutSwapBuffers();

}

int main (int argc,char**argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow ("03161104鄭玉妮");
    glutDisplayFunc (display);
    glutMouseFunc(mouse);
    glutMainLoop ();

}



Week10 柯竹盈

一、貼圖

解壓縮opengl

把freeglut放入opengl資料夾裡面

到FB電腦圖學社團下載my earth,找earth map的圖放入myearth資料夾


打開myEarth.exe檔,就完成

作業二--旋轉地球

打開my earth的project file (.cbp)檔

要把google.jpg放入,freeglut\bin裡面



Week 15 林庭亘

課堂作業1:

利用Excel 練習內差公式



內差公式




課堂作業2:

內差公式應用



應用公式









課堂作業3:

新增輔助程式








利用S按鍵儲存座標



利用R按鍵讓機器人動起來





利用R按鍵讓機器人動起來






#include <stdio.h>
#include <GL/glut.h>
FILE *fout=NULL, *fin=NULL;
float rot[10]={0}, rotOld[10]={0}, rotNew[10]={0};
int rotID=1, oldX=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glutWireCube(0.3);
        glPushMatrix();
            glTranslatef(0,0.2,0);
            glutWireCube(0.1);
        glPopMatrix();

        glPushMatrix();
            glTranslatef(0.15,0.1,0);
            glRotatef(rot[1],0,0,1);
            glTranslatef(0.05,0,0);
            glutWireCube(0.1);

            glTranslatef(0.05,0,0);
            glRotatef(rot[2],0,0,1);
            glTranslatef(0.05,0,0);
            glutWireCube(0.1);

            glTranslatef(0.05,0,0);
            glRotatef(rot[3],0,0,1);
            glTranslatef(0.05,0,0);
            glutWireCube(0.1);
        glPopMatrix();

        glPushMatrix();
            glTranslatef(-0.15,0.1,0);
            glRotatef(-rot[4],0,0,1);
            glTranslatef(-0.05,0,0);
            glutWireCube(0.1);

            glTranslatef(-0.05,0,0);
            glRotatef(-rot[5],0,0,1);
            glTranslatef(-0.05,0,0);
            glutWireCube(0.1);

            glTranslatef(-0.05,0,0);
            glRotatef(-rot[6],0,0,1);
            glTranslatef(-0.05,0,0);
            glutWireCube(0.1);
        glPopMatrix();

    glPopMatrix();
    glutSwapBuffers();
}
void mouse(int button, int state, int x, int y)
{
    if(state==GLUT_DOWN){
        oldX=x;
    }
}void motion(int x, int y)
{
    rot[rotID] += (x-oldX);
    oldX=x;
    glutPostRedisplay();

}
void timer(int t)
{
    float alpha=(t%10)/10.0;
    if(t%10==0)
    {
      for(int i=0;i<10;i++){
            rotOld[i]=rotNew[i];
            fscanf( fin, "%f ", &rotNew[i]);
            printf( "%f ", rotNew[i]);
        }
        fprintf(fin, "\n");
        printf("\n");
    }
    for(int i=0;i<10;i++)
    {
        rot[i] = rotNew[i]*alpha + rotOld[i]*(1-alpha);
    }
    glutTimerFunc(100, timer, t+1);
    glutPostRedisplay();
}
void keyboard(unsigned char key, int x, int y)
{
    if(key=='1') rotID=1;
    if(key=='2') rotID=2;
    if(key=='3') rotID=3;
    if(key=='4') rotID=4;
    if(key=='5') rotID=5;
    if(key=='6') rotID=6;

    if(key=='r'){
        if(fin==NULL) fin=fopen("motion.txt","r");
        for(int i=0;i<10;i++){
            fscanf( fin, "%f ", &rot[i]);;
            printf( "%f ", rot[i]);;
        }
        fprintf(fin, "\n");
        printf("\n");
    }
    if(key=='s')
    {
         if(fout==NULL) fout=fopen("motion.txt","w+");
    for(int i=0;i<10;i++){
        fprintf( fout, "%.1f ", rot[i]);;
        printf( "%.1f ", rot[i]);;
    }
    fprintf(fout, "\n");
    printf("\n");
    }
    if(key=='t')
    {
        if(fin==NULL) fin=fopen("motion.txt","r");
        for(int i=0;i<10;i++){
            fscanf( fin, "%f ", &rotNew[i]);
            printf( "%f ", rotNew[i]);
        }
        fprintf(fin, "\n");
        printf("\n");
        glutTimerFunc(100, timer, 0);
    }
    glutPostRedisplay();///請電腦貼個公告,有空就重新display
}


int main(int argc,char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("Robot");
    glutDisplayFunc(display);
    glutMotionFunc(motion);
    glutMouseFunc(mouse);
    glutKeyboardFunc(keyboard);
    glutMainLoop();

}









Week 15 曾子豪

課堂作業一



用excel做內插






課堂作業二

點選一排(A)
按住Ctrl
再點另一排(D)

選擇圖表






課堂作業三

讓機器人可以變動畫



#include <stdio.h>
#include <GL/glut.h>
float rot[10]={0}, rotOld[10]={0}, rotNew[10]={0};
int rotNow=0, oldX=0, oldY=0;;
FILE *fout=0, *fin=0;
void timer(int t)
{
    float alpha=(t%10)/10.0;///!!!!
    //pos = newX*alpha+oldX*(1-alpha);
    if(t%10==0){
        if(fin==NULL) fin=fopen("motion.txt", "r");
        for(int i=0;i<7;i++){
            rotOld[i]=rotNew[i];
            fscanf(fin, "%f", &rotNew[i]);
        }
    }
    for(int i=0;i<7;i++){
        rot[i]=rotNew[i]*alpha+rotOld[i]*(1-alpha);
    }
    glutTimerFunc(100, timer, t+1);
    glutPostRedisplay();
}

void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();

    glPushMatrix();
        glutWireCube(0.3);///body
        glPushMatrix();
             glTranslatef(0,0.2,0);
             glutWireCube(0.1);///head
        glPopMatrix();

        glPushMatrix();

            glTranslatef(0.15,0.1,0);
            glRotatef(rot[0],0,0,1);
            glTranslatef(0.05,0,0);
            glutWireCube(0.1);///upper arm

            glTranslatef(0.05,0,0);
            glRotatef(rot[1],0,0,1);
            glTranslatef(0.05,0,0);
            glutWireCube(0.1);///lower arm

            glTranslatef(0.05,0,0);
            glRotatef(rot[2],0,0,1);
            glTranslatef(0.05,0,0);
            glutWireCube(0.1);///right arm

        glPopMatrix();

        glPushMatrix();
            ///glTranslatef(-0.2,0.1,0);
            glTranslatef(-0.15,0.1,0);
            glRotatef(-rot[4],0,0,1);
            glTranslatef(-0.05,0,0);

            glutWireCube(0.1);///upper arm

            glTranslatef(-0.05,0,0);
            glRotatef(-rot[5],0,0,1);
            glTranslatef(-0.05,0,0);

            glutWireCube(0.1);///lower arm

            glTranslatef(-0.05,0,0);
            glRotatef(-rot[6],0,0,1);
            glTranslatef(-0.05,0,0);

            glutWireCube(0.1);///right hand
        glPopMatrix();


    glPopMatrix();
    glPopMatrix();
    glutSwapBuffers();
}
void keyboard(unsigned char key, int x, int y)
{
    if(key=='0') rotNow=0;
    if(key=='1') rotNow=1;
    if(key=='2') rotNow=2;
    if(key=='3') rotNow=3;
    if(key=='4') rotNow=4;
    if(key=='5') rotNow=5;
    if(key=='6') rotNow=6;
    if(key=='r'){///按小寫的r 會去讀1行/一組x,y
        if(fin==NULL) fin=fopen("motion.txt", "r");
        for(int i=0;i<7;i++){
            fscanf(fin, "%f", &rot[i]);
        }
    }
    if(key=='t'){
        if(fin==NULL) fin=fopen("motion.txt", "r");
        for(int i=0;i<7;i++){
            fscanf(fin, "%f", &rotNew[i]);
        }
        glutTimerFunc(100,timer, 0);
        glutPostRedisplay();
    }
    if(key=='s'){///!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        if(fout==NULL) fout=fopen("motion.txt", "w+");
        for(int i=0;i<7;i++){
            fprintf(fout, "%3.1f ", rot[i]);
            printf("%3.1f ", rot[i]);
        }
        fprintf(fout, "\n");
        printf("\n");
    }
    glutPostRedisplay();///電腦貼個Post-It便利貼,告訴GLUT有空要重畫畫面哦
}
void motion(int x, int y)
{
    rot[rotNow] += x-oldX;
    oldX = x;
    glutPostRedisplay();
}
void mouse(int button, int state, int x, int y)
{///先開冰箱門(滑鼠按下去),把大象塞進去(滑鼠drag),最後再關上冰箱門(起來)
    if(state==GLUT_DOWN){
        oldX=x; oldY=y;
    }
}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("3D Interpolate");
    glutDisplayFunc(display);
    glutMotionFunc(motion);
    glutKeyboardFunc(keyboard);
    glutMouseFunc(mouse);
    //glutTimerFunc(100, timer, 0);
    glutMainLoop();
}
作業一:



內插Interpolation



new*alpha+old*(1-alpha)



















作業二:







程式碼:


 #include <stdio.h>
#include <GL/glut.h>
FILE *fout=NULL, *fin=NULL;
float rot[10]={0}, rotold[10]={0}, rotnew[10]={0};
int rotID=1, oldX=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glutWireCube(0.3);
        glPushMatrix();
            glTranslatef(0,0.2,0);
            glutWireCube(0.1);
        glPopMatrix();

        glPushMatrix();
            glTranslatef(0.15,0.1,0);
            glRotatef(rot[1],0,0,1);
            glTranslatef(0.05,0,0);
            glutWireCube(0.1);

            glTranslatef(0.05,0,0);
            glRotatef(rot[2],0,0,1);
            glTranslatef(0.05,0,0);
            glutWireCube(0.1);

            glTranslatef(0.05,0,0);
            glRotatef(rot[3],0,0,1);
            glTranslatef(0.05,0,0);
            glutWireCube(0.1);
        glPopMatrix();

        glPushMatrix();
            glTranslatef(-0.15,0.1,0);
            glRotatef(-rot[4],0,0,1);
            glTranslatef(-0.05,0,0);
            glutWireCube(0.1);

            glTranslatef(-0.05,0,0);
            glRotatef(-rot[5],0,0,1);
            glTranslatef(-0.05,0,0);
            glutWireCube(0.1);

            glTranslatef(-0.05,0,0);
            glRotatef(-rot[6],0,0,1);
            glTranslatef(-0.05,0,0);
            glutWireCube(0.1);
        glPopMatrix();

    glPopMatrix();
    glutSwapBuffers();
}
void mouse(int button, int state, int x, int y)
{
    if(state==GLUT_DOWN){
        oldX=x;
    }
}void motion(int x, int y)
{
    rot[rotID] += (x-oldX);
    oldX=x;
    glutPostRedisplay();
}

void timer(int t)
{
    float alpha=(t%10)/10.0;
    if(t%10==0)
    {
        if(fin==NULL) fin=fopen("motion.txt","r");
        for(int i=0;i<10;i++)
        {
            rotold[i]=rotnew[i];
            fscanf( fin, "%f ", &rotnew[i]);;
            printf( "%f ", rotnew[i]);;
        }
        fprintf(fin, "\n");
        printf("\n");
    }
    for(int i;i<10;i++)
    {
        rot[i]=rotnew[i]*alpha+rotold[i]*(1-alpha);
    }
    glutTimerFunc(100, timer, t+1);
    glutPostRedisplay();
}

void keyboard(unsigned char key, int x, int y)
{
    if(key=='1') rotID=1;
    if(key=='2') rotID=2;
    if(key=='3') rotID=3;
    if(key=='4') rotID=4;
    if(key=='5') rotID=5;
    if(key=='6') rotID=6;

    if(key=='r'){
        if(fin==NULL) fin=fopen("motion.txt","r");
        for(int i=0;i<10;i++)
        {
            fscanf( fin, "%f ", &rot[i]);;
            printf( "%f ", rot[i]);;
        }
        fprintf(fin, "\n");
        printf("\n");
    }
    if(key=='s')
    {
        if(fout==NULL) fout=fopen("motion.txt","w+");
        for(int i=0;i<10;i++)
        {
            fprintf( fout, "%.1f ", rot[i]);;
            printf( "%.1f ", rot[i]);;
        }
        fprintf(fout, "\n");
        printf("\n");
    }
    if(key=='t')
    {
        if(fin==NULL) fin=fopen("motion.txt","r");
        for(int i=0;i<10;i++)
        {
            fscanf( fin, "%f ", &rotnew[i]);;
            printf( "%f ", rotnew[i]);;
        }
        fprintf(fin, "\n");
        printf("\n");
        glutTimerFunc(100, timer, 0);
    }
    glutPostRedisplay();
}

int main(int argc,char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("Robot");
    glutDisplayFunc(display);
    glutMotionFunc(motion);
    glutMouseFunc(mouse);
    glutKeyboardFunc(keyboard);
    glutMainLoop();

}

Week_15 梁文俞

作業一
用Excel作內插公式



作業二
Excel作圖表 畫圖-插入x-y圖


作業三

#include <stdio.h>
#include <GL/glut.h>
FILE *fout=NULL, *fin=NULL;
float rot[10]={0};
int rotID=1, oldX=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glutWireCube(0.3);
        glPushMatrix();
            glTranslatef(0,0.2,0);
            glutWireCube(0.1);
        glPopMatrix();

        glPushMatrix();
            glTranslatef(0.15,0.1,0);
            glRotatef(rot[1],0,0,1);
            glTranslatef(0.05,0,0);
            glutWireCube(0.1);

            glTranslatef(0.05,0,0);
            glRotatef(rot[2],0,0,1);
            glTranslatef(0.05,0,0);
            glutWireCube(0.1);

            glTranslatef(0.05,0,0);
            glRotatef(rot[3],0,0,1);
            glTranslatef(0.05,0,0);
            glutWireCube(0.1);
        glPopMatrix();

        glPushMatrix();
            glTranslatef(-0.15,0.1,0);
            glRotatef(-rot[4],0,0,1);
            glTranslatef(-0.05,0,0);
            glutWireCube(0.1);

            glTranslatef(-0.05,0,0);
            glRotatef(-rot[5],0,0,1);
            glTranslatef(-0.05,0,0);
            glutWireCube(0.1);

            glTranslatef(-0.05,0,0);
            glRotatef(-rot[6],0,0,1);
            glTranslatef(-0.05,0,0);
            glutWireCube(0.1);
        glPopMatrix();

    glPopMatrix();
    glutSwapBuffers();
}
void mouse(int button, int state, int x, int y)
{
    if(state==GLUT_DOWN){
        oldX=x;
    }
}void motion(int x, int y)
{
    rot[rotID] += (x-oldX);
    oldX=x;
    glutPostRedisplay();

    if(fout==NULL) fout=fopen("motion.txt","w+");
    for(int i=0;i<10;i++){
        fprintf( fout, "%.1f ", rot[i]);;
        printf( "%.1f ", rot[i]);;
    }
    fprintf(fout, "\n");
    printf("\n");
}
void keyboard(unsigned char key, int x, int y)
{
    if(key=='1') rotID=1;
    if(key=='2') rotID=2;
    if(key=='3') rotID=3;
    if(key=='4') rotID=4;
    if(key=='5') rotID=5;
    if(key=='6') rotID=6;

    if(key=='r'){
        if(fin==NULL) fin=fopen("motion.txt","r");
        for(int i=0;i<10;i++){
            fscanf( fin, "%f ", &rot[i]);
            printf( "%f ", rot[i]);
        }
        fprintf(fin, "\n");
        printf("\n");
    }
    glutPostRedisplay();///請電腦貼個公告,有空就重新display
}

int main(int argc,char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("Robot");
    glutDisplayFunc(display);
    glutMotionFunc(motion);
    glutMouseFunc(mouse);
    glutKeyboardFunc(keyboard);
    glutMainLoop();

}

程式要改:
1.motion()不要狂寫檔
2.keyboard()裡if(key=='s')要寫檔
   SAVE一次到定位
3.keyboard()的'r'讀一行改裝't'先讀一行 對應timer
4.加上timer  glutTimerFunc




123

課堂作業一
利用 Excel 計算內插 Interpolation

首先公式如下  =27*a5+10*(1-a5)




接著利用鎖定公式  =$C$12*A6+$C$2*(1-A6)