Log in or register to post comments

Filter Camera Position and Rotation to avoid jitter?

January 24, 2015 - 8:24pm #71

Would anyone be able to give a step by step on implementation of the Math3d.cs and SmoothCamera.cs scripts in Unity3D?  Would be much obliged!

 

Cheers!

Filter Camera Position and Rotation to avoid jitter?

October 20, 2014 - 12:33am #70

Did u read or apply one on the  https://gist.github.com/jankolkmeier/8543156

posted by jank. Will it help in my case

 

Filter Camera Position and Rotation to avoid jitter?

October 20, 2014 - 12:33am #69

Did u read or apply one on the  https://gist.github.com/jankolkmeier/8543156

posted by jank. Will it help in my case

 

Filter Camera Position and Rotation to avoid jitter?

October 20, 2014 - 12:27am #68

Is there still a need to add additional scripts as detailed in this thread to prevent object jitter?

My app works a treat and I have extended tracking checked but when holding the device perfectly still the object displayed when tracker is found suffers the described jitter.

I don't being to understand the code that has been posted here, but need to clarify is this still required and for example in the case of Track.cs do I attach that to the camera, the image tracker or the object?

Thanks in advance

 

Filter Camera Position and Rotation to avoid jitter?

October 19, 2014 - 11:48pm #67

Sir :)

The solution posted by loic_illogika and DavidBeard for the solution for Filter Camera position an Rotation does the same solution also support for the new SDK 3.0.6 . 

Sir Kindly reply ASAP as i desperately need the solution for it. In my application the Plane is rendered which is much larger than the target and I observe continuous shakes. 

Thanks in advanced and waiting for the reply

Filter Camera Position and Rotation to avoid jitter?

May 13, 2014 - 1:32pm #66

People keep bothering me because the link is down, it moved here: https://gist.github.com/jankolkmeier/8543156

Thank you!

Filter Camera Position and Rotation to avoid jitter?

May 13, 2014 - 11:47am #65

People keep bothering me because the link is down, it moved here: https://gist.github.com/jankolkmeier/8543156

Filter Camera Position and Rotation to avoid jitter?

May 13, 2014 - 3:04am #64

Hey fellas, 

 

Just wondering if there is any more word on this issue?

Filter Camera Position and Rotation to avoid jitter?

February 19, 2014 - 3:48am #63

Thank you very much for this example!

Unfortunately, your solution seems to be interfering with Extended Tracking or some other position operations from the last version of Vuforia - smoothing process interrupts the translation of an object performed by Vuforia and drops it into the center of a screen once the target starts going off screen (often causing trouble with recapturing of the object onto the marker once it returns to the view, too).

As about the suggestion by David to evaluate the use of Extended Tracking as a solution for jitter issues - unfortunately, I'm not getting any perpectible difference, the tracking is still noticeably unreliable even with very good images and modestly sized non-offset meshes, so use of a pose filter is still an absolute necessity.

Filter Camera Position and Rotation to avoid jitter?

January 21, 2014 - 8:56am #62

Thank you very much.

And, the Quaternion Averaging and other math functions are much appreciated.

Filter Camera Position and Rotation to avoid jitter?

January 21, 2014 - 8:33am #61

I needed the same thing. Since a solution was never posted, here is my (hacked, quick, dirty, yadda yadda, ...) implementation:

https://gist.github.com/jouz/8543156

There are two files.

SmoothCamera.cs is the behavior to be attached to the ARCamera (the one with the QCARBehaviour on it). Here you can set the number of past frames to consider (I recommend not to go too high. 2-5 gives already good filtering without introducing too much delay).

Math3d.cs is just a bunch of helper functions, only some of which are actually needed by SmoothCamera.cs (to calculate an average of several Quaternions).

Maybe it helps someone.

Filter Camera Position and Rotation to avoid jitter?

January 17, 2014 - 7:08am #60

Thanks, I'll give that a shot.

Filter Camera Position and Rotation to avoid jitter?

January 17, 2014 - 1:11am #59

You simply need to define a script in which you define a class that implements the ITrackerEventHandler interface;

in there, you need to implement the method OnTrackablesUpdated(), which is called whenever the trackas processed the trackables.

