/** * Construct a controller instance given an InteractionBehavior object. * @since 4.1.4 */ public static T CreateInstance <T>(InteractionBehaviour obj) where T : IControllerBase { T controller = CreateInstance <T>(); controller.Init(obj); return(controller); }
/** Initializes the controller based on the object settings. */ protected override void Init(InteractionBehaviour obj) { base.Init(obj); _maxVelocitySqrd = _maxVelocity * _obj.Manager.SimulationScale; _maxVelocitySqrd *= _maxVelocitySqrd; }
private void OnValidate() { if (intObj == null) { intObj = GetComponent <InteractionBehaviour>(); } }
private void Reset() { if (intObj == null) { intObj = GetComponent <InteractionBehaviour>(); } }
protected override void Init(InteractionBehaviour obj) { base.Init(obj); _handIdToPoints = new Dictionary <int, HandPointCollection>(); KabschC.Construct(ref _kabsch); }
/// <summary> /// Samples the current velocity and adds it to a rolling average. /// </summary> public void OnHold(InteractionBehaviour intObj, ReadonlyList <InteractionController> controllers) { _velocityQueue.Enqueue(new VelocitySample(intObj.rigidbody.position, intObj.rigidbody.rotation, Time.fixedTime)); while (true) { VelocitySample oldestVelocity = _velocityQueue.Peek(); // Dequeue conservatively if the oldest velocity is more than 4 frames later // than the start of the window. if (oldestVelocity.time + (Time.fixedDeltaTime * 4) < Time.fixedTime - _windowLength - _windowDelay) { _velocityQueue.Dequeue(); } else { break; } } }
public KabschGraspedPose(InteractionBehaviour interactionObj) { _intObj = interactionObj; _kabsch = new KabschSolver(); _points = new List <Vector3>(20); _refPoints = new List <Vector3>(20); _controllerToPoints = new Dictionary <InteractionController, PosePointCollection>(); }
protected override void Init(InteractionBehaviour obj) { base.Init(obj); _handIdToPoints = new Dictionary <int, HandPointCollection>(); _kabsch = new KabschSolver(); points = new List <Vector3>(20); refPoints = new List <Vector3>(20); }
/// <summary> /// Transfers the averaged velocity to the released object. /// </summary> public void OnThrow(InteractionBehaviour intObj, InteractionController throwingController) { if (_velocityQueue.Count < 2) { intObj.rigidbody.velocity = Vector3.zero; intObj.rigidbody.angularVelocity = Vector3.zero; return; } float windowEnd = Time.fixedTime - _windowDelay; float windowStart = windowEnd - _windowLength; // 0 occurs before 1, // start occurs before end. VelocitySample start0, start1; VelocitySample end0, end1; VelocitySample s0, s1; s0 = s1 = start0 = start1 = end0 = end1 = _velocityQueue.Dequeue(); while (_velocityQueue.Count != 0) { s0 = s1; s1 = _velocityQueue.Dequeue(); if (s0.time < windowStart && s1.time >= windowStart) { start0 = s0; start1 = s1; } if (s0.time < windowEnd && s1.time >= windowEnd) { end0 = s0; end1 = s1; // We have assigned both start and end and can break out of the loop. _velocityQueue.Clear(); break; } } VelocitySample start = VelocitySample.Interpolate(start0, start1, windowStart); VelocitySample end = VelocitySample.Interpolate(end0, end1, windowEnd); Vector3 interpolatedVelocity = PhysicsUtility.ToLinearVelocity(start.position, end.position, _windowLength); intObj.rigidbody.velocity = interpolatedVelocity; intObj.rigidbody.angularVelocity = PhysicsUtility.ToAngularVelocity(start.rotation, end.rotation, _windowLength); intObj.rigidbody.velocity *= _velocityMultiplierCurve.Evaluate(intObj.rigidbody.velocity.magnitude); }
public void MoveTo(Vector3 solvedPosition, Quaternion solvedRotation, InteractionBehaviour interactionObj, bool justGrasped) { //interactionObj.rigidbody.MovePosition(solvedPosition); //interactionObj.rigidbody.MoveRotation(solvedRotation); interactionObj.rigidbody.transform.position = solvedPosition; interactionObj.rigidbody.transform.rotation = solvedRotation; interactionObj.rigidbody.position = solvedPosition; interactionObj.rigidbody.rotation = solvedRotation; }
public ControllerContainer(InteractionBehaviour obj, InteractionMaterial material) { _material = material; _holdingPoseController = new DefinableController <IHoldingPoseController>(_material.CreateHoldingPoseController(obj)); _layerController = new DefinableController <ILayerController>(_material.CreateLayerController(obj)); _moveToController = new DefinableController <IMoveToController>(_material.CreateMoveToController(obj)); _suspensionController = new DefinableController <ISuspensionController>(_material.CreateSuspensionController(obj)); _throwingController = new DefinableController <IThrowingController>(_material.CreateThrowingController(obj)); }
public void MoveTo(Vector3 solvedPosition, Quaternion solvedRotation, InteractionBehaviour interactionObj, bool justGrasped) { interactionObj.rigidbody.MovePosition(solvedPosition); interactionObj.rigidbody.MoveRotation(solvedRotation); // Store the target position and rotation to prevent slippage in SwapGrasp // scenarios. interactionObj.latestScheduledGraspPose = new Pose(solvedPosition, solvedRotation); }
private void refreshInteractionBehaviour() { interactionBehaviour = GetComponent <InteractionBehaviour>(); _interactionBehaviourIsNull = interactionBehaviour == null; detachWhenGrasped = !_interactionBehaviourIsNull; if (_interactionBehaviourIsNull) { useTrajectory = false; } }
/** * Construct a controller instance given an InteractionBehavior object and another instance * to use as a template. * @since 4.1.4 */ public static T CreateInstance <T>(InteractionBehaviour obj, T template) where T : IControllerBase { if (template == null) { return(null); } T controller = Instantiate(template); controller.Init(obj); return(controller); }
void Start() { _intObj = GetComponent <InteractionBehaviour>(); Renderer renderer = GetComponent <Renderer>(); if (renderer == null) { renderer = GetComponentInChildren <Renderer>(); } if (renderer != null) { _material = renderer.material; } }
public void MoveTo(Vector3 solvedPosition, Quaternion solvedRotation, InteractionBehaviour intObj, bool justGrasped) { Vector3 solvedCenterOfMass = solvedRotation * intObj.rigidbody.centerOfMass + solvedPosition; Vector3 currCenterOfMass = intObj.rigidbody.rotation * intObj.rigidbody.centerOfMass + intObj.rigidbody.position; Vector3 targetVelocity = PhysicsUtility.ToLinearVelocity(currCenterOfMass, solvedCenterOfMass, Time.fixedDeltaTime); Vector3 targetAngularVelocity = PhysicsUtility.ToAngularVelocity(intObj.rigidbody.rotation, solvedRotation, Time.fixedDeltaTime); // Clamp targetVelocity by _maxVelocity. float maxScaledVelocity = _maxVelocity * intObj.manager.SimulationScale; float targetSpeedSqrd = targetVelocity.sqrMagnitude; if (targetSpeedSqrd > maxScaledVelocity * maxScaledVelocity) { float targetPercent = maxScaledVelocity / Mathf.Sqrt(targetSpeedSqrd); targetVelocity *= targetPercent; targetAngularVelocity *= targetPercent; } float followStrength = 1F; if (!justGrasped) { float remainingDistanceLastFrame = Vector3.Distance(_lastSolvedCoMPosition, currCenterOfMass); followStrength = _strengthByDistance.Evaluate(remainingDistanceLastFrame / intObj.manager.SimulationScale); } Vector3 lerpedVelocity = Vector3.Lerp(intObj.rigidbody.velocity, targetVelocity, followStrength); Vector3 lerpedAngularVelocity = Vector3.Lerp(intObj.rigidbody.angularVelocity, targetAngularVelocity, followStrength); intObj.rigidbody.velocity = lerpedVelocity; intObj.rigidbody.angularVelocity = lerpedAngularVelocity; _lastSolvedCoMPosition = solvedCenterOfMass; // Store the target position and rotation to prevent slippage in SwapGrasp // scenarios. intObj.latestScheduledGraspPose = new Pose(solvedPosition, solvedRotation); }
void Start() { interactionBehaviour = GetComponent <Leap.Unity.Interaction.InteractionBehaviour>(); // 悬停事件 interactionBehaviour.OnHoverBegin = () => { Debug.Log("刚开始悬停..."); }; interactionBehaviour.OnHoverStay = () => { //Debug.Log("悬停保持中..."); }; interactionBehaviour.OnHoverEnd = () => { Debug.Log("悬停结束"); }; // 抓取事件 interactionBehaviour.OnGraspBegin = () => { Debug.Log("抓取开始..."); }; interactionBehaviour.OnGraspStay = () => { // Debug.Log("抓取保持..."); }; interactionBehaviour.OnGraspEnd = () => { Debug.Log("抓取结束..."); }; // 触击事件 interactionBehaviour.OnContactBegin = () => { Debug.Log("开始触击.."); }; interactionBehaviour.OnContactStay = () => { // Debug.Log("保持触击.."); }; interactionBehaviour.OnContactEnd = () => { Debug.Log("触击结束"); }; }
public void MoveTo(Vector3 solvedPosition, Quaternion solvedRotation, InteractionBehaviour intObj, bool justGrasped) { Vector3 targetVelocity = PhysicsUtility.ToLinearVelocity(intObj.rigidbody.position, solvedPosition, Time.fixedDeltaTime); Vector3 targetAngularVelocity = PhysicsUtility.ToAngularVelocity(intObj.rigidbody.rotation, solvedRotation, Time.fixedDeltaTime); // Clamp by _maxVelocity. float maxScaledVelocity = _maxVelocity * intObj.manager.SimulationScale; float targetSpeedSqrd = targetVelocity.sqrMagnitude; if (targetSpeedSqrd > maxScaledVelocity * maxScaledVelocity) { float targetPercent = maxScaledVelocity / Mathf.Sqrt(targetSpeedSqrd); targetVelocity *= targetPercent; targetAngularVelocity *= targetPercent; } _useLastSolvedPosition = !justGrasped; float followStrength = 1F; if (_useLastSolvedPosition) { float remainingDistanceLastFrame = Vector3.Distance(_lastSolvedPosition, intObj.rigidbody.position); followStrength = _strengthByDistance.Evaluate(remainingDistanceLastFrame / intObj.manager.SimulationScale); } Vector3 lerpedVelocity = Vector3.Lerp(intObj.rigidbody.velocity, targetVelocity, followStrength); Vector3 lerpedAngularVelocity = Vector3.Lerp(intObj.rigidbody.angularVelocity, targetAngularVelocity, followStrength); Vector3 centerOfMassOffset = intObj.rigidbody.rotation * intObj.rigidbody.centerOfMass; intObj.rigidbody.velocity = lerpedVelocity + Vector3.Cross(lerpedAngularVelocity, centerOfMassOffset); intObj.rigidbody.angularVelocity = lerpedAngularVelocity; _lastSolvedPosition = solvedPosition; }
protected override void Init(InteractionBehaviour obj) { base.Init(obj); _renderers = obj.GetComponentsInChildren <Renderer>(); }
/** * Constructs an instance of the material's LayerController implementation * for an instance of an InteractionBehavior. * @since 4.1.4 */ public ILayerController CreateLayerController(InteractionBehaviour obj) { return(IControllerBase.CreateInstance(obj, _layerController)); }
/** * Constructs an instance of the material's ThrowingController implementation * for an instance of an InteractionBehavior. * @since 4.1.4 */ public IThrowingController CreateThrowingController(InteractionBehaviour obj) { return(IControllerBase.CreateInstance(obj, _throwingController)); }
/** * Constructs an instance of the material's SuspensionController implementation * for an instance of an InteractionBehavior. * @since 4.1.4 */ public ISuspensionController CreateSuspensionController(InteractionBehaviour obj) { return(IControllerBase.CreateInstance(obj, _suspensionController)); }
/** * Constructs an instance of the material's MoveToController implementation * for an instance of an InteractionBehavior. * @since 4.1.4 */ public IMoveToController CreateMoveToController(InteractionBehaviour obj) { return(IControllerBase.CreateInstance(obj, _moveToController)); }
/** * Constructs an instance of the material's HoldingPoseController implementation * for an instance of an InteractionBehavior. * @since 4.1.4 */ public IHoldingPoseController CreateHoldingPoseController(InteractionBehaviour obj) { return(IControllerBase.CreateInstance(obj, _holdingPoseController)); }
protected override void Init(InteractionBehaviour obj) { base.Init(obj); _renderers = obj.GetComponentsInChildren<Renderer>(); }
/** Initializes the controller based on the object settings. */ protected override void Init(InteractionBehaviour obj) { base.Init(obj); _maxVelocitySqrd = _maxVelocity * _obj.Manager.SimulationScale; _maxVelocitySqrd *= _maxVelocitySqrd; }
/** * Initialize the controller given an InteractionBehavior object. * @since 4.1.4 */ protected virtual void Init(InteractionBehaviour obj) { _obj = obj; }
protected override void Init(InteractionBehaviour obj) { base.Init(obj); _handIdToPoints = new Dictionary<int, HandPointCollection>(); KabschC.Construct(ref _kabsch); }