顯示具有 06160620_陳昱辰 標籤的文章。 顯示所有文章
顯示具有 06160620_陳昱辰 標籤的文章。 顯示所有文章

2019年6月12日 星期三

比利安娜工作室-balaboom_Week16

2019/6/6 Week16
(1)作業Q&A
(2)複習:貼圖
(3)複習:打光
(4)複習:模型

主要在複習~~


2019年5月30日 星期四

比利安娜工作室-balaboom_Week15

2019/05/30 Week15
(1)主題:攝影機、運鏡
(2)主題:投影、矩陣
(3)複習:位置移動 vs 轉動
(4)複習:背景貼圖
(5)期末作品

運鏡:http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/跟之前一樣的動作,開起網站下載必要的檔案,將檔案為至放置好就可以開始了~

接下來要用CodeBlocks開啟奇怪的大叔
(1)先下載source,copy裡面projection程式碼
(2)在CodeBlocks裡開啟glut專案,步驟之前都有教過
(3)在glut理add file=>glm.h及glm,c改成glm.cpp
(4)記得到目的地放入data資料夾
================================================================
#include <GL/glut.h>///GLUT 外掛
#include "glm.h"///glm.cpp for 3D model glmReadOBJ(), glmDraw(), glmUnitized()
GLMmodel * pmodel=NULL;///指標
void drawmodel(void)
{
    if (!pmodel) {
pmodel = glmReadOBJ("data/al.obj");
if (!pmodel) exit(0);
glmUnitize(pmodel);
glmFacetNormals(pmodel);
glmVertexNormals(pmodel, 90.0);
    }

    glmDraw(pmodel, GLM_SMOOTH | GLM_MATERIAL);
}
void display(void)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    drawmodel();
    glutSwapBuffers();
}

int main(int argc, char** argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE);
    glutInitWindowSize(512,512);
    glutInitWindowPosition(50, 50);
    glutCreateWindow("week15");

//    glutReshapeFunc(reshape);
    glutDisplayFunc(display);

    glutMainLoop();

    return 0;
}
這是沒有加燈光的大叔
=================================================================
#include <GL/glut.h>///GLUT 外掛
#include "glm.h"///glm.cpp for 3D model glmReadOBJ(), glmDraw(), glmUnitized()
GLMmodel * pmodel=NULL;///指標
void drawmodel(void)
{
    if (!pmodel) {
pmodel = glmReadOBJ("data/al.obj");
if (!pmodel) exit(0);
glmUnitize(pmodel);
glmFacetNormals(pmodel);
glmVertexNormals(pmodel, 90.0);
    }

    glmDraw(pmodel, GLM_SMOOTH | GLM_MATERIAL);
}
void display(void)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    drawmodel();
    glutSwapBuffers();
}

int main(int argc, char** argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE);
    glutInitWindowSize(512,512);
    glutInitWindowPosition(50, 50);
    glutCreateWindow("week15");

//    glutReshapeFunc(reshape);
    glutDisplayFunc(display);

    GLfloat light_pos[] = { 0.0, 0.0, -1.0, 0.0 };
    glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glLightfv(GL_LIGHT0, GL_POSITION, light_pos);

    glutMainLoop();

    return 0;
}
這是加了燈光的大叔
=====================================================================
#include <GL/glut.h>///GLUT 外掛
#include "glm.h"///glm.cpp for 3D model glmReadOBJ(), glmDraw(), glmUnitized()
GLMmodel * pmodel=NULL;///指標
void drawmodel(void)
{
    if (!pmodel) {
pmodel = glmReadOBJ("data/al.obj");
if (!pmodel) exit(0);
glmUnitize(pmodel);
glmFacetNormals(pmodel);
glmVertexNormals(pmodel, 90.0);
    }
    glmDraw(pmodel, GLM_SMOOTH | GLM_MATERIAL);
}
void display(void)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    drawmodel();
    glutSwapBuffers();
}
#include <math.h>///for sin() cos() ///NOW3
float eyeX=0.5, eyeY=0, eyeZ=0; ///NOW3
void timer(int t)///NOW3
{
    float angle = (t/180.0)*3.1415926; ///NOW3
    eyeX=0.5*cos(angle); ///NOW3
    eyeZ=0.5*sin(angle); ///NOW3

    glutTimerFunc(33, timer, t+1);///NOW3
    glMatrixMode(GL_MODELVIEW);///NOW3
    glLoadIdentity();///NOW3
    gluLookAt( eyeX, eyeY, eyeZ,///eye ///NOW3
           0, 0, 0,///center ///NOW3
               0, 1, 0);///up    ///NOW3

    glutPostRedisplay();///NOW3
}
int main(int argc, char** argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE);
    glutInitWindowSize(512,512);
    glutInitWindowPosition(50, 50);
    glutCreateWindow("week15");
