Samsung / GearVRf

The GearVR framework(GearVRf) is an Open Source VR rendering library for application development on VR-supported Android devices.
http://www.gearvrf.org
Apache License 2.0
407 stars 217 forks source link

Obtaining Transform position using getLookAt #1111

Closed sam16222 closed 7 years ago

sam16222 commented 7 years ago

Hello, Is there a way to obtain the transform position of the point being looked at via the head tracker? I was looking into getLookAt but it only gives the vector.

bohuang3d commented 7 years ago

Hi @sam16222 I think you are asking about getting the geometry/object at the center of the screen?

If so that's a ray casting problem. You may want to check out https://github.com/gearvrf/GearVRf-Demos/blob/master/gvr-eyepicking/

liaxim commented 7 years ago

There is also this: https://resources.samsungdevelopers.com/Gear_VR/020_GearVR_Framework_Project/060_Gear_VRf_Developer_Guide/020_GearVRf_Features/Picking

NolaDonato commented 7 years ago

You can call GVRScene.getMainCameraRig().getHeadTransform() to get the camera view matrix. It is updated every frame when your head moves.

liaxim commented 7 years ago

@sam16222 Do you need more help?

sam16222 commented 7 years ago

@liaxim I tried using what you suggested, but couldn't quite achieve what I wanted to. Here's what I want to do. Take a spherical mesh. It is blank all around. I want to point at a position and tap. At that location I should be able to spawn an image or a text box. Can you think of a way to do this? I tried using getHitLocation() but it didn't quite work.

liaxim commented 7 years ago

@sam16222 It didn't quite work in what way? Thanks.

sam16222 commented 7 years ago

It's just not giving me the exact position. As explained in the situation above, can you tell me a way to do it? I just want to look at a location, tap and then spawn a text box at the location, with the appropriate rotation values.

bohuang3d commented 7 years ago

@sam16222
Let me know if the following is of use:

If you follow the example https://github.com/gearvrf/GearVRf-Demos/blob/master/gvr-eyepicking/

You can modify the PickHandler's onInside() function and query the collision position:

public class PickHandler implements IPickEvents
    {
        public void onEnter(GVRSceneObject sceneObj, GVRPicker.GVRPickedObject pickInfo)
        {
        }
        public void onExit(GVRSceneObject sceneObj)
        {
        }
        public void onNoPick(GVRPicker picker) { }
        public void onPick(GVRPicker picker) { }
        public void onInside(GVRSceneObject sceneObj, GVRPicker.GVRPickedObject pickInfo) { 
//This function is called whenever your looking direction intersects with an object.

//This is supposed to be the exact position you look for
              float[] hitLocation = pickInfo.hitLocation;
//Do something about this position, such as spawning an image or text box
              ...

}      
    }
bohuang3d commented 7 years ago

We close issues if no more activity after awhile. Feel free to ask anew