顯示具有 02160430_陳繁鑫 標籤的文章。 顯示所有文章
顯示具有 02160430_陳繁鑫 標籤的文章。 顯示所有文章

2016年5月19日 星期四

Week 12 02160430 陳繁鑫

練習 : 打地鼠

準備環境

1. 先安裝 Kinect sdk 以及 KinectDeveloperToolkit



2.執行Processing並將OpenNI放入...\processing2.2.1\modes\java\libraries

3.測試是否能執行

import SimpleOpenNI.*;

SimpleOpenNI show;

void setup()

{
   size(640,480);

   show=new SimpleOpenNI(this);

   show.enableRGB();

   show.enableDepth(); 
}

void draw()

{

   show.update();

    image(show.rgbImage(),0,0,320,240);

    image(show.depthImage(),0,240,320,240);


}




--------------------------------------------------------------------------------------------------------------------------

偵測左手

import SimpleOpenNI.*; 
SimpleOpenNI show;
void setup()
{
  size(640, 480);
  show=new SimpleOpenNI(this);
  show.enableRGB();
  show.enableDepth(); 
  show.enableUser();
}
float xpos(PVector pos) 
{
  return width/2+pos.x*500/pos.z;
}
float ypos(PVector pos) 
{
  return height/2-pos.y*500/pos.z;
}
void draw()
{
  show.update();
  background(255);
  image(show.userImage(), 0, 0, 640, 480);
  int [] userlist=show.getUsers();
  PVector pos = new PVector(0, 0, 0);
  for (int userId : show.getUsers ()) 
  {
    show.getJointPositionSkeleton(userId,   SimpleOpenNI.SKEL_LEFT_HAND, pos);
  }
  ellipse(xpos(pos), ypos(pos), 50, 50); 
}
void onNewUser(SimpleOpenNI curContext, int userId) 
{
  curContext.startTrackingSkeleton(userId);
}



偵測頭、手(左右手)


for (int userId : show.getUsers ())
  {
    show.getJointPositionSkeleton(userId, SimpleOpenNI.SKEL_LEFT_HAND, pos); 
    show.convertRealWorldToProjective(pos,pos);
    fill(0,0,0);ellipse(pos.x,pos.y,50,50);
    show.getJointPositionSkeleton(userId, SimpleOpenNI.SKEL_RIGHT_HAND, pos); 
    fill(255,255,0);ellipse(pos.x,pos.y,50,50);
    show.convertRealWorldToProjective(pos,pos);
    show.getJointPositionSkeleton(userId, SimpleOpenNI.SKEL_HEAD, pos);
    show.convertRealWorldToProjective(pos,pos);
    fill(255,0,255);ellipse(pos.x,pos.y,50,50);
}


增加增測點以及優化

 for (int userId : show.getUsers ())
 {
    show.getJointPositionSkeleton(userId, SimpleOpenNI.SKEL_LEFT_HAND, pos);
    show.convertRealWorldToProjective(pos,pos);
    fill(0,0,0);ellipse(pos.x,pos.y,50,50); hand1.set(pos); hand1.z=0;
    fill(0,0,0);ellipse(pos.x/10,pos.y/10,5,5); 
    show.getJointPositionSkeleton(userId, SimpleOpenNI.SKEL_RIGHT_HAND, pos);
    show.convertRealWorldToProjective(pos,pos);
    fill(0,0,0);ellipse(pos.x,pos.y,50,50); hand2.set(pos); hand2.z=0;
    fill(0,0,0);ellipse(pos.x/10,pos.y/10,5,5); 
}
  PVector mouse1 = new PVector(mouseX,mouseY, 0);
  if(PVector.dist(mouse1,hand1)<100 || PVector.dist(mouse1,hand2)<100)
  {
    ellipse(mouseX,mouseY,200,200);
  }
}


2016年5月5日 星期四

Week 11 02160430 陳繁鑫


下載並安裝Kinect toolkit V1.8
https://www.microsoft.com/en-us/download/details.aspx?id=40276


安裝完並執行 



體驗Toolkit 的應用軟體
例如:3D掃描



左下角可以選擇存檔類型

接著安裝MeshLab來開啟輸出的檔案
http://meshlab.sourceforge.net/
MeshLab很好用!支援多種3D模型檔,而且不用錢!!

執行畫面:

 
 將剛才KinectFusion匯出的Mesh檔匯入

 使用Processing操作Kinect
 
