63
Tennis Game Using Kinect Member: 施施施 , 施施施 , 施施施 , 施施施 施施施施 : 施施施 施施

Tennis Game Using Kinect

  • Upload
    yorick

  • View
    128

  • Download
    2

Embed Size (px)

DESCRIPTION

Tennis Game Using Kinect. Member: 施立宸 , 李少宏 , 吳品頡 , 高顗泓 指導教授 : 連震杰 老師. Outline. 1. Introduction ( 施立宸 ) 2. Kinect System Setup and Diagram, and Software Tools 2.1Hardware: Kinect ( 施立宸 ) 2.2Software Tools: OpenNI ( 施立宸 ) 2.3Software Tools: 3Ds MAX ( 高顗泓 , 吳品頡 ) - PowerPoint PPT Presentation

Citation preview

Page 1: Tennis Game Using  Kinect

Tennis Game Using Kinect

Member: 施立宸 , 李少宏 , 吳品頡 , 高顗泓指導教授 : 連震杰 老師

1

Page 2: Tennis Game Using  Kinect

2

Outline1. Introduction ( 施立宸 )

2. Kinect System Setup and Diagram, and Software Tools

2.1 Hardware: Kinect ( 施立宸 )

2.2 Software Tools: OpenNI ( 施立宸 )

2.3 Software Tools: 3Ds MAX ( 高顗泓 , 吳品頡 )

2.4 Software Tools: Unity & Package ( 施立宸 , 李少宏 )

2.4.1 Software Tools: Unity3D ( 李少ˋ宏 )

2.4.2 Software Tools: Unity Wrapper ( 施立宸 )

3. Kinect Preprocessing Using OpenNI, 3Ds Max and Unity3D ( 施立宸 , 李少宏 , 吳品頡 , 高顗泓 )

3.1 Depth Map and Color Image Creation Using OpenNI to Process the Kinect ( 吳品頡 , 高顗泓 )

3.2 Human Body Calibration for Skeleton Creation Using OpenNI ( 施立宸 , 李少宏 )

3.3 Animated Object Component Creation Using 3Ds Max and Save to Unity3D ( 吳品頡 , 高顗泓 , 李少宏 )

4. Right Hand Point and Skeleton Tracking Using OpenNI ( 施立宸 )

5. Tennis Game Interaction between Human Motion and Animated Object Components

5.1 匯入 .fbx 並將匯入物件加入物理性質與程式 ( 李少宏 )

5.2 網球場地設定 ( 李少宏 )

5.3 玩家與遊戲間互動 ( 李少宏 , 施立宸 )

6. Animated Tennis Game Display ( 李少宏 , 施立宸 )

7. Schedule

8. Reference

Page 3: Tennis Game Using  Kinect

3

1. Introduction (1/2)

Background Motion game: Can detect our motion and give interaction. Usually be used on sport game.

Motivation We want to create a game in PC but use Xbox360’s Kinect. We want to play game with more “real”. Because I want to play with Aggassi.

PC XBOX360

Page 4: Tennis Game Using  Kinect

4

1. Introduction (2/2)

Example IR Light SourceCMOS Sensor Receiver

可將玩家位置轉換成遊戲中人物的位置,並且支援動作判定的網球遊戲

Skeleton analyze

Page 5: Tennis Game Using  Kinect

5

2. Kinect System Setup and Diagram, and Software Tools – Kinect System Setup

IR Light SourceCMOS Sensor Receiver PS1080 SoC

Skeleton Feature Extraction

Human Gesture

Recognition

Kinect

PC

Display recognized action

Skeleton Feature

USB

SceneRGB + Depth Image

Light Coding

Tennis Game Interaction

1. Depth Map and Color Image Creation Using OpenNI

2. Skeleton Extraction Using OpenNI3. Interaction Algorithm 4. Display on Screen

Page 6: Tennis Game Using  Kinect

0.2 Human Body Calibration for Skeleton Creation Using OpenNIUse and to Calibration

Update , to Unity in any time.

0.1 Depth Map and Color Image Creation Using OpenNI to Process Kinect

1.0 Right Hand Point and Skeleton Tracking Using OpenNIa) 偵測與追蹤 torso( 玩家正中心 ) 和 right hand 關節點b) 輸出 ,

2.0 Tennis Game Interaction between Human Motion and Animated Object Components in Unity3D

0.3 Animated Object Component Creation Using 3Ds MAX and Save to Unity3D

RGB Image Depth Map

Ball.fbx ,Racket.fbx,Player.fbx,etc.

2.3 玩家與遊戲間互動 玩家回擊a) 動作判定b) 位置轉換規則、碰撞與分數判定AI 回擊a) 位置移動b) 揮拍時間判定

2.1 匯入 .fbx並將匯入物件加入物理性質與程式a) 物理性質與參數設定b) 加入 script(Unity 中的程式碼 )

2.2 網球場地設定a) 球場材質貼上b) 光線設定c) 加入 script

t=1 t>1

t=0

t>1

網球、球拍等… .. 球場與周圍環境發球a) 給予球初速b) 動作判斷

: 球的速度 : 球的位置

校正後的RGB Image Depth Map

Display

2. Kinect System Setup and Diagram, and Software Tools – Kinect System Diagram (1/2)

Page 7: Tennis Game Using  Kinect

7

3.0 Animated Tennis Game Display in Unity3D

2. Kinect System Setup and Diagram, and Software Tools – Kinect System Diagram (2/2)

我們將每個物件的位置交給 Unity 去做繪圖動作,並透過 script 來˙完成物件互動並顯示

Page 8: Tennis Game Using  Kinect

8

1) Kinect Driver: OPENNI Connect Kinect to PC. Can catch skeleton joint point.

2) 3D graphic tool: 3Ds MaxGame engine can’t draw too delicate graph, so use graph drawing software. Have many exported file types such as .fbx. Can match many software like Unity and XNA.

3) Game Engine & Package3.1) Game Engine: Unity3D

Implement physics, light, polygon and GUI. Connect game engine and Kinect.

3.2) Package of Game Engine: UnityWrapper Bind Unity3D and OPENNI. Have many binding examples to use.

2. Kinect System Setup and Diagram, and Software Tools – Software Tools (1/2)

Page 9: Tennis Game Using  Kinect

9

3) Tennis Game Interaction between Human Motion and Animated Object Components in Unity3D

start Load UnityWrapper Connect Kinect Load .fbx

Write script to move

component.

1) Right Hand Point and Skeleton Tracking Using OpenNI

2) Animated Object Component Creation Using 3Ds MAX and Save to Unity3D

complete

Initialize Kinect

Draw 3Dobjects

Export .fbx

.fbx file

Kinect driver

Get joint points

joint points3D depth map

2. Kinect System Setup and Diagram, and Software Tools – Software Tools (2/2)

Page 10: Tennis Game Using  Kinect

10

2.1 Hardware: Kinect (1/3)

Kinect 介紹 屬於 Xbox360 的裝置, Microsoft 的產品 若使用 OpenNI 或 MicrosoftSDK ,即可運用於

PC 可蒐集彩色影像、 3D 深度影像、以及聲音訊號

Page 11: Tennis Game Using  Kinect

11

2.1 Hardware: Kinect (2/3)

運作原理中間的鏡頭為 RGB 彩色攝影機左右兩邊鏡頭則分別為紅外線發射器和紅外線

CMOS 攝影機所構成的 3D 深度感應器內建陣列式麥克風系統

Page 12: Tennis Game Using  Kinect

12

2.1 Hardware: Kinect – Spec. (3/3) Sensor

Colour and depth-sensing lenses Voice microphone array Tilt motor for sensor adjustment Fully compatible with existing Xbox 360 consoles

Field of View Horizontal field of view: 57 degrees Vertical field of view: 43 degrees Physical tilt range: ± 27 degrees Depth sensor range: 1.2m – 3.5m

Data Streams 320×240 16-bit depth @ 30 frames/sec 640×480 32-bit colour@ 30 frames/sec 16-bit audio @ 16 kHz

Skeletal Tracking System Tracks up to 6 people, including 2 active players Tracks 20 joints per active player Ability to map active players to Live Avatars

Audio System Live party chat and in-game voice chat (requires Xbox Live Gold Membership) Echo cancellation system enhances voice input Speech recognition in multiple

Page 13: Tennis Game Using  Kinect

13

2.2 Software Tools: OpenNI (1/2)

OpenNI IntroductionCertify and promote the compatibility of Natural

Interaction (NI) devices, applications and middleware.

Architecture

Page 14: Tennis Game Using  Kinect

14

2.2 Software Tools: OpenNI (2/2)

OpenNI vs MicrosoftSDK目前微軟也有自己的 tool kit-- MicrosoftSDK.

OpenNI Microsoft SDK

License includes commercial use Licensed for non-commercial use only

