Log in or register to post comments

Jitter

September 26, 2016 - 1:40am #1

Hi,

I previously had smoothcamera.cs and Mat3d.cs to help with jitter when moving in close to object.

It worked well, but I cannot seem to get remember how to implement it.

Extended tracking works great now, but I still have jitter (5 star target).

Can anyone help with this?

Perhaps a short tutorial?

smoothcamera.cs seems to be in error:

Assets/SmoothCamera.cs(9,21): error CS0234: The type or namespace name `QCARBehaviour' does not exist in the namespace `Vuforia'. Are you missing an assembly reference?

Here is the smoothcamera.cs:

 

using UnityEngine;

using System.Collections;

using System.Collections.Generic;



[RequireComponent(typeof (Vuforia.))]

public class SmoothCamera : MonoBehaviour, Vuforia.ITrackerEventHandler  {



    public int smoothingFrames = 10;

    private Vuforia.qcarBehavior;



    private Quaternion smoothedRotation;

    private Vector3 smoothedPosition;



    private Queue<Quaternion> rotations;

    private Queue<Vector3> positions;



    public void OnInitialized() {

    }



    public void OnTrackablesUpdated() {

        if (rotations.Count >= smoothingFrames) {

            rotations.Dequeue();

            positions.Dequeue();

        }

       

        rotations.Enqueue(transform.rotation);

        positions.Enqueue(transform.position);



        Vector4 avgr = Vector4.zero;

        foreach (Quaternion singleRotation in rotations) {

            Math3d.AverageQuaternion(ref avgr, singleRotation, rotations.Peek(), rotations.Count);

        }



        Vector3 avgp = Vector3.zero;

        foreach (Vector3 singlePosition in positions) {

            avgp += singlePosition;

        }

        avgp /= positions.Count;



        smoothedRotation = new Quaternion(avgr.x, avgr.y, avgr.z, avgr.w);

        smoothedPosition = avgp;

    }



// Use this for initialization

          void Start () {

        rotations = new Queue<Quaternion>(smoothingFrames);

        positions = new Queue<Vector3>(smoothingFrames);

        qcarBehavior = GetComponent<Vuforia.QCARBehaviour>();

       qcarBehavior.RegisterTrackerEventHandler(this);

}



// Update is called once per frame

void LateUpdate () {

        transform.rotation = smoothedRotation;

        transform.position = smoothedPosition;

}



}

 

Log in or register to post comments