//week13-1-processing-video //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(video,0,480);//若沒有視訊 就註解掉 就不會出錯 if(movie.available()) movie.read(); image(movie,0,0); }
//week13-2-camera-movie-eye-center-up //電腦圖學繪圖時 會設定camera的相關係數 import processing.video.*;//要使用影片外掛 Movie movie;//要放影片變數 void setup(){ size(600,400,P3D); //要記的加上P3D才能有OpenGL 3D功能 movie = new Movie(this,"street.mov");//請再把steet.mov拉進來 movie.loop();//迴圈播放 } void draw(){ background(128); camera(mouseX,mouseY,120,300,200,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-texture-textureMode-beginShape-vertex-endShape //先教貼圖再加進去 PImage img; void setup(){ size(400,400,P3D); img = loadImage("chessboard.png");//把圖檔拉進來 textureMode(NORMAL);//很多種貼圖模式 //先用最簡單的NORMAL來畫 2個三角形 不像是3D透視的效果 } void draw(){ background(128);//灰背景 beginShape();//開始畫 texture(img);//把圖片當貼圖 vertex(40,80,0,0);//4個頂點 的四邊形 會截出兩個三角形 vertex(320,20,1,0); vertex(380,360,1,1); vertex(160,380,0,1); endShape(); }
//week13-4-camera-chessboard-texture-front-left //把貼圖 跟camera整合再一起 PImage img; void setup(){ size(400,400,P3D); img = loadImage("chessboard.png"); textureMode(NORMAL); } void draw(){//攝影機往前方看 左右前後移動 camera(mouseX,200,mouseY,mouseX,200,mouseY-10,0,1,0); background(128); beginShape();//front 正前方 texture(img); vertex(0,0,0,0,0); vertex(400,0,0,1,0); vertex(400,400,1,1); vertex(0,400,0,0,1); endShape(); beginShape();//left左方 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-camera-keyPressed-keyCode-x-y-z-angle-cos-sin //修改自week13-4 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不是Y } if(keyCode==DOWN){ x-=cos(radians(angle)); z-=sin(radians(angle)); } } void draw(){//攝影機往前方看 左右前後移動 if(keyPressed) keyPressed();//補強 按鍵按下去不斷更新 //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();//front 正前方 texture(img); vertex(0,0,0,0,0); vertex(400,0,0,1,0); vertex(400,400,1,1); vertex(0,400,0,0,1); endShape(); beginShape();//left左方 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 //把今天教的加進來 //圖檔影片檔拉進來 import processing.video.*;//要使用影片外掛 Movie movie;//要放影片變數 PImage img; void setup() { size(400, 400, P3D); img = loadImage("chessboard.png"); movie = new Movie(this, "street.mov"); movie.loop(); 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();//front 正前方 texture(img); vertex(0,0,0,0,0); vertex(400,0,0,1,0); vertex(400,400,1,1); vertex(0,400,0,0,1); endShape(); translate(0,0,1); image(movie,0,0,360,240); if (video.available()) video.read();//有新畫面 就讀入 beginShape();//left左方 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(); beginShape(); texture(video); }
沒有留言:
張貼留言