顯示具有 40347015S_邱世弦 標籤的文章。 顯示所有文章
顯示具有 40347015S_邱世弦 標籤的文章。 顯示所有文章

2017年12月14日 星期四

世弦 week 14

一、試試 rasterization:

1.打上程式碼:

size(600,600,P3D);
background(255);
beginShape(TRIANGLE);

fill(255,0,0);
vertex(300,100);
fill(255,255,0);
vertex(500,500);
fill(0,0,255);
vertex(100,500);
endShape();

2.執行:




2017年12月7日 星期四

世弦 week13

一、色彩系統:

1.打上程式碼:

size(255,255);
colorMode(HSB, 255);

for(int x=0; x<255; x++)
{
    for(int y=0; y<255; y++)
    {
         stroke(x,y,255);
         point(x,y);
    }
}

2.執行:






2017年11月30日 星期四

世弦 qlqweek 12

一、Scene 場景:

1.從moodle 下載 myGL_Frustum 221_Multiview,並試著編譯:

2.新增glut 專案,並把myGL_Frustrum_skeleton.cpp  貼上去:

3.修正(新增這兩行):

int main(int argc, char **argv)
{
    glutInit(&argc, argv);
    ...
}

4.執行:



5. 跑processing 範例程式:



6.跑老師寫的程式testBVH:

2017年11月23日 星期四

世弦 week11

一、c++ 放音樂:

1. 開啟glut 專案,打上程式碼,把音樂檔放在freeglut/bin: 

#include <stdio.h>
#include "CMP3_MCI.h" ///使用外掛,可在FB下載
CMP3_MCI mp3;/// int a; 宣告變數
int main()
{
    mp3.Load("123.mp3");///讀入 mp3檔
    mp3.Play();///Play播放mp3檔
///PlaySoundA("file.wav", NULL, SND_SYNC);
    printf("現在在待輸入a\n");
    int a;
    scanf("%d", &a);///等待輸入時,程式還沒結束
}



二、processing 放音樂:

1.添加library: Minim:


2. 打上程式碼:

import ddf.minim.*;
Minim minim;
AudioPlayer player;
AudioPlayer play2;

void setup(){
    minim=new Minim(this);
    player=minim.loadFile("123.mp3"); //音樂檔放在processing 裡
    player.play();
}

void draw(){
    
}

2017年11月16日 星期四

世弦 week10

一、寫手機app

1.開啟process 寫 andriod app:

void setup()
{
  fullScreen();
}

void draw()
{
  if(mousePressed)background(255,0,0);
  else background(0,255,0);

}



2. 案執行會有綠色畫面,案移下滑鼠變紅色畫面:



2.偵測碰撞遊戲:

void setup(){
size(500,500);
}
float ballX=250,ballY=450, ballVX=1, ballVY=10;
float ball2X=250, ball2Y=50;
void draw(){
if(ballX>450||ballX<50) //牆壁
    ballVX=-ballVX;
if(ballY>450 || ballY<50) //牆壁
    ballVY=-ballVY;
if( dist(ballX, ballY, ball2X, ball2Y)<100 ){
float cx=(ballX+ball2X)/2, cy=(ballY+ball2Y)/2;
float nx=ballX-ball2X, ny=ballY-ball2Y;
PVector N=new PVector(nx,ny);
N.normalize();
PVector v0=new PVector(ballVX, ballVY);
float len= -N.dot(v0);
v0.add(N.mult(len*2));
ellipse(cx, cy, 10,10);
stroke(0); line(ballX, ballY, ball2X, ball2Y);
stroke(255,128,0); line(cx,cy, cx+5*ballVX, cy+5*ballVY);
stroke(255,128,0); line(cx,cy, cx+5*v0.x, cy+5*v0.y);
stroke(255,0,0); line(cx,cy, cx+N.x, cy+N.y);
//return;
ballVX=v0.x; ballVY=v0.y;
}
background(255);
ballX+=ballVX; ballY+=ballVY;
ellipse(ballX, ballY, 100,100);
ellipse(ball2X, ball2Y, 100,100);
}







