2025年5月15日 星期四

12750840_week13

Week13 


week13_1
//week13_1_processing_video
//Sketch - Library - manage libraries...安裝video
import processing.video.*; //Java使用外掛的匯入
//Capture video;//有視訊鏡頭的用這個版本
Movie movie;//沒有視訊鏡頭的用這個版本
void setup(){
  size(640,480); //常見的視訊
  //video = new Capture(this, 640, 480);
  //video.start(); //打開視訊
  movie = new Movie(this, "street.mov"); //讀檔案
  movie.loop();
}
void draw(){
  //if(video.available()) video.read();//若沒有視訊就註解掉
  //image(video, 0, 480);//若沒有視訊就註解掉
  if(movie.available()) movie.read();
  image(movie, 0, 0);
}

week13_2
//week13_2_camera_movie_eye_center_up
//電腦圖學繪圖時,會設定camera的相關係數
import processing.video.*; //使用影片的外掛
Movie movie; //要放影片的變數
void setup(){
  size(720, 480, P3D); //要記得加上P3D才能有OpenGL3D功能
  movie = new Movie(this, "street.mov");//把street,mov拉進來
  movie.loop(); //迴圈撥放 影片解析度720 480
}
void draw(){
  background(128);
  camera(mouseX, mouseY, 500, 360, 240, 0, 0, 1, 0);
  //很多參數eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ
  //                          現在把影片中心點,幫主角
  if(movie.available()) movie.read();//有新畫面就讀入
  image(movie, 0, 0);//放影片,在0, 0
}




week13_3
//week13_3_texture_textureMode_beginShape_vertex_endShape
//先教貼圖,之後再加進去
PImage img;
void setup(){
  size(400, 400, P3D); //要記得加上P3D才能有OpenGL3D功能
  img = loadImage("chessboard.png");
  textureMode(NORMAL);//有很多種貼圖模式
  //先用最簡單的NORMAL來畫,2個三角形,不像是3D透視的效果
}
void draw(){
  background(128); //灰背景
  beginShape();//開始畫
  texture(img);//把圖片,當貼圖
  vertex(40, 80, 0, 0);//4個頂點vertex的四邊形,會裁出2個三角形
  vertex(320, 20, 1, 0);
  vertex(380, 360, 1, 1);
  vertex(160, 380, 0, 1);
  endShape();
}

week13_4
//week13_4_camera_chessboard_texture_front_left
//把貼圖跟camera整合在一起
PImage img;
void setup(){
  size(400, 400, P3D); //要記得加上P3D才能有OpenGL3D功能
  img = loadImage("chessboard.png");
  textureMode(NORMAL);//有很多種貼圖模式
}
void draw(){ //攝影機往前方看,左右,前後移動
  camera(mouseX, 200, mouseY, mouseX, 200, mouseY-10, 0, 1, 0);
  background(128);
  beginShape();//正前方,z座標都放0
  texture(img);
  vertex(0, 0, 0, 0, 0);//x, y, z, u, v
  vertex(400, 0, 0, 1, 0);
  vertex(400, 400, 0, 1, 1);
  vertex(0, 400, 0, 0, 1);
  endShape();  
  beginShape(); //左方, x座標都放0
  texture(img);
  vertex(0, 0, 0, 0, 0);//x, y, z, u, v
  vertex(0, 400, 0, 1, 0);
  vertex(0, 400, 400, 1, 1);
  vertex(0, 0, 400, 0, 1);
  endShape(); 
  }



week13_5
//week13_5_camera_keyPressed_keyCode_x_y_z_angle_cos_sin
//修改至week13_4_camera_chessboard_texture_front_left
//利用方向鍵(上下左右建)來移動
PImage img;
void setup(){
  size(400, 400, P3D);
  img = loadImage("chessboard.png");
  textureMode(NORMAL);
}
float x = 200, y = 200, z = 200, angle = 180;
void keyPressed(){
  if(keyCode==LEFT) angle--;
  if(keyCode==RIGHT) angle++;
  if(keyCode==UP) {
    x += cos(radians(angle));
    z += sin(radians(angle)); //小心是Z(3D前後)不是y(3D上下)
  }
  if(keyCode==DOWN) {
    x -= cos(radians(angle));
    z -= sin(radians(angle));//小心是Z(3D前後)不是y(3D上下)
  }
}
    
void draw(){ //攝影機往前方看,左右,前後移動
  if(keyPressed) keyPressed(); //補強遺下,讓案件案下去會一直跟新
  camera(x, y, z, x+cos(radians(angle)), y, z + sin(radians(angle)), 0, 1, 0);
  //camera(mouseX, 200, mouseY, mouseX, 200, mouseY-10, 0, 1, 0);
  background(128);
  beginShape();//正前方,z座標都放0
  texture(img);
  vertex(0, 0, 0, 0, 0);//x, y, z, u, v
  vertex(400, 0, 0, 1, 0);
  vertex(400, 400, 0, 1, 1);
  vertex(0, 400, 0, 0, 1);
  endShape();  
  beginShape(); //左方, x座標都放0
  texture(img);
  vertex(0, 0, 0, 0, 0);//x, y, z, u, v
  vertex(0, 400, 0, 1, 0);
  vertex(0, 400, 400, 1, 1);
  vertex(0, 0, 400, 0, 1);
  endShape(); 
  }

week13_6
//week13_6_combine_all_Movie_Capture_PImage_camera_sin_cos_P3D
//all
import processing.video.*;
Movie movie; 
PImage img;
void setup(){
  size(400, 400, P3D);
  movie = new Movie(this, "street.mov"); //720x480
  movie.loop();//循環播放
  img = loadImage("chessboard.png");
  textureMode(NORMAL);
  video = new Capture(this, 640, 480);
  video.start(); //要記得開始撥放
}
Capture video; //有鏡頭在加他
void draw(){
  camera(200, 200, 200, 200+cos(radians(frameCount)), 200, 200 + sin(radians(frameCount)), 0, 1, 0);
  background(128);
  if(movie.available()) movie.read();
  beginShape(); //正前方
  vertex(0, 0, 0, 0, 0);//x, y, z, u, v
  vertex(400, 0, 0, 1, 0);
  vertex(400, 400, 0, 1, 1);
  vertex(0, 400, 0, 0, 1);
  endShape();
  translate(0, 0, 1);
  image(movie, 0, 0, 360, 240); //放影片,用2D的放圖方法
  if(movie.available()) video.read(); //有畫面就讀入畫面
  beginShape(); //左方直接放視訊畫面
  texture(video); //把視訊 當成是一面牆的貼圖
  vertex(0, 0, 0, 0, 0);//x, y, z, u, v
  vertex(0, 400, 0, 1, 0);
  vertex(0, 400, 400, 1, 1);
  vertex(0, 0, 400, 0, 1);
  endShape(); 
}

沒有留言:

張貼留言