Support for hands only mode Only tracks full body (no mode for hand only tracking)

No support for audio Support for audio

Also supports the Primesense and the ASUS WAVI Xtion sensors

Just for Kinect.

Comes with code for full support in Unity3D game engine

No support for Unity3D game engine

Three separate installers and a NITE license string

Single no-fuss installer

Needs a calibration pose to start tracking

Don’t need any calibration pose.

Power save. Seems to consume more CPU power than OpenNI/NITE

Has gesture recognition system No gesture recognition system

Page 15: Tennis Game Using  Kinect

15

2.3 Software Tools: 3Ds MAX

3Ds MAX IntroductionA modeling, animation and rendering package.It has modeling capabilities, a flexible plugin

architecture.Application

Video game developers TV commercial studios Movie effects Movie pre-visualization

Page 16: Tennis Game Using  Kinect

16

2.4 Software Tools: Unity & Package

We introduce Unity and its package.

Page 17: Tennis Game Using  Kinect

17

2.4.1 Software Tools: Unity3D

Unity introductionAn integrated authoring tool for creating 3D video

games.Features

Can use C# and java. Has its compiler environment Easy to use.

Page 18: Tennis Game Using  Kinect

18

2.4.2 Software Tools: Unity Wrapper

Unity Wrapper introduction 可以使 Unity 能提取 OpenNI 資料的 Package

Package: 一種可將 Unity 應用軟體包裝化的軟件有許多不同版本

We use Zigfu version.– 使用方面較為流暢 30 fps– 有附較為完整的說明– 軟體更新速度快– 問題較少

Page 19: Tennis Game Using  Kinect

0.2 Human Body Calibration for Skeleton Creation Using OpenNIUse and to Calibration

Update , to Unity in any time.

0.1 Depth Map and Color Image Creation Using OpenNI to Process Kinect

1.0 Right Hand Point and Skeleton Tracking Using OpenNIa) 偵測與追蹤 torso( 玩家正中心 ) 和 right hand 關節點b) 輸出 ,

2.0 Tennis Game Interaction between Human Motion and Animated Object Components in Unity3D

0.3 Animated Object Component Creation Using 3Ds MAX and Save to Unity3D

RGB Image Depth Map

Ball.fbx ,Racket.fbx,Player.fbx,etc.

2.3 玩家與遊戲間互動 玩家回擊a) 動作判定b) 位置轉換規則、碰撞與分數判定AI 回擊a) 位置移動b) 揮拍時間判定

2.1 匯入 .fbx並將匯入物件加入物理性質與程式a) 物理性質與參數設定b) 加入 script(Unity 中的程式碼 )

2.2 網球場地設定a) 球場材質貼上b) 光線設定c) 加入 script

t=1 t>1

t=0

t>1

網球、球拍等… .. 球場與周圍環境發球a) 給予球初速b) 動作判斷

: 球的速度 : 球的位置

校正後的RGB Image Depth Map

Display

3. Kinect Preprocessing Using OpenNI, 3Ds Max and Unity3D

Page 20: Tennis Game Using  Kinect

20

3.1 Depth Map and Color Image Creation Using OpenNI to Process the Kinect Kinect with OpenNI

OpenNI 可做為 driver 驅動 Kinect 並獲得彩色圖與深度圖 除負責溝通硬體外,尚可透過中介軟體進行更 進一步操作,獲取更進階資訊。 We use two class handpoint_controll() and

OpenNISkeleton() ,當被使用時,系統會連絡OpenNI 並且從 Kinect 中獲取深度圖與彩色圖

Page 21: Tennis Game Using  Kinect

21

3.2 Human Body Calibration for Skeleton Creation Using OpenNI

Why Calibration? 初始化骨架 使分析更精準 所有 OpenNI 的 function 都需要校正後 ( 僅需一次 ) 才能使用

Calibration 需要擺出 T pose 系統校正成功後便會顯示骨架

Page 22: Tennis Game Using  Kinect

0.2 Human Body Calibration for Skeleton Creation Using OpenNIUse and to Calibration

Update , to Unity in any time.

0.1 Depth Map and Color Image Creation Using OpenNI to Process Kinect

1.0 Right Hand Point and Skeleton Tracking Using OpenNIa) 偵測與追蹤 torso( 玩家正中心 ) 和 right hand 關節點b) 輸出 ,

2.0 Tennis Game Interaction between Human Motion and Animated Object Components in Unity3D

0.3 Animated Object Component Creation Using 3Ds MAX and Save to Unity3D