//    glutReshapeFunc(reshape);
    glutDisplayFunc(display);
    glutTimerFunc(33, timer, 0);///NOW3

    GLfloat light_pos[] = { 0.0, 0.0, 1.0, 0.0 };
    glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glLightfv(GL_LIGHT0, GL_POSITION, light_pos);

    glutMainLoop();

    return 0;
}
會旋轉的大叔
====================================================================
#include <GL/glut.h>///GLUT 外掛
#include "glm.h"///glm.cpp for 3D model glmReadOBJ(), glmDraw(), glmUnitized()
GLMmodel * pmodel=NULL;///指標
void drawmodel(void)
{
    if (!pmodel) {
pmodel = glmReadOBJ("data/al.obj");
if (!pmodel) exit(0);
glmUnitize(pmodel);
glmFacetNormals(pmodel);
glmVertexNormals(pmodel, 90.0);
    }
    glmDraw(pmodel, GLM_SMOOTH | GLM_MATERIAL);
}
void display(void)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    drawmodel();
    glutSwapBuffers();
}
#include <math.h>///for sin() cos() ///NOW3
float eyeX=0.5, eyeY=0, eyeZ=0; ///NOW3
void timer(int t)///NOW3
{

    glMatrixMode(GL_PROJECTION); ///NOW4
    glLoadIdentity(); ///NOW4
glOrtho(-1, +1,  -1,+1, -10,+10); ///NOW4 你可以看到 -10...+10範圍


    float angle = (t/180.0)*3.1415926; ///NOW3
    eyeX=0.5*cos(angle); ///NOW3
    eyeZ=0.5*sin(angle); ///NOW3

    glutTimerFunc(33, timer, t+1);///NOW3
    glMatrixMode(GL_MODELVIEW);///NOW3
    glLoadIdentity();///NOW3
    gluLookAt( eyeX, eyeY, eyeZ,///eye ///NOW3
           0, 0, 0,///center ///NOW3
               0, 1, 0);///up    ///NOW3

    glutPostRedisplay();///NOW3
}
int main(int argc, char** argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE);
    glutInitWindowSize(512,512);
    glutInitWindowPosition(50, 50);
    glutCreateWindow("week15");
//    glutReshapeFunc(reshape);
    glutDisplayFunc(display);
    glutTimerFunc(33, timer, 0);///NOW3

    GLfloat light_pos[] = { 0.0, 0.0, 1.0, 0.0 };
    glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glLightfv(GL_LIGHT0, GL_POSITION, light_pos);

    glutMainLoop();

    return 0;
}
多加了NOW4程式碼=>垂直投影
======================================================================
#include <GL/glut.h>///GLUT 外掛
#include "glm.h"///glm.cpp for 3D model glmReadOBJ(), glmDraw(), glmUnitized()
GLMmodel * pmodel=NULL;///指標
void drawmodel(void)
{
    if (!pmodel) {
pmodel = glmReadOBJ("data/al.obj");
if (!pmodel) exit(0);
glmUnitize(pmodel);
glmFacetNormals(pmodel);
glmVertexNormals(pmodel, 90.0);
    }
    glmDraw(pmodel, GLM_SMOOTH | GLM_MATERIAL);
}
void display(void)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    drawmodel();
    glutSwapBuffers();
}
#include <math.h>///for sin() cos() ///NOW3
float eyeX=2, eyeY=0, eyeZ=0; ///NOW3
void timer(int t)///NOW3
{

    glMatrixMode(GL_PROJECTION); ///NOW4
    glLoadIdentity(); ///NOW4
///glOrtho(-1, +1,  -1,+1, -10.0,10.0); ///NOW4 你可以看到 -10...+10範圍
gluPerspective(60, 1.0, 0.001, 1000);///NOW5


    float angle = (t/180.0)*3.1415926; ///NOW3
    eyeX=2*cos(angle); ///NOW3
    eyeZ=2*sin(angle); ///NOW3

    glutTimerFunc(33, timer, t+1);///NOW3
    glMatrixMode(GL_MODELVIEW);///NOW3
    glLoadIdentity();///NOW3
    gluLookAt( eyeX, eyeY, eyeZ,///eye ///NOW3
           0, 0, 0,///center ///NOW3
               0, 1, 0);///up    ///NOW3

    glutPostRedisplay();///NOW3
}
int main(int argc, char** argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE);
    glutInitWindowSize(512,512);
    glutInitWindowPosition(50, 50);
    glutCreateWindow("week15");
//    glutReshapeFunc(reshape);
    glutDisplayFunc(display);
    glutTimerFunc(33, timer, 0);///NOW3

    GLfloat light_pos[] = { 0.0, 0.0, 1.0, 0.0 };
    glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glLightfv(GL_LIGHT0, GL_POSITION, light_pos);

    glutMainLoop();

    return 0;
}
透視投影





2019年5月23日 星期四

比利安娜工作室-balaboom_Week14

2019/5/23 Week14
(1)主題:計時器Timer
(2)主題:內差公式
(3)主題:動畫
(4)期末作品

一如既往的先有10行茶壺程式碼
#include <GL/glut.h>
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);
    glutInitWindowSize(500,500);///變大了
    glutCreateWindow("week 14 timer");

    glutDisplayFunc(display);
    glutMainLoop();
}

今天要加入Timer=>
先到wav下載聲音檔,之前有交過匯入音檔,再加入Timer程式碼就好,再利用變數t去計算過了幾秒鐘














利用excel來學習內差公式














內差公式來跑茶壺














後面恍神了...回家有看小葉的影片,貼上程式碼表示看過~~
#include <GL/glut.h>
#include <opencv/highgui.h>
#include <opencv/cv.h>
#include "glm.h"
#include <stdio.h>
#include <windows.h>
#include <mmsystem.h>

float oldAngle[20];
float newAngle[20];
float angle[20];
float a=0;

GLMmodel* pmodel = NULL;///呼叫外掛,glm需要它(body)
GLMmodel* pmodel2 = NULL;///righthand1
GLMmodel* pmodel3 = NULL;///righthand2
GLMmodel* pmodel4 = NULL;///lefthand1
GLMmodel* pmodel5 = NULL;///lefthand2
GLMmodel* pmodel6 = NULL;///rightleg1
GLMmodel* pmodel7 = NULL;///rightleg2
GLMmodel* pmodel8 = NULL;///leftleg1
GLMmodel* pmodel9 = NULL;///leftleg2

int angleID=2;///NOW3
FILE * fout = NULL;///for fprintf()
FILE * fin = NULL;///for fscanf()

IplImage * img=cvLoadImage("filename.jpg");///讀圖
GLuint myTexture(char * filename) ///貼圖需要它
{
    IplImage * img = cvLoadImage(filename); ///NOW OpenCV ///貼圖需要它
    cvCvtColor(img, img, CV_BGR2RGB);///convert color ///NOW OpenCV ///貼圖需要它

    GLuint id; ///貼圖需要它
    glEnable(GL_TEXTURE_2D); ///貼圖需要它
    glGenTextures(1, &id ); ///貼圖需要它
    glBindTexture(GL_TEXTURE_2D, id); ///貼圖需要它, 綁貼圖
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); ///貼圖需要它
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); ///貼圖需要它
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); ///貼圖需要它
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); ///貼圖需要它
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, img->width, img->height, 0, GL_RGB, GL_UNSIGNED_BYTE, img->imageData); ///貼圖需要它
    return id;///貼圖需要它
}

