Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using Assets;
  6. using UnityEngine;
  7. using UnityEngine.iOS;
  8. using VinteR.Model.Gen;
  9.  
  10. public class Tracker : MonoBehaviour
  11. {
  12.  
  13. public VinterClient VinterClient;
  14. public float _xOffset;
  15. public float _yOffset;
  16. public float _zOffset;
  17.  
  18. private String TrackedObjectName;
  19. private Vector3 _position;
  20. private Quaternion _rotation;
  21.  
  22. // Use this for initialization
  23. void Start () {
  24. VinterClient.MocapFrameReceived += VinterClientOnMocapFrameReceived;
  25. TrackedObjectName = transform.name;
  26. }
  27.  
  28. private void VinterClientOnMocapFrameReceived(MocapFrame frame)
  29. {
  30. var body = frame.Bodies.SingleOrDefault(b => b.Name.Equals(TrackedObjectName));
  31. if (body != null)
  32. {
  33. _position = new Vector3(body.Centroid.Z * 0.001f +_xOffset, body.Centroid.Y * 0.001f +_yOffset, body.Centroid.X * 0.001f + _zOffset);
  34. transform.position = _position;
  35.  
  36. var quaternion = new Quaternion(body.Rotation.Z, body.Rotation.Y, body.Rotation.X, -body.Rotation.W);
  37. _rotation = Quaterniona.Euler(quaternion.eulerAngles.x, quaternion.eulerAngles.y, quaternion.eulerAngles.z);
  38. transform.rotation = _rotation;
  39. }
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement