Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 3D Game Programming 王銓彰 2005.

Similar presentations


Presentation on theme: "1 3D Game Programming 王銓彰 2005."— Presentation transcript:

1 1 3D Game Programming 王銓彰 kevin.cwang@msa.hinet.net 2005

2 2 Introduction to Game Development (3hr) Introduction to Game Development (3hr) Game System Analysis (3hr) Game System Analysis (3hr) The Game Main Loop (3hr) The Game Main Loop (3hr) 3D Game Engine Training (Using TheFly3D) (6hr) 3D Game Engine Training (Using TheFly3D) (6hr) Game Mathematics & Geometry (3hr) Game Mathematics & Geometry (3hr) Terrain (3hr) Terrain (3hr) Character Motion (3hr) Character Motion (3hr) Game Control System (3hr) Game Control System (3hr) Advanced Scene Management System (3hr) Advanced Scene Management System (3hr) Game AI (6hr) Game AI (6hr) Game Physics (3hr) Game Physics (3hr) Game FX (3hr) Game FX (3hr) Network Gaming (3hr) Network Gaming (3hr) MMOG (3hr) MMOG (3hr) Summary Summary Wang’s Method for Real-time 3D Game Development Wang’s Method for Real-time 3D Game Development課程大綱

3 3 One term project One term project The students are in teams. The students are in teams. Use TheFly3D 3D engine to code a Real-time 3D Game. Use TheFly3D 3D engine to code a Real-time 3D Game. Action RPG Action RPG The teacher will provide graphics materials and setup the game design. The teacher will provide graphics materials and setup the game design. Final examination Final examination Homework will be closely coupled with the term project. Homework will be closely coupled with the term project. 課程要求

4 4 目前 目前 數位內容學院 專任講師 / 顧問 數位內容學院 專任講師 / 顧問 宇峻奧汀 顧問 宇峻奧汀 顧問 鈊象電子 3D 技術顧問 鈊象電子 3D 技術顧問 學歷 學歷 台灣大學土木工程學系畢業 台灣大學土木工程學系畢業 資歷 資歷 04-04 資策會網路多媒體研究所 專案顧問 04-04 資策會網路多媒體研究所 專案顧問 97-04 昱泉國際股份有限公司 技術長 97-04 昱泉國際股份有限公司 技術長 96-96 虛擬實境電腦動畫股份有限公司 研發經理 96-96 虛擬實境電腦動畫股份有限公司 研發經理 93-96 西基電腦動畫股份有限公司 研發經理 93-96 西基電腦動畫股份有限公司 研發經理 90-93 國家高速電腦中心 助理研究員 90-93 國家高速電腦中心 助理研究員 89-90 台灣大學土木工程學系 CAE Lab 研究助理 89-90 台灣大學土木工程學系 CAE Lab 研究助理 王銓彰 (1/3)

5 5 Game 作品 Game 作品 Current Current TheFly3D 3D Engine TheFly3D 3D Engine 昱泉國際 昱泉國際 DragonFly 3D Game Engine DragonFly 3D Game Engine M2 神甲奇兵, VRLobby, 天劍記 M2 神甲奇兵, VRLobby, 天劍記 Lizard 3D Game Engine Lizard 3D Game Engine 幻影特攻、笑傲江湖 I & II 、神鵰俠侶 I & II 、風雲、小李飛刀、 笑傲江湖網路版、怪獸總動員、聖劍大陸、笑傲外傳 幻影特攻、笑傲江湖 I & II 、神鵰俠侶 I & II 、風雲、小李飛刀、 笑傲江湖網路版、怪獸總動員、聖劍大陸、笑傲外傳 西基電腦動畫 西基電腦動畫 Ultimate Fighter Ultimate Fighter 1 st real-time 3D fighting game in Taiwan 1 st real-time 3D fighting game in Taiwan 王銓彰 (2/3)

6 6 專長 (Expertise) 專長 (Expertise) 3D Computer Graphics 3D Computer Graphics Geometric Modeling Geometric Modeling Numerical Methods Numerical Methods Character Animation Character Animation Photo-realistic Rendering Photo-realistic Rendering Real-time Shading Real-time Shading Volume Rendering Volume Rendering 應用領域 (Applications) 應用領域 (Applications) 即時 3D 遊戲開發 (Real-time 3D Game Development) 即時 3D 遊戲開發 (Real-time 3D Game Development) 電腦動畫 (Computer Animation) 電腦動畫 (Computer Animation) 虛擬實境 (Virtual Reality) 虛擬實境 (Virtual Reality) 電腦輔助設計 (Computer-aided Design, CAD) 電腦輔助設計 (Computer-aided Design, CAD) 科學視算 (Scientific Visualization) 科學視算 (Scientific Visualization) 王銓彰 (3/3)

7 7 1st Introduction to Game Development

8 8 Game platform Game platform Game types Game types Game team Game team Game development pipeline Game development pipeline Game software system Game software system Tools Tools Introduction to Game Development

9 9 PC PC Single player Single player Match Makings Match Makings MMOG (Massive Multi-player Online Game) MMOG (Massive Multi-player Online Game) Web-based Games Web-based Games Console Console Sony PS2 Sony PS2 MS Xbox MS Xbox Nintendo GameCube Nintendo GameCube Arcade Arcade Mobile Mobile Nintendo GBA Nintendo GBA Nintendo DS Nintendo DS Sony PSP Sony PSP Hand-held Hand-held Game Platform

10 10 PC is designed for general office application. PC is designed for general office application. Not for entertainment purpose Not for entertainment purpose A virtual memory system A virtual memory system Unlimited system memory Unlimited system memory But video memory is limited. But video memory is limited. For frame buffers, z buffers, textures, vertices, … For frame buffers, z buffers, textures, vertices, … PCI / AGP might be a problem for performance. PCI / AGP might be a problem for performance. Open architecture Open architecture Hardware driver version issue Hardware driver version issue Different capabilities Different capabilities Different performance Different performance Compatibility test is very important. Compatibility test is very important. Development is easy to setup. Development is easy to setup. Visual C/C++ with DirectX Visual C/C++ with DirectX Game Development on PC

11 11 Specific hardware designed for games Specific hardware designed for games Single user OS Single user OS Single process OS Single process OS No hard disk drive (?) No hard disk drive (?) Closed system Closed system Native coding environment Native coding environment Proprietary SDK Proprietary SDK Hardware related features Hardware related features C language with assembly C language with assembly Limited resources Limited resources Memory for everything Memory for everything 32M for PS2 32M for PS2 64M for Xbox 64M for Xbox One console runs, the others do ! One console runs, the others do ! Use gamepad and no keyboard Use gamepad and no keyboard Game Development for Consoles

12 12 RPG (Role playing games) RPG (Role playing games) AVG (Adventure games) AVG (Adventure games) RTS (Real-time strategy games) RTS (Real-time strategy games) FPS (First-person shooting games) FPS (First-person shooting games) RSLG ( 戰棋 ) RSLG ( 戰棋 ) STG STG Sports Sports Action Action Puzzle games Puzzle games Table games Table games MMORPG MMORPG Massive Multiple Player Online Role Playing Games Massive Multiple Player Online Role Playing Games Game Types

13 13 開發團隊 開發團隊 製作人 製作人 執行製作人 執行製作人 企劃團隊 企劃團隊 程式團隊 程式團隊 美術團隊 美術團隊 行銷業務團隊 行銷業務團隊 產品經理 (PM) 產品經理 (PM) 測試團隊 測試團隊 遊戲審議委員會 遊戲審議委員會 Game project approval Game project approval 遊戲經營團隊 遊戲經營團隊 線上遊戲 game master (GM) 線上遊戲 game master (GM) Customer services Customer services MIS MIS Game Team Members

14 14 Team leader (usually) Team leader (usually) 資源管理 (Resource management) 資源管理 (Resource management) 行政管理 (Administration) 行政管理 (Administration) 專案管理 (Project management) 專案管理 (Project management) 向上負責 (Upward management) 向上負責 (Upward management) 團隊的決策 團隊的決策 風險管理 風險管理 Game Producer 遊戲製作人

15 15 專案管理執行 專案管理執行 Daily 運作 Daily 運作 House keeping House keeping Meeting coordinator Meeting coordinator Schedule checking Schedule checking Cross-domain communication Cross-domain communication Usually not a full-time job position Usually not a full-time job position A position for training and becoming a producer A position for training and becoming a producer遊戲執行製作人

16 16 故事設計 (Story telling) 故事設計 (Story telling) 腳本設計 (Scripting) 腳本設計 (Scripting) 玩法設計 (Game play design) 玩法設計 (Game play design) 角色設計 (Character design) 角色設計 (Character design) 動作設計 (Animation design) 動作設計 (Animation design) 關卡設計 (Level design) 關卡設計 (Level design) 特效設計 (Effect design) 特效設計 (Effect design) 物件設計 物件設計 介面設計 (User Interface design) 介面設計 (User Interface design) 遊戲調適 (Game tuning) 遊戲調適 (Game tuning) 數值設定 (Numerical setup) 數值設定 (Numerical setup) AI 設計 (Game AI design) AI 設計 (Game AI design) 音效設定 (Sound FX setup) 音效設定 (Sound FX setup) 遊戲企劃 (1/2)

17 17 場景設定 (Scene setup) 場景設定 (Scene setup) Game document writing Game document writing Game quality checking Game quality checking 遊戲企劃 (2/2)

18 18 Visual setup for game design Visual setup for game design 2D setup 2D setup 3D setup 3D setup Graphics design and production Graphics design and production 場景 (Terrain) 場景 (Terrain) 人物 (Character) 人物 (Character) 建模 (Models) 建模 (Models) 材質 (Textures) 材質 (Textures) 動作 (Motion / Animation) 動作 (Motion / Animation) 特效 (FX) 特效 (FX) User Interface User Interface 行銷支援 ( 封面. 海報.. 等 ) 行銷支援 ( 封面. 海報.. 等 )遊戲美術

19 19 遊戲程式 (Game Program) 撰寫 遊戲程式 (Game Program) 撰寫 遊戲開發工具 (Game Tools) 開發 遊戲開發工具 (Game Tools) 開發 Level editor Level editor Scene editor Scene editor FX editor FX editor Script editor Script editor Game editor Game editor 遊戲 Data exporters from 3D animation Software 遊戲 Data exporters from 3D animation Software 3dsMax / Maya / Softimage 3dsMax / Maya / Softimage Game engine development Game engine development Game technique research Game technique research Online game server development Online game server development遊戲程式

20 20 Basic Procedures for Game Development IdeaProposalProductionIntegration Testing DebugTuning Concept Approval PrototypePre-alphaAlphaBetaFinal 發想 (Idea) 發想 (Idea) 提案 (Proposal) 提案 (Proposal) 製作 (Production) 製作 (Production) 整合 (Integration) 整合 (Integration) 測試 (Testing) 測試 (Testing) 除錯 (Debug) 除錯 (Debug) 調適 (Tuning) 調適 (Tuning) > Concept approval > 雛形 (prototype) > Pre-alpha > Alpha > Beta遊戲開發流程

21 21 遊戲類型 (Game types) 遊戲類型 (Game types) 遊戲世界觀 (Game world) 遊戲世界觀 (Game world) 故事 (Story) 故事 (Story) 遊戲特色 (Features) 遊戲特色 (Features) 遊戲玩法 (Game play) 遊戲玩法 (Game play) 遊戲定位 (Game product positioning) 遊戲定位 (Game product positioning) Target player Target player Marketing segmentation / positioning Marketing segmentation / positioning 競爭對手評估 競爭對手評估 風險評估 (Risk) 風險評估 (Risk) SWOT (Strength/Weakness/Opportunity/Threat) 分析 SWOT (Strength/Weakness/Opportunity/Threat) 分析 產出物 產出物 Concept Design Document (CDD) Concept Design Document (CDD) 遊戲發想 (Concept Design)

22 22 系統分析 (System analysis) 系統分析 (System analysis) GDD 撰寫 (Game design document) GDD 撰寫 (Game design document) MDD 撰寫 (Media design document) MDD 撰寫 (Media design document) TDD 撰寫 (Technical design document) TDD 撰寫 (Technical design document) 遊戲專案建立 (Game project) 遊戲專案建立 (Game project) Schedule Schedule Milestones / Check points Milestones / Check points Risk management Risk management 測試計畫書 測試計畫書 團隊建立 (Team building) 團隊建立 (Team building) 產出物 產出物 GDD GDD MDD MDD TDD TDD The Team The Team 遊戲提案 (Proposal)

23 23 美術量產製作 美術量產製作 Modeling Modeling Textures Textures Animation Animation Motion Motion FX FX 程式開發 (Coding) 程式開發 (Coding) 企劃數值設定 企劃數值設定 … 量產 ! 遊戲開發 (Production)

