Log in or register to post comments

How to get Camera Rotation according to Tracker

February 23, 2013 - 9:12am #1

 

 

Hi,

I'm new to Vuforia SDK, I did many researches but I couldn’t find a proper answer. Is there a way to get the tracker (camera) 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.

How to get Camera Rotation according to Tracker

April 18, 2013 - 9:16am #19

Hi, 

Thanks a lot. I managed to do the code according to that artcle. 
Appriciate your help.

Thank you.

I have few more questions.
How can I switch between applications ? I have 2 different scenes in Unity. Now I need to prompt a welcome screen and promt the user to select which section to go. Then when he/she touch the back button on android device, it should go batck to welcome screen. Currently the back button also doesnt work when I install the apk to my android device. I have to terminate the task from task manager everytime. How can I configure this and give the user to navigate between scenes ?

Looking forward for a early response.
Thank you very much.

How to get Camera Rotation according to Tracker

April 15, 2013 - 11:21am #18

Did you try the code in this Knowledge Base article? - https://developer.vuforia.com/resources/dev-guide/unity-camera-image-access

 

How to get Camera Rotation according to Tracker

April 13, 2013 - 9:29am #17

Hi again,

For the past few days I'm trying to capture the camera image and save it in my device SD card. But still I cannot save the image. 
The only way I was able to save is a screenshot. But this will save the rendered AR content as well. I need only to save the plain camera image. I tried many ways like 

1)
Image img = CameraDevice.Instance.GetCameraImage(Image.PIXEL_FORMAT.RGB888); // this give a null pointer :(

2)
Application.CaptureScreenshot("Screenshot.png"); // this will save the virtually rendered AR content too :(

3)
//below code save a blank image :(
Texture2D captured = new Texture2D (640, 800);
Camera.current.Render();
RenderTexture.active = Camera.current.targetTexture;
captured.ReadPixels(new Rect(0,0,640,800),0,0);
captured.Apply();
RenderTexture.active = null;
byte[] bytes = captured.EncodeToPNG();
File.WriteAllBytes(Application.dataPath + "/testscreen.png", bytes);

Please can someone help me to write a complete C# code to save the plain camera image ?
Highly appriciate your help. Looking forward for a early reply.

Thanks,
Amal.

How to get Camera Rotation according to Tracker

April 6, 2013 - 11:12am #16

No problem.  No judgements here.  Just don't want to over/under explain things.  

Glad you're making progress.

How to get Camera Rotation according to Tracker

April 6, 2013 - 8:16am #15

Thanks a lot ! I manage to  open the project according to your instructions. I am new to Unity3D. Forgive me for my poor experience on Unity3D. Now I'm practicing Unity3D and getting used to it functionalities. Highly appreciate your help.

Thanks.

How to get Camera Rotation according to Tracker

March 30, 2013 - 6:57am #14

I think this might be a question of how you are loading your projects.  I'm only assuming you don't have much experience with Unity because you haven't used GUI's before but correct me if I'm wrong.

when you open a project, it doesn't automatically load the scene, so there would be nothing in the scene column, but you should see a unity logo in the project column somewhere.  That's your scene.  If you double click on that, it should load the scene.  Make sure to then add that scene to your build settings.

Other than that I haven't really use the user defined targets example.

How to get Camera Rotation according to Tracker

March 30, 2013 - 1:29am #13

 

Hi,

Thanks a lot for the guidance. By following the information you gave I managed to save the camera image and put the button to GUI. Thanks again for that valuable information. 

But still I couldnt figure our a way to configure the User-Defined targets. I downloaded the sample Unity3D project provided by Vuforia. But when I open it, there is nothing in the scene. I build it and install in my phone. Nothing happens. 

I think after importing them we have to put the camera and tracker and config the settings. I added the camera and tracker, but settings to config I dont know. Are there any tutorials regarding User-Defined Target Unity3D project setup ? Please help me. highly appreciate your help.

Thanks,
Amal

How to get Camera Rotation according to Tracker

March 26, 2013 - 4:09pm #12

daag123 wrote:

Hi again !! 

When I was coding I came up with few more problems. 

1) How to add a button on the screen display (not virtual buttons define in image targets)  using C# code ? is it possible to do in C# script or do I have to jump to android code to add the button ?

Do you mean GUI.Button?  It's dead easy:

http://docs.unity3d.com/Documentation/ScriptReference/GUI.Button.html

Quote:

2) How can we capture an image from the camera and save it in the galery (using c# scripting) ?

Unless there's a user defined targets way to do this I don't know about: http://answers.unity3d.com/questions/22954/how-to-save-a-picture-take-screenshot-from-a-camer.html

How to get Camera Rotation according to Tracker

March 26, 2013 - 8:09am #11

Hi again !! 

When I was coding I came up with few more problems. 

1) How to add a button on the screen display (not virtual buttons define in image targets)  using C# code ? is it possible to do in C# script or do I have to jump to android code to add the button ?

2) How can we capture an image from the camera and save it in the galery (using c# scripting) ?

3) I downloaded the User-Defined Targets sample unity project. But when I open it, there is no setup on the view. So I add the AR camera to the screen and added the UserDefinedTargetBuilder to the screen. Rest of the steps I'm confused. Can you please guide me on the rest of the steps please?

