/* * If in auto-update, the function just assigns current filtered value to local position. * Otherwise it inputs the current mouse position to the filter and then assigns filtered value to local position. */ void Update() { if (shouldUseComponent) { if (a != Parameters.a) { a = Parameters.a; mouseControl.SetA(a); } transform.localPosition = mouseControl.Get(); } else { if (a != Parameters.a) { a = Parameters.a; lowPassFilter.A = a; } lowPassFilter.Append(MousePositionWithOffset.GetOffsetMousePosition()); transform.localPosition = lowPassFilter.Get(); // or simply: // transform.localPosition = lowPassFilter.Append(MousePositionWithOffset.GetOffsetMousePosition()); } }
/* * Add points number equal to the square power of distance */ void Update() { float distance = (player.position - pacman.position).magnitude; points += distance * distance / 500.0f; pointsText.text = ((int)(pointsFilter.Append(points))).ToString() + " POINTS"; }
/* * If in auto-update, the function just assigns current filtered value to local position. * Otherwise it inputs the current value to the filter and then assigns filtered value to local position. */ void Update() { if (shouldUseComponent) { transform.localPosition = accelerometerControl.Get(); } else { lowPassFilter.Append(AccelerometerWithOffset.GetOffsetAccelerometerData()); transform.localPosition = lowPassFilter.Get(); // or simply: // transform.localPosition = lowPassFilter.Append(AccelerometerWithOffset.GetOffsetAccelerometerData()); } }
/* * This is the method that passess the input from the input provider to the filter. * It is invoked periodically from the outer class. */ public void Update() { lowPassFilter.Append(lowPassFilterInput.Get()); }
/* * Reset to initial values */ internal void Reset() { points = 0.0f; pointsFilter = new LowPassFilter <float>(alpha, points); pointsText.text = ((int)(pointsFilter.Append(points))).ToString() + " POINTS"; }
void UpdateActiveObjects() { foreach (var bhvr in m_VuMarkManager.GetActiveBehaviours()) { string vuMarkId = GetVuMarkId(bhvr.VuMarkTarget); float xOffset; float yOffset; float zOffset; GameObject associatedObject = FindObjectAndOffsetsForVuMark(vuMarkId, out xOffset, out yOffset, out zOffset); if (associatedObject != null) { associatedObject.SetActive(true); // Position Vector3 vuMarkPosition; if (filterPosition) { if (vuMarkPositionFilters.ContainsKey(vuMarkId)) { LowPassFilter <Vector3> positionFilter = vuMarkPositionFilters[vuMarkId]; vuMarkPosition = positionFilter.Append(bhvr.transform.position); } else { LowPassFilter <Vector3> positionFilter = new LowPassFilter <Vector3>(FILTER_ALPHA, transform.position); vuMarkPositionFilters[vuMarkId] = positionFilter; vuMarkPosition = bhvr.transform.position; } } else { vuMarkPosition = bhvr.transform.position; } vuMarkPosition.x += xOffset; vuMarkPosition.y += yOffset; vuMarkPosition.z += zOffset; associatedObject.transform.position = vuMarkPosition; // Rotation if (adjustRotation) { Quaternion zInverted = Quaternion.AngleAxis(-180.0f, Vector3.up); if (filterRotation) { if (vuMarkRotationFilters.ContainsKey(vuMarkId)) { LowPassFilter <Quaternion> rotationFilter = vuMarkRotationFilters[vuMarkId]; associatedObject.transform.rotation = rotationFilter.Append(bhvr.transform.rotation); } else { LowPassFilter <Quaternion> rotationFilter = new LowPassFilter <Quaternion>(FILTER_ALPHA, bhvr.transform.rotation); vuMarkRotationFilters[vuMarkId] = rotationFilter; associatedObject.transform.rotation = bhvr.transform.rotation; } } else { associatedObject.transform.rotation = bhvr.transform.rotation;// * zInverted; Don't seem to want this } } } else { Debug.Log("ERROR: Can't find object for VuMark: " + vuMarkId); } } }
/* * Move toward the player using filter */ void Update() { transform.position = targetPositionFilter.Append(target.position); }
/* * Move the camera */ void Update() { transform.localPosition = cameraPositionFilter.Append(GetOffsetMousePosition()); }
public void OnTrackablesUpdated() { // -------------------------------------------------------------------------- // Position // Optional low pass filter if (filterPosition) { if (cameraPositionFilter != null) { position = cameraPositionFilter.Append(transform.position); } else { cameraPositionFilter = new LowPassFilter <Vector3>(FILTER_ALPHA, transform.position); position = transform.position; } Debug.Log("position delta = " + (transform.position.x - position.x) + ", " + (transform.position.y - position.y) + ", " + (transform.position.z - position.z)); } else { position = transform.position; } // Optional smoothing if (smoothPosition) { if (smoothingPositions.Count >= smoothingFrames) { smoothingPositions.Dequeue(); } smoothingPositions.Enqueue(position); Vector3 avgp = Vector3.zero; foreach (Vector3 singlePosition in smoothingPositions) { avgp += singlePosition; } position = avgp / smoothingPositions.Count; } //Debug.Log("position = " + position.x + ", " + position.y + ", " + position.z); // -------------------------------------------------------------------------- // ROTATION // Optional low pass filter if (filterPosition) { if (cameraPositionFilter != null) { rotation = cameraRotationFilter.Append(transform.rotation); } else { cameraRotationFilter = new LowPassFilter <Quaternion>(FILTER_ALPHA, transform.rotation); rotation = transform.rotation; } } else { rotation = transform.rotation; } // Optional smoothing if (smoothRotation) { if (smoothingRotations.Count >= smoothingFrames) { smoothingRotations.Dequeue(); } smoothingRotations.Enqueue(rotation); Vector4 avgr = Vector4.zero; foreach (Quaternion singleRotation in smoothingRotations) { Math3d.AverageQuaternion(ref avgr, singleRotation, smoothingRotations.Peek(), smoothingRotations.Count); } rotation = new Quaternion(avgr.x, avgr.y, avgr.z, avgr.w); } }
/* * Smoothly rotate toward the player */ void Update() { transform.localRotation = rotationFilter.Append(Quaternion.LookRotation(negativeZ + target.position - transform.position)); // Z set to negative so the Pacman will rotate the right way (transition going through forward, not backward) }