float nowX=0;

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

    glDisable(GL_LIGHTING);///jsyeh: 我幫你加這行
    glEnable(GL_TEXTURE_2D);///jsyeh: 我幫你加這行
    glBegin(GL_POLYGON);
        glTexCoord2f(0,0); glVertex2f(-1,+1);
        glTexCoord2f(0,1); glVertex2f(-1,-1);
        glTexCoord2f(1,1); glVertex2f(+1,-1);
        glTexCoord2f(1,0); glVertex2f(+1,+1);
    glEnd();
    glDisable(GL_TEXTURE_2D);///jsyeh: 我幫你加這行
    glEnable(GL_LIGHTING);///jsyeh: 我幫你加這行

///body
    glPushMatrix();
            glTranslatef(0, 0.3, 0);
            //glRotatef(a,0,1,0);
            glScalef(0.4,0.4,0.4);
        if (!pmodel) {///glm需要它
            pmodel = glmReadOBJ("body.obj");///glm需要它
            if (!pmodel) exit(0);///glm需要它
            glmUnitize(pmodel);///glm需要它
            glmFacetNormals(pmodel);///glm需要它
            glmVertexNormals(pmodel, 90.0);///glm需要它
        }
        glmDraw(pmodel, GLM_SMOOTH | GLM_MATERIAL);
    glPopMatrix();
///body

///righthand1(1)p2
glPushMatrix();
            glTranslatef(0.25, 0.3, 0);///(3)掛上去
            glRotatef(angle[1], 0,0,1);///(2)旋轉
            glTranslatef(0.2, -0.1, 0);///(1)旋轉中心
            glScalef(0.2,0.2,0.2);
        if (!pmodel2) {///glm需要它
            pmodel2 = glmReadOBJ("righthand1.obj");///glm需要它
            if (!pmodel2) exit(0);///glm需要它
            glmUnitize(pmodel2);///glm需要它
            glmFacetNormals(pmodel2);///glm需要它
            glmVertexNormals(pmodel2, 90.0);///glm需要它
        }
        glmDraw(pmodel2, GLM_SMOOTH | GLM_MATERIAL);
    //glPopMatrix();
///righthand1(1)p2

///righthand2(2)p3
    glPushMatrix();
            glTranslatef(1, -0.9, 0);///(3)掛上去
            glRotatef(angle[2], 0,0,1);///(2)旋轉
            glTranslatef(0, -0.8, 0);///(1)旋轉中心
            glScalef(1,1,1);
        if (!pmodel3) {///glm需要它
            pmodel3 = glmReadOBJ("righthand2.obj");///glm需要它
            if (!pmodel3) exit(0);///glm需要它
            glmUnitize(pmodel3);///glm需要它
            glmFacetNormals(pmodel3);///glm需要它
            glmVertexNormals(pmodel3, 90.0);///glm需要它
        }
        glmDraw(pmodel3, GLM_SMOOTH | GLM_MATERIAL);
    glPopMatrix();

glPopMatrix();
///righthand2(2)p3

///lefthand1(3)p4
glPushMatrix();
            glTranslatef(-0.25, 0.3, 0);///(3)掛上去
            glRotatef(angle[3], 0,0,1);///(2)旋轉
            glTranslatef(-0.2, -0.1, 0);///(1)旋轉中心
            glScalef(0.2,0.2,0.2);
        if (!pmodel4) {///glm需要它
            pmodel4 = glmReadOBJ("lefthand1.obj");///glm需要它
            if (!pmodel4) exit(0);///glm需要它
            glmUnitize(pmodel4);///glm需要它
            glmFacetNormals(pmodel4);///glm需要它
            glmVertexNormals(pmodel4, 90.0);///glm需要它
        }
        glmDraw(pmodel4, GLM_SMOOTH | GLM_MATERIAL);
    //glPopMatrix();
///lefthand1(3)p4

