Download - EEC-693/793 Applied Computer Vision with Depth Cameras Lecture 13 Wenbing Zhao [email protected]
![Page 1: EEC-693/793 Applied Computer Vision with Depth Cameras Lecture 13 Wenbing Zhao wenbing@ieee.org](https://reader030.vdocuments.site/reader030/viewer/2022032611/56649e7b5503460f94b7d0a6/html5/thumbnails/1.jpg)
EEC-693/793EEC-693/793Applied Computer Vision Applied Computer Vision
with Depth Cameraswith Depth Cameras
Lecture 13Lecture 13
Wenbing ZhaoWenbing Zhao
[email protected]@ieee.org
![Page 2: EEC-693/793 Applied Computer Vision with Depth Cameras Lecture 13 Wenbing Zhao wenbing@ieee.org](https://reader030.vdocuments.site/reader030/viewer/2022032611/56649e7b5503460f94b7d0a6/html5/thumbnails/2.jpg)
OutlineOutline Introduction to Unity3D Based on Book:
Beginning 3D Game Development with Unity 4
![Page 3: EEC-693/793 Applied Computer Vision with Depth Cameras Lecture 13 Wenbing Zhao wenbing@ieee.org](https://reader030.vdocuments.site/reader030/viewer/2022032611/56649e7b5503460f94b7d0a6/html5/thumbnails/3.jpg)
Creating a New Unity ProjectCreating a New Unity Project Open Unity Select the Create New Project tab, change location folder to
KinectUnity Select packages for import, then click Create
![Page 4: EEC-693/793 Applied Computer Vision with Depth Cameras Lecture 13 Wenbing Zhao wenbing@ieee.org](https://reader030.vdocuments.site/reader030/viewer/2022032611/56649e7b5503460f94b7d0a6/html5/thumbnails/4.jpg)
Unity 3DUnity 3DLayoutLayout
![Page 5: EEC-693/793 Applied Computer Vision with Depth Cameras Lecture 13 Wenbing Zhao wenbing@ieee.org](https://reader030.vdocuments.site/reader030/viewer/2022032611/56649e7b5503460f94b7d0a6/html5/thumbnails/5.jpg)
Scene ViewScene View Where you plan and execute your ideasWhere you plan and execute your ideas
To show the grid, toggle off the game overlay buttonTo show the grid, toggle off the game overlay button
![Page 6: EEC-693/793 Applied Computer Vision with Depth Cameras Lecture 13 Wenbing Zhao wenbing@ieee.org](https://reader030.vdocuments.site/reader030/viewer/2022032611/56649e7b5503460f94b7d0a6/html5/thumbnails/6.jpg)
Hierarchy ViewHierarchy View Shows what’s in the currently active scene. GameObjects that are dynamically added and removed from
the scene during runtime will appear here when they are active in the scene
By default, the maincamera is added
![Page 7: EEC-693/793 Applied Computer Vision with Depth Cameras Lecture 13 Wenbing Zhao wenbing@ieee.org](https://reader030.vdocuments.site/reader030/viewer/2022032611/56649e7b5503460f94b7d0a6/html5/thumbnails/7.jpg)
Project ViewProject View Contains all the assets available to the current
project, as well as all scenes or levels available for the finished game or application
![Page 8: EEC-693/793 Applied Computer Vision with Depth Cameras Lecture 13 Wenbing Zhao wenbing@ieee.org](https://reader030.vdocuments.site/reader030/viewer/2022032611/56649e7b5503460f94b7d0a6/html5/thumbnails/8.jpg)
InspectorInspector Inspector is used to access
various properties and components for objects you’ve selected in either the Hierarchy or Project views
![Page 9: EEC-693/793 Applied Computer Vision with Depth Cameras Lecture 13 Wenbing Zhao wenbing@ieee.org](https://reader030.vdocuments.site/reader030/viewer/2022032611/56649e7b5503460f94b7d0a6/html5/thumbnails/9.jpg)
ToolbarToolbar
Transform tools: provide functionality for navigating the scene and transforming objects Left most button: pan, orbit, zoom tools for navigating and
adjusting scene view Pan tool: default, left click and drag to move the view
around Orbit tool: hold the Alt key while clicking left click and
dragging Zoom tool: Alt + right mouse click Other three buttons: move, rotate, and scale
![Page 10: EEC-693/793 Applied Computer Vision with Depth Cameras Lecture 13 Wenbing Zhao wenbing@ieee.org](https://reader030.vdocuments.site/reader030/viewer/2022032611/56649e7b5503460f94b7d0a6/html5/thumbnails/10.jpg)
ToolbarToolbar Privot point and coordinate system tools:
Objects can be transformed in different coordinate systems and from different pivot points
Play mode controls
Layers control: Layers are used in Unity for controlling which objects are rendered by which cameras or lit by which lights
Layout control
![Page 11: EEC-693/793 Applied Computer Vision with Depth Cameras Lecture 13 Wenbing Zhao wenbing@ieee.org](https://reader030.vdocuments.site/reader030/viewer/2022032611/56649e7b5503460f94b7d0a6/html5/thumbnails/11.jpg)
Elements to Build a SceneElements to Build a Scene Assets: non-mesh special effects, physics materials,
and scripts GameObject: base container for objects, scripts, and
other components in Unity Contains its transforms (location and orientation) and a few
other properties Component: items associated with objects, such as
meshes, rendering types, sound, scripts, and colliders, as well as those that create or extend functionality with predefined behaviors
![Page 12: EEC-693/793 Applied Computer Vision with Depth Cameras Lecture 13 Wenbing Zhao wenbing@ieee.org](https://reader030.vdocuments.site/reader030/viewer/2022032611/56649e7b5503460f94b7d0a6/html5/thumbnails/12.jpg)
Creating Simple Game Objects: Creating Simple Game Objects: CubeCube
![Page 13: EEC-693/793 Applied Computer Vision with Depth Cameras Lecture 13 Wenbing Zhao wenbing@ieee.org](https://reader030.vdocuments.site/reader030/viewer/2022032611/56649e7b5503460f94b7d0a6/html5/thumbnails/13.jpg)
Creating Simple Game ObjectsCreating Simple Game Objects To zoom, use middle
mouse roller or Alt-right mouse click
To set the camera to match the scene view Select the main camera in
the hierarchy view From the GameObject menu,
choose Align with View
![Page 14: EEC-693/793 Applied Computer Vision with Depth Cameras Lecture 13 Wenbing Zhao wenbing@ieee.org](https://reader030.vdocuments.site/reader030/viewer/2022032611/56649e7b5503460f94b7d0a6/html5/thumbnails/14.jpg)
Creating Simple Game ObjectsCreating Simple Game Objects Toggle the built-in
lighting off and the scene lighting on, by clicking the light button The cube is now lit only
with the scene ambient light, as in the Game window
Try out zoom, orbit and pan
![Page 15: EEC-693/793 Applied Computer Vision with Depth Cameras Lecture 13 Wenbing Zhao wenbing@ieee.org](https://reader030.vdocuments.site/reader030/viewer/2022032611/56649e7b5503460f94b7d0a6/html5/thumbnails/15.jpg)
Selecting and FocusingSelecting and Focusing To focus the viewport back to the cube, or to “find”
the cube, do the following Make sure the cube is selected in the Hierarchy view. Put the cursor over the Scene window. Press the F key on your keyboard
You can view scene objects in several other modes Wireframe, textured wire, textured (default)
![Page 16: EEC-693/793 Applied Computer Vision with Depth Cameras Lecture 13 Wenbing Zhao wenbing@ieee.org](https://reader030.vdocuments.site/reader030/viewer/2022032611/56649e7b5503460f94b7d0a6/html5/thumbnails/16.jpg)
Transforming ObjectsTransforming Objects In 3D space, the Cartesian coordinate
system is used X, Y, Z are color-coded with red, green, blue Objects can be transformed (moved,
rotated, scaled) around the scene Select the cube, select the move button, click
and drag on any of the three axis; Rotate is similar
Can also do these in inspector
![Page 17: EEC-693/793 Applied Computer Vision with Depth Cameras Lecture 13 Wenbing Zhao wenbing@ieee.org](https://reader030.vdocuments.site/reader030/viewer/2022032611/56649e7b5503460f94b7d0a6/html5/thumbnails/17.jpg)
Lights Lights Because there are no lights in the viewport yet, it went dark,
just as in the Game window, when you toggle off the lighting button
Adding light Focus the Scene view on the cube again and zoom out a bit From the GameObject menu, choose Create Other ➤
Create a Directional Light. Directional lights emit parallel rays, no matter where they are in
the scene. Move the light up and out of the way of the cube. Rotate it in the Scene window until the cube is lit nicely in
the Game window Use alt-left mouse click, drag/orbit the viewport so you are
facing the unlit side of the cube
![Page 18: EEC-693/793 Applied Computer Vision with Depth Cameras Lecture 13 Wenbing Zhao wenbing@ieee.org](https://reader030.vdocuments.site/reader030/viewer/2022032611/56649e7b5503460f94b7d0a6/html5/thumbnails/18.jpg)
Lights Lights Changing light
color: in inspector for light Click and drag in the
Color’s image/color swatch and watch the light’s color on the cube change
Choose something subtle.
Close the dialog
![Page 19: EEC-693/793 Applied Computer Vision with Depth Cameras Lecture 13 Wenbing Zhao wenbing@ieee.org](https://reader030.vdocuments.site/reader030/viewer/2022032611/56649e7b5503460f94b7d0a6/html5/thumbnails/19.jpg)
Material Material In the Inspector,
select the Cube 2. In the Mesh
Renderer section, click to open the Materials array list
![Page 20: EEC-693/793 Applied Computer Vision with Depth Cameras Lecture 13 Wenbing Zhao wenbing@ieee.org](https://reader030.vdocuments.site/reader030/viewer/2022032611/56649e7b5503460f94b7d0a6/html5/thumbnails/20.jpg)
Material Material From the Assets menu, choose Create Folder, ➤
Rename the folder My Materials
![Page 21: EEC-693/793 Applied Computer Vision with Depth Cameras Lecture 13 Wenbing Zhao wenbing@ieee.org](https://reader030.vdocuments.site/reader030/viewer/2022032611/56649e7b5503460f94b7d0a6/html5/thumbnails/21.jpg)
Material Material Right-click the new My Materials folder and, from the
same Create submenu, choose Material
![Page 22: EEC-693/793 Applied Computer Vision with Depth Cameras Lecture 13 Wenbing Zhao wenbing@ieee.org](https://reader030.vdocuments.site/reader030/viewer/2022032611/56649e7b5503460f94b7d0a6/html5/thumbnails/22.jpg)
Material Material A New Material entry appears in the Inspector, Name the new
material TestBark Drag and drop the material from the folder onto the cube in the
Scene window. In the Texture thumbnail window (not the Preview window),
pick the Select button and, with the preview slider all the way to the left in the Asset Selector, choose Palm Bark Diffuse.
![Page 23: EEC-693/793 Applied Computer Vision with Depth Cameras Lecture 13 Wenbing Zhao wenbing@ieee.org](https://reader030.vdocuments.site/reader030/viewer/2022032611/56649e7b5503460f94b7d0a6/html5/thumbnails/23.jpg)
Material Material In the Texture thumbnail window (not the Preview window),
pick the Select button and, with the preview slider all the way to the left in the Asset Selector, choose Palm Bark Diffuse.
![Page 24: EEC-693/793 Applied Computer Vision with Depth Cameras Lecture 13 Wenbing Zhao wenbing@ieee.org](https://reader030.vdocuments.site/reader030/viewer/2022032611/56649e7b5503460f94b7d0a6/html5/thumbnails/24.jpg)
ScriptingScripting A script is a program that controls the game objects in the
scene dynamically, Unity support a number of programming languages We will be using C#
To create a new script Create a New Folder in the Project view using the right-click menu
or Assets menu in the menu bar Name the new folder My Scripts With the new folder selected, right-click it to bring up the contents
of the right-click menu. Select C# Script from the Create submenu
![Page 25: EEC-693/793 Applied Computer Vision with Depth Cameras Lecture 13 Wenbing Zhao wenbing@ieee.org](https://reader030.vdocuments.site/reader030/viewer/2022032611/56649e7b5503460f94b7d0a6/html5/thumbnails/25.jpg)
ScriptingScripting To edit the script, click the open button. The MonoDevelop
editor will open
using UnityEngine;using System.Collections;
public class NewBehaviourScript : MonoBehaviour {
// Use this for initialization void Start () {
}
// Update is called once per frame void Update () {
}}
![Page 26: EEC-693/793 Applied Computer Vision with Depth Cameras Lecture 13 Wenbing Zhao wenbing@ieee.org](https://reader030.vdocuments.site/reader030/viewer/2022032611/56649e7b5503460f94b7d0a6/html5/thumbnails/26.jpg)
ScriptingScripting The Start function is only called once as the scene is started and is a
good place to initialize values that don’t exist until the game has been loaded
The Update function is checked at least every frame during runtime to see if anything needs to be executed It can make a transform such as a rotation continuously loop, check to see
if a particular condition is met, and many other things To attach the script to the game object, drag the script file to the game
object Add the following line in the Update function, save the script, click play
If you want to animate the object on a per-second basis, use Time.deltaTime
transform.Rotate(0,5,0);
(0,5,0) refers to the X, Y, and Z rotations parameters that are needed by the Rotate function
transform.Rotate(0,5 * Time.deltaTime,0);
![Page 27: EEC-693/793 Applied Computer Vision with Depth Cameras Lecture 13 Wenbing Zhao wenbing@ieee.org](https://reader030.vdocuments.site/reader030/viewer/2022032611/56649e7b5503460f94b7d0a6/html5/thumbnails/27.jpg)
ScriptingScripting We can also move the game object
using the Translate function
You can also add private or public variables into script Public variables are listed in the inspector
and their values can be set their Challenge Task:
Animate the cube such that it drops to the ground and then bounce back like a ball
transform.Translate(2 * Time.deltaTime,0,0);