week13_1
//week13_1_processing_vedio
// Sketch - Library - Manage Libraries... 安裝video
import processing.video.*; // Java使用外掛的 匯入
Capture video; //有用鏡頭用這個
Movie movie; //沒有鏡頭用這個
void setup(){
size(640,960);
//video = new Capture(this,640,480);
//video.start();
movie = new Movie(this,"street.mov");
movie.loop();
}
void draw(){
//if(video.available()) video.read();
//image(vedio,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(600,400,P3D);
movie = new Movie(this, "street.mov");
movie.loop();
}
void draw(){
background(128);
camera(mouseX,mouseY,120,300,200,0, 0,1,0);
if(movie.available()) movie.read();
image(movie,0,0);
}
week13_3_texture_textureMode_beginShape_vertex_endShape
// week13_3_texture_textureMode_beginShape_vertex_endShape
// 先教 貼圖 ,再加進去
PImage img;
void setup(){
size(400,400,P3D); //要加 P3D才有OpenGL 3D功能
img = loadImage("chessboard.png");
textureMode(NORMAL);
}
void draw(){
background(128); //灰背景
beginShape();
texture(img);
vertex(40,80,0,0);
vertex(320,20,1,0);
vertex(380,360,1,1);
vertex(160,380,0,1);
endShape();
}
week13_4_camera_chessboard_texture_front_left 加入攝影機
// week13_4_camera_chessboard_texture_front_left
PImage img;
void setup(){
size(400,400,P3D); //要加 P3D才有OpenGL 3D功能
img = loadImage("chessboard.png");
textureMode(NORMAL);
}
void draw(){
camera(mouseX,200,mouseY,mouseX,200,mouseY-10,0,1,0);
background(128); //灰背景
beginShape();
texture(img);
vertex(0,0,0,0,0);
vertex(400,0,0,1,0);
vertex(400,400,0,1,1);
vertex(0,400,0,0,1);
endShape();
beginShape();
texture(img);
vertex(0,0,0,0,0);
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); //要加 P3D才有OpenGL 3D功能
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));
}
if(keyCode==DOWN){
x -= cos(radians(angle));
z -= sin(radians(angle));
}
}
void draw(){
//camera(mouseX,200,mouseY,mouseX,200,mouseY-10,0,1,0);
camera(x,y,z,x+cos(radians(angle)),y,z-sin(radians(angle)),0,1,0);
background(128); //灰背景
beginShape();
texture(img);
vertex(0,0,0,0,0);
vertex(400,0,0,1,0);
vertex(400,400,0,1,1);
vertex(0,400,0,0,1);
endShape();
beginShape();
texture(img);
vertex(0,0,0,0,0);
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
//把今天教的全部加進來
//street.mov 及 chessboard.png 都加進來
import processing.video.*;
Movie movie;
PImage img;
void setup(){
size(400, 400, P3D); // 要記得加上P3D 才能有OpenGL 3D 功能
movie= new Movie(this, "street.mov");
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(); // 正前方的牆
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();
image(movie, 0, 0, 360, 240);
if(video.available()) video.read(); // 放影片,用2D放圖的方法
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();
}
沒有留言:
張貼留言