///lefthand2(4)p5
    glPushMatrix();
            glTranslatef(-1, -0.9, 0);///(3)掛上去
            glRotatef(angle[4], 0,0,1);///(2)旋轉
            glTranslatef(0, -0.8, 0);///(1)旋轉中心
            glScalef(1,1,1);
        if (!pmodel5) {///glm需要它
            pmodel5 = glmReadOBJ("righthand2.obj");///glm需要它
            if (!pmodel5) exit(0);///glm需要它
            glmUnitize(pmodel5);///glm需要它
            glmFacetNormals(pmodel5);///glm需要它
            glmVertexNormals(pmodel5, 90.0);///glm需要它
        }
        glmDraw(pmodel5, GLM_SMOOTH | GLM_MATERIAL);
    glPopMatrix();
glPopMatrix();
///lefthand2(4)p5

///rightleg1(5)p6
glPushMatrix();
            glTranslatef(0.1, 0, 0);///(3)掛上去
            glRotatef(angle[5], 0,0,1);///(2)旋轉
            glTranslatef(0.1, -0.2, 0);///(1)旋轉中心
            glScalef(0.15,0.15,0.15);
        if (!pmodel6) {///glm需要它
            pmodel6 = glmReadOBJ("rightleg1.obj");///glm需要它
            if (!pmodel6) exit(0);///glm需要它
            glmUnitize(pmodel6);///glm需要它
            glmFacetNormals(pmodel6);///glm需要它
            glmVertexNormals(pmodel6, 90.0);///glm需要它
        }
        glmDraw(pmodel6, GLM_SMOOTH | GLM_MATERIAL);
    //glPopMatrix();
///rightleg1(5)p6

///rightleg2(6)p7
    glPushMatrix();
            glTranslatef(0.5, -1, 0);///(3)掛上去
            glRotatef(angle[6], 0,0,1);///(2)旋轉
            glTranslatef(0, -1.5, 0);///(1)旋轉中心
            glScalef(2,2,2);
        if (!pmodel7) {///glm需要它
            pmodel7 = glmReadOBJ("rightleg2.obj");///glm需要它
            if (!pmodel7) exit(0);///glm需要它
            glmUnitize(pmodel7);///glm需要它
            glmFacetNormals(pmodel7);///glm需要它
            glmVertexNormals(pmodel7, 90.0);///glm需要它
        }
        glmDraw(pmodel7, GLM_SMOOTH | GLM_MATERIAL);
    glPopMatrix();
glPopMatrix();
///rightleg2(6)p7

///leftleg1(7)p8
glPushMatrix();
            glTranslatef(-0.1, 0, 0);///(3)掛上去
            glRotatef(angle[7], 0,0,1);///(2)旋轉
            glTranslatef(-0.1, -0.2, 0);///(1)旋轉中心
            glScalef(0.15,0.15,0.15);
        if (!pmodel8) {///glm需要它
            pmodel8 = glmReadOBJ("leftleg1.obj");///glm需要它
            if (!pmodel8) exit(0);///glm需要它
            glmUnitize(pmodel8);///glm需要它
            glmFacetNormals(pmodel8);///glm需要它
            glmVertexNormals(pmodel8, 90.0);///glm需要它
        }
        glmDraw(pmodel8, GLM_SMOOTH | GLM_MATERIAL);
    //glPopMatrix();
///leftleg1(7)p8

///leftleg2(8)p9
    glPushMatrix();
            glTranslatef(-0.5, -1, 0);///(3)掛上去
            glRotatef(angle[8], 0,0,1);///(2)旋轉
            glTranslatef(0, -1.5, 0);///(1)旋轉中心
            glScalef(2,2,2);
        if (!pmodel9) {///glm需要它
            pmodel9 = glmReadOBJ("leftleg2.obj");///glm需要它
            if (!pmodel9) exit(0);///glm需要它
            glmUnitize(pmodel9);///glm需要它
            glmFacetNormals(pmodel9);///glm需要它
            glmVertexNormals(pmodel9, 90.0);///glm需要它
        }
        glmDraw(pmodel9, GLM_SMOOTH | GLM_MATERIAL);
    glPopMatrix();