The rest is up to you, but I suggest to consult the API reference, as this will help you to use the right API:

https://developer.vuforia.com/resources/api/unity/index

 

Filter Camera Position and Rotation to avoid jitter?

January 16, 2014 - 1:05pm #58

AlessandroB wrote:

About the pose filtering:

The same functionality could be achieved by using the OnTrackablesUpdated callback of the ITrackerEventHandler (by implementing such interface in a script and registering it in QCARBehaviour).
You would just need to remember the poses of the last n frames and set the trackables to averaged/filtered poses in the callback.
 

I'm a bit of a novice in this area, could you give me an example of how to access the OnTrackablesUpdated callback? I'm not really sure how to do it when everything is in DLLs.

Filter Camera Position and Rotation to avoid jitter?

January 9, 2014 - 11:12am #57
DavidBeard, yes, only apply filters to the pose. Extended Tracking is awesome feature but sometimes this algorithm add to track unstable points such as people or random items that occasionally appear in frame. And position of marker begin to move relative real marker, this simple to simulate by moving near objects. I can record video tommorow.
 
In this case i think one variant is once save "3d points map" as trackable object for latter use.
 
AlessandroB thank you, realy your method easier)

Filter Camera Position and Rotation to avoid jitter?

January 9, 2014 - 10:37am #56

About the pose filtering:

The same functionality could be achieved by using the OnTrackablesUpdated callback of the ITrackerEventHandler (by implementing such interface in a script and registering it in QCARBehaviour).
You would just need to remember the poses of the last n frames and set the trackables to averaged/filtered poses in the callback.
 

Filter Camera Position and Rotation to avoid jitter?

January 9, 2014 - 9:52am #55

Are you referring to the ability to apply filters to the pose, or the ability to extend the extension libraries?

Also have you evaluated the Extended Tracking feature yet? - this should help with large scale augmentations. 

Filter Camera Position and Rotation to avoid jitter?

January 9, 2014 - 9:26am #54

+1 definitely a good thing...

Filter Camera Position and Rotation to avoid jitter?

January 9, 2014 - 9:14am #53

Sorry, can i expect the return of this functionality in the next release? On large image targets it is really needed

Filter Camera Position and Rotation to avoid jitter?

January 9, 2014 - 8:20am #52

Hey dvv,

I had to remove your attachment, as your "recompiled" library may break the Vuforia license....

 

Filter Camera Position and Rotation to avoid jitter?

January 9, 2014 - 7:48am #51
Previous version (2.6.7)  vuforia works with StateManagerImpl.cs
Now with (2.8.7) this code was moved to Qualcomm.Vuforia.UnityExtensions.dll
 
If anybody want this library with simplest filter you can get it from attachments to this post
 
For setup filter you should set StateManagerImpl.isFoundTracker = true; when trackable found;
For adjust strength of filtering use StateManagerImpl.LerpCoef from 0 to 1
 
This library was compiled by mono for NET 3.5
 
Also i post code
 
