protected void transformFrame(Frame source, Frame dest, bool resampleTemporalWarping = true) { LeapTransform leapTransform; if (_temporalWarping != null) { if (resampleTemporalWarping) { _temporalWarping.TryGetWarpedTransform(LeapVRTemporalWarping.WarpedAnchor.CENTER, out warpedPosition, out warpedRotation, source.Timestamp); warpedRotation = warpedRotation * transform.localRotation; } leapTransform = new LeapTransform(warpedPosition.ToVector(), warpedRotation.ToLeapQuaternion(), transform.lossyScale.ToVector() * 1e-3f); leapTransform.MirrorZ(); } else { leapTransform = transform.GetLeapMatrix(); } // My Modifications Start---> // leapTransform.MirrorX(); //leapTransform.translation = new Vector(0.5f,0.6f,0.7f); // My Modifications End---> dest.CopyFrom(source).Transform(leapTransform); }
public void transformFrame(Frame source, Frame dest) { LeapTransform leapTransform; _temporalWarping = null; ////////////////////////////////////////////// // 细细研究这个问题 弄清楚是为什么 ///////////////////////////////////////////// if (_temporalWarping != null) { Vector3 warpedPosition; Quaternion warpedRotation; _temporalWarping.TryGetWarpedTransform(LeapVRTemporalWarping.WarpedAnchor.CENTER, out warpedPosition, out warpedRotation, source.Timestamp); warpedRotation = warpedRotation * transform.localRotation; leapTransform = new LeapTransform(warpedPosition.ToVector(), warpedRotation.ToLeapQuaternion(), transform.lossyScale.ToVector() * 1e-3f); leapTransform.MirrorZ(); } else { leapTransform = transform.GetLeapMatrix(); } dest.CopyFrom(source).Transform(leapTransform); }
protected void updateIfTransformMoved(Frame source, ref Frame toUpdate) { if (transform.hasChanged) { _transformedFixedFrame = null; _transformedUpdateFrame = null; transform.hasChanged = false; } if (toUpdate == null) { LeapTransform leapTransform; if (_temporalWarping != null) { Vector3 warpedPosition; Quaternion warpedRotation; _temporalWarping.TryGetWarpedTransform(LeapVRTemporalWarping.WarpedAnchor.CENTER, out warpedPosition, out warpedRotation, source.Timestamp); warpedRotation = warpedRotation * transform.localRotation; leapTransform = new LeapTransform(warpedPosition.ToVector(), warpedRotation.ToLeapQuaternion(), transform.lossyScale.ToVector() * 1e-3f); leapTransform.MirrorZ(); } else { leapTransform = transform.GetLeapMatrix(); } toUpdate = source.TransformedCopy(leapTransform); } }
/** * Extracts a transform matrix containing translation, rotation, and scale from a Unity Transform object and * returns a Leap Motion LeapTransform object. * Use this matrix to transform Leap Motion tracking data to the Unity world relative to the * specified transform. * * In addition to applying the translation, rotation, and scale from the Transform object, the returned * transformation changes the coordinate system from right- to left-handed and converts units from millimeters to meters * by scaling. * @returns A Leap.LeapTransform object representing the specified transform from Leap Motion into Unity space. */ public static LeapTransform GetLeapMatrix(this Transform t) { Vector scale = new Vector(t.lossyScale.x * MM_TO_M, t.lossyScale.y * MM_TO_M, t.lossyScale.z * MM_TO_M); LeapTransform transform = new LeapTransform(t.position.ToVector(), t.rotation.ToLeapQuaternion(), scale); transform.MirrorZ(); // Unity is left handed. return(transform); }
public static LeapTransform GetLeapTransform(Vector3 position, Quaternion rotation) { Vector scale = new Vector(MM_TO_M, MM_TO_M, MM_TO_M); // Leap units -> Unity units. LeapTransform transform = new LeapTransform(position.ToVector(), rotation.ToLeapQuaternion(), scale); transform.MirrorZ(); // Unity is left handed. return(transform); }
protected void updateIfTransformMoved(Frame source, ref Frame toUpdate) { if (transform.hasChanged) { _transformedFixedFrame = null; _transformedUpdateFrame = null; transform.hasChanged = false; //Debug.Log("has changed "); } if (toUpdate == null) { LeapTransform leapTransform; if (_temporalWarping != null) { Vector3 warpedPosition; Quaternion warpedRotation; _temporalWarping.TryGetWarpedTransform(LeapVRTemporalWarping.WarpedAnchor.CENTER, out warpedPosition, out warpedRotation, source.Timestamp); warpedRotation = warpedRotation * transform.localRotation; leapTransform = new LeapTransform(warpedPosition.ToVector(), warpedRotation.ToLeapQuaternion(), transform.lossyScale.ToVector() * 1e-3f); leapTransform.MirrorZ(); } else { leapTransform = transform.GetLeapMatrix(); //Debug.Log("This is the transforme" + leapTransform.translation); } // Debug.Log("This is the source" + source); //toUpdate = source.TransformedCopy(leapTransform); try { toUpdate = source.TransformedCopy(leapTransform); //Debug.Log(webController.Frame()); //toUpdate = source.TransformedCopy(leapTransform); } catch (Exception e) { //Debug.Log("leaptransform " + transform); Debug.Log("Type: " + e + "Message: " + e.Message + " stacktrace:" + e.StackTrace); } //toUpdate = webController.Frame().TransformedCopy(leapTransform); } }
protected void transformHands(ref LeapTransform LeftHand, ref LeapTransform RightHand) { LeapTransform leapTransform; if (_temporalWarping != null) { leapTransform = new LeapTransform(warpedPosition.ToVector(), warpedRotation.ToLeapQuaternion(), transform.lossyScale.ToVector() * 1e-3f); leapTransform.MirrorZ(); } else { leapTransform = transform.GetLeapMatrix(); } LeftHand = new LeapTransform(leapTransform.TransformPoint(LeftHand.translation), leapTransform.TransformQuaternion(LeftHand.rotation)); RightHand = new LeapTransform(leapTransform.TransformPoint(RightHand.translation), leapTransform.TransformQuaternion(RightHand.rotation)); }
public void Start() { _settings = LeapSettings.Get(DataDir); _xform = new LeapTransform(Vector.Zero, LeapQuaternion.Identity, new Vector(MillimetersToMeters, MillimetersToMeters, MillimetersToMeters)); _xform.MirrorZ(); _controller = new Controller(); _controller.Connect += HandleLeapConnected; _controller.Disconnect += HandleLeapDisconnected; _controller.StartConnection(); var tickRate = _settings.UpdateRate_ms; if (tickRate <= 0) { tickRate = LeapSettings.Defaults().UpdateRate_ms; } _timer = new Timer(HandleTimerTick, null, 0, tickRate); }
protected Frame getTransformedFrame(Frame source) { LeapTransform leapTransform; if (_temporalWarping != null) { Vector3 warpedPosition; Quaternion warpedRotation; _temporalWarping.TryGetWarpedTransform(LeapVRTemporalWarping.WarpedAnchor.CENTER, out warpedPosition, out warpedRotation, source.Timestamp); warpedRotation = warpedRotation * transform.localRotation; leapTransform = new LeapTransform(warpedPosition.ToVector(), warpedRotation.ToLeapQuaternion(), transform.lossyScale.ToVector() * 1e-3f); leapTransform.MirrorZ(); } else { leapTransform = transform.GetLeapMatrix(); } return(source.TransformedCopy(leapTransform)); }
/** * Extracts a transform matrix containing translation, rotation, and scale from a Unity Transform object and * returns a Leap Motion LeapTransform object. * Use this matrix to transform Leap Motion tracking data to the Unity world relative to the * specified transform. * * In addition to applying the translation, rotation, and scale from the Transform object, the returned * transformation changes the coordinate system from right- to left-handed and converts units from millimeters to meters * by scaling. * @returns A Leap.LeapTransform object representing the specified transform from Leap Motion into Unity space. */ public static LeapTransform GetLeapMatrix(this Transform t) { Vector scale = new Vector(t.lossyScale.x * MM_TO_M, t.lossyScale.y * MM_TO_M, t.lossyScale.z * MM_TO_M); LeapTransform transform = new LeapTransform(t.position.ToVector(), t.rotation.ToLeapQuaternion(), scale); transform.MirrorZ(); // Unity is left handed. return transform; }
protected void transformFrame(Frame source, Frame dest) { LeapTransform leapTransform; if (_temporalWarping != null) { Vector3 warpedPosition; Quaternion warpedRotation; _temporalWarping.TryGetWarpedTransform(LeapVRTemporalWarping.WarpedAnchor.CENTER, out warpedPosition, out warpedRotation, source.Timestamp); warpedRotation = warpedRotation * transform.localRotation; leapTransform = new LeapTransform(warpedPosition.ToVector(), warpedRotation.ToLeapQuaternion(), transform.lossyScale.ToVector() * 1e-3f); leapTransform.MirrorZ(); } else { leapTransform = transform.GetLeapMatrix(); } dest.CopyFrom(source).Transform(leapTransform); }