24 24 關卡串聯 (Level integration) 關卡串聯 (Level integration) 數值調整 (Number tuning) 數值調整 (Number tuning) 音效置入 (Audio) 音效置入 (Audio) 完成所有美術 完成所有美術 程式與美術結合 程式與美術結合 Testing within the game team Testing within the game team Focus group (User study) Focus group (User study) Release some playable levels for focus group. Release some playable levels for focus group. Get the feedback from focus group to adjust the game play. Get the feedback from focus group to adjust the game play. Invited outside game players but evaluation in-house Invited outside game players but evaluation in-house 遊戲整合 (Integration)

25 25 Alpha 測試 Alpha 測試 除錯 (Debug) 除錯 (Debug) Make the game stable Make the game stable Beta 測試 Beta 測試 數值微調 數值微調 Game play 微調 Game play 微調 對線上遊戲而言 (MMOG) 對線上遊戲而言 (MMOG) 封閉測試 (Closed beta) 封閉測試 (Closed beta) Invited game players Invited game players 開放測試 (Open beta) 開放測試 (Open beta) Free for public players Free for public players 極限測試 (Critical testing) 極限測試 (Critical testing) Only for MMOG Only for MMOG Continuously implementing Continuously implementing For servers For servers 遊戲測試 (Test)

26 26 Bug 分級 (Bug Classification) Bug 分級 (Bug Classification) A Bug A Bug B Bug B Bug C Bug C Bug S Bug S Bug Principles Principles Bug 分級從嚴 Bug 分級從嚴 Tester vs Debugger Tester vs Debugger Bug Classification Bug Dispatch Debug Verify Bug FAQ Y N ?Bugs

27 27 Hardware 3D Graphics API2D APIInput DeviceOS API3D Scene Mngmt2D SpriteGamepadNetworkAudioTerrainCollisionCharacterUIDynamicsSound FX Fighting SystemFX SystemGame AIScript System NPC SystemVirtual AgentTrading SystemStory Game Game Play Layer Engine Layer System Layer Game Software System

28 28 3D Graphics API 3D Graphics API DirectX 9.0 SDK – Direct3D DirectX 9.0 SDK – Direct3D Newest update : DirectX 9.0c SDK Update (June, 2005) Newest update : DirectX 9.0c SDK Update (June, 2005) OpenGL OpenGL 2.0 2.0 2D API 2D API DirectX 9.0 SDK - DirectMedia DirectX 9.0 SDK - DirectMedia Win32 GDI Win32 GDI Input device Input device DirectX 9.0 SDK – DirectInput DirectX 9.0 SDK – DirectInput Audio Audio DirectX 9.0 SDK – DirectSound / Direct3DSound / DirectMedia DirectX 9.0 SDK – DirectSound / Direct3DSound / DirectMedia OpenAL OpenAL System Layer – APIs (1/2)

29 29 OS API OS API Win32 SDK Win32 SDK MFC MFC Network Network DirectX 9.0 SDK – DirectPlay DirectX 9.0 SDK – DirectPlay Socket library Socket library System Layer – APIs (2/2)

30 30 3D scene management system 3D scene management system Scene graph Scene graph Shaders Shaders 2D sprite system 2D sprite system Audio system Audio system Gamepad Gamepad Hotkeys Hotkeys Mouse Mouse Timers Timers Network Network DDK interface DDK interface Engine Layer (1/2)

31 31 Terrain system Terrain system Advanced scene management system Advanced scene management system Space partition technique Space partition technique BSP Tree BSP Tree Octree Octree Character system Character system Bone-skin Bone-skin Motion Blending Motion Blending Dynamics Dynamics Particle system Particle system Rigid-body dynamics Rigid-body dynamics Collision detection Collision detection Sound FX Sound FX User interface User interface Engine Layer (2/2)

32 32 NPC (Non-playable characters) management NPC (Non-playable characters) management Game AI Game AI Path finding Path finding Finite state machine (FSM) Finite state machine (FSM) Steering behavior Steering behavior Avatar Avatar Combat system Combat system FX system FX system Script system Script system Trading system Trading system Number system Number system … Game Play Layer

33 33 System Tools System Tools Visual C/C++ Visual C/C++.Net 2003.Net 2003 VC/C++ 7.1 VC/C++ 7.1 Visual C/C++ 6.0 + SP5 Visual C/C++ 6.0 + SP5 NuMega BoundsChecker NuMega BoundsChecker Finding memory leaking Finding memory leaking Intel vTune Intel vTune Finding computation performance bottlenecks Finding computation performance bottlenecks for CPU for CPU PIX PIX Finding graphics performance bottlenecks Finding graphics performance bottlenecks For GPU For GPU Game Development Tools for Programming (1/2)

34 34 SDKs SDKs System API System API Win32 SDK or MFC Win32 SDK or MFC DirectX SDK or OpenGL DirectX SDK or OpenGL Socket library Socket library Middleware (Game engine) Middleware (Game engine) Renderware Renderware Unreal Unreal … Physics Physics ODE ODE Game Development Tools for Programming (2/2)

35 35 3D tools 3D tools Discrete 3dsMax Discrete 3dsMax Maya Maya Softimage XSI Softimage XSI 2D tools 2D tools Photoshop Photoshop Illustrator Illustrator Motion tools Motion tools Motion capture devices Motion capture devices Motion Builder Motion Builder FiLMBOX FiLMBOX Game Development Tools for Artists

36 36 2nd Game System Analysis

37 37 The idea about system analysis (SA) The idea about system analysis (SA) Mind mapping Mind mapping Case study - Term project Case study - Term project What Will We Talk

38 38 For 程式結構 analysis For 程式結構 analysis The main program The main program Game development tools Game development tools To identify 工作量 To identify 工作量 New game engine ? New game engine ? Re-used code ? Re-used code ? Tools needed to be developed ? Tools needed to be developed ? For 資源 management For 資源 management Total man month Total man month How many programmers ? How many programmers ? How good the programmers ? How good the programmers ? For job dependency analysis For job dependency analysis Why System Analysis (1/2) Job AJob B Job C Job D

39 39 To do technical possibility analysis To do technical possibility analysis 技術可行性分析 技術可行性分析 R&D ? R&D ? Where is the technical bottleneck ? Where is the technical bottleneck ? Pre-processor for Pre-processor for Technical design document Technical design document Project management Project management Bridge from game design to programming Bridge from game design to programming Why System Analysis (2/2)

40 40 No standard procedures or approaches No standard procedures or approaches It’s not a theory. It’s not a theory. Experience Experience You can use your own method/tool You can use your own method/tool UML UML Mind mapping Mind mapping 心智圖法 心智圖法 This is the one we will use in this course This is the one we will use in this course … Something about System Analysis

41 41 Brainstorming Brainstorming Integration Integration Dependency analysis Dependency analysis Create the project Create the project Technical design document (TDD) writing Technical design document (TDD) writing Wang’s System Analysis Steps

42 42 Based on the game design to put everything as many as you could Based on the game design to put everything as many as you could Use mind mapping Use mind mapping Including Including Game system Game system Combat / Village / Puzzle / … Combat / Village / Puzzle / … Program modulus Program modulus Camera / PC control / NPC AI / UI / FX /… Camera / PC control / NPC AI / UI / FX /… Tools Tools Level editor / Scene editor / … Level editor / Scene editor / … Entities in games Entities in games Characters / vehicle / terrain / audio / … Characters / vehicle / terrain / audio / …Brainstorming

43 43 Confirm the resource limitation Confirm the resource limitation Technical implement possibility Technical implement possibility Put all related items together Put all related items together Man month analysis Man month analysis How many ? How many ? Who ? Who ? Jobs / System identification Jobs / System identificationIntegration

44 44 Sort the Jobs Sort the Jobs By job dependency By job dependency By programmers’ schedule By programmers’ schedule Prototype for scheduling Prototype for scheduling Dependency Analysis

45 45 Scheduling Scheduling Job assignment Job assignment Resource allocation Resource allocation Check points Check points Milestones Milestones Major check points Major check points Output Output Risk management Risk management Alternatives Alternatives Risk management policy Risk management policy System Analysis – Create the Project

46 46 Specification Specification Resources Resources Design in details Design in details Implement methods ( 工法 ) Implement methods ( 工法 ) Algorithms Algorithms “Project” “Project” Output in each milestone Output in each milestone SOP (optional) SOP (optional) TDD Template TDD Template TDD Template TDD Template Technical Design Document

47 47 心智圖法 心智圖法 A radiant thinking tool A radiant thinking tool Applications Applications 讀書心得 讀書心得 Proposal Proposal 上課筆記 上課筆記 遊記 遊記 System Analysis System Analysis … Reference Reference Programs Programs Visio Visio MindManager MindManager Books Books Tony Buzan, Barry Buzan Tony Buzan, Barry Buzan “The Mind Map Book: How to Use Radiant Thinking to Maximize Your Brain's Untapped Potential” “The Mind Map Book: How to Use Radiant Thinking to Maximize Your Brain's Untapped Potential” Mind Map

48 48

49 49

50 50 Use MindManager X5 pro Use MindManager X5 pro Developed by MindJet Developed by MindJet Mind Map Demo Using MindManager

51 51 3rd The Game Main Loop

