38 AlignmentVector = alignmentVector;
39 MaxDistance = maxDistance;
40 FlipDirecationOnCameraForward = flipDirectionOnCameraForward;
41 Direction =
new Vector3();
57 [Tooltip(
"What type of data processing should be used ? Raw, Camera aligned or vector aligned")]
64 [Tooltip(
"The distance in world space to compare the gesture's delta to")]
65 public float MaxGestureDistance = 0.15f;
71 [Tooltip(
"The vector to align the gesture to, only used when the Aligned GestureDataType is selected.")]
72 public Vector3 AlignmentVector =
new Vector3(1,1,1);
79 [Tooltip(
"Should we care if the Camera's forward is not Vector3.forward?")]
80 public bool FlipDirectionOnCameraForward =
false;
126 protected bool GestureStarted =
false;
143 protected float KeywordGestureTime = 0.5f;
148 protected float KeywordGestureTimeCounter = 0.5f;
174 CameraMatrix = GetCameraMatrix();
175 StartGesturePosition = startGesturePosition;
176 CurrentGesturePosition = startGesturePosition;
177 StartHeadPosition = startHeadOrigin;
178 StartHeadRay = startHeadRay;
179 GestureStarted =
true;
183 CurrentGesturePosition = currentGesturePosition;
190 GestureStarted =
false;
209 bool flipDirection = Vector3.Dot(Vector3.forward, StartHeadRay) < 0 && flipDirecationOnCameraForward;
229 Vector3 up = Vector3.up;
230 Vector3 forward = MainCamera.transform.forward;
232 if (Vector3.Angle(up, forward) < 10)
234 up = MainCamera.transform.up;
236 Vector3 right = Vector3.Cross(up, forward);
240 Matrix4x4 cameraWorld =
new Matrix4x4();
241 cameraWorld.SetColumn(0, right);
242 cameraWorld.SetColumn(1, up);
243 cameraWorld.SetColumn(2, forward);
244 cameraWorld.SetColumn(3,
new Vector4(0, 0, 0, 1));
255 public Vector3
WorldForwardVector(Vector3 direction, Vector3 orientation,
bool flipY =
false,
bool flipZ =
false)
257 Matrix4x4 cameraWorld = GetCameraMatrix();
260 Vector3 rawVector = direction - orientation;
265 rawVector.z = -rawVector.z;
270 rawVector.y = -rawVector.y;
273 Vector3 newDirection = cameraWorld.MultiplyVector(rawVector);
276 newDirection.y = rawVector.y;
292 KeywordGestureVector = gestureVector;
293 KeywordGestureTimeCounter = 0;
294 CameraMatrix = GetCameraMatrix();
295 StartGesturePosition = gestureVector * MaxGestureDistance * (KeywordGestureTimeCounter / KeywordGestureTime);
296 StartHeadPosition =
new Vector3();
297 StartHeadRay = Vector3.forward;
299 CurrentGesturePosition = gestureVector * MaxGestureDistance * (KeywordGestureTimeCounter/KeywordGestureTime);
313 switch (gestureValue)
316 SetGestureVector(Vector3.left);
319 SetGestureVector(Vector3.right);
322 SetGestureVector(Vector3.up);
325 SetGestureVector(Vector3.down);
340 float cameraDirectionX = flipX ? -directionVector.x : directionVector.x;
341 float cameraDirectionY = flipY ? -directionVector.y : directionVector.y;
342 return MainCamera.transform.forward * cameraDirectionY + MainCamera.transform.right * cameraDirectionX;
355 float angleDiff = Vector3.Angle(Vector3.forward, MainCamera.transform.forward);
357 float dot = Vector3.Dot(Vector3.right, MainCamera.transform.forward);
360 angleDiff = -angleDiff;
362 return RotateVectorOnY(gesturePosition, MainCamera.transform.position, angleDiff);
372 private Vector3 RotateVectorOnY(Vector3 vector, Vector3 pivot,
float angle)
374 return Quaternion.Euler(0, angle, 0) * (vector - pivot) + pivot;
388 Vector3 cameraRay = StartHeadPosition - controlPosition;
389 bool facingForward = Vector3.Dot(MainCamera.transform.forward, StartHeadRay) >= 0;
390 bool facingControl = Vector3.Dot(cameraRay, controlForward) >= 0;
418 DirectionVector = CurrentGesturePosition - StartGesturePosition;
419 CurrentDistance = DirectionVector.magnitude;
420 bool flipDirection = Vector3.Dot(Vector3.forward, StartHeadRay) < 0 && FlipDirectionOnCameraForward;
424 CurrentDistance = DirectionVector.magnitude;
429 DirectionVector = -DirectionVector;
431 CurrentDistance = Vector3.Dot(DirectionVector, MainCamera.transform.right);
434 CurrentDistance = Vector3.Dot(DirectionVector, AlignmentVector);
440 CurrentPercentage = Mathf.Min(Mathf.Abs(CurrentDistance) / MaxGestureDistance, 1);
445 if (KeywordGestureTimeCounter < 0)
449 KeywordGestureTimeCounter = KeywordGestureTime;
454 KeywordGestureTimeCounter += Time.deltaTime;
455 if (KeywordGestureTimeCounter > KeywordGestureTime)
457 KeywordGestureTimeCounter = KeywordGestureTime;
461 CurrentGesturePosition = KeywordGestureVector * MaxGestureDistance * (KeywordGestureTimeCounter / KeywordGestureTime);
463 ManipulationUpdate(StartGesturePosition, Vector3.up, StartHeadPosition, StartHeadRay, state);