public static bool isFoundTracker;
	public static float LerpCoef = 0.6f;

    private void PositionCamera(TrackableBehaviour trackableBehaviour, Camera arCamera, QCARManagerImpl.PoseData camToTargetPose)
    {
		//Debug.Log("PositionCam");
		if(isFoundTracker)
		{
			arCamera.transform.localPosition = trackableBehaviour.transform.rotation *
				Quaternion.AngleAxis(90, Vector3.left) *
					Quaternion.Inverse(camToTargetPose.orientation) *
					(-camToTargetPose.position) +
					trackableBehaviour.transform.position;
			
			arCamera.transform.rotation = trackableBehaviour.transform.rotation *
				Quaternion.AngleAxis(90, Vector3.left) *
					Quaternion.Inverse(camToTargetPose.orientation);
			isFoundTracker = false;
			Debug.Log("== SET POSE");
		}
		else
		{
			arCamera.transform.localPosition = Vector3.Lerp(arCamera.transform.localPosition, 
			                                                trackableBehaviour.transform.rotation *
			                                                Quaternion.AngleAxis(90, Vector3.left) *
			                                                Quaternion.Inverse(camToTargetPose.orientation) *
			                                                (-camToTargetPose.position) +
			                                                trackableBehaviour.transform.position, LerpCoef);
			
			arCamera.transform.rotation = Quaternion.Lerp( arCamera.transform.rotation, 
			                                              trackableBehaviour.transform.rotation *
			                                              Quaternion.AngleAxis(90, Vector3.left) *
			                                              Quaternion.Inverse(camToTargetPose.orientation), LerpCoef);
		}
    }

    private void PositionTrackable(TrackableBehaviour trackableBehaviour, Camera arCamera, QCARManagerImpl.PoseData camToTargetPose)
    {
		//Debug.Log("PositionTrackable");
		if(isFoundTracker)
		{
			trackableBehaviour.transform.position = arCamera.transform.TransformPoint(camToTargetPose.position);
			trackableBehaviour.transform.rotation = (arCamera.transform.rotation * camToTargetPose.orientation) * Quaternion.AngleAxis(270f, Vector3.left);
			isFoundTracker = false;
			Debug.Log("== SET POSE");
		}
		else
		{
			trackableBehaviour.transform.position = Vector3.Lerp(trackableBehaviour.transform.position, 
			                                                arCamera.transform.TransformPoint(camToTargetPose.position), LerpCoef);
			
			trackableBehaviour.transform.rotation = Quaternion.Lerp(trackableBehaviour.transform.rotation, 
			                                              (arCamera.transform.rotation * camToTargetPose.orientation) * Quaternion.AngleAxis(270f, Vector3.left), LerpCoef);
		}
    }

 

 

Filter Camera Position and Rotation to avoid jitter?

November 5, 2013 - 8:58am #50

Does the new version of Vuforia use the Tracker.cs and does this low pass filter work?

 

I added the low pass filter stuff to my scripts and I don't get any of the debug messages, no errors and I can adjust the ongui slider but I get no debug statements and it makes no difference, so what has changed in the new version of vuforia vs. the examples at the bottom of this thread?

Filter Camera Position and Rotation to avoid jitter?

September 25, 2013 - 3:10pm #49

I converted my target to a multitarget, dividing the single map image into quadrants and adjusting the XML file manually so they were in the correct positions. On a small scale it does seem to have improved. I'll follow up here when I have tested it large scale.

Filter Camera Position and Rotation to avoid jitter?

September 25, 2013 - 8:56am #48

That may be an issue if the larger target isn't being captured in the camera's field of view when observing the model. Have you tried dividing the target into sections and configuring these as a MultiTarget?

Filter Camera Position and Rotation to avoid jitter?

September 23, 2013 - 8:11pm #47

I know there has been discussion about having a model that is much larger than the target, as well as significantly offset, but could having a model that is much smaller than the target also create jitter?

In the case of my project, the target is a map, so I'm having to use portions of the whole target to track an object specific to that area of the map. However, in another project, where the model is about the same size as the target and you view the entire target in the camera, the jitter is nearly imperceptible. It seems the less tracking information Vuforia has (i.e. the smaller percentage of the whole target that's in view), the more it's prone to make errors in position and rotation tracking. Which is understandable.

Filter Camera Position and Rotation to avoid jitter?

September 20, 2013 - 9:41am #46

Yes I'm referring to the filter in this thread. I haven't had a chance to update this for the current SDK version, but it shouldn't be difficult to do so. If you can send me a video to evaluate, I can advise on whether filtering might help.

Filter Camera Position and Rotation to avoid jitter?

September 18, 2013 - 10:19am #45

Hello @DavidBeard.  Has there been any updates to this?  I was getting ready to implement this in an attempt to smooth things out for us and was hoping for an update.  

Also, I hope this isn't too noob, but in one of your earlier posts you say "Are you deactivating, or modifying the filter strength, while the camera is moving".  I looked through all my cameras and targets and didn't see anything regarding filter strenght.  Are you referring to the values applied to the variables in the smoothing script below?

Thanks!

-Mo

Filter Camera Position and Rotation to avoid jitter?

August 19, 2013 - 4:19pm #44

There will always be some jitter due to the nature of pose estimation, but it can be imperceptible.

One factor affecting jitter is the relative orientation of the plane of the target to that of the camera lense. Pose estimation benefits from some perspective distortion. You'll probably notice that the jitter is worse when the camera is parallel and centered on the target, for example.