RGB Image Depth Map

Ball.fbx ,Racket.fbx,Player.fbx,etc.

2.3 玩家與遊戲間互動 玩家回擊a) 動作判定b) 位置轉換規則、碰撞與分數判定AI 回擊a) 位置移動b) 揮拍時間判定

2.1 匯入 .fbx並將匯入物件加入物理性質與程式a) 物理性質與參數設定b) 加入 script(Unity 中的程式碼 )

2.2 網球場地設定a) 球場材質貼上b) 光線設定c) 加入 script

t=1 t>1

t=0

t>1

網球、球拍等… .. 球場與周圍環境發球a) 給予球初速b) 動作判斷

: 球的速度 : 球的位置

校正後的RGB Image Depth Map

Display

3.3 Animated Object Component Creation Using 3Ds Max and Save to Unity3D (1/8)

Page 23: Tennis Game Using  Kinect

23

3.3 Animated Object Component Creation Using 3Ds Max and Save to Unity3D (2/8)

Create Tennis racket

circle plane

cylinder

Figure: 球拍製作方法

Page 24: Tennis Game Using  Kinect

24

MaterialTo make objects more real.

3.3 Animated Object Component Creation Using 3Ds Max and Save to Unity3D (3/8)

Page 25: Tennis Game Using  Kinect

The Process of Creating a Tennis Ball

25

1 2

3 4

↑拉出一個立方體 ↑將其圓弧化

↑選定凹槽之分段線 ↑凸顯所選之分段線

3.3 Animated Object Component Creation Using 3Ds Max and Save to Unity3D (4/8)

Page 26: Tennis Game Using  Kinect

26

5 6

7 8

↑球型化 ↑調整凹槽深度

↑網球形狀完成 ↑貼上材質

3.3 Animated Object Component Creation Using 3Ds Max and Save to Unity3D (5/8)

Page 27: Tennis Game Using  Kinect

Final Result

3.3 Animated Object Component Creation Using 3Ds Max and Save to Unity3D (6/8)

Page 28: Tennis Game Using  Kinect

28

Use some object to compose a tennis net. In Unity3D,using a invisible plane to allocate

physical character.

box

cylinder

Figure: Tennis net

3.3 Animated Object Component Creation Using 3Ds Max and Save to Unity3D (7/8)

Page 29: Tennis Game Using  Kinect

29

Export .FBX file in 3Ds MAX

將此物件輸出成 .FBX檔案

3.3 Animated Object Component Creation Using 3Ds Max and Save to Unity3D (8/8)

Page 30: Tennis Game Using  Kinect

4. Right Hand Point and Skeleton Tracking Using OpenNI (1/2)

0.2 Human Body Calibration for Skeleton Creation Using OpenNIUse and to Calibration

Update , to Unity in any time.

0.0 獲得深度圖與彩色圖透過 OpenNI操控 Kinect1.0 Right Hand Point and Skeleton Tracking Using OpenNIa) 偵測與追蹤 torso( 玩家正中心 ) 和 right hand 關節點b) 輸出 ,

2.0 Tennis Game Interaction between Human Motion and Animated Object Components

0.3 Animated Object Component Creation Using 3Ds MAX and Save to Unity3D

RGB Image Depth Map

Ball.fbx ,Racket.fbx,Player.fbx,etc.

2.3 玩家與遊戲間互動 玩家回擊a) 動作判定b) 位置轉換規則、碰撞與分數判定AI 回擊a) 位置移動b) 揮拍時間判定

2.1 匯入 .fbx並將匯入物件加入物理性質與程式a) 物理性質與參數設定b) 加入 script(Unity 中的程式碼 )

2.2 網球場地設定a) 球場材質貼上b) 光線設定c) 加入 script

t=1 t>1

t=0

t>1

網球、球拍等… .. 球場與周圍環境發球a) 給予球初速b) 動作判斷

: 球的速度 : 球的位置

校正後的RGB Image Depth Map

Display

Page 31: Tennis Game Using  Kinect

31

4. Right Hand Point and Skeleton Tracking Using OpenNI (2/2)

Track right hand point by OpenNI:Handpoint_control()

After calibration this class will detect right hand point. Then, track right hand point and output to Unity. This class will output all the time.

OpenNISkeleton(int skeletonnum) 輸入 skeleton 的號碼,此 class 可回傳指定骨架座標 After calibration, this class will detect skeleton point. Then, track skeleton point and output to Unity. This class will output all the time.