Once again I am hoping for your kind support. Looking forward for a early reply. Highly appriciate your support.

Thanks,
Amal

How to get Camera Rotation according to Tracker

March 2, 2013 - 5:47pm #10

Great - you're welcome.

How to get Camera Rotation according to Tracker

February 28, 2013 - 7:45pm #9

Awesome !! Thanks a lot. Its working !! ;-)
This is the code line I was looking for 

mTrackableBehaviour.gameObject.transform.position

Thanks for posting that code segment. 
I like to share some interesting code that I found while I was researching for my code at the next level. After updating the object position from  mTrackableBehaviour position coordinates and rotation from ARCamera coordinates, The object started rotaing from its center since the pivot point was in the middle. So I wanted to rotate its x rotation from the bottom. When I was looking to move the pivot point I came to realize that Unity3D doesn't have such feature integrated yet. I found this interesting script done by an awesome person when I was researching through the following link. 

http://solvethesystem.wordpress.com/2010/01/15/solving-the-pivot-problem-in-unity/

Thanks again for the support given. Highly appriciated.

How to get Camera Rotation according to Tracker

February 28, 2013 - 1:40pm #8

Here is how you can obtain the target's transform data ..

 

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

        // Enable rendering:
        foreach (Renderer component in rendererComponents)
        {
            component.enabled = true;
        }

        // Enable colliders:
        foreach (Collider component in colliderComponents)
        {
            component.enabled = true;
        }

        Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " found at "+ mTrackableBehaviour.gameObject.transform.position.ToString());
    }

But this is always going to be 0,0,0 if the target is the world origin.

Also you can rotate an object on the target independently of the target pose. The object will move relative to the target but can still rotate and translate within the local space. That's why transform.lookAt can still work for an object that is a child of a target.

How to get Camera Rotation according to Tracker

February 28, 2013 - 12:43pm #7

Thanks. Those are great ideas. I looked into the first idea which is, setting the object transform.parent to ImagerTarget transform. But then I came to notice that they do not provide any methods to retrieve the ImageTarget transform data. So I am going for the second option now.

Is there a way to get the transform data from ImageTarget and if I assign it, will it override the rotation details as well ? Because I need only to override postion and scale values of the object. Since rotation is getting updated by the ARCamera so that it face the camera always.

I am looking into 2nd option right now. But its better if I can achieve this by the 1st option. Can you please let me know whether there is a way to get the ImageTarget transform information?  and whether it overrides the rotation or not by assigning as parent transform to object? 

Thank you very much for your support. Appriciate a lot.
 

How to get Camera Rotation according to Tracker

February 28, 2013 - 7:45am #6

To have the object follow the target, assign the target's transform as the transform.parent of the object.

http://docs.unity3d.com/Documentation/ScriptReference/Transform-parent.html

To have the object always look at the camera, use a lookAt method

http://docs.unity3d.com/Documentation/ScriptReference/Transform.LookAt.html

There is also a smooth lookat script available that will animate the lookat transition - http://wiki.unity3d.com/index.php/SmoothLookAt_CS

How to get Camera Rotation according to Tracker

February 28, 2013 - 6:41am #5

Thank you very much. I manage to get the proper angle now with degrees using 

Camera.current.transform.eulerAngles.y

There is another problem I'm facing at the next level. I have a child GameObject parented to the ARCamera. Because I want to have camera rotation coordinates to guide the child object so that it will always face the camera. 

But now I need to move the GameObject according to the movements of the tracker and scale it too. No interference to the rotation. When I use the below code 

myObject.transform.localPosition.Set(xPosition,yPosition,zPosition);
myObject.transform.localScale.Set(xScale,yScale,zScale);

This won't work. I think it overrides the values back from the values it gets relative to ARCamera. 
Any Idea how to achieve this ?

Thanks in advance.
Amal.
 

How to get Camera Rotation according to Tracker

February 27, 2013 - 1:22pm #4

The transform rotation.y is a Quaternion component. Try obtaining the rotation in Euler angles : http://docs.unity3d.com/Documentation/ScriptReference/Quaternion-eulerAngles.html

transform.rotation.eulerAngles : gives you the rotation in world space

transform.localRotation.eulerAngles : gives you the same in local space, this is what you see in the Inspector.

How to get Camera Rotation according to Tracker

February 27, 2013 - 6:57am #3

Thanks a lot for the guidance.
I checked the code for past few days and finally I managed to do it using 

Camera.current.transform.rotation.y

It gives the rotation value in a float. Now I need to convert this value to degrees. But when I check the values it returns, some times it gives positive values and sometimes it gives negative values. Any Idea how to convert these values to degrees (from 0 to 360) ?

Thanks

Amal

How to get Camera Rotation according to Tracker

February 23, 2013 - 12:06pm #2

Check out this KB article - https://developer.vuforia.com/resources/dev-guide/getting-camera-position

In Unity, you can accomplish the same using the camera transform.

But it's important to understand that the camera is independent of the Tracker. The Tracker is responsible to determining the poses of scene elements, either the targets or camera, depending on how you've defined the world origin (i.e. 0,0,0 ). This is set by defining the World Center Mode for a scene in Unity.

Log in or register to post comments