import SimpleOpenNI.*;
SimpleOpenNI openni;
void setup()
{
  size(600,400);
  openni = new SimpleOpenNI(this);
  openni.enableRGB();
  openni.enableDepth();
  openni.enableUser();
}
void draw()
{
  openni.update();
  image(openni.userImage(),0,0,600,400);
  for(int  userId : openni.getUsers()){
    PVector pos = new PVector(0,0,0);
    float confidence = openni.getJointPositionSkeleton(
      userId,SimpleOpenNI.SKEL_HEAD,pos);
    ellipse(pos.x,pos.y,50,50);
    println(pos);
  }
}
void onNewUser(SimpleOpenNI openni,int userId){
  openni.startTrackingSkeleton(userId);
}


2016年4月28日 星期四

Week10__02160430 陳繁鑫

安裝Kinect SDK

下載網址 :
https://www.microsoft.com/en-us/download/confirmation.aspx?id=40278


Processing 安裝kinect函式庫




Microsoft HoloLens 體驗

HTC Vive 體驗




下載 Kinect Toolkit 有很多實用範例!!
https://www.microsoft.com/en-us/download/details.aspx?id=40276
老師推薦:KinectFusion(必玩)



下載 FAAST
http://projects.ict.usc.edu/mxr/faast/


2016年4月14日 星期四

Week 08 02160430 陳繁鑫

 期中作品 : 打雪仗




開始畫面:將雙手放置方塊中開始遊戲

 

進入遊戲後雙手為玩家的控制器

 
左手為移動與旋轉,右手為攻擊


 右手握拳時會發射雪球


手握拳為移動,手旋轉則為玩家轉向 
 

遊戲中會不斷有NPC朝你移動並攻擊,玩家必須靠雪球來打倒她們。
當玩家擊倒她們則分數會上升,分數越高則NPC出現頻率越高,而當她們攻擊到玩家時則會損寫。


當玩家HP歸零時則遊戲結束。


2016年4月7日 星期四

Week 07 02160430 陳繁鑫

本周將記錄期中作品(打雪仗)相關的資訊

 一、Model準備

首先我們從Unity 裡進入Asset store 搜尋場景:Japanese Dosanko City作為遊戲場景。
從此下載
在搜尋人物 Unity-chan!作為遊戲角色。

從此下載

Import後到Japanese Dosanko City下尋找Sapporo_Ground.fbx與Sapporo_Prop.fbx拉至目前場景中。

再到UnityChan>Model下找到UnityChan.fbx並拉至目前場景中。

將兩者調整到適當位置後,目前場景應該會是下圖的樣子:



到此完成最初步的模型匯入工作!


 二、Sence環境建立

目前的遊戲地圖應該會是如下圖:


場景中的地圖沒有任何物理性質(碰撞),會造成人物會穿過房屋的結果,所以我們需要自己建立好地圖的物理性質。

最簡單的方式為我們建立多個空物件並加上Collision,將Collision拉成不同的適當大小給每一個房屋。

以下為預期的結果:



如此一來就不會發生人物穿透房屋的樣子,並且我們可以在外圍加上一層Collision,透過這層Collision來決定出我們的遊戲範圍,角色就只能夠在這範圍中移動了!

接著我們在Create一個Camera作為玩家(第一人稱,之後會用LeapMotion取代)

之後在Camera下新增一個Particle System(粒子系統)命名為Snow_1產生出下雪的效果,在Particle System最底下選擇適合貼圖,並將Snow_1放到適當高度與適當的角度產生出下雪的效果。


這個Snow會隨著我們的Camera的移動同時移動(為Camera的子物件),之後我們在Create一個Plane並選擇適合的貼圖作為雪地。便完成下雪天的設置了!



三、NPC建立

先前拉入場景的UnityChan將作為NPC使用。
首先我們給UnityChan一個Rigidbody,一個Capsule Collider賦予她物理性質讓他能夠站在場景中,之後再加入一個Sphere Collider 並將Is Trigger打勾作為觸發器使用。


之後我們在Asset底下加入一個Animation Controller物件作為UnityChan的動作資料。
打開Animation Controller
並到UnityChan資料夾下的Animation找到以下動作並丟進來


在Empty上按右鍵Make Trasition選擇下一個動作,最後串成上的樣子。

之後我們到Parameters中加入兩個Bool(Dead ,PlayerDead)

在選擇剛才Make Trasition後出現的箭頭


在旁邊的Conditions選擇剛剛加入的Bool之一,代表當這個Conditions的條件為true時才會執行下一個動作,而這Bool值的判斷將使用程式腳本做判斷。

2016年3月31日 星期四

Week 06 02160430 陳繁鑫

