Log in or register to post comments

How to place an image at specified position?

August 1, 2012 - 9:12am #1

I have placed a gameObject into scene and linked it to ArCamera as a child.The problem is that the gameObject is in a little different position onto ipad screen against its position on iphone screen.SO how can i correctly position the object,maybe progamatically?

I tried something like

 

heroController = GameObject.Find("Hero").GetComponent();

heroController.transform.position = Camera.main.ScreenToWorldPoint( new Vector3(Screen.width/2, Screen.height/2, Camera.main.nearClipPlane) ) ;

in  QCARBehaviour.cs in  void StartQCAR() function after calling CameraDevice.Instance.Start();

 

and nothing happened.How can i fix the gameObject position?

 

How to place an image at specified position?

August 8, 2012 - 5:10pm #13

The world space origin shouldn't change w/ the device orientation.

To post code, you should be able to copy and paste it from MonoDevelop into the editor's 'rich-text' view ..

 

    void Start()
    {
        QCARBehaviour qcarBehaviour = GetComponent<QCARBehaviour>();
        if (qcarBehaviour)
        {
            qcarBehaviour.RegisterTrackerEventHandler(this);
        }
    }

 

*wrapping the code w/ the '' (quote) button will inset it a bit.

How to place an image at specified position?

August 7, 2012 - 1:21am #12

Can someone indicate me how to correctly add Unity code in this forum,it's a really problem for a good show of it

How to place an image at specified position?

August 7, 2012 - 1:17am #11

I have found another problem.I'd like to modify the object position in relation to the device orientation

 </p><p>void Update ()</p><p>{ if(ipad) { } else { if (Input.deviceOrientation == DeviceOrientation.LandscapeLeft && !rotation) { transform.Rotate(0, 0, -90); ThirdPart = 5*Screen.width/8F; transform.position = new Vector3(7, -ThirdPart, transform.position.z); rotation = true; } else if(Input.deviceOrientation != DeviceOrientation.LandscapeLeft && rotation) { transform.Rotate(0, 0, 90); ThirdPart = 5*Screen.height/8F; transform.position = new Vector3(7, -ThirdPart, transform.position.z); rotation = false; } } Debug.Log("Rotation= "+rotation+"\n Device orientation"+Input.deviceOrientation); Debug.Log("Coordinate Y: "+transform.position.y); }</p><p> 

But the origin of the coordinate system seems to change after different rotation.How to resolve this? 

How to place an image at specified position?

August 6, 2012 - 9:51am #10

Make sure that you're employing the same orientation settings between these devices. Also confirm that you're not encountering a known issue w/ certain version combinations of Unity and XCode - https://ar.qualcomm.at/content/unity-352f2-and-ios-fixed-orientation-causes-distorted-output

How to place an image at specified position?

August 6, 2012 - 7:27am #9

I have the same problem, they don't even match between the editor and the device.

I have just found this:

http://docs.unity3d.com/Documentation/ScriptReference/Camera.ScreenToWorldPoint.html

Have yet to test it, hope it works.

How to place an image at specified position?

August 6, 2012 - 4:01am #8

 

Is the origin different for the ipad and for the iphone when the object is the child of the ar camera?I wrote  a script to place an object in the bottom of the screen: 

 

using UnityEngine;

using System.Collections;

public class HeroPosition : MonoBehaviour {

     void Start () {

            float ThirdPart; ThirdPart = Screen.height / 4f + 20;

            transform.position = new Vector3(7, -ThirdPart, transform.position.z);

            Debug.Log("Screen width: "+Screen.width); }

            } 

And it sems to be different for the ipad and the iphone-for the ipad the object is then correctly placed at the bottom, on the iphone at the top.Are origins different on these devices?

How to place an image at specified position?

August 3, 2012 - 9:30am #7

How can i move the object to the needed position, when apps is loaded?

To place it in a static position, use myobject.transform.position.

To move the object in a given direction, for a given distance use transform.Translate.

To animate the movement, you can use..

function Update() {
// Move the object forward along its z axis 1 unit/second.
transform.Translate(Vector3.forward * Time.deltaTime);

// Move the object upward in world space 1 unit/second.
transform.Translate(Vector3.up * Time.deltaTime, Space.World);
}


.. in a MonoBehaviour script attached to the object.

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

How to place an image at specified position?

August 3, 2012 - 7:01am #6

Thank you DavidBeard.It helped and have resolved the problem.

How to place an image at specified position?

August 3, 2012 - 3:05am #5

How can i move the object to the needed position, when apps is loaded?

I'm using Xcode 4.4 and Unity 3.5.2f2

How to place an image at specified position?

August 2, 2012 - 12:31pm #4

When you make an object a child of the ARCamera, its transform position coordinates will be relative to the ARCamera's origin - so x = 0 and y = 0 should center the object in the camera's view which should place them at the center of the screen.The z value will be the distance from the camera.

Another consideration is that there is a known issue between certain versions of Unity and XCode which distorts the perspective in landscape vs portrait orientation.

Which versions of Unity and XCode are you using?

How to place an image at specified position?

August 2, 2012 - 8:23am #3

I don't understand what you mean.I have tried another way.

void Start () {

//the y-coordinate of the first third part of the height screen

float ThirdPart = Screen.height / 3F; ThirdPart = ThirdPart* 2F + ThirdPart / 2F; transform.position = new Vector3(Screen.width/2, ThirdPart, transform.position.z); } 

 

into a script attached to the gameObject,which is as I said before a child of Arcamera and it completely disapeared from the screen.Wgat is wrong? 

How to place an image at specified position?

August 1, 2012 - 6:39pm #2

In which direction is the object offset when you position it so that x and y are 0 as a child of the camera?

Log in or register to post comments