-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGrab.cs
More file actions
160 lines (124 loc) · 3.6 KB
/
Grab.cs
File metadata and controls
160 lines (124 loc) · 3.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using System;
public class Grab : OVRGrabber
{
private bool isGrabbing;
private bool insideObject;
private Vector3 prevPost;
private Quaternion prevRot;
private OVRHand m_hand;
private OVRMeshRenderer m_renderer;
//private Hand m_handtype;
private GameObject r_preview;
private GameObject l_preview;
public Material defaultHandMaterial;
public Material noneMaterial;
//private float pinchThreshold = 0.6f;
//private HandDetector handDetector;
protected override void Start()
{
Debug.Log("start!");
base.Start();
m_hand = GetComponent<OVRHand>();
r_preview = GameObject.FindWithTag("PreviewHand_R");
l_preview = GameObject.FindWithTag("PreviewHand_L");
r_preview.SetActive(false);
l_preview.SetActive(false);
//renderer
m_renderer = m_hand.GetComponent<OVRMeshRenderer>();
isGrabbing = false;
insideObject = false;
}
public override void Update()
{
base.Update();
//object 닿지 않을 때
if (!(insideObject))
return;
if (isGrabbing)
{
prevPost = transform.position;
prevRot = transform.rotation;
}
}
public void InsideObjectTurnOn()
{
insideObject = true;
}
public void InsideObjectTurnOff()
{
insideObject = false;
}
public void GrabStart()
{
if (!(insideObject) && (isGrabbing))
{
return;
}
Debug.Log("Grab Grabbing");
isGrabbing = true;
if (m_grabbedObj == null && m_grabCandidates.Count > 0 && isGrabbing)
{
Debug.Log("grabbing");
GrabBegin();
}
}
public void GrabFinish()
{
if (!(insideObject) && !(isGrabbing))
return;
Debug.Log("Grab Not Grabbing");
isGrabbing = false;
if (m_grabbedObj != null && !(isGrabbing))
{
SetPlayerIgnoreCollision(m_grabbedObj.gameObject, false);
Debug.Log("not grabbing");
GrabEnd2();
}
}
protected override void GrabBegin()
{
base.GrabBegin();
//renderer
//m_renderer.enabled = false;
m_renderer._originalMaterial = noneMaterial;
if((int)m_hand.HandType == 2)
{
l_preview.SetActive(true);
}
else if((int)m_hand.HandType == 1)
{
r_preview.SetActive(true);
}
}
public void GrabEnd2()
{
if (m_grabbedObj == null)
{
GrabVolumeEnable(true);
return;
}
/*
Vector3 linearVelocity = (transform.parent.position - prevPost)/Time.deltaTime; //속도 = (변위)/시간
Vector3 angularVelocity = (transform.parent.eulerAngles - prevRot.eulerAngles)/Time.deltaTime;
*/
Vector3 linearVelocity = (transform.position - prevPost); //속도 = (변위)/시간
Vector3 angularVelocity = (transform.rotation.eulerAngles - prevRot.eulerAngles);
GrabbableRelease(new Vector3(0, 0, 0), new Vector3(0, 0, 0));
GrabVolumeEnable(true);
//renderer
//m_renderer.enabled = true;
m_renderer._originalMaterial = defaultHandMaterial;
if ((int)m_hand.HandType == 2)
{
l_preview.SetActive(false);
}
else if ((int)m_hand.HandType == 1)
{
r_preview.SetActive(false);
}
}
}