2017年11月9日 星期四

世弦 week 09

一、Bump Mapping : 網址體驗

1. 執行:



2. 程式碼:



3.把上述程式碼貼到P語言(process-3.3.6),並在random(512)裡面加上亂數:



4.執行:



二、自己寫程式: 

1.畫正方形:

size(200, 200); //200*200的視窗
fill(#D64747); //填顏色
rect(10, 10, 50, 50);



2.畫多拉A夢:

PImage img=loadImage("dora.jpg");
size(600, 600);
image(img, 0,0, 600, 600);



3.畫連續error:

PImage img;
void setup(){
    size(1280,800);
    img=loadImage("error.jpg");
}

void draw(){
    image(img, mouseX, mouseY);
}



4. 做馬力歐遊戲:

PImage imgMario, imgBrick;
void setup(){
 size(800,600);
    imgMario=loadImage("mario.jpg");
    imgBrick=loadImage("brick.jpg");
}
float marioX=200, marioY=100, marioVY=0;
void draw(){
    background(255);
    for (int x=0; x<18; x++)
        image(imgBrick, x*50, 500, 100, 100);
    image(imgMario, mouseX, mouseY, 100, 100);
    marioY+=marioVY;
    marioVY+=0.98;
    if(marioY>500-80){marioY=500-80; marioVY=0;}
}

















2017年10月26日 星期四

世弦 week07

一、 Mouse 打光:用滑鼠調光源:

1. 在glut 範例專案加入函式:

void motion(int x, int y)
{
    light_position[0]= (x-150)/150.0 *2;
    light_position[1]= -(y-150)/150.0 *2;
    glLightfv(GL_LIGHT0, GL_POSITION, light_position);
    glutPostRedisplay();

};

int main()
{
    .
    .
    .
    glutMotionFunc(motion);
 
}

2.執行,滑鼠拉放可以改變光源:




2017年10月19日 星期四

世弦 week06

一、打光:

1. 打開上次的week05,並加上以下幾行 在程式中:

GLfloat pos[]={0.0, 0.0, -1.0, 0.0}; //偷來的打光(3)
glEnable(GL_DEPTH_TEST); //偷來的3D深度測試,打開Enable
glEnable(GL_LIGHTING); //偷來的打光(2),打開Enable
glEnable(GL_LIGHT0); //偷來的打光(1),打開Enable
glLightfv(GL_LIGHT0, GL_POSITION, pos);




2.並執行:





二、寫回家作業(keyboard、Mouse、轉動、移動):

1.加入keyboard、Mouse 函式讓他可以印滑鼠所在座標:

void keyboard(unsigned char key, int x, int y)
{
    printf("now %c (%d,%d)\n", key, x, y);
}
void mouse(int button, int state, int x, int y)
{

}

int main(...)
{
   .
   .
   .
   glutDisplayFunc(display);
   glutKeyboardFunc(keyboard);
   glutMouseFunc(mouse);

}

2. 並且執行,滑鼠一直在畫面移動,並按鍵盤:



3.鍵盤讓他轉動:

int rotateX, rotateY, rotateZ; //旋轉軸
void keyboard(unsigned char key, int x, int y)
{
    printf("now %c (%d,%d)\n", key, x, y);
    if(key=='1')rotateX++; //控制旋轉方向
    else if(key=='2')rotateY++;
    else if(key=='3')rotateZ++;
    glutPostRedisplay(); //把畫面重新re-display
}

void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
       glRotatef(rotateX, 1, 0, 0);
       glRotatef(rotateY, 0, 1, 0);
       glRotatef(rotateZ, 0, 0, 1);
       drawmodel();
    glPopMatrix();

    glutSwapBuffers();
}



4.滑鼠讓他轉動:

int OldX=0, OldY=0; //舊座標
void mouse(int button, int state, int x, int y)
{
    printf("button: %d  state: %d (%d %d)\n", button, state, x, y);
    if(state==GLUT_DOWN) //點下滑鼠
    {
        OldX=x, OldY=y; //
    }
}
void motion(int x, int y)
{
    rotateX+=-(y-OldY); //X方向轉動
    rotateY+=-(x-OldX); //Y 方向轉動
    OldX=x, OldY=y; //更新座標
    glutPostRedisplay();
}