Page 32: Tennis Game Using  Kinect

5. Tennis Game Interaction between Human Motion and Animated Object Components

0.2 Human Body Calibration for Skeleton Creation Using OpenNIUse and to Calibration

Update , to Unity in any time.

0.1 Depth Map and Color Image Creation Using OpenNI to Process Kinect

1.0 Right Hand Point and Skeleton Tracking Using OpenNIa) 偵測與追蹤 torso( 玩家正中心 ) 和 right hand 關節點b) 輸出 ,

2.0 Tennis Game Interaction between Human Motion and Animated Object Components

0.3 Animated Object Component Creation Using 3Ds MAX and Save to Unity3D

RGB Image Depth Map

Ball.fbx ,Racket.fbx,Player.fbx,etc.

2.3 玩家與遊戲間互動 玩家回擊a) 動作判定b) 位置轉換規則、碰撞與分數判定AI 回擊a) 位置移動b) 揮拍時間判定

2.1 匯入 .fbx並將匯入物件加入物理性質與程式a) 物理性質與參數設定b) 加入 script(Unity 中的程式碼 )

2.2 網球場地設定a) 球場材質貼上b) 光線設定c) 加入 script

t=1 t>1

t=0

t>1

網球、球拍等… .. 球場與周圍環境發球a) 給予球初速b) 動作判斷

: 球的速度 : 球的位置

校正後的RGB Image Depth Map

Display

Page 33: Tennis Game Using  Kinect

33

5.1 匯入 .fbx 並將匯入物件加入物理性質與程式 (1/3)

Import .FBX file in Unity3D

Figure: We import “ball.FBX” into our game system

Page 34: Tennis Game Using  Kinect

34

5.1 匯入 .fbx 並將匯入物件加入物理性質與程 式 (2/3) 物理特性附加 ( 以鋼體附加為例 )

點選欲加入特性物件 選擇 Component->Rigidbody 即可發現特性視窗多了Rigidbody 屬性

Page 35: Tennis Game Using  Kinect

35

5.1 匯入 .fbx 並將匯入物件加入物理性質與程式 (3/3)

Script 附加方式 Script 為 Unity 中的程式碼,可獨立運作並互相影響,導入物件中。

左圖為遊戲物件,我們希望把右邊的 Ball_Behavior 的 script 附加於 ball 上,直接拖曳到物件上

由於球被附加上了 Ball_Behavior 的 script ,故其屬性多了一項 Ball_Behavior

Page 36: Tennis Game Using  Kinect

36

5.2 網球場地設定 (1/4)

Scene Setting1. Terrain ( 我們需要細部修改場地與其附加程式,故此物件不由 3Ds MAX畫出而是在 Unity 內完成 )2. Light3. Camera

Page 37: Tennis Game Using  Kinect

37

5.2 網球場地設定 (2/4)

Terrain -Tennis CourtResolution

Width, Length and Height

Transform Position Location scale 1. Create Terrain 2. Set Resolution

3. Paint Terrain Texture4. Add Net

5. Set Transform

6. Set Property

7. Set Material

Page 38: Tennis Game Using  Kinect

38

5.2 網球場地設定 (3/4)

Light Directional Light (figure a) Point Light (figure b) Spot Light (figure c)

a. Directional Light b. Point Light c. Spot Light

1. Add GameObject 2. Set Transform 3. Set Property

Page 39: Tennis Game Using  Kinect

39

5.2 網球場地設定 (4/4)

Camera Projection

Perspective (figure a) Orthographic (figure b)

1. Add Camera 2. Set Transform 3. Set Property

a. Perspective b. Orthographic 選擇攝影機並修改projection選項

Page 40: Tennis Game Using  Kinect

5.3 玩家與遊戲間互動 (1/6)

40

3. Play and Display by Unity

3.4 Player 接球

3.1 發球 (假設為玩家擊球 )

Change velocity of Ball

3.3 電腦玩家接球使用人工智慧

Change velocity of Ball

揮拍根據M 來選擇動作並改變,拍子與球碰撞

Match motion根據兩 frame 的做相減,得到三維向量,根據查表得 M

Predict falling location

Hit zone detectIf ( (< && < ) &&M!=0 )

Change velocity of Ball

x y z M

+ + + 1

- + + 2

Display

3.2 規則與碰撞判定

3.5 分數判定

碰撞判定球與人、場地、球網的碰撞決定 , 的變化規則判定1. 失誤2. Ace, Return Ace, Out….3. 球對球網4. 球對球拍

