2015-02-08 8 views
0

Я пытаюсь изменить систему координат по умолчанию для перехода на скачок от контроллера скачка в кость в скелете.Leap Motion Система координат re таргетинга

Этот скрипт поставляется с прыжком, и я надеялся, что кто-то может помочь мне в том, как я могу это достичь.

/******************************************************************************\ 
* Copyright (C) Leap Motion, Inc. 2011-2014.         * 
* Leap Motion proprietary. Licensed under Apache 2.0       * 
* Available at http://www.apache.org/licenses/LICENSE-2.0.html     * 
\******************************************************************************/ 

using UnityEngine; 
using System.Collections; 
using Leap; 

// Interface for all hands. 
public abstract class HandModel : MonoBehaviour { 
    public const int NUM_FINGERS = 5; 
    public float handModelPalmWidth = 0.085f; 
    public FingerModel[] fingers = new FingerModel[NUM_FINGERS]; 

    protected Hand hand_; 
    protected HandController controller_; 
    protected bool mirror_z_axis_ = false; 

    public Vector3 GetHandOffset() { 
    if (controller_ == null || hand_ == null) 
     return Vector3.zero; 

    Vector3 additional_movement = controller_.handMovementScale - Vector3.one; 
    Vector3 scaled_wrist_position = 
     Vector3.Scale(additional_movement, hand_.WristPosition.ToUnityScaled(mirror_z_axis_)); 

    return controller_.transform.TransformPoint(scaled_wrist_position) - 
      controller_.transform.position; 
    } 

    // Returns the palm position of the hand in relation to the controller. 
    public Vector3 GetPalmPosition() { 
    return controller_.transform.TransformPoint(hand_.PalmPosition.ToUnityScaled(mirror_z_axis_)) + 
      GetHandOffset(); 
    } 

    // Returns the palm rotation of the hand in relation to the controller. 
    public Quaternion GetPalmRotation() { 
    return GetController().transform.rotation * GetLeapHand().Basis.Rotation(mirror_z_axis_); 
    } 

    // Returns the palm direction of the hand in relation to the controller. 
    public Vector3 GetPalmDirection() { 
    return controller_.transform.TransformDirection(hand_.Direction.ToUnity(mirror_z_axis_)); 
    } 

    // Returns the palm normal of the hand in relation to the controller. 
    public Vector3 GetPalmNormal() { 
    return controller_.transform.TransformDirection(hand_.PalmNormal.ToUnity(mirror_z_axis_)); 
    } 

    // Returns the lower arm direction in relation to the controller. 
    public Vector3 GetArmDirection() { 
    return controller_.transform.TransformDirection(hand_.Arm.Direction.ToUnity(mirror_z_axis_)); 
    } 

    // Returns the lower arm center in relation to the controller. 
    public Vector3 GetArmCenter() { 
    Vector leap_center = 0.5f * (hand_.Arm.WristPosition + hand_.Arm.ElbowPosition); 
    return controller_.transform.TransformPoint(leap_center.ToUnityScaled(mirror_z_axis_)) + 
      GetHandOffset(); 
    } 

    // Returns the lower arm elbow position in relation to the controller. 
    public Vector3 GetElbowPosition() { 
    Vector3 local_position = hand_.Arm.ElbowPosition.ToUnityScaled(mirror_z_axis_); 
    return controller_.transform.TransformPoint(local_position) + GetHandOffset(); 
    } 

    // Returns the lower arm wrist position in relation to the controller. 
    public Vector3 GetWristPosition() { 
    Vector3 local_position = hand_.Arm.WristPosition.ToUnityScaled(mirror_z_axis_); 
    return controller_.transform.TransformPoint(local_position) + GetHandOffset(); 
    } 

    // Returns the rotation quaternion of the arm in relation to the controller. 
    public Quaternion GetArmRotation() { 
    Quaternion local_rotation = hand_.Arm.Basis.Rotation(mirror_z_axis_); 
    return controller_.transform.rotation * local_rotation; 
    } 

