t1 / TFDContents / Assets / KinectDemos / FittingRoomDemo / Scripts / OverlayController.cs @ 3
이력 | 보기 | 이력해설 | 다운로드 (3.3 KB)
1 | 3 | KTH | using UnityEngine; |
---|---|---|---|
2 | using System.Collections; |
||
3 | |||
4 | public class OverlayController : MonoBehaviour |
||
5 | { |
||
6 | [Tooltip("GUI-texture used to display the color camera feed on the scene background.")] |
||
7 | public GUITexture backgroundImage; |
||
8 | |||
9 | [Tooltip("Camera used to display the background image from the Kinect point of view.")] |
||
10 | public Camera backgroundCamera; |
||
11 | |||
12 | [Tooltip("Camera used to display the clothing models from the Kinect point of view.")] |
||
13 | public Camera foregroundCamera; |
||
14 | |||
15 | // [Tooltip("Use this setting to minimize the offset between the image and the model overlay.")] |
||
16 | // [Range(-0.1f, 0.1f)] |
||
17 | // public float adjustedCameraOffset = 0f; |
||
18 | // |
||
19 | // |
||
20 | // // variable to track the current camera offset |
||
21 | // private float currentCameraOffset = 0f; |
||
22 | |||
23 | |||
24 | void Start () |
||
25 | { |
||
26 | KinectManager manager = KinectManager.Instance; |
||
27 | |||
28 | if(manager && manager.IsInitialized()) |
||
29 | { |
||
30 | KinectInterop.SensorData sensorData = manager.GetSensorData(); |
||
31 | |||
32 | if(foregroundCamera != null && sensorData != null && sensorData.sensorInterface != null) |
||
33 | { |
||
34 | // foregroundCamera.transform.position = new Vector3(sensorData.depthCameraOffset + adjustedCameraOffset, |
||
35 | // manager.sensorHeight, 0f); |
||
36 | foregroundCamera.transform.position = new Vector3(0f, manager.sensorHeight, 0f); |
||
37 | foregroundCamera.transform.rotation = Quaternion.Euler(-manager.sensorAngle, 0f, 0f); |
||
38 | // currentCameraOffset = adjustedCameraOffset; |
||
39 | |||
40 | // foregroundCamera.fieldOfView = sensorData.colorCameraFOV; |
||
41 | } |
||
42 | |||
43 | if(backgroundCamera != null && sensorData != null && sensorData.sensorInterface != null) |
||
44 | { |
||
45 | backgroundCamera.transform.position = new Vector3(0f, manager.sensorHeight, 0f); |
||
46 | backgroundCamera.transform.rotation = Quaternion.Euler(-manager.sensorAngle, 0f, 0f); |
||
47 | } |
||
48 | } |
||
49 | } |
||
50 | |||
51 | void Update () |
||
52 | { |
||
53 | KinectManager manager = KinectManager.Instance; |
||
54 | |||
55 | if(manager && manager.IsInitialized()) |
||
56 | { |
||
57 | KinectInterop.SensorData sensorData = manager.GetSensorData(); |
||
58 | |||
59 | if(manager.autoHeightAngle == KinectManager.AutoHeightAngle.AutoUpdate || |
||
60 | manager.autoHeightAngle == KinectManager.AutoHeightAngle.AutoUpdateAndShowInfo) // || |
||
61 | //currentCameraOffset != adjustedCameraOffset) |
||
62 | { |
||
63 | // update the cameras automatically, according to the current sensor height and angle |
||
64 | if(foregroundCamera != null && sensorData != null) |
||
65 | { |
||
66 | // foregroundCamera.transform.position = new Vector3(sensorData.depthCameraOffset + adjustedCameraOffset, |
||
67 | // manager.sensorHeight, 0f); |
||
68 | foregroundCamera.transform.position = new Vector3(0f, manager.sensorHeight, 0f); |
||
69 | foregroundCamera.transform.rotation = Quaternion.Euler(-manager.sensorAngle, 0f, 0f); |
||
70 | // currentCameraOffset = adjustedCameraOffset; |
||
71 | } |
||
72 | |||
73 | if(backgroundCamera != null && sensorData != null) |
||
74 | { |
||
75 | backgroundCamera.transform.position = new Vector3(0f, manager.sensorHeight, 0f); |
||
76 | backgroundCamera.transform.rotation = Quaternion.Euler(-manager.sensorAngle, 0f, 0f); |
||
77 | } |
||
78 | |||
79 | } |
||
80 | |||
81 | if(backgroundImage) |
||
82 | { |
||
83 | if(backgroundImage.texture == null) |
||
84 | { |
||
85 | backgroundImage.texture = manager.GetUsersClrTex(); |
||
86 | //backgroundImage.texture = BackgroundRemovalManager.Instance.GetForegroundTex(); |
||
87 | } |
||
88 | } |
||
89 | } |
||
90 | |||
91 | } |
||
92 | |||
93 | } |