/// <summary> /// Integrates curPose's inertia from prevPose to give it bouncy-feeling physics /// while gradually shifting it towards the target pose. /// </summary> private void integratePose(ref Pose curPose, ref Pose prevPose, Pose targetPose, float deltaTime) { // Calculate motion from prevPose to curPose. var deltaPose = curPose.inverse().mul(prevPose); // prevPose in curPose's local space. deltaPose = new Pose(-deltaPose.position, Quaternion.Inverse(deltaPose.rotation)); deltaPose = deltaPose.Lerp(Pose.identity, damping * deltaTime); // Dampen. // Verlet-integrate curPose based on the delta from prevPose. Pose tempPose = curPose; curPose = curPose.mul(deltaPose); prevPose = tempPose; // Pull the integrated hand toward the target a little bit based on stiffness. curPose = curPose.Lerp(targetPose, stiffness * deltaTime); }
private void updateLerp(float t) { this.transform.SetWorldPose(Pose.Lerp(simulator.GetSimulatedPose(), targetPose, t)); // Reset the absolute rotation of the object being simulated; // this adds a lot of rotational "drag" but prevents flips due to the complex // nature of quaternions :\ simulator.SetSimulatedRotation(this.transform.rotation); bool isFinished = t == 1f; if (isFinished) { simulator.StopSimulating(); OnReachTarget(); } OnMovementUpdate(); }
public void Update() { int shadowVal = UIManager.skillManager.cardSelected(definition) ? 1 : 0; Color col = shadow.color; col.a = Mathf.Lerp(0f, .5f, shadowVal); shadow.color = col; if (targetPose.equal(rectTransform)) { return; } Pose current = new Pose(rectTransform); current = Pose.Lerp(current, targetPose, 6.0f * Time.deltaTime); rectTransform.anchoredPosition = current.position; rectTransform.localRotation = current.rotation; rectTransform.localScale = current.scale; rectTransform.pivot = current.pivot; }
public void Step() { UI.PushId("RenderCameraWidget"); UI.Handle("from", ref from, new Bounds(Vec3.One * 0.02f), true); UI.HandleBegin("at", ref at, new Bounds(Vec3.One * 0.02f), true); UI.ToggleAt("On", ref _previewing, new Vec3(4, -2, 0) * U.cm, new Vec2(8 * U.cm, UI.LineHeight)); if (_previewing && UI.ToggleAt("Record", ref _recording, new Vec3(4, -6, 0) * U.cm, new Vec2(8 * U.cm, UI.LineHeight))) { _frameTime = Time.ElapsedUnscaledf; _frameIndex = 0; } UI.HandleEnd(); UI.PopId(); float fov = 10 + Math.Max(0, Math.Min(1, (Vec3.Distance(from.position, at.position) - 0.1f) / 0.2f)) * 110; Vec3 previewAt = at.position + at.orientation * Vec3.Up * 0.06f; Vec3 renderFrom = at.position + (at.position - from.position).Normalized * 0.06f; _renderFrom = Pose.Lerp(_renderFrom, new Pose(renderFrom, Quat.LookDir(at.position - from.position)), Time.Elapsedf * damping); Lines.Add(from.position, at.position, Color.White, 0.005f); from.orientation = at.orientation = Quat.LookDir(from.position - at.position); if (_previewing) { Hierarchy.Push(Matrix.TR(previewAt, Quat.LookAt(previewAt, Input.Head.position))); Default.MeshQuad.Draw(_frameMaterial, Matrix.S(V.XYZ(0.08f * ((float)Width / Height), 0.08f, 1))); Text.Add("" + (int)fov, Matrix.TS(-0.03f, 0, 0, 0.5f), TextAlign.CenterLeft); Hierarchy.Pop(); Renderer.RenderTo(_frameSurface, _renderFrom.ToMatrix(), Matrix.Perspective(fov, (float)Width / Height, 0.01f, 100)); } if (_recording) { SaveFrame(FrameRate); } }
void SetObjectForce() { if (holdingObject == null) { return; } float timeStep = Time.fixedDeltaTime * Application.targetFrameRate; Pose temp = Pose.Lerp(prevPose, pose, timeStep); Vector3 force = holdingObject.mass * model.CalcForce(temp, holdingObject); Vector3 torque = holdingObject.inertiaTensor.magnitude * 4 * model.CalcTorque(temp, holdingObject); if (curMultiHold) { force *= 0.5f; torque *= 0.5f; } holdingObject.AddForce(force); holdingObject.AddTorque(torque); }