顯示具有 05160655_羅聖閔 標籤的文章。 顯示所有文章
顯示具有 05160655_羅聖閔 標籤的文章。 顯示所有文章

2018年6月4日 星期一

WWEEK15

week01
跑OPENGL

week02
1.GLUT專案

week03
移動 旋轉 縮放

week04
roatae 矩陣

week05
TRT

week06
glm 3D

week07


week08
打光
week10
貼圖

week11
keyboard 配PlaySound()變鍵盤鋼琴
mouse 配 ..                      射擊
MP3 

2018年5月21日 星期一

WEEK13

#include <stdio.h>
int main()
{
    FILE *fout=fopen("output.txt","w+");

    printf("Hello world\n");
    fprintf(fout,"Hello world\n");
}
#include <GL/glut.h>
#include <stdio.h>
float angle=0;
FILE * fout =NULL;
int  oldX=0;
void mouse (int button,int state,int x ,int y)
{
    oldX=x;

}
void motion(int x,int y)
{
    angle+=x-oldX;
    oldX=x;
    if(fout==NULL)
    {
        fout = fopen("output.txt","w+");
    }
    fprintf(fout ,"%3f\n",angle);
    printf("%.3f\n",angle);
    glutPostRedisplay();
}

void display()///以下是老師提供的
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glutSolidTeapot(0.3);///正中間,當成身體的茶壼
        glPushMatrix();
            glTranslatef(0.4, 0,0);///掛上去
            glRotatef(angle, 0,0,1);///
            glTranslatef(0.4, 0,0);///把柄放中間
            glutSolidTeapot(0.3);///右邊,當成手臂的茶壼
        glPopMatrix();
    glPopMatrix();
    glutSwapBuffers();
}
///上面是我們增加的程式碼
///打光的部分留著 (陣列,main() ) 其他都刪掉
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 };

/* Program entry point */

int main(int argc, char *argv[])
{
    glutInit(&argc, argv);
    glutInitWindowSize(640,480);
    glutInitWindowPosition(10,10);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);

    glutCreateWindow("GLUT Shapes");
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    ///glutReshapeFunc(resize);
    glutDisplayFunc(display);
    ///glutKeyboardFunc(key);
    ///glutIdleFunc(idle);

    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();

    return EXIT_SUCCESS;
}

#include <GL/glut.h>
#include <stdio.h>
float angle=0;
FILE * fout =NULL;
FILE * fin=NULL;
int  oldX=0;
void keyboard(unsigned char key,int x,int y)
{
    if(fin==NULL)
    {
        fin=fopen("output.txt","r");
    }
    fscanf(fin,"%f",&angle);
    printf("%f\n", angle);
    glutPostRedisplay();
}
void mouse (int button,int state,int x ,int y)
{
    oldX=x;

}
void motion(int x,int y)
{
    angle+=x-oldX;
    oldX=x;
    if(fout==NULL)
    {
        fout = fopen("output.txt","w+");
    }
    fprintf(fout ,"%3f\n",angle);
    printf("%.3f\n",angle);
    glutPostRedisplay();
}

void display()///以下是老師提供的
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glutSolidTeapot(0.3);///正中間,當成身體的茶壼
        glPushMatrix();
            glTranslatef(0.4, 0,0);///掛上去
            glRotatef(angle, 0,0,1);///
            glTranslatef(0.4, 0,0);///把柄放中間
            glutSolidTeapot(0.3);///右邊,當成手臂的茶壼
        glPopMatrix();
    glPopMatrix();
    glutSwapBuffers();
}
///上面是我們增加的程式碼
///打光的部分留著 (陣列,main() ) 其他都刪掉
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 };

/* Program entry point */

int main(int argc, char *argv[])
{
    glutInit(&argc, argv);
    glutInitWindowSize(640,480);
    glutInitWindowPosition(10,10);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);

    glutCreateWindow("GLUT Shapes");
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    glutKeyboardFunc(keyboard);
    ///glutReshapeFunc(resize);
    glutDisplayFunc(display);
    ///glutKeyboardFunc(key);
    ///glutIdleFunc(idle);

    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();

    return EXIT_SUCCESS;
}

2018年5月14日 星期一

WEEK12

1.File-New-Project,GULT專安
2.把CODEBLOCKS Project.cbp檔改
notpad++(working-dir"..."改成.)
3.把freeglut\bin\freeglut32.dll(複製到目錄
)
使用MP3

