2016年9月5日 星期一

Week 01 吳東峻

FB: 2016互動技術
facebook.com/groups/2016interaction
2016interaction.blogspot.com

1. TODO: 看學長姐的作品 2015interaction.blogspot.com

2. http://www.cmlab.csie.ntu.edu.tw/~jsyeh/processing/angryBirdsBrick/

課堂作業1: 想做出 AngryBird範例裡面, 那條線

打上程式碼line(10,10,90,90);
劃出一條線

打上Stroke();在()裡貼上所選的顏色


如何找指令
從help=>Reference


改變視窗大小size(800,600);

改變線的粗細
strokeWeight(10);


畫一個Y
利用小畫家找座標點
line(183,513,209,557);
line(233,513,209,557);
line(209,557,209,611);

讓線跟著滑鼠移動
line(183,513,mouseX,mouseY);
line(233,513,mouseX,mouseY);

更改背景顏色
background(255)

2016年6月24日 星期五

2016年6月21日 星期二

2016年6月20日 星期一

Week 04 蔡雯茜

【課堂作業二】

jsyeh/3dcg10/ 如前週操作指示開啟

glTranslatef(x,y,z);
glRotatef(角度,x,y,z);
glScalef(x,y,z);

調整旋轉方向和角度
看右手手指的旋轉方向










【課堂作業三】

開啟空貝殼專案,並新增咒語(如前週)

輸入以下程式碼:(茶壺會動)

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

  
    glClearColor(1,1,0,1);
    glClear(GL_COLOR_BUFFER_BIT);
  
  
    glTranslatef(0, 0.1, 0);
    glColor3f(1,0,0);
    glutSolidTeapot(0.3);
  
  
  
    glutSwapBuffers();

}

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


    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("Hello 3D");

    glutDisplayFunc(display);
    ///glutMouseFunc(mouse);

    glutMainLoop();

}




【課堂作業 四】

輸入以下程式碼:(用滑鼠移動光源)

#include <GL/glut.h>

const GLfloat light_ambient[]  = { 0.0f, 0.0f, 0.0f, 1.0f };
const GLfloat light_diffuse[]  = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat light_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
 GLfloat light_position[] = { 2.0f, 5.0f, -5.0f, 0.0f };

const GLfloat mat_ambient[]    = { 0.7f, 0.7f, 0.7f, 1.0f };
const GLfloat mat_diffuse[]    = { 0.8f, 0.8f, 0.8f, 1.0f };
const GLfloat mat_specular[]   = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat high_shininess[] = { 100.0f };

void motion (int x, int y)

{
   light_position [0] = (x-150)/150.0 *5;
   light_position [1]= -(y-150)/150.0 *5;
    glLightfv(GL_LIGHT0, GL_POSITION, light_position);
    glutPostRedisplay();
}


void display()
{
     glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glutSolidTeapot(0.3);
     glutSwapBuffers();
}
int main(int argc,char**argv)
{


    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("Hello 3D");

    glutDisplayFunc(display);
    glutMotionFunc(motion);

    glClearColor(1,1,1,1);
    glEnable(GL_CULL_FACE);
    glCullFace(GL_BACK);

    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LESS);

    glEnable(GL_LIGHT0);
    glEnable(GL_NORMALIZE);
    glEnable(GL_COLOR_MATERIAL);
    glEnable(GL_LIGHTING);

    glLightfv(GL_LIGHT0, GL_AMBIENT,  light_ambient);
    glLightfv(GL_LIGHT0, GL_DIFFUSE,  light_diffuse);
    glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
    glLightfv(GL_LIGHT0, GL_POSITION, light_position);

    glMaterialfv(GL_FRONT, GL_AMBIENT,   mat_ambient);
    glMaterialfv(GL_FRONT, GL_DIFFUSE,   mat_diffuse);
    glMaterialfv(GL_FRONT, GL_SPECULAR,  mat_specular);
    glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);

    glutMainLoop();
}




【課堂作業 五】

輸入以下程式碼:(換顏色)

#include <GL/glut.h>

const GLfloat light_ambient[]  = { 0.0f, 0.0f, 0.0f, 1.0f };
const GLfloat light_diffuse[]  = { 1.0f, 0.0f, 0.0f, 1.0f };
const GLfloat light_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
 GLfloat light_position[] = { 2.0f, 5.0f, -5.0f, 0.0f };

const GLfloat mat_ambient[]    = { 0.7f, 0.7f, 0.7f, 1.0f };
const GLfloat mat_diffuse[]    = { 0.8f, 0.8f, 3.0f, 1.0f };
const GLfloat mat_specular[]   = { 1.0f, 1.0f, 0.0f, 0.0f };
const GLfloat high_shininess[] = { 100.0f };

void motion (int x, int y)