期中作品製作


這次期中作品要使用Unity做為開發環境
要透過Unity操作LeapMotion必須先做好環境設置
先到 : https://developer.leapmotion.com/unity 安裝必要軟體

先安裝完上面3個SDK

最後在下載Unity Assets


 第一個程式我們要安裝左邊的(Orion Beta)裡面也會包含V2Desktop的內容

 環境準備完成後,我們就可以使用Assets了

----------------------------------------------------------------------------------------------------------------------------

匯入Assets,我們到LeapMotion -> Scenes -> Leap_Hand_Demo_Desktop

開啟桌面板的操作 



2016年3月24日 星期四

Week 05 02160430 陳繁鑫


processing create window (multiple windows)開啟多視窗

https://forum.processing.org/one/topic/multiple-windows-2-4-2011.html

此Code為舊版的,需要加入import java.awt.Frame;才能執行!!

1.

--------------------------------------------------------------------------------------------------------------------------
2.建立個程式畫會自動旋轉的眼睛




將旋轉角度(t)使用atan2自動計算角度,讓眼珠跟隨滑鼠位置移動


--------------------------------------------------------------------------------------------------------------------------

3.建立個程式畫會螺旋狀旋轉的東西




2016年3月17日 星期四

Week 04 02160430 陳繁鑫

***LeapMotion函式庫只能在Processing2.2.1使用(未更新)***



Leap Motion 下載:https://www.leapmotion.com/setup

本周目標:學習射擊、打棒球遊戲的操作。

---------------------------------------------------------------------------------

射擊遊戲

先抓出一根手指當作手槍槍把


 PVector pos = finger_index.getPosition(); //取得手指座標

    PVector dir = finger_index.getDirection();//取得手指方向

lights();  //打光

  fill(255,0,0);  //填充顏色

  translate(width/2,height/2); //將物體座標移動到中心

  rotateY(radians(frameCount)); //每秒旋轉的徑度

  box(100,100,50); //畫box


PVector pos = null,dir = null;  //給初值,後面判斷才不會出錯

pushMatrix();

    translate(width/2,height/2);

    for(int i=0;i<10;i++){  //一次畫出10顆球,當作砲管

    if(dir!=null) {translate(dir.x*10*i,dir.y*10*i,dir.z*10*i); 

      sphere(40);}

    }

  popMatrix();


PVector []bullet = new PVector[10]; //10個子彈 

PVector []bullet_dir = new PVector[10]; //10個子彈向量 

並給初值


 pushMatrix();

    fill(0, 0, 255);

    for (int i=0; i<10; i++)
    {
      pushMatrix(); //每個子彈各別畫

        translate(bullet[i].x, bullet[i].y, bullet[i].z);

        sphere(50);

        bullet[i].x += bullet_dir[i].x;

        bullet[i].y += bullet_dir[i].y;

        bullet[i].z += bullet_dir[i].z;

      popMatrix();
    }
  popMatrix();

void keyPressed() {   //當按鍵時發射

  bullet[bulletNow].x =0; bullet[bulletNow].y =0; 

  bullet[bulletNow].z =0;

  bullet_dir[bullerNow].x = dir.x*5;    

  bullet_dir[bullerNow].y = dir.y*5;

  bullet_dir[bullerNow].z = dir.z*5;

  bullerNow++;  //換下一個子彈

  if(bulletNow>=10)

    bulletNow = 0;

}


完整程式碼
import de.voidplus.leapmotion.*;
LeapMotion leap;
PVector pos = null, dir=null;
PVector []bullet = new PVector[10];
PVector []bullet_dir = new PVector[10];
int bulletNow = 0;
void setup() {
  size(640, 480, P3D);
  leap = new LeapMotion(this);
  for (int i=0; i<10; i++) {
    bullet[i] = new PVector(0, 0, 0);
    bullet_dir[i] = new PVector(0, 0, 0);
  }
}
void draw() {
  background(255);
  for (Hand hand : leap.getHands ()) {
    Finger finger_index = hand.getIndexFinger();
    finger_index.draw();
    pos = finger_index.getPosition();
    dir = finger_index.getDirection();
    println(pos);
    println(dir);
  }
  lights(); 
  fill(255, 0, 0);  
  translate(width/2, height/2);
  pushMatrix();
  for (int i=0; i<10; i++) {
    if (dir!=null) {
      translate(dir.x*10*i, dir.y*10*i, dir.z*10*i);
      sphere(40);
    }
  }
  popMatrix();
  pushMatrix();
    fill(0, 0, 255);
    for (int i=0; i<10; i++)
    {
      pushMatrix();
        translate(bullet[i].x, bullet[i].y, bullet[i].z);
        sphere(50);
        bullet[i].x += bullet_dir[i].x;
        bullet[i].y += bullet_dir[i].y;
        bullet[i].z += bullet_dir[i].z;
      popMatrix();
    }
  popMatrix();
}
void keyPressed() {
  bullet[bulletNow].x =0; bullet[bulletNow].y =0; bullet[bulletNow].z =0;
  bullet_dir[bulletNow].x = dir.x*5;
  bullet_dir[bulletNow].y = dir.y*5;
  bullet_dir[bulletNow].z = dir.z*5;
  bulletNow++;
  if(bulletNow>=10)
    bulletNow = 0;
}
---------------------------------------------------------------------------------