#include <mmsystem.h>
#include "CMP3_MCI.h"
 CMP3_MCI myMP3;
int main(int argc, char *argv[])
{
 
    myMP3.Load("123.mp3");
    myMP3.Play();
計時器

void timer (int t)
{
    glutTimerFunc(2000,timer,0);
    PlaySound("Shot.wav",NULL,SND_ASYNC);
}
glutTimerFunc(7000,timer,0);
內差公式
新*a+舊*(1-a)
#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 };
float angle=0;
float alpha=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glutSolidTeapot(0.3);
            glPushMatrix();
            glTranslatef(0.4,0,0);
            glRotatef(angle,0,0,1);
        glTranslatef(0.4,0,0);
        glutSolidTeapot(0.3);
        glPopMatrix();
    glPopMatrix();
    glutSwapBuffers();
}
/* Program entry point */
#include <mmsystem.h>
#include "CMP3_MCI.h"
 CMP3_MCI myMP3;
void timer (int t)
{
    glutTimerFunc(500,timer,t+1);
    alpha=t/100.0;
    angle= alpha*90+(1-alpha)*0;
    PlaySound("Shot.wav",NULL,SND_ASYNC);
}
int main(int argc, char *argv[])
{
    ///PlaySound("Shot.wav",NULL,SND_ASYNC);
    ///myMP3.Load("123.mp3");
    ///myMP3.Play();
    glutInit(&argc, argv);
    glutInitWindowSize(640,480);
    glutInitWindowPosition(10,10);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);

    glutCreateWindow("GLUT Shapes");


    glutDisplayFunc(display);


    glutTimerFunc(1000,timer,0);

    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();

    return EXIT_SUCCESS;
}



2018年5月7日 星期一

WEEK11 mc

音樂

#include <mmsystem.h>
{
PlaySoundA("hicup[1].wav",NULL,SND_ASYNC);
}



#include <stdio.h>
#include <windows.h>
#include <mmsystem.h>

int main()
{
    PlaySoundA("hicup[1].wav",NULL,SND_SYNC);
    printf("Hello world!\n");

}

不等

#include <stdio.h>
#include <windows.h>
#include <mmsystem.h>

int main()
{
   PlaySoundA("hicup[1].wav",NULL,ASND_SYNC);
    printf("Hello world!\n");

}


鍵盤鋼琴
case'1':PlaySound("Do.wav",NULL, SND_ASYNC);
            break;
        case'2':PlaySound("Re.wav",NULL, SND_ASYNC);
            break;
        case'3':PlaySound("Mi.wav",NULL, SND_ASYNC);
            break;
        case'4':PlaySound("Fa.wav",NULL, SND_ASYNC);
            break;
        case'5':PlaySound("Sol.wav",NULL, SND_ASYNC);
            break;
        case'6':PlaySound("La.wav",NULL, SND_ASYNC);
            break;
        case'7':PlaySound("Si.wav",NULL, SND_ASYNC);
            break;
\
槍聲
void mouse (int button,int state,int x,int y)
{
    if(state==GLUT_DOWN) PlaySound("Shot.wav",NULL,SND_ASYNC);
}
....
.....
........
.....
glutMouseFunc(mouse);

2018年4月16日 星期一

WEEK08

cone>>>>>>水壺
轉起來
#include "glm.h"
GLMmodel * pmodel =NULL;
float angle =0;
void motion(int x,int y)
{
    angle =x;
    glutPostRedisplay();
}


static void display(void)
{


    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glColor3d(1,0,0);

    glPushMatrix();
    glRotatef(-angle,0,1,0);
    if (!pmodel) {
pmodel = glmReadOBJ("data/porsche.obj");
if (!pmodel) exit(0);
glmUnitize(pmodel);
glmFacetNormals(pmodel);
glmVertexNormals(pmodel, 90.0);
    }

    glmDraw(pmodel, GLM_SMOOTH | GLM_MATERIAL);
    glPopMatrix();

    glutSwapBuffers();
}






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

/* Program entry point */

int main(int argc, char *argv[])
{
    glutInit(&argc, argv);

    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);

    glutCreateWindow("GLUT Shapes");

    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();

    return EXIT_SUCCESS;
}

2018年3月26日 星期一

week05