Also tall targets will have more jitter than short ones, because their height is equivalent to lateral offset.

What you might try, is to deliberately move the models away fromt the target, and adjust the filter weight to determine if it's having any effect. It may be that there's something wrong and that the script needs to be revised. I'll take a look at it when I have a chance.

Filter Camera Position and Rotation to avoid jitter?

August 19, 2013 - 3:24pm #43

I'm using WCM = FIRST_TARGET, so that should be ok.

I'm using a 5-star target. I have 5 models that are spread across the target evenly, so it's not really an offset issue. 

Basically, if I have the camera stationary and put the target on something stationary, so no phyiscal movement, the AR still jumps around slightly / jitters. Not bad, and pretty consistent with previous AR projects I've done with Vuforia. I was hoping this script would alter it so if nothing is moving, there would be no movement of the AR. Is it unrealistic to expect that?

 

Filter Camera Position and Rotation to avoid jitter?

August 19, 2013 - 3:01pm #42

What's your World Center Mode set to? That script filters the camera position relative to the target, which only occurs if a target serves as the scene origin (e.g. WCM = SPECIFIC_TARGET or FIRST_TARGET.

Also what are you trying to affect? - is your augmentation offset from the center of the target significantly, or is it that you're using a poor target?

Are you seeing a lot of shaking?

 

 

 

 

   
 

 

Filter Camera Position and Rotation to avoid jitter?

August 19, 2013 - 2:23pm #41

Hello-

Forgive me if this is an oversight on my part - my C# skills aren't the strongest. Using Vuforia 2.6.7 with Unity 4

I've cut and paste the code exactly from the 2.x scripts DavidBeard posted. (BTW, you need to add the TEXT_TRACKER to the Type section to avoid an error)

All builds and works well, but I can't see much effect by moving the sliders or updaing the values manually (even when I use extreme values, like damping of 100). I assume doing this should give me drastic results, but if anything changes it's very subtle. I also notice I don't see the output of the Debug.Log statements in the Tracker.cs file. Not in the console of Unity using Play Mode or the output in XCode when building to a device. Should those show up somewhere? I guess I'm concerned the new code is never being run since I never see the log statements.

Thanks for any insight.

dp

Filter Camera Position and Rotation to avoid jitter?

July 19, 2013 - 8:47am #40

I think that you've accurately diagnosed the problem. Filtering may help, but you'll need to experiment w/ the weight of the filter. Are you using Unity or the native iOS SDK?

Though an easier and more reliable approach would be to orient the arrow differently, or use a different model.

Filter Camera Position and Rotation to avoid jitter?

July 17, 2013 - 9:47pm #39

Before you even attempt filtering the pose matrix, can you describe the implementation? - just to determine whether filtering will even help.

Are you seeing shaking because your model is significantly larger than your target, or offset from the target's origin, or is that you are far away from the target?

 

Thanks for the quick reply. I think it's not far away because it happens when the target mostly occupies the screen. Also, as noted on another thread, the effect is lessened if not viewed head-on but at an angle.

I'm not sure if you can say the model is larger than the target, as I did think of something whilewriting this comment. Notably, the target is significantly wider than it is tall. This may be why the target flaps up and down on the y axis, but doesn't really move side-to-side. However, the targets are based on real-world images and I'm not going to get them changed in the course of this project.  

Being offset definitely has something to do with it, as the model currently is a long rectangle that extends straight out from the target (actually an arrow pointing to the target) though by less than the width of the target itself. It is offset y positive positively to be just above the target, centered on X though that could change. Currently, the point of the arrow "on" the target at z=0 mostly stays in place, but the offset side jitters: this exaggerates the jitter and creates the "flapping" effect. 

The flapping happens rapidly, and if it could stay displayed as the average of the range of its jitter, that would be great. Even if they fluttered less rapidly than a few times per second would be great - can you suggest a modification that updates the pose matrix less frequently instead of or in addition to using the average?

In exchagne for the average I'll gladly take the hit in responsiveness - this is new, unfamiliar technology, and I think it's reached an amazing point just recently - and the last message that we want to communicate to users is it's literally "shaky."  Thanks.  