{
    light_position [0] = (x-150)/150.0 *5;
    light_position [1]= -(y-150)/150.0 *5;
    glLightfv(GL_LIGHT0, GL_POSITION, light_position);
    glutPostRedisplay();
}


void display()
{
     glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glutSolidTeapot(0.3);
     glutSwapBuffers();
}
int main(int argc,char**argv)
{


    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("Hello 3D");

    glutDisplayFunc(display);
    glutMotionFunc(motion);

    glClearColor(1,1,0,0);
    glEnable(GL_CULL_FACE);
    glCullFace(GL_BACK);

    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LESS);

    glEnable(GL_LIGHT0);
    glEnable(GL_NORMALIZE);
    glEnable(GL_COLOR_MATERIAL);
    glEnable(GL_LIGHTING);

    glLightfv(GL_LIGHT0, GL_AMBIENT,  light_ambient);
    glLightfv(GL_LIGHT0, GL_DIFFUSE,  light_diffuse);
    glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
    glLightfv(GL_LIGHT0, GL_POSITION, light_position);

    glMaterialfv(GL_FRONT, GL_AMBIENT,   mat_ambient);
    glMaterialfv(GL_FRONT, GL_DIFFUSE,   mat_diffuse);
    glMaterialfv(GL_FRONT, GL_SPECULAR,  mat_specular);
    glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);

    glutMainLoop();
}


2016年6月17日 星期五

Week 17期末作品 顏士傑


https://www.youtube.com/watch?v=SmdB8zdU1ac&feature=youtu.be










在幾天內要繳交這次的作業使的我大量的閱讀許多相關程式碼

但由於自身沒有SENSE把許多良莠不齊的程式組合再一起

結果變成一堆垃圾

無奈的情況去用SKYPE請教老師,結果被轟到臭頭

但也是因為老師的關鍵性提點才讓我知道問題出在哪裡

雖然作品瑕疵 BUG 超多,但也盡了我全力

謝謝老師這一學期的帶領,


很遺憾我在期末作業時才感受到自己在學習一樣很有趣且了不起的科目




程式碼:


#include <GL/glut.h>
#include "glm.h"
#include <stdio.h>
#include <windows.h>
#include <mmsystem.h>


GLMmodel * pmodel1=NULL;
GLMmodel * pmodel2=NULL;
GLMmodel * pmodel3=NULL;
GLMmodel * pmodel4=NULL;
GLMmodel * pmodel5=NULL;
GLMmodel * pmodel6=NULL;
GLMmodel * pmodel7=NULL;
GLMmodel * pmodel8=NULL;
GLMmodel * pmodel9=NULL;

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<10;i++){
            rotOld[i]=rotNew[i];
            fscanf(fin, "%f", &rotNew[i]);
        }
    }
    for(int i=0;i<10;i++){
        rot[i]=rotNew[i]*alpha+rotOld[i]*(1-alpha);
    }
    glutTimerFunc(10000, timer, t+1);
    glutPostRedisplay();
}