倒茶
#include<GL/glut.h>
float angle=0;
void motion(int x,int y)
{
    angle=x;
    glutPostRedisplay();
}
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glRotatef(angle,0,0,1);
        glTranslatef(0.45,-0.08,0);
        glutSolidTeapot(0.3);
    glPopMatrix();
    glutSwapBuffers();
}
int main(int argc,char**argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week05 TRT");
    glutDisplayFunc(display);
    glutMotionFunc(motion);
    glutMainLoop();
}

多軸
#include<GL/glut.h>
float angle=0;
void motion(int x,int y)
{
    angle=x;
    glutPostRedisplay();
}
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glutSolidTeapot(0.3);
        glPushMatrix();
            glTranslatef(0.5,0.15,0);
            glRotatef(angle,0,0,1);
            glTranslatef(0.45,-0.08,0);
            glutSolidTeapot(0.3);
        glPushMatrix();
            glTranslatef(0.5,0.15,0);
            glRotatef(angle,0,0,1);
            glTranslatef(0.45,-0.08,0);
            glutSolidTeapot(0.3);
        glPopMatrix();
    glPopMatrix();


    glPushMatrix();
            glTranslatef(-0.5,0.15,0);
            glRotatef(angle,0,0,1);
            glTranslatef(-0.45,-0.08,0);
            glutSolidTeapot(0.3);

            glPushMatrix();
            glTranslatef(-0.5,0.15,0);
            glRotatef(angle,0,0,1);
            glTranslatef(-0.45,-0.08,0);
            glutSolidTeapot(0.3);
        glPopMatrix();
    glPopMatrix();
    glPopMatrix();
    glutSwapBuffers();


}
int main(int argc,char**argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week05 TRT");
    glutDisplayFunc(display);
    glutMotionFunc(motion);
    glutMainLoop();
}



2018年3月19日 星期一

week04




非等速

#include <GL/glut.h> //呼叫GLUT_外掛
#include <stdio.h>
float angle=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
    glRotatef(angle,0,0,1);
    glutSolidTeapot(0.3);  /// 呼叫茶壺圖示
    glPopMatrix();
    glutSwapBuffers();
    printf("%.1f\n",angle);
    angle++;

}
int main(int argc ,char *argv[])  //呼叫main函式
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("05160655_Week04_Transformation");  /// 視窗標題
    glutIdleFunc(display);
    glutDisplayFunc(display);


    glutMainLoop();  // 函式迴圈
}


手動
#include <GL/glut.h> //呼叫GLUT_外掛
#include <stdio.h>
float angle=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glRotatef(angle,0,0,1);
        glutSolidTeapot(0.3);  /// 呼叫茶壺圖示
    glPopMatrix();
    glutSwapBuffers();


}
void mouse (int button,int state,int x,int y)
{

}
void motion (int x,int y)
{
    angle=x;
    glutPostRedisplay();
}
int main(int argc ,char *argv[])  //呼叫main函式
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("05160655_Week04_Transformation");  /// 視窗標題
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    ///glutIdleFunc(display);
    glutDisplayFunc(display);


    glutMainLoop();  // 函式迴圈
}





2018年3月12日 星期一

week03

基本架構

#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("week03 Mouse");

    glutDisplayFunc(display);

    glutMainLoop();
}




    mouse印程式碼
    #include <stdio.h>
   void mouse(int button, int state,int x,int y)
  {
       if(state==GLUT_DOWN)printf("glVert2f(%f,%f);\n",(x-150)/150.0,-(y-150)/150.0);
  }
.....
.....
...
  glutMouseFunc(mouse);


MOTION
#include <GL/glut.h>
float teapotX=0,teapotY=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
    glTranslatef(teapotX,teapotY,0);
    glutSolidTeapot(0.3);
    glPopMatrix();

    glutSwapBuffers();

}
#include <stdio.h>
void mouse(int button, int state,int x,int y)
{
    if(state==GLUT_DOWN)printf("glVert2f(%f,%f);\n",(x-150)/150.0,-(y-150)/150.0);
}
void motion(int x,int y)
{
    teapotX=(x-150)/150.0; teapotY=-(y-150)/150.0;
    printf("%d %d\n",x,y);
    glutPostRedisplay();
}
int main(int argc,char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE |GLUT_DEPTH);
    glutCreateWindow("week03 Mouse");

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





                                                       

2018年3月5日 星期一

week02

連結: jsyeh.org/3dcg10
1.下載data
2.下載win32
3.下載glut32.dll   複製 移至 win32


trytry

bang 顏色 茶
bang 顏色 三角