Filter Camera Position and Rotation to avoid jitter?

July 17, 2013 - 4:03pm #38

Before you even attempt filtering the pose matrix, can you describe the implementation? - just to determine whether filtering will even help.

Are you seeing shaking because your model is significantly larger than your target, or offset from the target's origin, or is that you are far away from the target?

Filter Camera Position and Rotation to avoid jitter?

July 17, 2013 - 3:14pm #37

Hi, 

I'm an independent developer working on a Vuforia project for iOS (and Android coming soon) -- really impressed with Vuforia overall by the way -- but encountering this same issue of the violent shaking. 

This is not really my area of expertise, and don't know anything about Unity. Can someone explain how this code (it's C#?) could be adapted into an iOS project? I not asking for it to be rewritten (though I wouldn't object) I just think DavidBeard's code is alot more self-explanatory to some people than to others.  Even just knowing which precise files to modify under iOS and which sections are new would be helpful. 

Or if there's a simpler way, such as just averaging the posematrix directly in renderFrameQCAR. I'll take less optimal results, but I have to do something, right now some flat planes coming straight out of the target on the z axis are flapping like flags in a hurricane. Thanks. 

Filter Camera Position and Rotation to avoid jitter?

May 15, 2013 - 10:58am #36

Thanks for posting it !

What kind of improvements did you do? 

Filter Camera Position and Rotation to avoid jitter?

April 5, 2013 - 8:31pm #35

Here is my way to smooth/dump QCAR's Harlem Shake :)

1. Edit method PositionCamera in StateManagerImpl.cs (code below. dont forget the bool)

http://clip2net.com/s/4RYwku (Pic)

http://pastebin.com/c34xGen4 (Code)