glPopMatrix();
///leftleg2(8)p9

    //glutSolidTeapot(0.3);

    glutSwapBuffers();
}

int oldX=0;///NOW2
void mouse(int button, int state, int x, int y)///NOW2
{///NOW2
    oldX = x;///NOW2
}
#include <stdio.h>///NOW3
void motion(int x, int y)///NOW2
{///NOW2
    angle[angleID] += x-oldX;///NOW3
    oldX = x;///NOW2
    /*if(fout == NULL) fout = fopen("motion.txt","w+");///now file
    for(int i=0;i<20;i++){///NOW3
        //printf(" %.2f ", angle[i]);///NOW3
        //fprintf(fout, " %.2f ", angle[i]);
    }
    //printf("\n");///NOW3
    //fprintf(fout,"\n");*/
    display();///NOW2
}

void timer(int t)
{///NOW4
    glutTimerFunc(33, timer, t+1);///NOW4 變快了... 撥好下一個timer的時間.... 等一下它會醒來
    if(t%30==0){///關鍵的時間 每過1秒,讀新的 ///NOW4
        if(fin==NULL) fin=fopen("motion.txt", "r");///NOW4
        for(int i=0; i<20; i++){///NOW4
            oldAngle[i] = newAngle[i];///NOW4 原本的新的,就變舊的
            fscanf(fin, "%f", &newAngle[i]);///NOW4 再從檔案,讀入新的
        }///NOW2
    }
    float alpha= (t%30)/30.0;///NOW4 算出alpha值 0.0 ... 1.0
    for(int i=0; i<20; i++){///NOW4 20個關節角度
        angle[i] = alpha * newAngle[i] + (1-alpha) * oldAngle[i];///NOW4 都要做內插
    }
    glutPostRedisplay();///NOW4 重畫畫面
}

///內插公式 ans = alpha * future + (1-alpha) * old

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

    if(key=='w'){///只有按下'w'才存一行動作
        if(fout==NULL)  fout=fopen("motion.txt","w+");
        for(int i=0;i<20;i++){
            fprintf(fout," %.1f ", angle[i]);
        }
        fprintf(fout,"\n");
    }
    if(key=='r'){
        if(fin==NULL)   fin=fopen("motion.txt", "r");
        for(int i=0;i<20;i++){
            fscanf(fin, "%f",&angle[i]);
        }
    }
    if(key=='p'){
        glutTimerFunc(500,timer,0);
        if(fin==NULL)   fin=fopen("motion.txt", "r");
        for(int i=0;i<20;i++){
            fscanf(fin, "%f",&newAngle[i]);
        }
    }
    glutPostRedisplay();
}

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 };
const 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 };

int main(int argc,char**argv)
{
    PlaySoundA("C:\\Users\\陳昱辰\\Desktop\\Victory",NULL,SND_ASYNC);///音樂

    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutInitWindowSize(600,600);
    glutCreateWindow("期末作品");

    glutKeyboardFunc(keyboard);
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    //glutTimerFunc(1000,timer,0);

    myTexture("filename.jpg");///background
    glutDisplayFunc(display);


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

    glEnable(GL_DEPTH_TEST);
    //glDepthFunc(GL_LESS);

    glEnable(GL_LIGHT0);///glm需要它
    glEnable(GL_NORMALIZE);///glm需要它
    glEnable(GL_COLOR_MATERIAL);///glm需要它
    glEnable(GL_LIGHTING);///glm需要它

    glLightfv(GL_LIGHT0, GL_AMBIENT,  light_ambient);///glm需要它
    glLightfv(GL_LIGHT0, GL_DIFFUSE,  light_diffuse);///glm需要它
    glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);///glm需要它
    glLightfv(GL_LIGHT0, GL_POSITION, light_position);///glm需要它

    glutMainLoop();
}

2019年5月16日 星期四

比利安娜工作室-balaboom_Week13

2019/05/16 Week13
(1)主題:檔案
(2)主題:關節,擺動作
(3)主題:複習
(4)作業:機器人擺動作

