Forum Discussion

🚨 This forum is archived and read-only. To submit a forum post, please visit our new Developer Forum. 🚨
sredburn's avatar
sredburn
Honored Guest
12 years ago

Finding the OVRCrosshair in 3D Space

Okay, so I have a problem where I need to get the OVRGUI Crosshair's position in 3D space so I can apply raycasting on it. I have dug through all of the Oculus scripts and cannot determine a way to calculate this.

I want to use the way the cursor is currently set up, ie, where it has a certain deadspace where it turns the player once it reaches a certain position in pixels. It is simple to calculate the crosshair when it is initially centered by calculating the forward direction of the centerAnchor. Unfortunately, I do not know how to calculate the offset on the crosshair since it is measured in 2D pixels on the plane instead of a vector3 coordinate in 3D space.

The code that creates the crosshair at the desired location is:
GUI.DrawTexture(new Rect(XL - (ImageCrosshair.width * 0.5f),
YL - (ImageCrosshair.height * 0.5f),
ImageCrosshair.width,
ImageCrosshair.height), ImageCrosshair);


Anyone have any ideas on how to accomplish this? Thanks in advance.

2 Replies

Replies have been turned off for this discussion
  • OVRCrosshair is not drawn in 3D space. It's drawn at the center of the screen for each eye, making it infinitely far away. So you could approximate its position as OVRCameraRig.centerEyeAnchor.position + 100f * OVRCameraRig.centerEyeAnchor.forward.
  • Okay that actually answers a lot of questions about my playing around with it.

    Although that helps, the issue I am having involves determining the GUI offset value. For example, when the cursor is moved while on-screen with GUI coordinates, it is changed from the center x,y - (640,400) to another value, say (540, 450) for example. When the cursor is offset from the center, I do not know how to approximate the position.

    Any ideas on how I could attempt to do this?