void display()
{
 {
    glClearColor(129/255.0,200/255.0,183/255.0,1);
    GLfloat pos[]={-0.5,0.5, 1, 0};
    glLightfv(GL_LIGHT0, GL_POSITION, pos);
    glEnable(GL_LIGHT0);
    glEnable(GL_LIGHTING);
    glEnable(GL_DEPTH_TEST);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 }

    /*glPushMatrix();///body
        glScalef(0.4,0.4,0.4);
        glRotatef(rot[0],0,1,0);
        glTranslatef(0,0,0);
        glmDraw(pmodel1,GLM_SMOOTH|GLM_MATERIAL);*/


 glPushMatrix();///body
    glScalef(0.4,0.4,0.4);
    glRotatef(rot[1],0,1,0);
    glTranslatef(0,0.0,0);
    glmDraw(pmodel2,GLM_SMOOTH|GLM_MATERIAL);


   /* glPushMatrix();///done
    glScalef(0.4,0.4,0.4);
    glTranslatef(0,1,0);
    glRotatef(rot[2],0,0,0.5);
    glTranslatef(0,-2,0);
    glmDraw(pmodel3,GLM_SMOOTH|GLM_MATERIAL);
    glPopMatrix();*/


            glPushMatrix();///lefthand
                glScalef(0.8,0.8,0.8);
                glTranslatef(0.5,0.75,-0.2);
                glRotatef(rot[3],1,0,0);
                glTranslatef(-0.5,-0.8,0.0);
                glmDraw(pmodel4,GLM_SMOOTH|GLM_MATERIAL);
            glPopMatrix();

            glPushMatrix();///righthand
                glScalef(0.8,0.8,0.8);
                glTranslatef(-0.3,0.75,-0.2);
                glRotatef(rot[4],1,0,0);
                glTranslatef(0.5,-0.8,0);
                glmDraw(pmodel5,GLM_SMOOTH|GLM_MATERIAL);
            glPopMatrix();

            glPushMatrix();///rightlag
                glScalef(0.8,0.8,0.8);
                glTranslatef(-0.3,0.3,-0.3);
                glRotatef(rot[5],1,0,0);
                glTranslatef(0.5,-0.8,0);
                glmDraw(pmodel6,GLM_SMOOTH|GLM_MATERIAL);
            glPopMatrix();

            glPushMatrix();///leftlag
                glScalef(0.8,0.8,0.8);
                glTranslatef(0.65,0.3,-0.3);
                glRotatef(rot[6],1,0,0);
                glTranslatef(-0.5,-0.8,0);
                glmDraw(pmodel7,GLM_SMOOTH|GLM_MATERIAL);
            glPopMatrix();
  glPopMatrix();

 /* glPushMatrix();
    glScalef(0.4,0.4,0.4);
    glRotatef(rot[7],0,0,1);
    glTranslatef(-0.8,0,0);
    glmDraw(pmodel8,GLM_SMOOTH|GLM_MATERIAL);
    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=='7') rotNow=7;///for camera
    if(key=='8') rotNow=8;///for camera
    //PlaySoundA("song.wav",NULL, SND_ASYNC);
    //if(key=='8') rotNow=8;///for camera
    //if(key=='9') rotNow=9;///for camera
    if(key=='r'){///按小寫的r 會去讀1行/一組x,y
        if(fin==NULL) fin=fopen("motion.txt", "r");
        for(int i=0;i<10;i++){
            fscanf(fin, "%f", &rot[i]);
        }
    }

          if(key=='t'){
        if(fin==NULL) fin=fopen("motion.txt", "r");
        for(int i=0;i<10;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<10;i++){
            fprintf(fout, "%3.1f ", rot[i]);
            printf("%3.1f ", rot[i]);
        }
        fprintf(fout, "\n");
        printf("\n");
    }
    glutPostRedisplay();///電腦貼個Post-It便利貼,告訴GLUT有空要重畫畫面哦
}
void mouse(int button, int state, int x, int y)
{///先開冰箱門(滑鼠按下去),把大象塞進去(滑鼠drag),最後再關上冰箱門(起來)
    if(state==GLUT_DOWN){
        oldX=x; oldY=y;
    }
}
void motion(int x,int y)
{
    rot[rotNow] += x-oldX;
    oldX = x;
    rot[rotNow] += y-oldY;
    oldY = y;
    glutPostRedisplay();
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(rot[7]/80.0,rot[8]/200.0,5,
             0,0,0,
             0,1,0);
    glutPostRedisplay();
}
void resize(int w,int h)
{
    glViewport(0,0,(GLsizei)w,(GLsizei)h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(10.0,(GLdouble)w/h,1.0,100.0);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(0.0,0.0,5.0,
              0.0,0.0,0.0,
              0.0,2.0,0.0);
}
int main (int argc,char**argv)
{
    glutInit(&argc,argv);

        /*pmodel1 = glmReadOBJ("BB.obj");
        if (!pmodel1) exit(0);
        glmUnitize(pmodel1);
        glmFacetNormals(pmodel1);
        glmVertexNormals(pmodel1, 50.0);*/

        pmodel2 = glmReadOBJ("BB.obj");
        if (!pmodel2) exit(0);
        glmUnitize(pmodel2);
        glmFacetNormals(pmodel2);
        glmVertexNormals(pmodel2, 50.0);

      /*  pmodel3 = glmReadOBJ("data/done.obj");
        if (!pmodel3) exit(0);
        glmUnitize(pmodel3);
        glmFacetNormals(pmodel3);
        glmVertexNormals(pmodel3, 10.0);*/

        pmodel4 = glmReadOBJ("LH.obj");
        if (!pmodel4) exit(0);
        glmUnitize(pmodel4);
        glmFacetNormals(pmodel4);
        glmVertexNormals(pmodel4, 50.0);

        pmodel5 = glmReadOBJ("RH.obj");
        if (!pmodel5) exit(0);
        glmUnitize(pmodel5);
        glmFacetNormals(pmodel5);
        glmVertexNormals(pmodel5, 50.0);

        pmodel6 = glmReadOBJ("RL.obj");
        if (!pmodel6) exit(0);
        glmUnitize(pmodel6);
        glmFacetNormals(pmodel6);
        glmVertexNormals(pmodel6, 50.0);

        pmodel7 = glmReadOBJ("LL.obj");
        if (!pmodel7) exit(0);
        glmUnitize(pmodel7);
        glmFacetNormals(pmodel7);
        glmVertexNormals(pmodel7, 50.0);

    PlaySound("onepunchmanOpening.wav",NULL,SND_ASYNC);





    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("03161254");
    glutDisplayFunc(display);
    glutKeyboardFunc(keyboard);

    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    glutReshapeFunc(resize);
    glutMainLoop();
}