檔案:
#include <stdio.h>
FILE * fout=NULL;
int main()
{
    fout = fopen("filename.txt", "w+");
    for(int i;i<=20;i++){
    ///    printf("Hello World\n");
        fprintf(fout,"Hello World\n");
    }
}

加上關節角度
#include <stdio.h>
//FILE * fout=NULL;
FILE * fout2=NULL;
FILE * fin2=NULL;
float angle[20];
int main()
{
    fout2 = fopen("motion.txt", "w+");
    for(int i;i<=20;i++){
    ///    printf("Hello World\n");
        fprintf(fout2," %.2f ", angle);
    }
}


用glut秀出關節、擺動作





加上繁瑣的程式碼(看FB小葉影片可深入了解)



2019年5月9日 星期四

比利安娜工作室-balaboom_Week12

2019/5/9 Week12
(1)主題:鍵盤
(2)主題:聲音、音樂WAV、MP3
(3)複習:階層T-R-T骨架
(4)作業:能操控的機器人

用codeblocks播放音樂
1.先到google下載"WAV"音檔
2.開啟codeblocks建立Console application專案
3.打上程式碼
    ⇨最後在執行時,專案的設定,要在link時,加入一個winmm的library


音樂與glut的結合
1.先建立一個glut的專案
2.#include<mmsystem.h>
   PlaySoundA("C:\\Users\\user\\Downloads\\lightning.wav",NULL,SND_SYNC);
   加上這兩行之後,執行時就會先有音樂再跑出六個圖形



利用鍵盤播出do re mi fa so的聲音
 #include <mmsystem.h>
    if(key=='1') PlaySoundA("C:\\Users\\user\\Downloads\\do.wav",NULL,SND_ASYNC);
    if(key=='2') PlaySoundA("C:\\Users\\user\\Downloads\\re.wav",NULL,SND_ASYNC);
    if(key=='3') PlaySoundA("C:\\Users\\user\\Downloads\\mi.wav",NULL,SND_ASYNC);
    if(key=='4') PlaySoundA("C:\\Users\\user\\Downloads\\fa.wav",NULL,SND_ASYNC);
    if(key=='5') PlaySoundA("C:\\Users\\user\\Downloads\\so.wav",NULL,SND_ASYNC);
執行後一樣先有自己加入的音樂,然後跑出6張圖,接著按著1~5就有do re mi fa so 的旋律


MP3檔的執行


2019年4月25日 星期四

比利安娜工作室-balaboom_Week10

2019/4/25 Week10
(1)期中考:OpenGL必備10函式
(2)複習:移動,旋轉,縮放
(3)T-R-T旋轉(改變旋轉軸)
(4)主題:glut

Transformation.exe 自轉vs公轉
   glTranslatef(...)

   glRotatef(...)
    
   glRotatef(...)
   glTranslatef(...)

T-R-T旋轉(改變旋轉軸)
(1)先打出基本茶壺程式碼
#include <GL/glut.h>
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("week TRT");

    glutDisplayFunc(display);

    glutMainLoop();
}
(2)要把Cone移到茶壺的嘴巴


2019年4月11日 星期四

比利安娜工作室-balaboom_Week08

Week08 2019/04/11
(1)主題:貼圖Texture
(2)範圍:OpenCV
(3)實作:OpenCV
(4)實作:OpenCV+OpenGL貼圖
下載source.zip windows.zip and data.zip and glut32.dll
然後將windows.zip解壓縮,再將glut32.dll複製到解壓完的windows裡
  1. 開啟Texture.exe       🌑glTexCoord2f(tx,ty); glVertex3f(x,y,z)為期中考題
  2. 期中考試考題說明及複習
✦Google:OpenCV 2.1找到第一個
裡面OpenCV-2.1.0-win32-vs-2008.exe安裝
(1)要C:\OpenCV2.1 目錄
(2)要選Add PATH
(3)裝好後才能啟動CodeBlocks
✦下載freeglut window版,裝桌面\freeglut
(1)複製出桌面\freeglut\lib\libglut32.a
(2)CodeBlocks開GLUT專案,設定好
✦先將10行打好
(1)#include <opencv/highgui.h>加在#include<GL/glut.h>後面
(2)IplImage * img=cvLoadImage("earth.jpg");
    cvShowImage("opencv Window",img);
    cvWaitKey(0);
    這三行加在int main函式裡頭