52 52 int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow) { WNDCLASSEX wc;... // register window class ZeroMemory(&wc, sizeof(WNDCLASSEX)); wc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS; wc.lpfnWndProc = KKMainProc;... RegisterClassEx(&wc);... // the main loop KKMainLoop(); // unregister the window class UnregisterClass(wc.lpszClassName, hInst); return id; } Win32 Application (1/3)

53 53 LRESULT CALLBACK KKMainProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { LRESULT l = FALSE;... // switch for all incoming messages from WindowsXX switch (uMsg) { case WM_KEYDOWN:... l = TRUE; break;... } // echo the result if (l) { return l; } else { return DefWindowProc(hWnd, uMsg, wParam, lParam); } Win32 Application (2/3)

54 54 void KKMainLoop() { MSG msg; BOOL kkBeQuit = FALSE; // the main loop while (!kkBeQuit) { // check window's messages while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { if (msg.message == WM_QUIT) { kkBeQuit = TRUE; } // invoke the WindowsX to handle the incoming messages TranslateMessage(&msg); DispatchMessage(&msg); } // do your jobs here, for example, check the timing and do something in regular... } Win32 Application (3/3)

55 55 Win32 programs are event-driven Win32 programs are event-driven Messages = events Messages = events So as all windows system (for example : X window) So as all windows system (for example : X window) We need an infinitive loop to check all incoming events. We need an infinitive loop to check all incoming events. In the loop : In the loop : Check if there are incoming events (messages) Check if there are incoming events (messages) Handle the events Handle the events Check the time and do something in regular Check the time and do something in regular Incoming events : Incoming events : Interrupts Interrupts System requests System requests Event-driven Programming

56 56 Timers (do something in regular timing) Timers (do something in regular timing) The sub-system to handle timing The sub-system to handle timing Must be precise to at least 1 ms or less Must be precise to at least 1 ms or less 30fps = 1/30 second = 33.333… ms 30fps = 1/30 second = 33.333… ms On win32 platform, you can use “performance counter” instead of the win32’s “WM_TIMER” message On win32 platform, you can use “performance counter” instead of the win32’s “WM_TIMER” message For windows9x, WM_TIMER = 18.2 fps (maximum) For windows9x, WM_TIMER = 18.2 fps (maximum) Events Events Input devices Input devices Mouse Mouse Keyboard Keyboard Something coming from network Something coming from network System requests System requests Re-draw Re-draw Losing/getting the input focus Losing/getting the input focus … Timers & Events (1/2)

57 57 Two types of jobs (Callbacks) to do (Call) : Two types of jobs (Callbacks) to do (Call) : In regular In regular Timers callbacks Timers callbacks By requests By requests Input device callbacks Input device callbacks So as the game main program So as the game main program A game is an interactive application. A game is an interactive application. Mouse Mouse Hotkeys Hotkeys Gamepads Gamepads A game is time-bound. A game is time-bound. Rendering locked in 30fps or 60fps Rendering locked in 30fps or 60fps Motion data produced in 30fps Motion data produced in 30fps Game running in 30fps Game running in 30fps Timers & Events (2/2)

58 58 On PC platform : use “Performance Counter” On PC platform : use “Performance Counter” QueryPerformanceFrequency() QueryPerformanceCounter() // timers data structure typedef struct { BOOL beAble; // is the timer is enabled/disabled ? BOOL be1st; // is this the 1st time for the timer to be checked // after last initialization ? BOOL beLockFps; // is locked on FPS ? double initTime; // initial time double timeInv; // system ticks for one frame double nxtTime; // next checking time void (*timer)(int); // timer's callback double resetTime; // reset time } TIMERs, *TIMERptr; Implement the Timer (1/6)

59 59 /*---------------------------------------------------------------------- initialize a timer and bind a user-defined timer callback ------------------------------------------------------------------------*/ void FyBindTimer(DWORD id, float fps, void (*fun)(int), BOOL beLock) { if (id = MAXTIMERS) return; /* assign the timer's callback */ fyTimer[id].timer = fun; /* set lock-to-fps flag */ fyTimer[id].beLockFps = beLock; /* calculate the ticks for one frame */ fyTimer[id].timeInv = (double) (fyFreq) / (double) fps; fyTimer[id].be1st = TRUE; fyTimer[id].beAble = TRUE; } Implement the Timer (2/6)

60 60 /*------------------------------------ get current system clock tick --------------------------------------*/ double FYGetCurrentSystemTick() { LARGE_INTEGER timeCount; /* get current tick */ QueryPerformanceCounter(&timeCount); return (double) timeCount.QuadPart; } /* // get the system ticks for one second QueryPerformanceFrequency(&timeFreq); fyFreq = timeFreq.LowPart; */ Implement the Timer (3/6)

61 61 /*------------------------------------------------------------ invoke the TheFly3D system to handle the timers --------------------------------------------------------------*/ void FyInvokeTheFly(BOOL beTimer) { MSG msg; if (fyBeQuit) return; while (!fyBeQuit) { // check window's messages while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { if (msg.message == WM_QUIT) fyBeQuit = TRUE; TranslateMessage(&msg); DispatchMessage(&msg); } // check the timer if (beTimer && fyBeTimer) FYInvokeTimer(); } Implement the Timer (4/6)

62 62 /*--------------------- check all timers ----------------------*/ void FYInvokeTimer() { int i, skipS; double dTime; // get current time dTime = FYGetCurrentSystemTick(); for (i = 0; i < MAXTIMERS; i++) { if (fyTimer[i].beAble && fyTimer[i].timer != NULL) { // for the first time..... if (fyTimer[i].be1st) { // initialize the timer fyTimer[i].be1st = FALSE; fyTimer[i].initTime = dTime; fyTimer[i].nxtTime = dTime + fyTimer[i].timeInv; (*(fyTimer[i].timer))(1); } Implement the Timer (5/6)

63 63 else { if (fyTimer[i].beLockFps) { if (dTime >= fyTimer[i].nxtTime) { // calculate skip frames skipS = (int)((dTime - fyTimer[i].nxtTime) / (double)fyTimer[i].timeInv) + 1; // get next checking time fyTimer[i].nxtTime += (double) (skipS * fyTimer[i].timeInv); // check some abnormal conditions... // invoke the timer callback (*(fyTimer[i].timer))(skipS); } else { (*(fyTimer[i].timer))(1); } Implement the Timer (6/6)

64 64 Single player Single player Check game over Peek player input Implement timer callback Exit the loop Rendering Loop y n Game Loop (1/2)

65 65 Network client Network client Check game over Peek user input Receive messages Send messages Timer callbacks Rendering Exit y n From network To network Loop Game Loop (2/2)

66 66 Check “Win/Lose” Check “Win/Lose” Check “Quit” Check “Quit” Make objects moving … Make objects moving … Play character’s motion to the next frame Play character’s motion to the next frame Play animation to the next frame Play animation to the next frame Models Models Textures Textures … Perform game logic calculation Perform game logic calculation Perform geometry associated calculation Perform geometry associated calculation i.e. LOD i.e. LOD Perform AI “Thinking” Perform AI “Thinking” Perform collision detection Perform collision detection Perform the 3D rendering Perform the 3D rendering Play FX Play FX … Jobs in Regular (In Timers)

67 67 Mouse Input Mouse Input Press/release the mouse button Press/release the mouse button Drag Drag Double-click Double-click Move Move Keyboard Input Keyboard Input Hotkey Hotkey Typing Typing Gamepad Gamepad Same behavior as the hotkey Same behavior as the hotkey Except looking not like the keyboard Except looking not like the keyboard Network Network System System … Jobs By Request

68 68 4th TheFly3D Game Engine

69 69 void main(int argc, char **argv) { // create the game world & 3D scene... // set Hotkeys FyDefineHotKey(FY_ESCAPE, QuitGame, FALSE);... // define some mouse functions FyBindMouseFunction(LEFT_MOUSE, InitPivot, PivotCam, EndPivot, NULL);... // bind a timer for rendering, frame rate = 60 fps FyBindTimer(0, 60.0f, RenderIt, TRUE); // bind a timer for game AI, frame rate = 30 fps FyBindTimer(1, 30.0f, GameAI, TRUE); // invoke the system FyInvokeTheFly(TRUE); } The Main Program

70 70 //------------------- // quit the game //------------------- void QuitGame(WORLDid gID, BYTE code, BOOL value) { if (code == FY_ESCAPE) { if (value) { FyWin32EndWorld(gID); } Hotkey Callback

71 71 /*----------------------------------------- initialize the pivot of the camera ------------------------------------------*/ void InitPivot(WORLDid g, int x, int y) { oldX = x; oldY = y; } /*------------------ pivot the camera -------------------*/ void PivotCam(WORLDid g, int x, int y) { FnModel model; if (x != oldX) { model.Object(cID); model.Rotate(Z_AXIS, (float) (x - oldX), GLOBAL); oldX = x; } if (y != oldY) { model.Object(cID); model.Rotate(X_AXIS, (float) (y - oldY), GLOBAL); oldY = y; } Mouse Callback

72 72 //---------------------------------------------------------------------------------------- // Render callback which will be invoked by TheFly3D every 1/60 second //---------------------------------------------------------------------------------------- void RenderIt(int skip) { FnViewport vp; FnWorld gw; // render the scene vp.Object(vID); vp.Render(cID, TRUE, TRUE); // perform double-buffering gw.Object(gID); gw.SwapBuffers(); } The Timer Callback

73 73 Introduction to TheFly3D A real-time 3D graphics programming library A real-time 3D graphics programming library Using C++ Using C++ Cross-platform Cross-platform DirectX9.0c DirectX9.0c OpenGL 1.5 OpenGL 1.5 An API for 3D graphics developers An API for 3D graphics developers Provide a fundamental scene management system Provide a fundamental scene management system Scene tree Scene tree Built-in visibility culling Built-in visibility culling According to the experiences from the author, some game development features are added. According to the experiences from the author, some game development features are added. Characters Characters Terrain system Terrain system … Current version 0.8a1 (0920, 2005) Current version 0.8a1 (0920, 2005) Shader has been added in D3D version Shader has been added in D3D version

74 74 TheFly3D in A Chart Hardware 3D Graphics API2D APIInput DeviceOS API 3D Scene Mngmt2D SpriteGamepadNetworkAudio TerrainCollisionCharacterUIDynamicsSound FX Combat SystemFX SystemGame AIScript System NPC SystemVirtual AgentTrading SystemStory Game Game Play Layer Engine Layer System Layer Developing Developed

75 75 Development Environment.NET2003 Visual C++ 7.1.NET2003 Visual C++ 7.1 DirectX9.0c SDK (Dec, 2004) DirectX9.0c SDK (Dec, 2004) Two include files : (must!) Two include files : (must!) TheFly.h TheFly.h TheFlyWin32.h (Win32 version + D3D) TheFlyWin32.h (Win32 version + D3D) Linked libraries (API version) Linked libraries (API version) TheFlyLibD_08_01.lib TheFlyLibD_08_01.lib d3d9.lib d3dx9.lib dsound.lib dxguid.lib winmm.lib d3d9.lib d3dx9.lib dsound.lib dxguid.lib winmm.lib

76 76 Create the Visual C++ Project for “TheFly3D” Create folders for TheFly3D API Create folders for TheFly3D API …\include …\include …\lib …\lib New a Win32 application project New a Win32 application project Set the additional include/library directories to TheFly3D API Set the additional include/library directories to TheFly3D API Add DirectX 9.0 SDK’s include/lib to additional search directories Add DirectX 9.0 SDK’s include/lib to additional search directories Add d3d9.lib d3dx9.lib dsound.lib dxguid.lib winmm.lib to additional dependencies Add d3d9.lib d3dx9.lib dsound.lib dxguid.lib winmm.lib to additional dependencies Add TheFly.h, TheFlyWin32.h, TheFly3DLibD_xxxx.lib into the project Add TheFly.h, TheFlyWin32.h, TheFly3DLibD_xxxx.lib into the project

77 77 The 1 st TheFly3D Program – hello.cpp Create a 3D world Create a 3D world Create a viewport Create a viewport Create a scene Create a scene Create 3D entities Create 3D entities A camera A camera A teapot model A teapot model A light source A light source Translate the camera to show the model Translate the camera to show the model Bind callbacks to make the program interactive Bind callbacks to make the program interactive

78 78 Demo - Hello Do it!

79 79 The Basics to Write TheFly3D Program All Win32 code is transparent. All Win32 code is transparent. void main(int argc, char *argv[]) void main(int argc, char *argv[]) All Win32 & DirectX code are hidden within the engine. All Win32 & DirectX code are hidden within the engine. ID & Function class ID & Function class TheFly3D creates the objects for you. TheFly3D creates the objects for you. Return the object ID Return the object ID TheFly3D owns the objects. TheFly3D owns the objects. You have the right to handle the objects. You have the right to handle the objects. Use function classes Use function classes No internal data structure & functions revealed No internal data structure & functions revealed // create a viewport vID = gw.CreateViewport(ox, oy, ww, hh); FnViewport vp; vp.Object(vID); vp.SetBackgroundColor(0.3f, 0.3f, 0.0f);

80 80 Initialize TheFly3D In general the 1 st function to use TheFly3D is : In general the 1 st function to use TheFly3D is : FyWin32CreateWorld() FyWin32CreateWorld() After the calling successfully, you can get the non-zero ID (WORLDid) of a world object. After the calling successfully, you can get the non-zero ID (WORLDid) of a world object. Assign the ID to a world function class object for manipulating the world. Assign the ID to a world function class object for manipulating the world. // create a new world WORLDid gID = FyWin32CreateWorld(“Tester", 0, 0, 800, 600, 16, FALSE); FnWorld gw; gw.Object(gID); gw.SetTexturePath("Data\\textures");

81 81 3D Graphics Layers A World Frame Buffers (front + back) The World in TheFly3D A world is a set of graphics layers where the 3D objects acts on. A world is a set of graphics layers where the 3D objects acts on.

82 82 Camera 3D Models Lights Backdrop Board A 3D Scene The 3D Graphics Layer A 3D graphics layer is a projection of the rendering of a 3D view. A 3D graphics layer is a projection of the rendering of a 3D view. The set of the 3D objects in the view : The set of the 3D objects in the view : We call it the “Scene”. We call it the “Scene”. The projection we call the “Viewport” The projection we call the “Viewport”

83 83 The Viewports & Scenes TheFly3D supports the multiple viewports. TheFly3D supports the multiple viewports. A scene can be rendered on different viewports. A scene can be rendered on different viewports. Viewports & scenes are created by the world object. Viewports & scenes are created by the world object. // create a new world WORLDid gID; gID = FyWin32CreateWorld(Tester", 0, 0, 800, 600, 16, FALSE); FnWorld world; world.Object(gID); SCENEid sID = world.CreateScene(); VIEWPORTid vID = world.CreateViewport(0, 0, 400, 300); world.DeleteScene(sID); world.DeleteViewport(vID);

84 84 The Scene A scene is not a “real” 3D object, just a “set” of 3D objects. A scene is not a “real” 3D object, just a “set” of 3D objects. A scene provides multiple rendering groups to handle the priority sorting for the rendering of 3D objects. A scene provides multiple rendering groups to handle the priority sorting for the rendering of 3D objects. There are three object lists within a rendering group. There are three object lists within a rendering group. Invisible list Invisible list Opacity list Opacity list Semi-transparent list Semi-transparent list The objects are rendered by the order of rendering groups. The objects are rendered by the order of rendering groups. In the same rendering group, the opaque objects are rendered first. In the same rendering group, the opaque objects are rendered first. And the semi-transparent objects are sorted and rendered from far to near… And the semi-transparent objects are sorted and rendered from far to near…

85 85 The 3D Entities – Objects A 3D scene is constructed by a set of “objects” which are the basic entities in a scene. A 3D scene is constructed by a set of “objects” which are the basic entities in a scene. An object is a carrier to carry real 3D data including : An object is a carrier to carry real 3D data including : Model geometry Model geometry Camera data Camera data Lighting data Lighting data Terrain data Terrain data Particle emitters Particle emitters Forces Forces Audio Audio Objects are created/deleted by its host scene. Objects are created/deleted by its host scene. Objects can be switched between scenes. Objects can be switched between scenes. Objects should be assigned to a rendering group. Objects should be assigned to a rendering group.

86 86 The Objects Can … Can have shapes (geometric data) Can have shapes (geometric data) Can be grouped (hierarchy) Can be grouped (hierarchy) Can move (transformation) Can move (transformation) Can look alike (clone or data sharing) Can look alike (clone or data sharing) Can perform (animation or deformation) Can perform (animation or deformation) Can be affected (lighted, listened) Can be affected (lighted, listened) Can be changed dynamically (modification) Can be changed dynamically (modification)

87 87 Etc Parameters Geometric Data Shape Transformation Move Parent Object Hierarchy Motion Data Animation Clone A Scene Object

88 88 A Model Object An object to carry a set of geometry data is a model object An object to carry a set of geometry data is a model object You can load the model data from files. You can load the model data from files. TheFly3D loads.cw3 model files in default. TheFly3D loads.cw3 model files in default. // create 3D entities nID = scene.CreateObject(ROOT); FnObject model; model.Object(nID); // load a teapot model.Load("Teapot.cw3");

89 89 A tree-based representation Simplified scene graph Root TheFly3D Scene Tree

90 90 A tree-based representation Simplified scene graph TheFly3D Scene Tree Is Simplified Scene Graph Root

91 91 nID = scene.CreateObject(ROOT); cID = scene.CreateCamera(ROOT); FnObject model; model.Object(nID); model.SetParent(cID); nID cID Object Hierarchy

92 92 OBJECTid nID = scene.CreateObject(ROOT); FnObject model; model.Object(nID); OBJECTid nID1 = model.Instance(); Clone a Model Object nIDnID1 Data instance

93 93 TheFly3D Major Model Object Functions (1/2) void model.SetParent(parent_object_ID); void model.SetParent(parent_object_ID); void model.Show(be_show); void model.Show(be_show); void model.SetOpacity(opacity); void model.SetOpacity(opacity); opacity = 0.0 – 1.0 opacity = 0.0 – 1.0 void model.SetRenderMode(mode); void model.SetRenderMode(mode); mode = WIREFRAME or TEXTURE mode = WIREFRAME or TEXTURE OBJECTid clonedID = model.Instance(); OBJECTid clonedID = model.Instance(); void model.ChangeScene(sID); void model.ChangeScene(sID); BOOL model.Load(char *file); BOOL model.Load(char *file); Load a.cw3 model file to a model object Load a.cw3 model file to a model object void model.ShowBoundingBox(beShow); void model.ShowBoundingBox(beShow); void model.Translate(x, y, z, op); void model.Translate(x, y, z, op);

94 94 TheFly3D Major Model Object Functions (2/2) model.SetRenderOption(item, value); model.SetRenderOption(item, value); (item, value) = (item, value) = (Z_BUFFER, TRUE/FALSE) (Z_BUFFER, TRUE/FALSE) (Z_BUFFER_WRITE, TRUE/FALSE) (Z_BUFFER_WRITE, TRUE/FALSE) (ALPHA, TRUE/FALSE) (ALPHA, TRUE/FALSE) Add/remove the model to/from alpha sorting list Add/remove the model to/from alpha sorting list (FOG, TRUE/FALSE) (FOG, TRUE/FALSE) (SPECULAR, TRUE/FALSE) (SPECULAR, TRUE/FALSE) (LIGHTING, TRUE/FALSE) (LIGHTING, TRUE/FALSE) (ANTIALIASING, TRUE, FALSE) (ANTIALIASING, TRUE, FALSE) (SOURCE_BLEND_MODE BLEND_ZERO / BLEND_ONE / BLEND_SRC_COLOR / BLEND_INV_SRC_COLOR / BLEND_SRC_ALPHA / BLEND_INV_SRC_ALPHA / BLEND_DEST_ALPHA / BLEND_INV_DEST_ALPHA / BLEND_DEST_COLOR / BLEND_INV_DEST_COLOR / BLEND_SRC_ALPHA_SAT / BLEND_BOTH_SRC_ALPHA / BLEND_BOTH_INV_SRC_ALPHA) (SOURCE_BLEND_MODE BLEND_ZERO / BLEND_ONE / BLEND_SRC_COLOR / BLEND_INV_SRC_COLOR / BLEND_SRC_ALPHA / BLEND_INV_SRC_ALPHA / BLEND_DEST_ALPHA / BLEND_INV_DEST_ALPHA / BLEND_DEST_COLOR / BLEND_INV_DEST_COLOR / BLEND_SRC_ALPHA_SAT / BLEND_BOTH_SRC_ALPHA / BLEND_BOTH_INV_SRC_ALPHA) (DESTINATION_BLEND_MODE values are same as the SOURCE_BLEND_MODE) (DESTINATION_BLEND_MODE values are same as the SOURCE_BLEND_MODE)

95 95 Coordinate System Every model should have its own local coordinate system. Every model should have its own local coordinate system. Local space Local space Model space Model space The space when it’s modeled The space when it’s modeled To its parent model, it is in the global space. To its parent model, it is in the global space. Global space Global space The space for reference The space for reference World space World space The global space of the “Root” The global space of the “Root” X Y Z x y z

96 96 Rotation matrixTransformation Three basic linear transformations used in TheFly3D. Three basic linear transformations used in TheFly3D. Translate Translate Rotate Rotate Scale Scale Principles : Principles : Right-handed rule Right-handed rule v’ = v M 0 M 1 v’ = v M 0 M 1 Matrix in 12-element (I call the M12) Matrix in 12-element (I call the M12) a 0 a 1 a 2 0 a 3 a 4 a 5 0 a 6 a 7 a 8 0 a 9 a 10 a 11 1 Translation vector

97 97 x’ = x + dx y’ = y + dy z’ = z + dz model.Translate(dx, dy, dz, op); T = 1 0 0 0 1 0 0 0 1 dx dy dz (dx dy dz)Translation

98 98Rotation model.Rotate(Z_AXIS, 30.0f, op); i.e. rotate with z axis x’ = x cos  – y sin  y’ = x sin  + y cos  z’ = z Rz =Rz = cos  sin  0 -sin  cos  0 0 0 1 0 0 0 x y z

99 99Scaling model.Scale(sx, sy, sz, op); x’ = x * sx y’ = y * sy z’ = z * sz T = sx 0 0 0 sy 0 0 0 sz 0 0 0

100 100 Matrix Operations Matrix operation Matrix operation REPLACE, LOCAL, GLOBAL REPLACE, LOCAL, GLOBAL x y z X Y Z [M][ML][ML][MG][MG] Object Transformation Matrix op = REPLACE op = GLOBAL op = LOCAL

101 101 TheFly3D Model Transformation Functions model.Translate(x, y, z, op); model.Translate(x, y, z, op); op = LOCAL, GLOBAL, or REPLACE op = LOCAL, GLOBAL, or REPLACE model.Rotate(axis, angle, op); model.Rotate(axis, angle, op); op = LOCAL, GLOBAL, or REPLACE op = LOCAL, GLOBAL, or REPLACE axis = X_AXIS, Y_AXIS, Z_AXIS axis = X_AXIS, Y_AXIS, Z_AXIS model.Scale(sx, sy, sz, op); model.Scale(sx, sy, sz, op); op = LOCAL, GLOBAL, or REPLACE op = LOCAL, GLOBAL, or REPLACE model.Quaternion(w, x, y, z, op); model.Quaternion(w, x, y, z, op); w : the scalar part of the quaternion w : the scalar part of the quaternion x, y, z : the vector part of the quaternion x, y, z : the vector part of the quaternion The quaternion should be a unit quaternion The quaternion should be a unit quaternion op = LOCAL, GLOBAL, or REPLACE op = LOCAL, GLOBAL, or REPLACE model.SetMatrix(M12, op); model.SetMatrix(M12, op); M12 : an M12 matrix M12 : an M12 matrix op = LOCAL, GLOBAL, or REPLACE op = LOCAL, GLOBAL, or REPLACE float *model.GetMatrix(); float *model.GetMatrix(); Get the pointer of the model object’s matrix Get the pointer of the model object’s matrix

102 102 Transformation is the term used in computer graphics but not friendly for games. We use movements to control the 3D objects moving around in the scene. Move forward Move right Move up Turn right Turn left … Move forward Move up Move right Turn right / left Transformations vs Movements

103 103 x y z z up + facing to -y Facing Direction and Up Direction Each object is modeled with a facing direction and up direction “visually” In TheFly3D, we use –y axis as the default facing direction for a model, z axis as the default up direction But for a camera : -z axis is the facing direction y axis is the up direction

104 104 new position = old position + distance *(facing direction in unit) Move Forward (1/2)

105 105 The object has a local coordinate system. Align a local axis of the object with the facing direction Make a translation to move the object align the local axis Apply the matrix first before to apply the existing transformations (op = LOCAL) Then the object is moving forward! Move Forward (2/2) FnObject model; model.Object(nID); model.Translate(0.0f, -dist, 0.0f, LOCAL); // facing to -y

106 106 -1 -1 -1 M = T1 * R1 * R2 * Rx(angle) * R2 * R1 * T1 T1 = / 1 0 0 0 R1 = / cs2 -sn2 0 0 0 1 0 0 -z sn2 cs2 0 0 0 0 1 0 0 0 1 0 -x -y -z 1 / 0 0 0 1 / R2 = / cs1 0 -sn1 0 Rx = / 1 0 0 0 y 0 1 0 0 0 cs sn 0 sn1 0 cs1 0 0 -sn cs 0 0 0 0 1 / 0 0 0 1 / An example : (rotate with an arbitrary axis) Turn Right/Left (1/2)

107 107 The object has a local coordinate system Align a local axis of the object with the up direction Make a rotation matrix to turn the object along the local axis Apply the matrix first before to apply the existing transformations Then the object is turning ! Turn Right/Left (2/2) FnObject model; model.Object(nID); model.Rotate(Z_AXIS, -angle, LOCAL); // turn right

108 108 A terrain is a place for 3D objects to walk on A terrain is a place for 3D objects to walk on A terrain can be generated from a model file A terrain can be generated from a model file Neighboring triangles are the next searching target for current triangle for terrain following Neighboring triangles are the next searching target for current triangle for terrain following A terrain for terrain following is not the same as the terrain in visual A terrain for terrain following is not the same as the terrain in visualTerrain

109 109 Generate Terrain in TheFly3D // create a terrain object tID = scene.CreateTerrain(); FnTerrain t; t.Object(tID); // load a terrain model (just like a regular object) // but a terrain is invisible in default t.Load("test_terrain_following.cw3"); // generate the neighboring data for terrain following // otherwise, the terrain model is for visual only t.GenerateTerrainData();

110 110 Put a Model on Terrain Using TheFly3D // if tID is the terrain object (OBJECTid) // load a model OBJECTid nID = scene.CreateObject(ROOT); FnObject obj; obj.Object(nID); // put the model on terrain float pos[3]; pos[0] = x; pos[1] = y; pos[2] = 10000.0f; // should be higher than the terrain! obj.SetPosition(pos); obj.PutOnTerrain(tID, be3D, offset, rangeF, rangeB, angle);

111 111 Terrain Following (3D) Terrain Following (2D) offset Terrain Following

112 112 Probe for a Model on Terrain probeFront probeBack : terrain following check point

113 113 TheFly3D Model Movement Functions (1/3) void model.GetPosition(pos) void model.GetPosition(pos) pos is a 3D vector to get the position of the model object pos is a 3D vector to get the position of the model object void model.GetDirection(faceDir, upDir) void model.GetDirection(faceDir, upDir) If you just want to get one of the directions, just send NULL pointer to the one that you do not want to query If you just want to get one of the directions, just send NULL pointer to the one that you do not want to query void model.SetPosition(pos) void model.SetPosition(pos) The position is related to its parent object The position is related to its parent object void model.SetDirection(faceDIr, upDir) void model.SetDirection(faceDIr, upDir) If you just want to set one of the directions, just send NULL pointer to the one that you do not want to set If you just want to set one of the directions, just send NULL pointer to the one that you do not want to set Void model.SetDirectionAlignment(fDAxis, uDAxis) Void model.SetDirectionAlignment(fDAxis, uDAxis) You can change the local axes for facing and up directions You can change the local axes for facing and up directions

114 114 TheFly3D Model Movement Functions (2/3) BOOL model.PutOnTerrain(tID, be3D, offset, probeFront, probeBack, probeAngle, hightLimit) BOOL model.PutOnTerrain(tID, be3D, offset, probeFront, probeBack, probeAngle, hightLimit) tID is a terrain object tID is a terrain object be3D = TRUE for 3D terrain following be3D = TRUE for 3D terrain following Offset is the height above the terrain Offset is the height above the terrain hightLimit is the terrain following height limit hightLimit is the terrain following height limit Return TURE if you successfully put the model on a terrain Return TURE if you successfully put the model on a terrain int model.MoveForward(dist, beTerrainFollow, be3D, offset) int model.MoveForward(dist, beTerrainFollow, be3D, offset) If you just want to move the model forward but not on terrain, set beTerrainFollow to FALSE If you just want to move the model forward but not on terrain, set beTerrainFollow to FALSE You should put a model on terrain first. Then you can move it forward on terrain. You should put a model on terrain first. Then you can move it forward on terrain. Return value : Return value : WALK (ok for moving) WALK (ok for moving) BOUNDARY (hit the terrain boundary) BOUNDARY (hit the terrain boundary) BLOCK (not implemented yet, for collision) BLOCK (not implemented yet, for collision) DO_NOTHING (something wrong …) DO_NOTHING (something wrong …)

115 115 TheFly3D Model Movement Functions (3/3) int MoveRight(dist, beTerrainFollow, be3D, offset) int MoveRight(dist, beTerrainFollow, be3D, offset) Same as the MoveForward except moving in right-hand direction void model.TurnRight(float angle) void model.TurnRight(float angle) Angle is in degree format Angle is in degree format int model.GetCurrentTerrainTriangle() int model.GetCurrentTerrainTriangle() Get current triangle ID in terrain, where the model is standing Get current triangle ID in terrain, where the model is standing

116 116 A Character

117 117 Character with motion

118 118 Introduction to Characters The characters are the actors of the games. The characters are the actors of the games. Three types of characters implemented in games : Three types of characters implemented in games : Segmented Segmented Mesh Mesh Bone-skin Bone-skin Root-base concept Root-base concept Base Production : Production : 3D animation tools 3D animation tools Motion capture (MoCap) Motion capture (MoCap) For motion data For motion data

119 119 A character is composed by a set of models with motion data to simulate a live creature in real world A character is composed by a set of models with motion data to simulate a live creature in real world A Segmented Character Benefits Benefits Hierarchical structure Hierarchical structure Easy to implement in a scene tree Easy to implement in a scene tree Drawbacks Drawbacks Segment-like Segment-like

120 120 groin body head thigh_r thigh_l shin_r shin_l foot_r foot_l up_arm_l up_arm_r fore_arm_l fore_arm_r hand_l hand_r Base The scene tree of a segmented character : The scene tree of a segmented character : head body up arm fore arm hand groin thigh shin foot

121 121 Vertex animation on skins Vertex animation on skins Animated positional data on skins Animated positional data on skins 3D warping 3D warping A Mesh Character Benefits Benefits Easy to implement Easy to implement Flexible mesh in animation Flexible mesh in animation Drawbacks Drawbacks No hierarchy No hierarchy Each frame is independent. Each frame is independent. Massive dataset Massive dataset

122 122 Bone-skin skeleton Bone-skin skeleton Hierarchical bones Hierarchical bones Skin deformation run-timely Skin deformation run-timely Bone A Skin Bone B A Bone-skin Character Benefits Benefits Hierarchical structure Hierarchical structure Not segmented look Not segmented look Drawbacks Drawbacks More complicated than the other solutions More complicated than the other solutions Skin deformation need more CPU cost than transformation only Skin deformation need more CPU cost than transformation only

123 123 Keyframe system 3ds MAX Softimage Maya Motion Production – by 3D Animation Tools (1/2)

124 124 Low cost (relatively) Easy to combine animations Hand-made animations Hard to make “good” motions Long production time Motion Production – by 3D Animation Tools (2/2)

125 125 Motion Capture “MoCap” in short Types : Optical Magnetic... Motion Production – by Motion Capture (1/2)

126 126 Expensive solution Hardware and software Every frame is a keyframe Very live motion Noise ! Need post-processing for games Patching the data Re-keyframing Cleaning noise Re-targeting Hard to combine motions Motion Production – by Motion Capture (2/2)

127 127 Use root-base structure to construct the character Use root-base structure to construct the character Base Root (groin) Base The Root-Base Concept (1/2)

128 128 A character has some models to be the geometry roots of the character system. A character has some models to be the geometry roots of the character system. The root plays as the gravity center of the character. The root plays as the gravity center of the character. The root can be translated and rotated. The root can be translated and rotated. The others are joints. The others are joints. The joints can rotate only. The joints can rotate only. A ghost object is added to be the parent of the root, which is the base of the character. A ghost object is added to be the parent of the root, which is the base of the character. The base is the center for the character’s movement. The base is the center for the character’s movement. We move the base to perform character’s moves. We move the base to perform character’s moves. The Root-Base Concept (2/2)

129 129 A set of frames to describe a character’s motion A set of frames to describe a character’s motion For examples : Walk, run, attack, … For examples : Walk, run, attack, … Keyframed or non-keyframed Keyframed or non-keyframed Motion data in Motion data in Position (pivot) + quaternion Position (pivot) + quaternion Position (pivot) + Euler angles Position (pivot) + Euler angles Position (pivot) + (q, n) Position (pivot) + (q, n) Matrix Matrix walkrunattackfall Motion Data - Pose

130 130 Load a Character FnScene scene; CHARACTERid actorID; scene.Object(sceneID); actorID = scene.LoadCharacter(“fm.cwc");.cwc is a character description file.

131 131 Play a Pose BLENDTREEid btID = actor.GetBlendTree(); FnBlendTree bt; bt.Object(btID); // the 2nd motion definition BLENDNODEid aaaID; aaaID = bt.CreateAnimationNode(2); // start to play a pose (1 st time) actor.PlayBlendNode(aaaID, (float) 0, START, TRUE); // continue to play a pose actor.PlayBlendNode(CURRENT, (float) skip, LOOP, TRUE);

132 132 Make a Character to Move Forward FnCharacter actor; // play walking pose actor.Object(actorID); actor.PlayBlendNode(CURRENT, (float) skip, LOOP, TRUE); // move it forward actor.MoveForward(dist, beTF, be3D, offset);

133 133 TheFly3D Character Movement Functions (1/2) void actor.GetPosition(pos) void actor.GetPosition(pos) pos is a 3D vector to get the position of the character pos is a 3D vector to get the position of the character void actor.GetDirection(faceDir, upDir) void actor.GetDirection(faceDir, upDir) If you just want to get one of the directions, just send NULL pointer to the one that you do not want to query If you just want to get one of the directions, just send NULL pointer to the one that you do not want to query void actor.SetPosition(pos) void actor.SetPosition(pos) The position is related to its parent object The position is related to its parent object void actor.SetDirection(faceDIr, upDir) void actor.SetDirection(faceDIr, upDir) If you just want to set one of the directions, just send NULL pointer to the one that you do not want to set If you just want to set one of the directions, just send NULL pointer to the one that you do not want to set BOOL actor.PutOnTerrain(tID, be3D, offset, probeFront, probeBack, probeAngle, hightLimit) BOOL actor.PutOnTerrain(tID, be3D, offset, probeFront, probeBack, probeAngle, hightLimit) tID is a terrain object tID is a terrain object be3D = TRUE for 3D terrain following be3D = TRUE for 3D terrain following Offset is the height above the terrain Offset is the height above the terrain hightLimit is the terrain following height limit hightLimit is the terrain following height limit Return TURE if you successfully put the character on a terrain Return TURE if you successfully put the character on a terrain

134 134 TheFly3D Character Movement Functions (2/2) void actor.MoveForward(dist, beTF, be3D, offset) void actor.MoveForward(dist, beTF, be3D, offset) If you just want to move the character forward but not on terrain, set beTF to FALSE If you just want to move the character forward but not on terrain, set beTF to FALSE You should put a character on terrain first. Then you can move it forward on terrain. You should put a character on terrain first. Then you can move it forward on terrain. A character is always using his local -y-axis as facing direction A character is always using his local -y-axis as facing direction void actor.TurnRight(float angle) void actor.TurnRight(float angle) Angle is in degree Angle is in degree A character is always using his local z-axis as up direction A character is always using his local z-axis as up direction

135 135 TheFly3D Character Functions OBJECTid actor.GetBaseObject() OBJECTid actor.GetBaseObject() You can get the base object of the character You can get the base object of the character OBJECTidactor.GetObjectByName(name) OBJECTid actor.GetObjectByName(name) You can get the each model part of the character by its name in character file You can get the each model part of the character by its name in character file For a bone-skin character, this function can get the bones in the skeleton For a bone-skin character, this function can get the bones in the skeleton BOOL actor.PlayFrame(frame, beIncludeBase) BOOL actor.PlayFrame(frame, beIncludeBase) The function is to play the motion for a specific frame The function is to play the motion for a specific frame Set beIncludeBase = TRUE to play the base object’s motion Set beIncludeBase = TRUE to play the base object’s motion BLENDTREEid actor.GetBlendTree() BLENDTREEid actor.GetBlendTree() Get the character’s blend tree data Get the character’s blend tree data You can define all poses in a blend tree (blend nodes) You can define all poses in a blend tree (blend nodes) float actor.PlayBlendNode(btNodeID, skipFrame, mode, beIncludeBase) float actor.PlayBlendNode(btNodeID, skipFrame, mode, beIncludeBase) All poses for a character is defined as a blend node All poses for a character is defined as a blend node Skip frames can be floating-point Skip frames can be floating-point Mode can be ONCE or LOOP! Mode can be ONCE or LOOP!

136 136 5th Game Mathematics

137 137 Matrices Matrices Vectors Vectors Fixed-point Real Numbers Fixed-point Real Numbers Triangle Mathematics Triangle Mathematics Intersection Issues Intersection Issues Euler Angles Euler Angles Angular Displacement Angular Displacement Quaternion Quaternion Differential Equation Basics Differential Equation Basics Essential Mathematics for Game Development

138 138 Matrix basics Matrix basics Definition Definition Transpose Transpose Addition Addition Matrices (1/7) A = (a ij ) = a 11.. a 1n.. a m1.. a mn C = A T c ij = a ji C = A + B c ij = a ij + b ij

139 139 Scalar-matrix multiplication Scalar-matrix multiplication Matrix-matrix multiplication Matrix-matrix multiplication C =  A c ij =  a ij C = A B c ij =  a ik b kj k = 1 r Matrices (2/7)

140 140 Transformations in Matrix form Transformations in Matrix form A point or a vector is a row matrix (de facto convention) A point or a vector is a row matrix (de facto convention) V = [x y z] Using matrix notation, a point V is transformed under translation, scaling and rotation as : Using matrix notation, a point V is transformed under translation, scaling and rotation as : V’ = V + D V’ = VS V’ = VR where D is a translation vector and S and R are scaling and rotation matrices Matrices (3/7)

141 141 To make translation be a linear transformation, we introduce the homogeneous coordinate system To make translation be a linear transformation, we introduce the homogeneous coordinate system V (x, y, z, w), where w is always 1 Translation Transformation Translation Transformation x’ = x + T x y’ = y + T y z’ = z + T z V’ = VT [x ’ y ’ z ’ 1] = [x y z 1] = [x y z 1] T 1 0 0 0 0 1 0 0 0 0 1 0 T x T y T z 1 Matrices (4/7)

142 142 Scaling Transformation Scaling Transformation x’ = xS x y’ = yS y z’ = zS z V’ = VS [x ’ y ’ z ’ 1] = [x y z 1] = [x y z 1] S S x 0 0 0 0 S y 0 0 0 0 S z 0 0 0 0 1 Here S x, S y and S z are scaling factors. Matrices (5/7)

143 143 Rotation Transformations Rotation Transformations 1 0 0 0 0 cos  sin  0 0 -sin  cos  0 0 0 0 1 R x = R y = R z = cos  0 -sin  0 0 1 0 0 sin  0 cos  0 0 0 0 1 cos  sin  0 0 -sin  cos  0 0 0 0 1 0 0 0 0 1 Matrices (6/7)

144 144 Net Transformation matrix Net Transformation matrix [x ’ y ’ z ’ 1] = [x y z 1] M 1 and [x” y” z” 1] = [x’ y’ z’ 1] M 2 then the transformation matrices can be concatenated M 3 = M 1 M 2 and [x” y” z” 1] = [x y z 1] M 3 M 1 M 2 = M 2 M 1 Matrices (7/7) Matrix multiplication are not commutative Matrix multiplication are not commutative

145 145 A vector is an entity that possesses magnitude and direction. A vector is an entity that possesses magnitude and direction. A 3D vector is a triple : A 3D vector is a triple : V = (v 1, v 2, v 3 ), where each component v i is a scalar. V = (v 1, v 2, v 3 ), where each component v i is a scalar. A ray (directed line segment), that possesses position, magnitude and direction. A ray (directed line segment), that possesses position, magnitude and direction. Vectors (1/5) (x 1,y 1,z 1 ) (x 2,y 2,z 2 ) V = (x 2 -x 1, y 2 -y 1, z 2 -z 1 )

146 146 Addition of vectors Addition of vectors X = V + W = (x 1, y 1, z 1 ) = (v 1 + w 1, v 2 + w 2, v 3 + w 3 ) V W V + W V W |V| = (v 1 2 + v 2 2 + v 3 2 ) 1/2 U = V / |V| Vectors (2/5) Length of vectors Length of vectors

147 147 Cross product of vectors Cross product of vectors Definition Definition X = V X W = (v 2 w 3 -v 3 w 2 )i + (v 3 w 1 -v 1 w 3 )j + (v 1 w 2 -v 2 w 1 )k where i, j and k are standard unit vectors : i = (1, 0, 0), j = (0, 1, 0), k = (0, 0, 1) NpNp V2V2 V1V1 polygon defined by 4 points N p = V 1 X V 2 Vectors (3/5) Application Application A normal vector to a polygon is calculated from 3 (non- collinear) vertices of the polygon. A normal vector to a polygon is calculated from 3 (non- collinear) vertices of the polygon.

148 148 Transformation of the normal vectors Transformation of the normal vectors N(X) = detJ J -1T N(x) where X = F(x) J the Jacobian matrix, J i (x) =  F(x) xixi "Global and Local Deformations of Solid Primitives" Alan H. Barr Computer Graphics Volume 18, Number 3 July 1984 Vectors (4/5)

149 149 Dot product of vectors Dot product of vectors Definition Definition |X| = V. W = v 1 w 1 + v 2 w 2 + v 3 w 3  V W cos  = V. WV. W |V||W| Vectors (5/5) Application Application

150 150 Fixed point arithmetics : n bits (signed) integer Fixed point arithmetics : n bits (signed) integer Example : N = 16 gives range –32768  ă  32767 Example : N = 16 gives range –32768  ă  32767 We can use fixed scale to get the decimals. We can use fixed scale to get the decimals. Fixed Point Arithmetics (1/2) a = ă / 2 8 111 8 integer bits 8 fractional bits ă = 315, a = 1.2305

151 151 Multiplication then requires rescaling Multiplication then requires rescaling Fixed Point Arithmetics (2/2) e = a. c = ă / 2 8. ĉ / 2 8  ĕ = (ă. ĉ) / 2 8 e = a+c = ă / 2 8 + ĉ / 2 8  ĕ = ă + ĉ Addition just like normal Addition just like normal

152 152 Compression for floating-point real numbers Compression for floating-point real numbers 4 bytes reduced to 2 bytes 4 bytes reduced to 2 bytes Lost some accuracy but affordable Lost some accuracy but affordable Network data transfer Network data transfer Software 3D rendering (without hardware-assistant) Software 3D rendering (without hardware-assistant) Fixed Point Arithmetics - Application

153 153 h haha hbhb hchc AaAa AcAc AbAb h = h a + h b + h c where A = A a + A b + A c If (A a < 0 || A b < 0 || A c < 0) than the point is outside the triangle “Triangular Coordinate System” AaAa AbAb AcAc A A A p (x a,y a,z a ) (x b,y b,z b ) (x c,y c,z c ) Triangular Coordinate System

154 154 Area of a triangle in 2D x a y a A = ½ x b y b x c y c x a y a = ½ (x a *y b + x b *y c + x c *y a – x b *y a – x c *y b – x a *y c ) Triangle Area – 2D (x a,y a,z a ) (x b,y b,z b ) (x c,y c,z c )

155 155 Area of a triangle in 3D A = ½ (N. Sum(P i1 cross P i2 )) where (i1, i2) = (a,b), (b,c), (c,a) Triangle Area – 3D float GmArea3(float *x0, float *x1, float *x2, float *n) { float area, len, sum1, sum2, sum0; len = (float) sqrt(n[0] * n[0] + n[1] * n[1] + n[2] * n[2]) * 2.0f; /* find sum of cross products */ sum0 = x1[1] * (-x0[2] + x2[2]) + x2[1] * (-x1[2] + x0[2]) + x0[1] * (-x2[2] + x1[2]); sum1 = x1[2] * (-x0[0] + x2[0]) + x2[2] * (-x1[0] + x0[0]) + x0[2] * (-x2[0] + x1[0]); sum2 = x1[0] * (-x0[1] + x2[1]) + x2[0] * (-x1[1] + x0[1]) + x0[0] * (-x2[1] + x1[1]); /* find the area */ return = (sum0 * n[0] + sum1 * n[1] + sum2 * n[2]) / len; }

156 156 Terrain following Terrain following Interpolating the height of arbitrary point within the triangle Interpolating the height of arbitrary point within the triangle Hit test Hit test Intersection of a ray from camera to a screen position with a triangle Intersection of a ray from camera to a screen position with a triangle Ray cast Ray cast Intersection of a ray with a triangle Intersection of a ray with a triangle Collision detection Collision detection Intersection Intersection Triangular Coordinate System - Application

157 157 Ray cast Ray cast Containment test Containment testIntersection

158 158 Ray Cast – The Ray x = x 0 + (x 1 – x 0 ) t y = y 0 + (y 1 – y 0 ) t, t = 0, z = z 0 + (z 1 – z 0 ) t { Cast a ray to calculate the intersection of the ray with models Cast a ray to calculate the intersection of the ray with models Use parametric equation for a ray Use parametric equation for a ray 8 When t = 0, the ray is on the start point (x 0,y 0,z 0 ) When t = 0, the ray is on the start point (x 0,y 0,z 0 ) Only the t  0 is the answer candidate Only the t  0 is the answer candidate The smallest positive t is the answer The smallest positive t is the answer

159 159 Ray Cast – The Plane Each triangle in the 3D models has its plane equation. Each triangle in the 3D models has its plane equation. Use ax + by + cz + d = 0 as the plane equation. Use ax + by + cz + d = 0 as the plane equation. (a, b, c) is the plane normal vector. (a, b, c) is the plane normal vector. |d| is the distance of the plane to origin. |d| is the distance of the plane to origin. Substitute the ray equation into the plane. Substitute the ray equation into the plane. Solve the t to find the intersect point. Solve the t to find the intersect point. Check the intersect point within the triangle or not by using “Triangle Area Test” (p. 155) Check the intersect point within the triangle or not by using “Triangle Area Test” (p. 155)

160 160 Intersection = 1, inside Intersection = 2, outside Intersection = 0, outside Trick : Parametric equation for a ray which is parallel to the x-axis x = x 0 + t y = y 0, t = 0, { 8 (x 0, y 0 ) 2D Containment Test “if the No. of intersection is odd, the point is inside, otherwise, is outside”

161 161 3D Containment Test “if the No. of intersection is odd, the point is inside, otherwise, is outside” Same as the 2D containment test Same as the 2D containment test

162 162 A rotation is described as a sequence of rotations about three mutually orthogonal coordinates axes fixed in space A rotation is described as a sequence of rotations about three mutually orthogonal coordinates axes fixed in space X-roll, Y-roll, Z-roll X-roll, Y-roll, Z-roll R(  1,  2,   ) represents an x-roll, followed by y-roll, followed by z-roll R(  1,  2,    c 2 c 3 c 2 s 3 -s 2 0 s 1 s 2 c 3 -c 1 s 3 s 1 s 2 s 3 +c 1 c 3 s 1 c 2 0 c 1 s 2 c 3 +s 1 s 3 c 1 s 2 s 3 -s 1 c 3 c 1 c 2 0 0 0 0 1 where s i = sin  i and c i = cos  i Euler Angles There are 6 possible ways to define a rotation. There are 6 possible ways to define a rotation. 3! 3!

163 163 Interpolation happening on each angle Interpolation happening on each angle Multiple routes for interpolation Multiple routes for interpolation More keys for constrains More keys for constrains z x y R z x y R Euler Angles & Interpolation

164 164 R( , n), n is the rotation axis. R( , n), n is the rotation axis. n rRr  n r rvrv rhrh V  rvrv V Rr v r h = (n. r)n r v = r - (n. r)n, rotate into position Rr v V = nxr v = nxr Rr v = (cos  )r v + (sin  )V -> Rr = Rr h + Rr v = r h + (cos  )r v + (sin  )V = (n. r)n + (cos  )  r - (n. r)n) + (sin  ) nxr = (cos  )r + (1-cos  ) n (n. r) + (sin  ) nxr Angular Displacement

165 165 Sir William Hamilton (1843) Sir William Hamilton (1843) From Complex numbers (a + ib), i 2 = -1 From Complex numbers (a + ib), i 2 = -1 16,October, 1843, Broome Bridge in Dublin 16,October, 1843, Broome Bridge in Dublin 1 real + 3 imaginary = 1 quaternion 1 real + 3 imaginary = 1 quaternion q = a + bi + cj + dk q = a + bi + cj + dk i 2 = j 2 = k 2 = -1 i 2 = j 2 = k 2 = -1 ij = k & ji = -k, cyclic permutation i-j-k-i ij = k & ji = -k, cyclic permutation i-j-k-i q = (s, v), where (s, v) = s + v x i + v y j + v z k q = (s, v), where (s, v) = s + v x i + v y j + v z kQuaternion

166 166 q 1 = (s 1, v 1 ) and q 2 = (s 2, v 2 ) q 3 = q 1 q 2 = (s 1 s 2 - v 1. v 2, s 1 v 2 + s 2 v 1 + v 1 xv 2 ) Conjugate of q = (s, v), q = (s, -v) qq = s 2 + |v| 2 = |q| 2 A unit quaternion q = (s, v), where qq = 1 A pure quaternion p = (0, v) Noncommutative Quaternion Algebra

167 167 Take a pure quaternion p = (0, r) and a unit quaternion q = (s, v) where qq = 1 and define R q (p) = qpq -1 where q -1 = q for a unit quaternion R q (p) = (0, (s 2 - v. v)r + 2v(v. r) + 2svxr) Let q = (cos , sin  n), |n| = 1 R q (p) = (0, (cos 2  - sin 2  )r + 2sin 2  n(n. r) + 2cos  sin  nxr) = (0, cos2  r + (1 - cos2  )n(n. r) + sin2  nxr) Conclusion : The act of rotating a vector r by an angular displacement ( , n) is the same as taking this displacement, ‘lifting’ it into quaternion space, by using a unit quaternion (cos(  /2), sin(  /2)n) Quaternion VS Angular Displacement

168 168 1-2y 2 -2z 2 2xy-2wz 2xz+2wy 0 2xy+2wz 1-2x 2 -2z 2 2yz-2wx 0 2xz-2wy 2yz+2wx 1-2x 2 -2y 2 0 0 0 0 1 q = (w,x,y,z) Quaternion VS Rotation Matrix

169 169 M 0 M 1 M 2 0 M 3 M 4 M 5 0 M 6 M 7 M 8 0 0 0 0 1 float tr, s; tr = m[0] + m[4] + m[8]; if (tr > 0.0f) { s = (float) sqrt(tr + 1.0f); q->w = s/2.0f; s = 0.5f/s; q->x = (m[7] - m[5])*s; q->y = (m[2] - m[6])*s; q->z = (m[3] - m[1])*s; } else { float qq[4]; int i, j, k; int nxt[3] = {1, 2, 0}; i = 0; if (m[4] > m[0]) i = 1; if (m[8] > m[i*3+i]) i = 2; j = nxt[i]; k = nxt[j]; s = (float) sqrt((m[i*3+i] - (m[j*3+j] + m[k*3+k])) + 1.0f); qq[i] = s*0.5f; if (s != 0.0f) s = 0.5f/s; qq[3] = (m[j+k*3] - m[k+j*3])*s; qq[j] = (m[i+j*3] + m[j+i*3])*s; qq[k] = (m[i+k*3] + m[k+i*3])*s; q->w = qq[3]; q->x = qq[0]; q->y = qq[1]; q->z = qq[2]; }

170 170 Spherical linear interpolation, slerp Spherical linear interpolation, slerp A B P  t slerp(q 1, q 2, t) = q 1 + q 2 sin((1 - t)  ) sin  sin(t  ) Quaternion Interpolation

171 171 Initial value problems Initial value problems ODE ODE Ordinary differential equation Ordinary differential equation Numerical solutions Numerical solutions Euler’s method Euler’s method The midpoint method The midpoint method Differential Equation Basics

172 172 An ODE An ODE x = f (x, t) wheref is a known function x is the state of the system, x is the x’s time derivative x & x are vectors x(t 0 ) = x 0, initial condition. Start here Follow the vectors … Initial Value Problems.. Vector field Vector field Solutions Solutions Symbolic solution Symbolic solution Numerical solution Numerical solution

173 173 A numerical solution A numerical solution A simplification from Tayler series A simplification from Tayler series Discrete time steps starting with initial value Discrete time steps starting with initial value Simple but not accurate Simple but not accurate Bigger steps, bigger errors Bigger steps, bigger errors O(  t 2 ) errors O(  t 2 ) errors Can be unstable Can be unstable Not even efficient Not even efficient x(t +  t) = x(t) +  t f(x, t) Euler’s Method

174 174 Concept :x(t 0 + h) = x(t 0 ) + h x(t 0 ) + h 2 /2 x(t 0 ) + O(h 3 ) Result : x(t 0 +h) = x(t 0 ) + h(f(x 0 + h/2 f(x 0 )) Method :a. Compute an Euler step  x =  t f(x, t) b. Evaluate f at the midpoint f mid = f((x+  x)/2, (t+  t)/2) c. Take a step using the midpoint x(t+  t) = x(t) +  t f mid... a b c Error term The Midpoint Method

175 175 Midpoint = Runge-Kutta method of order 2 Midpoint = Runge-Kutta method of order 2 Runge-Kutta method of order 4 Runge-Kutta method of order 4 O(h 5 ) O(h 5 ) k 1 = h f(x 0, t 0 ) k 2 = h f(x 0 + k 1 /2, t 0 + h/2) k 3 = h f(x 0 + k 2 /2, t 0 + h/2) k 4 = h f(x 0 + k 3, t 0 + h) x(t 0 +h) = x 0 + 1/6 k 1 + 1/3 k 2 + 1/3 k 3 + 1/6 k 4 The Runge-Kutta Method

176 176 Dynamics Dynamics Particle system Particle system Game FX system Game FX system Fluid simulation Fluid simulation Initial Value Problems - Application

177 177 6th Game Geometry

178 178 Geometry Geometry Position Position vertex normals vertex normals vertex colors vertex colors texture coordinates texture coordinates Tangent / Bi-normal Tangent / Bi-normal Topology Topology Primitive Primitive Lines / triangles / surfaces / … Lines / triangles / surfaces / … Property Property Materials Materials Textures Textures Motion Motion Hierarchy Hierarchy Level-of-detail Level-of-detail Game Models

179 179 Vertex position Vertex position (x, y, z, w) (x, y, z, w) In model space or screen space In model space or screen space Vertex normal Vertex normal (n x, n y, n z ) (n x, n y, n z ) Vertex color Vertex color (r, g, b) or (diffuse, specular) (r, g, b) or (diffuse, specular) Texture coordinates on vertex Texture coordinates on vertex (u 1, v 1 ), (u 2, v 2 ), … (u 1, v 1 ), (u 2, v 2 ), … Skin weights Skin weights (bone 1, w 1, bone 2, w 2, …) (bone 1, w 1, bone 2, w 2, …) Tangent and bi-normal Tangent and bi-normal Geometry Data N T Bn

180 180 Lines Lines Line segments Line segments Polyline Polyline Open / closed Open / closed Indexed triangles Indexed triangles Triangle strips / fans Triangle strips / fans Surfaces Surfaces Non-uniform Rational B Spline (NURBS) Non-uniform Rational B Spline (NURBS) Subdivision Subdivision Topology Data

181 181 Geometric data Vertex data v 0, v 1, v 2, v 3, … (x, y, z, n x, n y, n z, t u, t v ) or (x, y, z, c r, c g, c b, t u, t v, … ) Topology Face v 0 v 3 v 6 v 7 Edge table v0v0 v3v3 v6v6 v7v7 Right-hand rule for index polygon normal vertex normal Indexed Triangles

182 182 v0v0 v1v1 v2v2 v3v3 v4v4 v5v5 v6v6 v7v7 T0T0 T1T1 T2T2 T3T3 T4T4 T5T5 v 0, v 1, v 2, v 3, v 4, v 5, v 6, v 7 Triangle Strips “Get great performance to use triangle strips for rendering on current hardware

183 183 Material Material Textures Textures Shaders Shaders Property on Surface

184 184 Material Material Ambient Ambient Environment Environment Non-lighted area Non-lighted area Diffuse Diffuse Dynamic lighting Dynamic lighting Emissive Emissive Self-lighting Self-lighting Specular with shineness Specular with shineness Hi-light Hi-light View-dependent View-dependent Not good for hardware rendering Not good for hardware rendering Local illumination Local illuminationMaterials

185 185 Textures Textures Single texture Single texture Texture coordinate animation Texture coordinate animation Texture animation Texture animation Multiple textures Multiple textures Alphamap AlphamapTextures Material or vertex colors Base color texture Lightmap

186 186 Programmable shading language Programmable shading language Vertex shader Vertex shader Pixel shader Pixel shader Procedural way to implement some process of rendering Procedural way to implement some process of rendering Transformation Transformation Lighting Lighting Texturing Texturing BRDF BRDF Rasterization Rasterization Pixel fill-in Pixel fill-in Post-processing for rendering Post-processing for renderingShaders

187 187 Vertex DataTopology Data Classic Transform & Lighting Vertex Shader Clipping & Viewport Mapping TexturingPixel Shader Fog Alpha, Stencil, Depth Testing Geometry Stage Rasterizer Stage Shader Pipeline

188 188 Per-pixel lighting Per-pixel lighting Motion blur Motion blur Volume / Height fog Volume / Height fog Volume lines Volume lines Depth of field Depth of field Fur rendering Fur rendering Reflection / Refraction Reflection / Refraction NPR NPR Shadow Shadow Linear algebra operators Linear algebra operators Perlin noise Perlin noise Quaternion Quaternion Sparse matrix solvers Sparse matrix solvers Skin bone deformation Skin bone deformation Normal map Normal map Displacement map Displacement map Particle shader Particle shader Procedural Morphing Water Simulation Powered by Shader

189 189 Time-dependent data Time-dependent data Transformation data Transformation data Position Position Orientation Orientation Formats Formats Pivot Pivot Position vector Position vector Quaternion Quaternion Eurler angles Eurler angles Angular displacement Angular displacement Motion Data

190 190 Discrete LOD Discrete LOD Switch multiple resolution models run-timely Switch multiple resolution models run-timely Continuous LOD Continuous LOD Use progressive mesh to dynamically reduce the rendered polygons Use progressive mesh to dynamically reduce the rendered polygons View-dependent LOD View-dependent LOD Basically for terrain Basically for terrainLevel-of-detail

191 191 Render a model in different Level-of-Detail at run time Render a model in different Level-of-Detail at run time User-controlledly or automatically change the percentage of rendered vertices User-controlledly or automatically change the percentage of rendered vertices Use collapse map to control the simplification process Use collapse map to control the simplification process Progressive Mesh Collapse map Vertex list Triangle list Index012345678 Map011230456 012345678 025012358 00 6 4

192 192 Real-time Optimal Adapting Meshes (ROAM) Real-time Optimal Adapting Meshes (ROAM) Use height map Use height map Run-timely to re-construct the active (for rendering) geometric topology (re-mesh) to get an optimal mesh (polygon count) to improve the rendering performance Run-timely to re-construct the active (for rendering) geometric topology (re-mesh) to get an optimal mesh (polygon count) to improve the rendering performance Someone calls this technique as the view-dependent level- of-detail Someone calls this technique as the view-dependent level- of-detail Very good for fly-simulation-like application Very good for fly-simulation-like application View-dependent LOD for Terrain - ROAM

193 193 Apply progressive mesh for multi-resolution model generation Apply progressive mesh for multi-resolution model generation Use in-game discrete LOD for performance tuning Use in-game discrete LOD for performance tuning Why ? Why ? For modern game API / platform, dynamic vertex update is costly on performance For modern game API / platform, dynamic vertex update is costly on performance Lock video memory stall CPU/GPU performance Lock video memory stall CPU/GPU performance Level-of-detail Suggestion

194 194 Bounding sphere Bounding cylinder Axis-aligned bounding box (AABB) Oriented bounding box (OBB) Discrete oriented polytope (k-DOP) Bounding Sphere AABB OBB k-DOP Bounding Volume Bounding Cylinder

195 195 Collision detection Collision detection Visibility culling Visibility culling Hit test Hit test Steering behavior Steering behavior In “Game AI” section In “Game AI” section Bounding Volume - Application

196 196 Bounding sphere B 1 (c 1, r 1 ), B 2 (c 2, r 2 ) If the distance between two bounding spheres is larger than the sum of radius of the spheres, than these two objects have no chance to collide. D > Sum(r 1, r 2 ) D B1B1 B2B2 c1c1 c2c2 Application Example - Bounding Sphere

197 197 Axis-aligned bounding box (AABB) Axis-aligned bounding box (AABB) Simplified calculation using axis-alignment feature Simplified calculation using axis-alignment feature But need run-timely to track the bounding box But need run-timely to track the bounding box AABB Application Example - AABB

198 198 Oriented bounding box (OBB) Oriented bounding box (OBB) Need intersection calculation using the transformed OBB geometric data Need intersection calculation using the transformed OBB geometric data 3D containment test 3D containment test Line intersection with plane Line intersection with plane For games, For games, OBB Application Example - OBB

199 199 7thTerrain

200 200 Very game type oriented data Very game type oriented data Terrain Terrain For visual purpose For visual purpose Ground / Building / Static models / Dynamic models Ground / Building / Static models / Dynamic models For terrain following For terrain following Polygon mesh Polygon mesh Grids Grids For path finding For path finding Polygon mesh Polygon mesh Grids Grids Terrain following Terrain following Make a 3D entity (character or model) walking on terrain Make a 3D entity (character or model) walking on terrain Path finding Path finding Find a “shortest” path to walk before moving Find a “shortest” path to walk before moving Will be taught in Game AI section. Will be taught in Game AI section. A* algorithm A* algorithmIntroduction

201 201 Grid Grid 2D 2D Quadtree Quadtree Height map Height map Procedural height map Procedural height map Using noise function to generate the height Using noise function to generate the height Terrain Formats Perlin Noise ROAM ROAM Real-time Optimally Adapting Meshes Real-time Optimally Adapting Meshes Triangular mesh Triangular mesh Procedurally generated Procedurally generated Created by artists Created by artists

202 202 2D grid map 2D grid map Rectangular or Hexagonal grids Rectangular or Hexagonal grids Attributes Attributes Height Height Walkable or not Walkable or not Texture pattern ID Texture pattern ID Grid Map Step look terrain Step look terrain Application Application 2D games 2D games 3D games with god view 3D games with god view 2D tile-based game terrain 2D tile-based game terrain

203 203 Almost as same as 2D grid map but :" Almost as same as 2D grid map but :" Height on grid vertex Height on grid vertex Only height is saved Only height is saved Regular grid Regular grid Irregular grid but structured Irregular grid but structured Height Map Top view Application Application As the base data structure for ROAM terrain As the base data structure for ROAM terrain Water simulation Water simulation

204 204 Real-time optimally adapting mesh Real-time optimally adapting mesh http://www.llnl.gov/graphics/ROAM/ http://www.llnl.gov/graphics/ROAM/ http://www.llnl.gov/graphics/ROAM/ ROAM Application Application Fly-simulation Fly-simulation

205 205 Use quad tree to construct the level-of-detail of terrain Use quad tree to construct the level-of-detail of terrain A quad tree for LOD A quad tree for LOD Chunked LOD Terrain

206 206 Possibly the most popular way for 3D games Possibly the most popular way for 3D games General General Can be created by artists Can be created by artists Triangular Mesh Multiple-layered terrain issue Multiple-layered terrain issue

207 207 Solve the terrain height for the object to stand on. Solve the terrain height for the object to stand on. Use the triangular coordinate system (p. 154) Use the triangular coordinate system (p. 154) Find the next neighboring triangle Find the next neighboring triangle Half-edge data structure Half-edge data structure Terrain Following Using Triangular Mesh

208 208 Create cohesive relationship between triangles using “half edge” Create cohesive relationship between triangles using “half edge” Use half-edge table to search the neighboring triangles Use half-edge table to search the neighboring triangles Edge = two halves Half-edge (1/2)

209 209 struct HE_edge { HE_vert* vert; // vertex at the end of the half-edge HE_edge* pair; // oppositely oriented adjacent half-edge HE_face* face; // face the half-edge borders HE_edge* next; // next half-edge around the face }; struct HE_vert { float x; float y; float z; HE_edge* edge; // one of the half-edges // emantating from the vertex }; struct HE_face { HE_edge* edge; // one of the half-edges bordering the face }; http://www.flipcode.com/tutorials/tut_halfedge.shtml Half-edge (2/2)

210 210 8th Character Motion

211 211 A character is composed by a set of models with motion data to simulate a live creature in real world A character is composed by a set of models with motion data to simulate a live creature in real world A Segmented Character

212 212 Vertex animation on skins Vertex animation on skins Animated positional data on skins Animated positional data on skins 3D warping 3D warping A Mesh Character

213 213 Bone-Skin Skeleton Bone-Skin Skeleton Hierarchical bones Hierarchical bones Skin deformation run-timely Skin deformation run-timely Bone A Skin Bone B A Bone-skin Character

214 214 Motion Data Euler angles Euler angles Angular displacement Angular displacement Quaternion Quaternion Can achieve the interpolation by “Slerp” Can achieve the interpolation by “Slerp” But finally they will be converted into “matrix” But finally they will be converted into “matrix”

215 215 Optical Motion Capture Device Device Data acquired Data acquired From skin to joint (Mocap) From skin to joint (Mocap) From joint to skeleton (Post-processing) From joint to skeleton (Post-processing) From skeleton to skin (In-game) From skeleton to skin (In-game) The shooting plan The shooting plan

216 216 Mocap Devices

217 217 Raw Data (Positional Data) Joint End Point Bio-Data Data Acquirement During the Mocap

218 218 Skeletons Skin Skeletons Bone-Skin Bone-skin Implementation In Game

219 219 Starting out – reviewing the animation list and flowchart Planning a Mocap Shoot

220 220

221 221 Creating a shot list Create a database File names Preliminary shot list A Data Record of Shot List

222 222 A Shoot List

223 223 Getting ready for the shoot When to Shoot ? Find a Studio Make Sure No Technical Blocks Casting Preparing a shooting schedule Organize the Shot List Daily Schedule Do You Need a Rehearsal Day ? Take care of your performer

224 224 A Daily Schedule

225 225

226 226

227 227 Apply motion data on bones Apply motion data on bones Joint = pivot(p x,p y,p z ) in A A B (x,y,z, ,axis) ( ,axis) = [R B ][T B ][R A ][T A ] From pivot From position Apply Motion for Characters

228 228 To create more animation from limited work To create more animation from limited work Run-time or pre-processing Run-time or pre-processing Issues : Issues : Motion re-targeting Motion re-targeting Run-time Run-time Re-key-framing Re-key-framing Pre-processing Pre-processing Interpolation between flames Interpolation between flames Run-time Run-time Motion blending Motion blending Run-time Run-time Motion connection Motion connection Run-time Run-time Motion Editing

229 229 walk raw_start_frameraw_end_frame cut_frame Parameter { raw_start_frame raw_end_frame start_frame end_frame cut_frame play_speed length transition_mode } start_frameend_frame A Pose Definition Example

230 230 walk 048 Frame 5.3 1.If the motion data is in quaternion form 2.Get the motion data on frame 5 & 6 3.Convert the data into quaternion format 4.Apply slerp(5, 6, 0.3) to get the interpolation on frame 5.3 5.Convert the result of step 3 into a rotation matrix 6.Apply the matrix to the object for its transformation Play a Pose

231 231 Pose 1 Pose 2 cut_frame start_frame length Pose Connection

232 232 Motion blending in run-time Motion blending in run-time Quaternion is used Quaternion is used “Blend Tree” “Blend Tree” Cross fade Cross fade Countinuous blending Countinuous blending Feather blending Feather blending Pose Blending

233 233 Reference Reference Game Developers Conference 2003 Game Developers Conference 2003 Proceedings CD, Programming Track Proceedings CD, Programming Track “Animation Blending : Achieving Inverse Kinematics and More” “Animation Blending : Achieving Inverse Kinematics and More” Jerry Edsall Jerry Edsall Mech Warrior blend tree Mech Warrior blend tree Fall Transition Forward Motion Fall Down Walk Run Blend Tree

234 234 Pose 1 Pose2 0 1 0 1 Cross Fade

235 235 Pose 1 Pose 2 0 1 0 1 Continuous Blending

236 236 左右搏擊 左右搏擊 Pose 1Pose 2 Pose 3 Feather Blending

237 237 Weights to assign the influences of the deformation by bones on skin vertices Weights to assign the influences of the deformation by bones on skin vertices 1-weight 1-weight 2-weight 2-weight N-weight N-weight CPU cost CPU cost Another way to perform the skin deformation calculation is using vertex shader Another way to perform the skin deformation calculation is using vertex shader Skin Deformation

238 238 Bone A (root object) Bone B (Bone A’s child) base 1.Apply motion data to bones 2.Convert the vertex from “base” space to its associated bone’s space using the natural pose’s inverse transformation 3.Multiple the influence weight 4.Accumulate all influences 5.Then the vertex is deformed by the bone in “base” space

239 239 M b = R b T pivot M a = R a T position M vb = M nb -1 M b M a M va = M na -1 M a v in_base = v s *w a M va + v s *w b M vb A two-weight skin vertex example

240 240 9th Game Control

241 241 Game Control System (1/2) Game control is the interface between the game and the user. Game control is the interface between the game and the user. Game control is not only input device control but also the camera control Game control is not only input device control but also the camera control Input device control Input device control On PC On PC Mouse Mouse Keyboard Keyboard Gamepad Gamepad On game console On game console Gamepad buttons Gamepad buttons 0 or 255 0 or 255 Joystick Joystick 0 - 255 0 - 255

242 242 Game Control System (2/2) Camera control Camera control First-personal view First-personal view Third-personal view Third-personal view God view God view Pre-set camera view Pre-set camera view Etc Etc

243 243 Mouse Control (1/3) Mouse is a 2D device. Mouse is a 2D device. 2-axis moving 2-axis moving Related movement Related movement 2 or 3 buttons 2 or 3 buttons Mouse can : Mouse can : Move Move Drag Drag Double-click Double-click Behaviors Behaviors Hit test Hit test Selection Selection Pilot Pilot Position & orientation Position & orientation

244 244 Mouse Control (2/3) Typical game types using mouse control Typical game types using mouse control Real-time strategy games Real-time strategy games Role Playing Game Role Playing Game Typical game play examples : Typical game play examples : Path finding for playable character Path finding for playable character Hitting the enemy Hitting the enemy Selecting a group of units Selecting a group of units Orientating the camera in FPS games Orientating the camera in FPS games Menu selection Menu selection … Features Features Always coupling with god-view camera control Always coupling with god-view camera control Viewing from the top of game world Viewing from the top of game world

245 245 Mouse Control (3/3) Easy to hand on Easy to hand on 一鼠到底 一鼠到底 Slow action Slow action Compared with joystick Compared with joystick Value range from -32727 - 32727 Value range from -32727 - 32727

246 246 Keyboard Control (1/3) Standard PC input device Standard PC input device Simulating the gamepads usually Simulating the gamepads usually Not every PC game player having gamepad Not every PC game player having gamepad Using keyboard as the alternative device Using keyboard as the alternative device Hotkey system Hotkey system Each key has two states. Each key has two states. Pressed Pressed Released Released 256 keys 256 keys Behaviors Behaviors Key presses/released Key presses/released ASCII code ASCII code One hotkey can represent a command One hotkey can represent a command

247 247 Keyboard Control (2/3) Communication tool Communication tool Typing messages Typing messages Typical game types using keyboard Typical game types using keyboard MMORPG MMORPG Needs chatting with friends Needs chatting with friends Real-time strategy games Real-time strategy games Hotkey system Hotkey system First-person shooting games First-person shooting games Fighting games Fighting games Typical game play examples : Typical game play examples : Chatting Chatting Character controls Character controls Move forward Move forward Turning Turning

248 248 Keyboard Control (3/3) Features Features Shortcut for a sequence of actions Shortcut for a sequence of actions Commands Commands Menu selection Menu selection But a little bit complicated for players But a little bit complicated for players 256 keys 256 keys

249 249 Gamepad Control (1/3) A small “keyboard” designed for game playing A small “keyboard” designed for game playing Gamepad can map to the hotkey system Gamepad can map to the hotkey system Same behaviors Same behaviors Less than 20 keys Less than 20 keys Majors keys : Majors keys :

250 250 Gamepad Control (2/3) Recent gamepad capable of two extra digital joysticks Recent gamepad capable of two extra digital joysticks For buttons For buttons Value range : 0 or 255 Value range : 0 or 255 For joystick For joystick Value range : 0 to 255 Value range : 0 to 255 Typical game types using gamepad Typical game types using gamepad Almost all types of games except Almost all types of games except Need typing Need typing Need large-range selection for game units Need large-range selection for game units Typical game play examples : Typical game play examples : Character controls Character controls Move forward Move forward Turn Turn

251 251 Gamepad Control (3/3) Combat system in a fighting game Combat system in a fighting game Move forward Move forward Turn Turn … Features Features Designed for game playing Designed for game playing Look and feel Look and feel Easy to hand-on Easy to hand-on If you not to challenge the players’ usual practice If you not to challenge the players’ usual practice

252 252 Camera Control Types Types First-personal view First-personal view Third-personal view but following the playable character Third-personal view but following the playable character God view God view Fixed Fixed Following the playable character Following the playable character Fixed view Fixed view Pre-rendered background Pre-rendered background Pre-set view Pre-set view … Very sensitive to game play design & game control Very sensitive to game play design & game control Camera control is not an independent system Camera control is not an independent system

253 253 God-view Camera Example Age of Empire 3

254 254 Case Study – Third-personal View (1/6) Use arrow keys on keyboard or gamepad Use arrow keys on keyboard or gamepad Basic key assignments : Basic key assignments : Up key to move the playable character forward Up key to move the playable character forward Down key to turn character facing to the camera and move forward Down key to turn character facing to the camera and move forward Left & right keys to turn the character to left or right Left & right keys to turn the character to left or right

255 255 Case Study – Third-personal View (2/6) The camera following the character to move The camera following the character to move And keeping a range of distance, a reasonable height and look-down angle with the character. And keeping a range of distance, a reasonable height and look-down angle with the character.  Distance PC Camera Height

256 256 Case Study – Third-personal View (3/6) Detailed key assignments : Detailed key assignments : Up key Up key Turn the character facing back to the camera Turn the character facing back to the camera Move the character forward Move the character forward If the distance between the character and the camera is larger a pre-set range, move the camera forward to keep the distance. If the distance between the character and the camera is larger a pre-set range, move the camera forward to keep the distance. At the same time, the height to the ground will be changed to synchronize with the character. At the same time, the height to the ground will be changed to synchronize with the character. Down key Down key Turn the character facing to the camera Turn the character facing to the camera Move the character forward Move the character forward The camera will move backward to keep a distance with the character. The camera will move backward to keep a distance with the character. The height to the ground will be changed to synchronize with the character. The height to the ground will be changed to synchronize with the character.

257 257 Case Study – Third-personal View (4/6) If the camera is blocked by obstacle to move backward, raise the height of the camera but keep the eyes on the character. If the camera is blocked by obstacle to move backward, raise the height of the camera but keep the eyes on the character. PC Camera

258 258 Case Study – Third-personal View (5/6) Right key Right key Turn the character facing to the right of the camera. Turn the character facing to the right of the camera. Take the camera’s position as a circle center and the distance between the camera and the character as the radius. Take the camera’s position as a circle center and the distance between the camera and the character as the radius. Set the circle as the movement orbit. Set the circle as the movement orbit. Let the character move on the orbit. Let the character move on the orbit. When the character moving, turn the camera to right to keep eyes on the character. When the character moving, turn the camera to right to keep eyes on the character.

259 259 Case Study – Third-personal View (6/6) When the character hitting the obstacle, let the character keep on turning and moving, use the same approach in “Down key” step to raise the camera. When the character hitting the obstacle, let the character keep on turning and moving, use the same approach in “Down key” step to raise the camera. Left key Left key As same as “Right key” step except the left direction. As same as “Right key” step except the left direction. Reference game examples: Reference game examples: Sprinter cell 3 Sprinter cell 3 PSO PSO Prince of Persia( 波斯王子 ) Prince of Persia( 波斯王子 ) The Legend of Zelda ( 薩爾達傳說 ) The Legend of Zelda ( 薩爾達傳說 ) … Demo : 1st DCI students’ work : iRobot Demo : 1st DCI students’ work : iRobot


Download ppt "1 3D Game Programming 王銓彰 2005."

Similar presentations


Ads by Google