Hello everyone.

We have decided to phase out the Mixed Reality Forums over the next few months in favor of other ways to connect with us.

The first way we want to connect with you is our mixed reality developer program, which you can sign up for at https://aka.ms/IWantMR.

The plan between now and the beginning of May is to clean up old, unanswered questions that are no longer relevant. The forums will remain open and usable.

On May 1st we will be locking the forums to new posts and replies. They will remain available for another three months for the purposes of searching them, and then they will be closed altogether on August 1st.

So, where does that leave our awesome community to ask questions? Well, there are a few places we want to engage with you. For technical questions, please use Stack Overflow, and tag your questions using either hololens or windows-mixed-reality. If you want to join in discussions, please do so in the HoloDevelopers Slack, which you can join by going to https://aka.ms/holodevelopers. And always feel free to hit us up on Twitter @MxdRealityDev.

How I can save/get a rotation from Hololens anchor?

I'm using anchor in my application to be the "center of the world" instead of hololens be the "center of the world". I instantiate a cube and turn this my reference to display my 3d objects.

I can get the position normally, but the rotation not. Always when I change of scene and open it again, the position reference of cube is ok. My 3d objects get the position reference and is be displayed ok, but the rotation is come from hololens. If I rotate my head (hololens), the 3d object get this "rotation" and is changed, but I want get the rotation of my cube anchor.

This is my code:

//Instantiate the cube
AnchorController anchorController = anchorManager.GetComponent<AnchorController>();    
referenceGameObject = GameObject.Find("Cube");    
referenceGameObject = anchorController.instance;

//Getting the position and rotation of cube
Vector3 referencePosition = referenceGameObject.transform.position;
Quaternion referenceRotation = referenceGameObject.transform.rotation;


//Instantiate a 3d object and inside her I instantiate my 3d objects     
GameObject parent = new GameObject("Obj3D");

Quaternion originalRot = parent.transform.rotation;

//step.anchorX/Y/Z is a coordinates that came from json file, are running perfectly.
//Here I get the position reference of my cube, works perfectly.
parent = Instantiate(parent, referencePosition, referenceRotation);
parent.transform.position = referencePosition;
parent.transform.position = parent.transform.position + (referenceGameObject.transform.right * step.anchorX);
parent.transform.position = parent.transform.position + (referenceGameObject.transform.forward * step.anchorY);
parent.transform.position = parent.transform.position + (referenceGameObject.transform.up * step.anchorZ);

//Here I'm getting the reference rotation of my cube and insert a rotation of my cube  
parent.transform.Rotate(referenceRotation.eulerAngles.x, referenceRotation.eulerAngles.y, referenceRotation.eulerAngles.z); 


//Here is my 3d objects 
childObject = Instantiate(SetPrefab(step), parent.transform);

childObject.transform.localPosition = Vector3.zero;
object3d = parent;

if (step.HLScaleX != 0f && step.HLScaleY != 0f && step.HLScaleZ != 0f){
    object3d.transform.localScale = new Vector3(step.HLScaleX, step.HLScaleY, step.HLScaleZ);
}
object3d.transform.localRotation = Quaternion.Euler(new Vector3(step.HLRotationX, step.HLRotationY, step.HLRotationZ));

In resume,

How I can save/get the rotation of my anchor in Hololens?

Answers

  • dbarrettdbarrett ✭✭✭
    edited January 2018

    Not sure if this will help but, if you're just trying to instantiate everything in reference to an anchor you can do something like:

    object.transform.position = anchor.transform.InverseTransformPoint(desiredWorldPoint);

    what this says is put my object at the desired world position relative to this anchor's local position. There is also an InverseTransformDirection method as well for dealing with direction vectors. Also there is a TransformPoint/Direction as well from converting to world space from local space.

    https://docs.unity3d.com/ScriptReference/Transform.InverseTransformPoint.html

    This is how most multiplayer HoloLens apps do it since they use a shared world coordinate and base everything off of that to get it relative to their position.

    AR Developer

  • I'm not sure if this will help either but what I've tended to do is to make the object that I apply a world anchor to be an empty game object and then use that empty object as the parent of my actual holograms (within a suitable distance as per the guidance in the documentation).

    If I do that then I can save/load the anchor using (e.g.) the WorldAnchorManager and its Load/Save functionality or I can it over the network using the WorldAnchorTransferBatch and its Export/Import functionality.

    The job of saving/recreating holograms then becomes the job of saving/restoring the local transform to the parent (anchor) once the anchor is 'live' in the app.

Sign In or Register to comment.