顯示具有 Week13 標籤的文章。 顯示所有文章
顯示具有 Week13 標籤的文章。 顯示所有文章

2015年6月28日 星期日

20150520_譚崇彣_HW11

#include <GL/glut.h>

void display(){
    glPushMatrix();
        glutSolidTeapot(100);
    glPopMatrix();
    glFlush();
}

int main(int argc, char** argv){
    glutInit(&argc, argv);
    glutInitWindowSize(800,600);
    glutCreateWindow("Camera");
    glutDisplayFunc(display);
    glViewport(0,0,800,600);
    glMatrixMode(GL_PROJECTION);
    glOrtho(-400,400,-300,300,-1000,1000);
    glMatrixMode(GL_MODELVIEW);

    glutMainLoop();
}

但是上訴的方法在手動調整視窗的時候茶壺又變形了,於是又有了下面的方法


#include <GL/glut.h>

void display(){
    glPushMatrix();
        glutSolidTeapot(100);
    glPopMatrix();
    glFlush();
}
void reshape(int w, int h){
    glViewport(0,0,w,h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(-w/2,w/2,-h/2,h/2,-1000,1000);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
}

int main(int argc, char** argv){
    glutInit(&argc, argv);
    glutInitWindowSize(800,600);
    glutCreateWindow("Camera");
    glutDisplayFunc(display);
    glutReshapeFunc(reshape);

    glutMainLoop();
}

加入計時器,自動轉


#include <GL/glut.h>

float eyeX=-100, eyeY=80, eyeZ=-200;
void display(){
    GLfloat pos[] = {0,0,200,0};
    glLightfv(GL_LIGHT0, GL_POSITION, pos);     ///打燈光
    glEnable(GL_LIGHT0);
    glEnable(GL_NORMALIZE);
    glEnable(GL_LIGHTING);

    glEnable(GL_DEPTH_TEST);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        gluLookAt(eyeX,eyeY,eyeZ, 0,0,0, 0,1,0);
        glPushMatrix();
            glutSolidTeapot(100);
        glPopMatrix();
    glPopMatrix();
    glFlush();
}

void motion(int x, int y){                    ///eye-移動
    eyeX=-400; eyeY=300-y;
    glutPostRedisplay();
}

void reshape(int w, int h){
    glViewport(0,0,w,h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(90,w/h,0.001,1000);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
}

void timer(int t){                          ///計時
    glutTimerFunc(20,timer,t+1);
    eyeX+=2;
    if(eyeX>300) eyeY+=4;
    glutPostRedisplay();
}

int main(int argc, char** argv){
    glutInit(&argc, argv);
    glutInitWindowSize(800,600);
    glutCreateWindow("Camera");
    glutDisplayFunc(display);
    glutReshapeFunc(reshape);
    glutMotionFunc(motion);
    glutTimerFunc(0,timer,0);

    glutMainLoop();
}

2015年6月17日 星期三

WEEK13

#include <GL/glut.h>
float eyeX=-100,eyeY=80,eyeZ=-200;

void display()
{   GLfloat pos[]={0,0,200,0};
    glLightfv(GL_LIGHT0, GL_POSITION, pos);
    glEnable(GL_LIGHT0);
    glEnable(GL_NORMALIZE);
    glEnable(GL_LIGHTING);

    glEnable(GL_DEPTH_TEST);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
      gluLookAt(eyeX,eyeY,eyeZ, 0,0,0,0,1,0);
      glPushMatrix();
      glutSolidTeapot(100);
     glPopMatrix();
    glPopMatrix();
    glFlush();
}

void motion(int x,int y)
{
    eyeX=x-400;eyeY=300-y;
    glutPostRedisplay();
}
void reshape(int w, int h)
{
    glViewport(0,0, w,h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(-w/2,w/2, -h/2,h/2,-1000,1000);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

}
void timer(int t)
{
    glutTimerFunc(20,timer,t+1);
    eyeX+=2;
    if(eyeX>300) eyeY+=4;
    glutPostRedisplay();
}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitWindowSize(800,600);
    glutCreateWindow("3D");
    glutDisplayFunc(display);
    glutReshapeFunc(reshape);
    glutMotionFunc(motion);
    glutTimerFunc(0,timer,0);
glViewport(0,0,800,600);
    glMatrixMode(GL_PROJECTION);
    glOrtho(-400,400,-300,300,-1000,1000);
    glMatrixMode(GL_MODELVIEW);

    glutMainLoop();
}

2015年5月27日 星期三

02160596李昱呈,WEEK13



Week13 02160510黃品鈞


#include <GL/glut.h>
float eyeX=-100,eyeY=80,eye2=-200;

void display()
{
    GLfloat pos[]={0,0,200,0};
    glLightfv(GL_LIGHT0,GL_POSITION,pos);
    glEnable(GL_LIGHT0);
    glEnable(GL_NORMALIZE);
    glEnable(GL_LIGHTING);

    glEnable(GL_DEPTH_TEST);
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        gluLookAt(eyeX,eyeY,eye2,0,0,0,0,1,0);
    glPushMatrix();
        glutSolidTeapot(100);
    glPopMatrix();
    glPopMatrix();
    glFlush();
}
void motion(int x,int y)
{
    eyeX=x-400;eyeY=300-y;
    glutPostRedisplay();
}

void reshape(int w,int h)
{
     glViewport(0,0,w,h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(90,w/h,0.001,10000);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

}
void timer(int t )
{
    glutTimerFunc(20,timer,t+1);
    eyeX+=2;
    if(eyeX>300)eyeY+=4;
    glutPostRedisplay();
}
int main(int argc, char**argv)
{
    glutInit(&argc,argv);
    glutInitWindowSize(800,600);
    glutCreateWindow("3D");
    glutDisplayFunc(display);
    glutReshapeFunc(reshape);
    glutMotionFunc(motion);
    glutTimerFunc(0,timer,0);



    glutMainLoop();
}

2015年5月24日 星期日

02163051_邱冠程 Week13

設定茶壺大小,
讓螢幕內的茶壺不會變形。


帶入 音樂、鏡頭
#include <GL/glut.h>
#include "CMP3_MCI.h" ///宣告
CMP3_MCI    MyMP3;
float eyeX=-100, eyeY=80, eyeZ=-200;

void display()
{
    GLfloat pos[] = {0, 0, 200, 0};
    glLightfv(GL_LIGHT0, GL_POSITION, pos);

    glEnable(GL_LIGHT0); ///開頭的複製
    glEnable(GL_NORMALIZE);
    glEnable(GL_LIGHTING);

    glEnable(GL_DEPTH_TEST);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        gluLookAt(eyeX,eyeY,eyeZ, 0,0,0, 0,1,0);

    glPushMatrix();
        glutSolidTeapot(100); ///要多少有多少
    glPopMatrix();
    glPopMatrix();
    glFlush();
}
void motion(int x, int y)
{
    eyeX=x-400; eyeY=300-y;
    glutPostRedisplay();
}
void reshape(int w, int h)
{
    glViewport(0,0, w,h); ///寬度跟高度
    glMatrixMode(GL_PROJECTION); ///可以等比例了
    glLoadIdentity(); ///保護用的
    gluPerspective(90, w/h, 0.001, 10000);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
}
void timer(int t)
{
    glutTimerFunc(20, timer, t+1);
    eyeX+=2;
    if(eyeX>300) eyeY+=4;
    glutPostRedisplay();
}
void keyboard(unsigned char key, int x, int y)
{
    MyMP3.Play(); ///按按鍵
}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitWindowSize(800,600);
    glutCreateWindow("3D");
    glutDisplayFunc(display);

    glutReshapeFunc(reshape); ///視窗變形,交給他 重要!!

    glutMotionFunc(motion);
    glutTimerFunc(0, timer, 0);
    glutKeyboardFunc(keyboard);
    MyMP3.Load("music.mp3");
    //glViewport(0,0, 800,600);
    //glMatrixMode(GL_PROJECTION); ///可以等比例了
    //glOrtho(-400,400, -300,300,-1000,1000); ///投影矩陣
    //glMatrixMode(GL_MODELVIEW);

    glutMainLoop();
}


2015年5月20日 星期三

Week13_02131735_郭盈萱


#include <GL/glut.h>
float eyeX=-100,eyeY=80,eyeZ=-200;

void display()
{   GLfloat pos[]={0,0,200,0};
    glLightfv(GL_LIGHT0, GL_POSITION, pos);
    glEnable(GL_LIGHT0);
    glEnable(GL_NORMALIZE);
    glEnable(GL_LIGHTING);

    glEnable(GL_DEPTH_TEST);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
      gluLookAt(eyeX,eyeY,eyeZ, 0,0,0,0,1,0);
      glPushMatrix();
      glutSolidTeapot(100);
     glPopMatrix();
    glPopMatrix();
    glFlush();
}

void motion(int x,int y)
{
    eyeX=x-400;eyeY=300-y;
    glutPostRedisplay();
}
void reshape(int w, int h)
{
    glViewport(0,0, w,h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(-w/2,w/2, -h/2,h/2,-1000,1000);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

}
void timer(int t)
{
    glutTimerFunc(20,timer,t+1);
    eyeX+=2;
    if(eyeX>300) eyeY+=4;
    glutPostRedisplay();
}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitWindowSize(800,600);
    glutCreateWindow("3D");
    glutDisplayFunc(display);
    glutReshapeFunc(reshape);
    glutMotionFunc(motion);
    glutTimerFunc(0,timer,0);
glViewport(0,0,800,600);
    glMatrixMode(GL_PROJECTION);
    glOrtho(-400,400,-300,300,-1000,1000);
    glMatrixMode(GL_MODELVIEW);

    glutMainLoop();
}

02160092_黃冠瑜_week13

 依網址jsyeh.org/3dcg10下載標示的兩個檔案,提供參考用!
打開老師給的windows資料夾,打開裡面的Projection執行檔,試著轉動上面的數字可以發現人物會隨著數字而改變方向、大小、角度、胖瘦!

 開啟code blocks後,把打光的程式碼先複製起來!
接著寫下這些程式,可以創造出我們自訂的視窗大小

#include <GL/glut.h>
void display()
{
    glPushMatrix();
        glutSolidTeapot(150);
    glPopMatrix();
    glFlush();
}
int main(int argc,char**argv)
{
    glutInit(&argc,argv);
    glutInitWindowSize(800,600);
    glutCreateWindow("3D");
    glutDisplayFunc(display);
    ///glutReshapeFunc(reshape);
    glViewport(0,0,800,600);
    glMatrixMode(GL_PROJECTION);
    glOrtho(-400,400,-300,300,-1000,1000);
    glMatrixMode(GL_MODELVIEW);
    glutMainLoop();
}

#include <GL/glut.h>
void display()
{
    glPushMatrix();
        glutSolidTeapot(150);
    glPopMatrix();
    glFlush();
}
void reshape(int w,int h)    ///寫reshape使改變視窗大小,也不會讓茶壺變形!
{
    glViewport(0,0,w,h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(-w/2,w/2,-h/2,h/2,-1000,1000);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
}
int main(int argc,char**argv)
{
    glutInit(&argc,argv);
    glutInitWindowSize(800,600);
    glutCreateWindow("3D");
    glutDisplayFunc(display);
    glutReshapeFunc(reshape);

    glutMainLoop();
}

#include <GL/glut.h>
float eyeX=-100,eyeY=80,eyeZ=-200;
void display()
{
    GLfloat pos[]={0,0,200,0};
    glLightfv(GL_LIGHT0,GL_POSITION,pos);
    glEnable(GL_LIGHT0);
    glEnable(GL_NORMALIZE);
    glEnable(GL_LIGHTING);

    glEnable(GL_DEPTH_TEST);
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        gluLookAt(eyeX,eyeY,eyeZ,0,0,0, 0,1,0);
        glPushMatrix();
            glutSolidTeapot(100);
        glPopMatrix();
    glPopMatrix();
    glFlush();
}
void motion(int x,int y)
{
    eyeX=x-400;eyeY=300-y;
    glutPostRedisplay();
}
void reshape(int w,int h)    ///寫reshape使改變視窗大小,也不會讓茶壺變形!
{
    glViewport(0,0,w,h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(90,w/h,0.001,10000);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
}
void timer(int t)
{
    glutTimerFunc(20,timer,t+1);
    eyeX+=2;
    if(eyeX>300) eyeX+=4;
    glutPostRedisplay();
}
int main(int argc,char**argv)
{
    glutInit(&argc,argv);
    glutInitWindowSize(800,600);
    glutCreateWindow("3D");
    glutDisplayFunc(display);
    glutReshapeFunc(reshape);
    glutMotionFunc(motion);
    glutTimerFunc(0, timer, 0);
    glutMainLoop();
}
這次加入音樂檔,讓程式可以跑出音樂

#include <GL/glut.h>
#include "CMP3_MCI.H"
CMP3_MCI  MyMP3;
float eyeX=-100,eyeY=80,eyeZ=-200;
void display()
{
    GLfloat pos[]={0,0,200,0};
    glLightfv(GL_LIGHT0,GL_POSITION,pos);
    glEnable(GL_LIGHT0);
    glEnable(GL_NORMALIZE);
    glEnable(GL_LIGHTING);

    glEnable(GL_DEPTH_TEST);
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        gluLookAt(eyeX,eyeY,eyeZ,0,0,0, 0,1,0);
        glPushMatrix();
            glutSolidTeapot(100);
        glPopMatrix();
    glPopMatrix();
    glFlush();
}
void motion(int x,int y)
{
    eyeX=x-400;eyeY=300-y;
    glutPostRedisplay();
}
void reshape(int w,int h)    ///寫reshape使改變視窗大小,也不會讓茶壺變形!
{
    glViewport(0,0,w,h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(90,w/h,0.001,10000);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
}
void timer(int t)
{
    glutTimerFunc(20,timer,t+1);
    eyeX+=2;
    if(eyeX>300) eyeX+=4;
    glutPostRedisplay();
}
void keyboard(unsigned char key,int x,int y)
{
    MyMP3.Play();
}
int main(int argc,char**argv)
{
    glutInit(&argc,argv);
    glutInitWindowSize(800,600);
    glutCreateWindow("3D");
    glutDisplayFunc(display);
    glutReshapeFunc(reshape);
    glutMotionFunc(motion);
    glutTimerFunc(0, timer, 0);
    glutKeyboardFunc(keyboard);
    MyMP3.Load("music.mp3");
    glutMainLoop();
}