2. In DefaultTrackableEventHandler.cs in method OnTrackerFound add this line StateManagerImpl.isFoundTracker = true; (http://clip2net.com/s/4RYxfL)

   private void OnTrackingFound()
    {
		StateManagerImpl.isFoundTracker = true;
        Renderer[] rendererComponents = GetComponentsInChildren<Renderer>();
        Collider[] colliderComponents = GetComponentsInChildren<Collider>();
.........

3. In QCARBehaviour.cs declare two vars and assign lerpCoef to LerpCoef in Awake method

	public float lerpCoef = .4f;
	public static float LerpCoef = .4f;

 

	void Awake()
	{
		LerpCoef = lerpCoef;
	}

Then you can configure the smooth coefficient as you like in Inspector of ARCamera (http://clip2net.com/s/4RYzZC)

AttachmentSize
Binary Data bytes

Filter Camera Position and Rotation to avoid jitter?

March 2, 2013 - 11:36pm #34

Good question,

I didn't try, maybe DavidBeard can answer to this question.

Filter Camera Position and Rotation to avoid jitter?

March 2, 2013 - 2:47pm #33

loic_illogika - your method has been very useful. I had to pump up the values quite a bit for my situation (deltaPosition = .0745f, deltaPositionRotation = 45f, dampingTime = 4.05f), but the damping helps.

However, useful as it might be, it doesn't completely meet the needs for my specific project since I'm using multiple targets. Can you point me in the right direction as to how I could change the code to accomodate damping of the targets, and not the camera?

Filter Camera Position and Rotation to avoid jitter?

February 23, 2013 - 9:15am #32

Thank you (loic_illogika) very much for your support. Highly appriciate. I will try to do the code with your clue. I am opening a new thread for this topic. Looking forward for your support. It will be better if I can have a sample segement of code to have a clear idea. 

 

https://developer.vuforia.com/forum/general-discussion/how-get-camera-rotation-according-tracker

Please follow the link and help me on this when you have time. 
Thank in advance.

Filter Camera Position and Rotation to avoid jitter?

February 23, 2013 - 6:08am #31

Hi,

the tracker is not rotating, it's the camera rotating around the tracker. So get the transform.eulerAngles.y to get the actual rotation.

But this question is off-topic, create a new thread if you want a better answer.

Filter Camera Position and Rotation to avoid jitter?

February 23, 2013 - 12:51am #30

 

Hi,

I did many researches but I couldn’t find a proper answer. Is there a way to get the tracker rotation angles? I need to display several different images based on the tracker angle.
For example: In 0 degrees one image and in 10 degrees another image and it goes on...
For that I need to get the tracker rotation. Please acknowledge me on how to get the tracker angle, either from JAVA Android code or from C# code.
It will be great if this can be achieved by Java Android code, But even C# code also would be fine. 
Thanks in advance.

Amal.

Filter Camera Position and Rotation to avoid jitter?

February 13, 2013 - 8:35am #29

I have up until now - I thought it was going crazy because of the axes alignment - but looks like it was the other way around - the noise causing axes alignment, not the alignment causing the noise.

Filter Camera Position and Rotation to avoid jitter?

February 13, 2013 - 8:28am #28

Sir :)

And no, I never had gimbal lock issues, but it could happen I guess because there is a conversion from a Vector3 to a Quaternion.
Honestly I made this little code when I joined the game dev industry a year ago and I'm sure now I can do better (without using any Vector3 for example).

But I tried it this morning and it works very well, mostly when you have objects far away from the center.

 

How about you, have you run into gimbal lock issues?

Filter Camera Position and Rotation to avoid jitter?

February 13, 2013 - 8:23am #27

Auww yess, that last bit is what the fix needed to make it work.

Thank you sir or madam, that script's a gem. Tell me, however...have you run into any gimbal lock issues?

Filter Camera Position and Rotation to avoid jitter?

February 13, 2013 - 6:46am #26

Double post.

Filter Camera Position and Rotation to avoid jitter?

February 13, 2013 - 6:44am #25

Hi guys,

I tried to implement this feature into the new version of the plugin.
It works pretty well, but I'm using user target mode, so I needed to change another script that do exactly the same thing (duplicated code :D), this is script is StateManagerImpl.cs.

You have the same function, called PositionCamera, that you need to change. Copy paste the function from the script Tracker.cs (don't forget variables !), and it will work.

I don't know if it's only related to user target mode, I don't really have the time now to test it right now.

Loic.

Filter Camera Position and Rotation to avoid jitter?

February 3, 2013 - 7:43pm #24

This week I've to update an old project to vuforia 2.0, I'll tell you,

thanks !

Filter Camera Position and Rotation to avoid jitter?

February 3, 2013 - 2:14pm #23

I've updated your scripts for the 2.0 API. Please test them to confirm that they are behaving as expected.

 

Tracker.cs

/*==============================================================================
Copyright (c) 2010-2012 QUALCOMM Austria Research Center GmbH.
All Rights Reserved.
Qualcomm Confidential and Proprietary
==============================================================================*/

using UnityEngine;

/// <summary>
/// The common base class for the ImageTracker and the MarkerTracker
/// </summary>
public abstract class Tracker
{
    #region NESTED

    /// <summary>
    /// Enumeration of the different tracker types
    /// </summary>
    public enum Type
    {
        IMAGE_TRACKER,    // Tracks ImageTargets and MultiTargets
        MARKER_TRACKER    // Tracks Markers
    }

    #endregion // NESTED

   #region PRIVATE _MEMBERS
   
   private Vector3 previousTrackPosition, previousTrackerOrientation, currentTrackPosition, currentTrackPositionRef;
   private float currentTrackOrientationX, currentTrackOrientationY, currentTrackOrientationZ, currentTrackOrientationXRef, currentTrackOrientationYRef, currentTrackOrientationZRef, acceleration = 0f, deltaPositionRef;
   private bool firstCall = true;
	
   #endregion
	
   #region PUBLIC_MEMBERS
   
   [HideInInspector]
   public float deltaPosition = .5f, deltaPositionRotation = 5f, dampingTime = .5f;
   
   #endregion

    #region PUBLIC_METHODS

    /// <summary>
    /// Starts the Tracker
    /// </summary>
    public abstract bool Start();

    /// <summary>
    /// Stops the Tracker
    /// </summary>
    public abstract void Stop();

    #endregion // PUBLIC_METHODS



    #region PROTECTED_METHODS

    // Position the camera relative to a Trackable
    protected void PositionCamera(TrackableBehaviour trackableBehaviour,
                                  Camera arCamera,
                                  QCARManagerImpl.PoseData camToTargetPose)
    {
      //First call of this function, init variables
      if(firstCall)
      {
         firstCall = false;
         previousTrackPosition = camToTargetPose.position;
         currentTrackPosition = previousTrackPosition;
         previousTrackerOrientation = camToTargetPose.orientation.eulerAngles;
         currentTrackOrientationX = previousTrackerOrientation.x;
         currentTrackOrientationY = previousTrackerOrientation.y;
         currentTrackOrientationZ = previousTrackerOrientation.z;
      }
      
      //If the position limit is reached, update the new position target
      if(Mathf.Abs (Vector3.Magnitude(camToTargetPose.position - previousTrackPosition)) > deltaPosition)
      {
         //And update the acceleration
         acceleration += (Mathf.Sign(Vector3.Magnitude(camToTargetPose.position - previousTrackPosition)) * deltaPosition * 100f);
         previousTrackPosition = camToTargetPose.position;
      }
      //Same for rotation
      if(Mathf.Abs (Vector3.Magnitude(camToTargetPose.orientation.eulerAngles - previousTrackerOrientation)) > deltaPositionRotation)
      {
         previousTrackerOrientation = camToTargetPose.orientation.eulerAngles;
      }
      
      Debug.Log("deltaPosition : " + Mathf.Abs (Vector3.Magnitude(camToTargetPose.position - previousTrackPosition)) + " dampingTime:" + (dampingTime / acceleration)); 
      Debug.Log( " previousTrackPosition :" + previousTrackPosition + "\npreviousTrackerOrientation:" + previousTrackerOrientation);
      
      //smoothdamping values with the actual value of position / rotation and the target
      currentTrackPosition = Vector3.SmoothDamp(currentTrackPosition, previousTrackPosition, ref currentTrackPositionRef, dampingTime / acceleration);
      currentTrackOrientationX = Mathf.SmoothDampAngle(currentTrackOrientationX, previousTrackerOrientation.x, ref currentTrackOrientationXRef,dampingTime / acceleration);
      currentTrackOrientationY = Mathf.SmoothDampAngle(currentTrackOrientationY, previousTrackerOrientation.y, ref currentTrackOrientationYRef,dampingTime / acceleration);
      currentTrackOrientationZ = Mathf.SmoothDampAngle(currentTrackOrientationZ, previousTrackerOrientation.z, ref currentTrackOrientationZRef,dampingTime / acceleration);
      
      //Create a quaternion from the the actual deg values
      Quaternion orientation = Quaternion.identity;
      orientation.eulerAngles = new Vector3(currentTrackOrientationX, currentTrackOrientationY, currentTrackOrientationZ);
      
      //smooth down acceleration
      acceleration = Mathf.SmoothDamp(acceleration, 0f, ref deltaPositionRef, 1f);
      
      //Calculate the new position
      Vector3 newPosition = trackableBehaviour.transform.rotation *
                Quaternion.AngleAxis(90, Vector3.left) *
                Quaternion.Inverse(orientation) *
                (-currentTrackPosition) +
                trackableBehaviour.transform.position;
      
      //Apply it
        arCamera.transform.localPosition = newPosition;
      
      //Calculate the new rotation and apply it
        arCamera.transform.rotation =
                trackableBehaviour.transform.rotation *
                Quaternion.AngleAxis(90, Vector3.left) *
                Quaternion.Inverse(orientation);
    }    
    

    // Position a Trackable relative to the Camera.
    protected void PositionTrackable(TrackableBehaviour trackableBehaviour,
                                     Camera arCamera,
                                     QCARManagerImpl.PoseData camToTargetPose)
    {
        trackableBehaviour.transform.position =
                arCamera.transform.TransformPoint(camToTargetPose.position);

        trackableBehaviour.transform.rotation =
                arCamera.transform.rotation *
                camToTargetPose.orientation *
                Quaternion.AngleAxis(270, Vector3.left);
    }


    #endregion // PROTECTED_METHODS
}

DataSetLoadBehaviour.cs

 

/*==============================================================================
Copyright (c) 2010-2012 QUALCOMM Austria Research Center GmbH.
All Rights Reserved.
Qualcomm Confidential and Proprietary
==============================================================================*/

using System.Collections.Generic;
using UnityEngine;

/// <summary>
/// This behaviour allows to automatically load and activate one or more DataSet on startup
/// </summary>
public class DataSetLoadBehaviour : MonoBehaviour
{
    #region PRIVATE_MEMBER_VARIABLES

    [SerializeField]
    [HideInInspector]
    public List<string> mDataSetsToActivate = new List<string>();
	
	private ImageTracker lastTracker;
   	private float testValue = 0.05f;

    #endregion // PRIVATE_MEMBER_VARIABLES



    #region PUBLIC_MEMBER_VARIABLES

    [SerializeField]
    [HideInInspector]
    public List<string> mDataSetsToLoad = new List<string>();
	
	public GUISkin skin;
    #endregion // PUBLIC_MEMBER_VARIABLES



    #region UNITY_MONOBEHAVIOUR_METHODS

    void Awake()
    {
        if (!QCARRuntimeUtilities.IsQCAREnabled())
        {
            return;
        }

        if (QCARRuntimeUtilities.IsPlayMode())
        {
            // initialize QCAR 
            QCARUnity.CheckInitializationError();
        }

        if (TrackerManager.Instance.GetTracker(Tracker.Type.IMAGE_TRACKER) == null)
        {
            TrackerManager.Instance.InitTracker(Tracker.Type.IMAGE_TRACKER);
        }

        if (mDataSetsToLoad.Count <= 0)
        {
            Debug.LogWarning("No data sets defined. Not loading any data sets.");
            return;
        }

        foreach (string dataSetName in mDataSetsToLoad)
        {
            if (!DataSet.Exists(dataSetName))
            {
                Debug.LogError("Data set " + dataSetName + " does not exist.");
                continue;
            }

            ImageTracker imageTracker = (ImageTracker)TrackerManager.Instance.GetTracker(Tracker.Type.IMAGE_TRACKER);
            DataSet dataSet = imageTracker.CreateDataSet();
			
			lastTracker = imageTracker;

            if (!dataSet.Load(dataSetName))
            {
                Debug.LogError("Failed to load data set " + dataSetName + ".");
                continue;
            }

            // Activate the data set if it is the one specified in the editor.
            if (mDataSetsToActivate.Contains(dataSetName))
            {
                imageTracker.ActivateDataSet(dataSet);
            }
        }
    }
	
	void OnGUI()
   {
      GUI.skin = skin;
      if(lastTracker != null)
      {
         lastTracker.deltaPosition = GUI.HorizontalSlider(new Rect(0,0,Screen.width / 2f, Screen.height / 6f), lastTracker.deltaPosition,   0,0.2f);
         GUI.Label(new Rect(0,Screen.height / 6f,Screen.width / 2f, Screen.height / 6f), lastTracker.deltaPosition.ToString());
         lastTracker.deltaPositionRotation = GUI.HorizontalSlider(new Rect(0,Screen.height / 6f * 2f,Screen.width / 2f, Screen.height / 6f), lastTracker.deltaPositionRotation,   0f,180f);
         GUI.Label(new Rect(0,Screen.height / 6f * 3f,Screen.width / 2f, Screen.height / 6f), lastTracker.deltaPositionRotation.ToString());
         lastTracker.dampingTime = GUI.HorizontalSlider(new Rect(0,Screen.height / 6f * 4f,Screen.width / 2f, Screen.height / 6f), lastTracker.dampingTime,   0f,5f);
         GUI.Label(new Rect(0,Screen.height / 6f * 5f,Screen.width / 2f, Screen.height / 6f), lastTracker.dampingTime.ToString());
         
         
      }
      else
      {
         testValue = GUI.HorizontalSlider(new Rect(0,0,Screen.width / 2f, Screen.height / 6f), testValue,   0,0.1f);
         GUI.Label(new Rect(0,Screen.height / 6f,Screen.width / 2f, Screen.height / 6f), testValue.ToString());
      }
   }


    #endregion // UNITY_MONOBEHAVIOUR_METHODS

}

 

I was waiting this update

December 14, 2012 - 12:55pm #22

I was waiting this update since so many months, good job guys \o/

Thank you !

Pages

Log in or register to post comments