1. 分數顯示 15->30->402. Deuce情況判定3. 獲勝條件判定

Give S if C==1

C set to 0

,

Give , If T==1

Give , If T==0

, , 揮拍根據M 來選擇動作並改變,拍子與球碰撞

拋球改變球的速度為 (0,2,0) ,使其往上

Match motion

計算時間並揮拍,拍子與球碰撞

Page 41: Tennis Game Using  Kinect

41

: Location of player’s right hand point 相對於 Kinect. : Location of player’s torso point 相對於 Kinect. : Location of player’s location in Unity3D. : Location of ball in Unity3D. : Velocity of ball in Unity3D. : Collision times of ball with court.: 兩張 frame 內,右手的距離 (三維向量 )M : Which command match our motion. 0 is none.: 揮拍前與球的距離,尚未實作固令: Player’s score: CPU’s scoreS : 誰得分 (1 為玩家 2 為電腦 )C: 是否計算T: 最後一次誰擊球 (1 為玩家 0 為電腦 )

5.3 玩家與遊戲間互動 - 參數對照表 (2/6)

Page 42: Tennis Game Using  Kinect

5.3 玩家與遊戲間互動 (3/6)

42

3. Play and Display by Unity

3.4 Player 接球

3.1 發球 (假設為玩家擊球 )

Change velocity of Ball

3.3 電腦玩家接球使用人工智慧

Change velocity of Ball

揮拍根據M 來選擇動作並改變,拍子與球碰撞

Match motion根據兩 frame 的做相減,得到三維向量,根據查表得 M

Predict falling location

檢測玩家是否在球附近If ( (< && < ) &&M!=0 )

Change velocity of Ball

x y z M

+ + + 1

- + + 2

Display

3.2 規則與碰撞判定

3.5 分數判定

碰撞判定球與人、場地、球網的碰撞決定 , 的變化規則判定1. 失分2. Ace, Return Ace, Out….3. 球對球網4. 球對球拍

1. 分數顯示 15->30->402. Deuce情況判定3. 獲勝條件判定

Give S if C==1

C set to 0

,

Give , If T==1

Give , If T==0

, , 揮拍根據M 來選擇動作並改變,拍子與球碰撞

拋球改變球的速度為 (0,2,0) ,使其往上

Match motion

計算時間並揮拍,拍子與球碰撞

Page 43: Tennis Game Using  Kinect

5.3 玩家與遊戲間互動 (4/6)

3.2 與 3.3之間數值傳遞不斷進行,因為球的狀態需要再 3.2 中不斷更新

43

3. Play and Display by Unity

3.4 Player 接球

3.1 發球 (假設為玩家擊球 )

Change velocity of Ball

3.3 電腦玩家接球使用人工智慧

Change velocity of Ball

揮拍根據M 來選擇動作並改變,拍子與球碰撞

Match motion根據兩 frame 的做相減,得到三維向量,根據查表得 M

Predict falling location

檢測玩家是否在球附近If ( (< && < ) &&M!=0 )

Change velocity of Ball

x y z M

+ + + 1

- + + 2

Display

3.2 規則與碰撞判定

3.5 分數判定

碰撞判定球與人、場地、球網的碰撞決定 , 的變化規則判定1. 失分2. Ace, Return Ace, Out….3. 球對球網4. 球對球拍

1. 分數顯示 15->30->402. Deuce情況判定3. 獲勝條件判定

Give S if C==1

C set to 0

,

Give , If T==1

Give , If T==0

, , 揮拍根據M 來選擇動作並改變,拍子與球碰撞

拋球改變球的速度為 (0,2,0) ,使其往上

Match motion

計算時間並揮拍,拍子與球碰撞

Page 44: Tennis Game Using  Kinect

3.2 與 3.4之間數值傳遞不斷進行,因為球的狀態需要再 3.2 中不斷更新,以左方突來說玩家不在球附近,儘管有揮拍動作但還是無法回擊球,因此碰撞判定得知球碰地兩下而沒人接,規則判定為失分,接球失敗,進入分數判定。

5.3 玩家與遊戲間互動 (5/6)

44

3. Play and Display by Unity

3.4 Player 接球

3.1 發球 (假設為玩家擊球 )

Change velocity of Ball

3.3 電腦玩家接球使用人工智慧

Change velocity of Ball

揮拍根據M 來選擇動作並改變,拍子與球碰撞

Match motion根據兩 frame 的做相減,得到三維向量,根據查表得 M

Predict falling location