glutMouseFunc(mouse);
glutMotionFunc(motion);



















2017年10月12日 星期四

世弦 week05

一、 執行範例檔:

1. 下載檔案並解壓縮;


2.準備好檔案:


3.執行transformation.exe:


4.執行看看projection.exe:


gluPerspective(fovy,  aspect,  zNear,  zFar)
                         視野 y/x比例

5. gluOrtho (左, 右, 下, 上, 近, 遠) 
    glFrustum (左, 右, 下, 上, 近, 遠) 
    glutLookAt (eyeX, eyeY, eyeZ,
                         centerX, centerY, centerZ,
                         upX, upY, upZ)



2017年10月5日 星期四

世弦 Week04

一、在glut範例專案改display()函式:

1.在glPushMatrix();和 glPopMatrix(); 中間 加入glutSolidTeapot(1.35);



2. 執行:



3.glRotated(角度, x, y, z); 改旋轉角度(右手座標系統):



glTranslatef(x, y, z); //float,移動到哪
glTranslated(x, y, z); //double,移動到哪
glRotatef(角度, x, y, z); //旋轉角度
glRotated(角度*t, x, y, z); //每單位時間旋轉角度

4.glScaled(2, 2, 2) //x,y,z 都放大兩倍:






2017年9月28日 星期四

世弦 Week03

一、繪製小小兵

1.下載學姐的cpp 貼在上次的 glut 專案的main.cpp裡:















2. 並把minion.txt 放在 freeglut/bin 裡:















3.  並案F9執行:


二、 跑3D足球圖
1.下載 soccerball.obj 丟到3DExploration 並選存成 .cpp:


2 選sample app:


3. 丟到opengl 專案:


4. 執行:

.

2017年9月22日 星期五

邱世弦 Week02

1. 任務一: 茶壺

#include <GL/glut.h>//呼叫3D  glut外掛
static void display(void)
{

    glClearColor(1,0,0,0);//設定背景顏色為紅色
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);//清理背景顏色
    glColor3f(0,0,1);//設定顏色(3=3色,f=浮點數)
    glutSolidTeapot(0.3);//呼叫茶壺圖案
    glutSwapBuffers();//清理繪圖buffer
}

int main(int argc, char *argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("GLUT Shapes"); //設定視窗名
    glutDisplayFunc(display);//執行display函式
    glutMainLoop();//執行迴圈

}














2. 任務二: 親手打造自己的點、線、面、顏色

#include <GL/glut.h>//呼叫3D  glut外掛
static void display(void)
{

    glClearColor(1,0,0,0);//設定背景顏色為紅色
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);//清理背景顏色
    glColor3f(0,0,1);//設定顏色(3=3色,f=浮點數)

    glBegin(GL_POLYGON);//開始畫多邊形
    glVertex3f(1,-1,0);//設置頂點
    glVertex3f(-1,-1,0);
    glVertex3f(0,1,0);
    glEnd();//結束畫

    glutSwapBuffers();//清理繪圖buffer
}

int main(int argc, char *argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("GLUT Shapes"); //設定視窗名
    glutDisplayFunc(display);//執行display函式
    glutMainLoop();//執行迴圈
}



2017年9月15日 星期五

邱世弦 Week 01

openGL:

1, 開啟code blocks --> file --> new --> project:



2.點選OpenGL project:



3.打好檔名 --> 存在桌面 --> next:



4.按F9編譯並執行,並觀察結果:















glut:

1.下載 freeglut-MinGW-3.0.0-1.mp.zip 並解壓縮到桌面:



2. 把 freeglut\lib\ libfreeglut.a 複製一份,並改名成libglut32.a:



3.file --> new --> project --> GLUTproject:



4.命名 --> 存在桌面 -- > next:


5.路徑改為  "C:\Users\邱世弦\Desktop\freeglut"  --> next :



6.按F9編譯並執行,並觀察結果: