回顧:
雖然看上去是用手畫,但實際上還是在2D的平面上劃線
改進的3D空間劃線:
程式碼:
import de.voidplus.leapmotion.*;
LeapMotion leap;
PVector [][] pt = new PVector[5][50];
//PVector pt1,pt2,pt3,pt4,pt5,pt6,pt7,pt8,pt9,pt10;
void setup(){
size(640,480,P3D);
colorMode(HSB, 100);
for(int f=0;f<5;f++)
for(int i=0;i<50;i++)
pt[f][i] = new PVector(0,0,0);
leap = new LeapMotion(this);
}
void draw(){
background(0);
//stroke(48,191,153);
stroke(#30BF99);
for(int f=0;f<5;f++)
for(int i=49;i>0;i--){pt[f][i].x=pt[f][i-1].x;pt[f][i].y=pt[f][i-1].y;pt[f][i].z=pt[f][i-1].z;}
for(Hand hand : leap.getHands()){
for(Finger finger : hand.getFingers()){
int f=finger.getType();
PVector now = finger.getPosition();
pt[f][0].x = now.x;
pt[f][0].y = now.y;
if(f==1)println(now);
}
}
translate(width/2,height/2);
rotateY(radians(frameCount));
translate(-width/2,-height/2);
for(int f=0;f<5;f++){
stroke(f*20, 100,100);
for(int i=1;i<10;i++)
line(pt[f][i].x,pt[f][i].y,pt[f][i].z,pt[f][i-1].x,pt[f][i-1].y,pt[f][i-1].z);
}
}
程式碼是在2D劃線的基礎上再作修改,增加了z軸的坐標值
期中作品計劃:
我們以前也稍微用過unity來做了一些小的Demo。現在上課得知processing可以結合unity引擎來做出很好的作品,所以這次的期中作品想用unity引擎結合processing,做出模擬真實騎馬的遊戲,通過手部的動作來模擬抓著馬的韁繩,在草原上騎馬的感覺。
沒有留言:
張貼留言