檢測玩家是否在球附近If ( (< && < ) &&M!=0 )

Change velocity of Ball

x y z M

+ + + 1

- + + 2

Display

3.2 規則與碰撞判定

3.5 分數判定

碰撞判定球與人、場地、球網的碰撞決定 , 的變化規則判定1. 失分2. Ace, Return Ace, Out….3. 球對球網4. 球對球拍

1. 分數顯示 15->30->402. Deuce情況判定3. 獲勝條件判定

Give S if C==1

C set to 0

,

Give , If T==1

Give , If T==0

, , 揮拍根據M 來選擇動作並改變,拍子與球碰撞

拋球改變球的速度為 (0,2,0) ,使其往上

Match motion

計算時間並揮拍,拍子與球碰撞

Page 45: Tennis Game Using  Kinect

5.3 玩家與遊戲間互動 (6/6)

45

3. Play and Display by Unity

3.4 Player 接球

3.1 發球 (假設為玩家擊球 )

Change -- velocity of Ball

3.3 電腦玩家接球使用人工智慧

Change velocity of Ball

揮拍根據M 來選擇動作並改變

Match motion根據兩 frame 的做相減,得到三維向量,根據查表得 M

Predict falling location

檢測玩家是否在球附近If ( (< && < ) &&M!=0 )

Change -- velocity of Ball

x y z M

+ + + 1

- + + 2

Display

3.2 規則與碰撞判定

3.5 分數判定

碰撞球與人、場地、球網、拍子的碰撞決定 , 的變化規則1. 失分2. Ace, Return Ace, Out….3. 球對球網4. 球對球拍

1. 分數顯示 15->30->402. Deuce情況判定3. 獲勝條件判定

Give S if C==1

C set to 0

,

Give , If T==1

Give , If T==0

, , 揮拍根據M 來選擇動作並改變

拋球改變球的速度為 (0,2,0) ,使其往上

Match motion

Page 46: Tennis Game Using  Kinect

46

5.3.1 發球 (1/2)

向上拋球We use rigidbody. Rigidbody 類別控制 script 所附加物體的基本特性,包含速度、力、加速度和位置。Throw up the ball, so rigidbody.velocity.y=2.

rigidbody在此為球體本身,底下的資料結構 velocity為其速度, y 則為 y軸上的速度,在 Unity 中可隨時改變物體的速度,而球已被加上鋼體,固往上丟後會受重力影響到最高點後下墜。

Page 47: Tennis Game Using  Kinect

47

5.3.1 發球 (2/2)

擊球抓取兩 frame 的,假設第一張為,第二張為,,將查表得 M 。

根據M 做出不同揮拍動作並改變。

x軸 y軸 z軸 Motion number M

+ + + 0

+ - + 1

- + + 2

- - + 3

Page 48: Tennis Game Using  Kinect

48

5.3.2 規則與碰撞判定 (1/5)

碰撞判定OnTriggerEnter()

在 script 中使用,可用來偵測是否發生碰撞 使用此法可偵測球與指定物件碰撞

Tennis CourtIn court’s script:

OnTriggerEnter(){尋找物件“ Ball”底下的 ballmove script;修改 ballmove script 的 ++;}

𝐶𝑏=0Ball

Page 49: Tennis Game Using  Kinect

49

5.3.2 規則與碰撞判定 (2/5)

碰撞判定OnTriggerEnter()

在 script 中使用,可用來偵測是否發生碰撞 使用此法可偵測球與指定物件碰撞

Tennis CourtIn court script:

OnTriggerEnter(){尋找物件“ Ball”;修改 Ball 的 script 並使 ++;}

𝐶𝑏=1Ball

Collision Happen!!!++

Page 50: Tennis Game Using  Kinect

50

5.3.2 規則與碰撞判定 (3/5)

碰撞判定球與拍子的碰撞

Lichen: 兩者皆為鋼體,可由系統決定碰撞後球飛出的方向或將球的速度與方向寫成幾個固定的數值。 =0 (打擊後落地次數應重算 ) T 從 0 與 1 間交換 (T儲存最後一次打擊的人物編號 )

球與場地的碰撞 發生碰撞則 ++, ++ ,當實作規則判定 ( 出界或得分 )

Page 51: Tennis Game Using  Kinect

51

5.3.2 規則與碰撞判定 (4/5)

得分規則變數儲存

計算落地次數,被擊出則歸零 來計算最後一次是誰打擊 ( 方便計算分數 ) 總落地次數, S 來判斷誰得分, C 來開啟分數統計