    public Hand GetLeapHand() { 
    return hand_; 
    } 

    public void SetLeapHand(Hand hand) { 
    hand_ = hand; 
    for (int i = 0; i < fingers.Length; ++i) { 
     if (fingers[i] != null) { 
     fingers[i].SetLeapHand(hand_); 
     fingers[i].SetOffset(GetHandOffset()); 
     } 
    } 
    } 

    public void MirrorZAxis(bool mirror = true) { 
    mirror_z_axis_ = mirror; 
    for (int i = 0; i < fingers.Length; ++i) { 
     if (fingers[i] != null) 
     fingers[i].MirrorZAxis(mirror); 
    } 
    } 

    public bool IsMirrored() { 
    return mirror_z_axis_; 
    } 

    public HandController GetController() { 
    return controller_; 
    } 

    public void SetController(HandController controller) { 
    controller_ = controller; 
    for (int i = 0; i < fingers.Length; ++i) { 
     if (fingers[i] != null) 
     fingers[i].SetController(controller_); 
    } 
    } 

    public abstract void InitHand(); 

    public abstract void UpdateHand(); 
} 

Имею некоторые проблемы с моим синтаксисом, поскольку я новичок.

Thanks

+0

Вы хотите использовать Leapmotion для передвижения персонажей? –

+0

да я делаю ...... –

+0

Можете ли вы снять мне электронное письмо по адресу [email protected]? Я был бы рад связать вас с одним из наших инженеров Unity. –

ответ

0

Я не уверен, могу ли я полностью понять ваш вопрос. Но если вы хотите преобразовать данные в скелет, то увидите этот код.

// using Mesh, a custom class of mine 
public List<GeometryModel3D> drawLeftHand(Hand hand) { 
     List<GeometryModel3D> list = new List<GeometryModel3D>(); 
     for (int i = 0; i < hand.Fingers.Count; i++) 
     { 
      // material = materials[i]; 
      Finger finger = hand.Fingers[i]; 
      List<Bone> allBones = new List<Bone>(); 

      Bone _m = finger.Bone(Leap.Bone.BoneType.TYPE_METACARPAL); 
      Bone _pp = finger.Bone(Leap.Bone.BoneType.TYPE_PROXIMAL); 
      Bone _ip = finger.Bone(Leap.Bone.BoneType.TYPE_INTERMEDIATE); 
      Bone _dp = finger.Bone(Leap.Bone.BoneType.TYPE_DISTAL); 
      allBones.Add(_m); 
      allBones.Add(_pp); 
      allBones.Add(_ip); 
      allBones.Add(_dp); 

      for (int j = 0; j < allBones.Count; j++) 
      { 
       material = materials[j]; 
       if (allBones[j].IsValid) 
       { 
        Vector before = allBones[j].PrevJoint; 

        GeometryModel3D sphere = new GeometryModel3D(mesh.createSphere(new Point3D(before.x, before.y, before.z)), material); 
        list.Add(sphere); 
        Vector after = allBones[j].NextJoint; 
        GeometryModel3D cylinder = new GeometryModel3D(mesh.createCylinder(new Point3D(before.x, before.y, before.z), new Point3D(after.x, after.y, after.z)), material); 
          list.Add(cylinder); 

          if (j == allBones.Count - 1) 
          { 
           Vector last = allBones[j].NextJoint; 
           GeometryModel3D _sphere = new GeometryModel3D(mesh.createSphere(new Point3D(last.x, last.y, last.z)), material); 
           list.Add(_sphere); 
          }  
       } 
      } 
     } 
     return list; 
    } 

Дело в том, чтобы привести в порядок каждую пару суставов и соединить их с костью, чтобы иметь что-то вроде O-о-о-о

Я не могу разделить весь мой проект еще. Я скоро это сделаю. Но если у вас есть какие-либо вопросы, не стесняйтесь спрашивать.