打棒球關鍵

一顆球進來碰到手指控制的方塊(球棒)畫面會變黃色

透過dist()抓出兩個物體的距離,以此來判斷是否有碰到物體





2016年3月10日 星期四

Week 03 02160430 陳繁鑫

***LeapMotion函式庫只能在Processing2.2.1使用(未更新)***
繼續上禮拜的程式。

Leap Motion 下載:https://www.leapmotion.com/setup


  size(640, 480, P3D); //開啟3D深度


將初始點(0,0)移動到畫面中間,並自動旋轉。最後再將初始點

移回原始點。

  translate(width/2, height/2);

  rotateY(radians(frameCount));

  translate(-width/2, -height/2);


---------------------------------------------------------------------------------

增加z軸的位移量

pt[f][0].z=now.z*3-135;

放慢旋轉速度

rotateY(radians(frameCount)/4);

最後畫出背後網格


stroke(60, 100, 100);

  for (int i=0; i<640; i+=20)

  {

    for (int j=0; j<480; j+=20)
    {
      noFill() ; rect(i,j,20,20);
    }
  }




執行結果



最後程式碼
import de.voidplus.leapmotion.*;
LeapMotion leap;
PVector [][] pt = new PVector[5][50];
void setup() {
  size(640, 480, P3D);
  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);
  colorMode(HSB, 100);
}

void draw() {
  background(0);
  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;
      pt[f][0].z=now.z*3-135;
      if (f==1) println(now);
    }
  }
  translate(width/2, height/2 ,0);
    rotateY(radians(frameCount)/4);
  translate(-width/2, -height/2,0);
  for (int f=0; f<5; f++) {
    for (int i=1; i<50; i++)    
    {
      strokeWeight(3);
      stroke(f*20, 100, 100);
      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);
    }
  }

  stroke(60, 100, 100);
  for (int i=0; i<640; i+=20)
  {
    for (int j=0; j<480; j+=20)
    {
      noFill() ; rect(i,j,20,20);
    }
  }
}


---------------------------------------------------------------------------------

調色盤設計

透過
 
hand.isLeft() / hand.isRight()分辨左右手


左手:調色盤


右手:畫筆


建立調色盤顏色


左手必須new 第一支伸出右手時才不會有bug


最後程式碼

import de.voidplus.leapmotion.*;
LeapMotion leap;
void setup() {
  size(640, 480, P3D);
  leap = new LeapMotion(this);
  leftPos = new PVector(0,0,0);
}
color nowColor = color(0, 0, 0); 

PVector leftPos;
void draw() {

  background(255);
  for (Hand hand : leap.getHands ()) {
    PVector pos = hand.getPosition();
    if (hand.isLeft()) {
      fill(0, 0, 0);
      ellipse(pos.x, pos.y, 200, 100);   
      fill(255, 0, 0); 
      ellipse(pos.x+100, pos.y-50, 50, 50); 
      fill(255, 255, 0); 
      ellipse(pos.x+50, pos.y-75, 50, 50);
      fill(0, 255, 0); 
      ellipse(pos.x, pos.y-100, 50, 50);
      fill(0, 255, 255); 
      ellipse(pos.x-50, pos.y-75, 50, 50);
      fill(0, 0, 255); 
      ellipse(pos.x-100, pos.y-50, 50, 50);
      leftPos = pos;
    } else if (hand.isRight()) {
      fill(nowColor); 
      rect(pos.x, pos.y, 10, 100);
      println(pos);
      println(leftPos);

      if (dist(pos.x, pos.y, leftPos.x+100, leftPos.y-50)<30) {
        nowColor = color(255, 0, 0);
      }
    }
  }
}


---------------------------------------------------------------------------------

期中作品想做:小朋友打雪仗類型的遊戲