例外判定 雙發失誤 Ace, Return Ace

Page 52: Tennis Game Using  Kinect

52

5.3.2 規則與碰撞判定 (5/5)

舉例 Ace 的情況 ( 發球即得分 )

計算落地次數,被擊出則歸零 來計算最後一次是誰打擊 ( 方便計算分數 ) 總落地次數, S 判斷誰得分, C=1 時開啟分數統計

球落地兩次 (電腦漏接 )

𝐶𝑡=2 T=1 =2

球落地一次𝐶𝑡=1 T=1 =1

玩家發球( 球擊出 ) T=1(最後一次為玩家擊球 ) =0( 尚未落地 )

T 為 1 ,而 =2 ,已可判定勝負,故 S 為1( 玩家得分 ) , C 設為 1 ,開啟分數計算

Page 53: Tennis Game Using  Kinect

53

5.3.3 AI接球 以下為 AI 接球的動作1. 預測球的落點2. 計算時間是否足夠

a) 時間足夠 : 扣殺b) 時間不夠 : 落地後擊球

Page 54: Tennis Game Using  Kinect

54

5.3.3.1 預測球的落點 We predict falling location by physics.

以下為我們的推導公式 我們將分量切成 ,與落第時間相關的僅有,根據萬有引力算距離的公式為,由此方法可算出,而負不合,故 ( 球的預設落點位置 ) 為

Page 55: Tennis Game Using  Kinect

55

5.3.3.2 計算時間 計算時間方法

變數 : 電腦玩家剩下多少時間可以擊球 : 等待或直接扣殺的基準時間值 : 電腦與球的距離 : 電腦人物移動速度

方法 當 4.4.1電腦預測落點完畢後,電腦可求出與落點的距離 ,而 / (距離 / 速度 = 時間 ) 則能算出,當 ( 來不及直接追上 ) ,則等待球落地後回擊,除此之外,扣殺。

Page 56: Tennis Game Using  Kinect

56

5.3.4 玩家回擊 回擊流程1. 必須先偵測球是否在人物附近,設定容忍距離為,判斷是否成立

(< && < ) 成立後再判斷是否玩家有動作出現,若有則回到發球的查表動作 (詳見 5.3.1) ,腳色會自動追球並回擊。2. 若不在人物附近或玩家無動作判定,判定為漏接,則系統進入分數判定。

Page 57: Tennis Game Using  Kinect

57

5.3.5 分數判定 分數判定方法

變數 Input: C 與 S ( 當 C 為 1 則進入分數判定, S代表誰得分 ) Output: 使用來記錄分數

方法 為避免不停計算分數,故我們只有當 C==1 的時候再分析 S 判定得分,將分數加於,處理完後 C歸零,回到發球狀態。

Lichen: 目前只考慮一小場的狀況,故沒有總計分的變數,之後會加上,並附上搶七的狀況。

Page 58: Tennis Game Using  Kinect

58

6. Animated Tennis Game Display

After click the “play”. Unity can display our object.

Play button

Page 59: Tennis Game Using  Kinect

59

6. Animated Tennis Game Display

Unity will collect object’s information, and display by the information.

Page 60: Tennis Game Using  Kinect

60

7. Schedule (1/3)

We find UnityWrapper can reduce our work time.

After 9/13 開學 (專題進度會拖慢 ) 9/15 美工物體 ( 拍子 + 球 ) 完成 9/22 將 2D 版本移植至 3D 版本 10/7 3D 場景加入 + 遊戲選單 10/12 3D 人物模組整合進遊戲引擎 10/15 3D 完成 (3D 物體 + 場景 ) 11/1 3D 版本全完成、美工精緻化開始 12/1 最終版本完成、最佳化與額外功能增加開始 12/30 最終 demo 準備

Page 61: Tennis Game Using  Kinect

61

7. Schedule (2/3)

12

Project

07 10 11

1) 2D 版本總製作時間2) 3D 版本總製作時間3) 程式測試、最佳化、美工

201108 09

: Check Point

Page 62: Tennis Game Using  Kinect

62

7. Schedule (3/3)

12

3D 版本總製作時間

07 10 11

1) 將 2D 版本移植至 3D 版本2) 3D 場景加入3) 人物模組整合進遊戲引擎

201108 09

: Check Point

4) 拍子、球、球網、人物5) 規則與計分6) OpenNI研究 7) 整合

Page 63: Tennis Game Using  Kinect

63

8. Reference