(這樣依然不能執行程式,還要加上以下步驟~)
(1)在CodeBlocks裡選擇build options將OpenCV 2.1\include資料夾加進去(search directories/Compiler)

(2)將OpenCV 2.1\lib也加進去(search directories/Linker)
(3)在Linker Setting裡加上桃園三結義的資料夾
(4)程式碼執行結果(圖檔要放在freeglut-bin裡)

2019年3月28日 星期四

比利安娜工作室-balaboom_Week06

Week06 2019/03/28
下載source.zip windows.zip and data.zip and glut32.dll
然後將windows.zip解壓縮,再將glut32.dll複製到解壓完的windows裡
(1)主題:打光part1
(2)主題:模型OBJ檔
(3)實作:GLM vs OBJ
(4)回家作業
  1. 先開啟Light Material.exe
  2. 不同的燈光效果跟物體顏色會有不同的效果
接下來是跟之前一樣的做法(freeglut那種)→開啟codeblocks→十行程式碼→茶壺(之前的步驟)
🔘加上打燈效果的茶壺(程式碼)=>上課重點
#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 };
const 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 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("week06");

    glutDisplayFunc(display);

    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();
}
用notepad++開啟transformation.c複製其中的幾行加到今天的程式碼,但是這樣還是不能執行
  1. 還要在今天存的資料夾加入glm.c跟glm.h並將glm.c改名為glm.cpp
  2. 在freeglut->lib加入data
  3. 還要在codeblocks的sources裡加入glm.cpp就好了


2019年3月21日 星期四

比利安娜工作室-balaboom_Week05

Week05 2019/03/21
(1)主題:旋轉Rotation
下載windows.zip and data.zip and glut32.dll
然後將windows.zip解壓縮,再將glut32.dll複製到解壓完的windows裡
  1. 開啟Transformation
  2. glRotation(旋轉角度,x,y,z)
  3. 不同的數值所呈現的模型也會不同
(2)實作:glRotatef( )
(3)滑鼠轉、自動轉
(4)滑鼠事件:把大象放入冰箱

  1. 比照上周的作法開啟並建立glut檔
    (大概長這樣~~)
  2. 接下來打程式碼(這是基本的glut程式架構碼)
  3. 在加上今天及上周所教得程式碼讓茶壺可以轉動
  4. 再加上一點點程式碼(用滑鼠以X為軸讓茶壺旋轉)
  5. 在視窗中點擊將會在小黑窗中顯示滑鼠的資訊(第一個數中左鍵為0,中鍵為1,右鍵為2,滾輪往上為3,滾輪往下為4;第二個數點下為0,放開為1;第三個數為X的值;第四個數為Y的值)


2019年3月14日 星期四

比利安娜工作室-balaboom_Week04

Week04 2019/03/14
(1)主題:移動
下載windows.zip and data.zip and glut32.dll
然後將windows.zip解壓縮,再將glut32.dll複製到解壓完的windows裡
之後開啟Transformation.exe

🌑不同的角度大小及圖形也會呈現出不一樣的畫面
(2)示範:glTranslatef(x,y,z)
  1. 先去https://www.transmissionzero.co.uk/software/freeglut-devel/網站下載Download freeglut 3.0.0 for MinGW 
  2. 將解壓縮後的檔案放在桌面,之後將裡面的lib資料夾做動作如下圖
  3. 開他媽的codeblocks,建立一個glut專案(步驟已經在前幾的禮拜熟悉了~~)
  4. 開始撰寫程式(這是Week03的程式碼)
  5. 今天要加上glTranslatef的指令使他改變位置(多了3行程式碼)
(3)主題:滑鼠
  1. 由於強大寫程式的人控制滑鼠移動圖片居多,小葉老師教同學如何運滑鼠移動