A 2D GUI in mid air, for oculus, tracking an object.

Think of a selection box, in an RTS. What I want, is to draw something like that, on the screen, around a 3d object, while moving. I’m using the Oculus, and using VRGUI for another part of the UI. I was thinking of having a plane in between the object, and the camera, but I’m not sure how to draw GUI on it, without using Unity’s build in GUI, or NGUI. Here’s an image that hopefully will help you understand:
[31090-selection+box.png|31090]

How can I draw the selection box on a plane, or do you have any other ideas?

EDIT:

I found another way of doing it. For those curious, I decided to project the bounding boxes on a sphere around the camera, with a mesh for each corner :slight_smile:

Hey there, I have some code that does this from a while ago, it uses a Texture as the ‘tracking scope’ but I would sugeest you update it to use something like vectorsity or linerenderer or similar as the scaling of the texture means that the line around the object changes size as it is scaled. It would make more sense for the lines to stay the same pixel width, and only change the corner positions! (This code is probably not very efficient but I am not likely to change it anytime soon)

C# code:

public GameObject target;
public Texture2D trackingTexture;
public float padding = 0.1f;
Renderer targRenderer;

float x;
float y;
float width;
float height;

Vector3 min = Vector3.one*Mathf.Infinity;
Vector3 max = Vector3.one*Mathf.NegativeInfinity;

Camera cam;

void Start(){
	targRenderer = target.GetComponent<Renderer>();
	Debug.Log(targRenderer.bounds.ToString());
	cam = Camera.main;
}

void Update(){
	min = Vector3.one*Mathf.Infinity;
	max = Vector3.one*Mathf.NegativeInfinity;
	for(int i = -1; i < 2; i+=2){
		for(int j = -1; j < 2; j+=2){
			for(int k = -1; k < 2; k+=2){
				Vector3 worldPos = Vector3.zero;
				worldPos.x = targRenderer.bounds.center.x + i*(targRenderer.bounds.extents.x+padding);
				worldPos.y = targRenderer.bounds.center.y + j*(targRenderer.bounds.extents.y+padding);
				worldPos.z = targRenderer.bounds.center.z + k*(targRenderer.bounds.extents.z+padding);
				min = Vector3.Min(min, cam.WorldToScreenPoint(worldPos));
				max = Vector3.Max(max, cam.WorldToScreenPoint(worldPos));
			}
		}
	}
	Debug.Log(min);
	Debug.Log(max);
	x = min.x;
	y = (Screen.height-max.y);
	width = (max.x-min.x);
	height = -(min.y-max.y);
}

void OnGUI(){
	GUI.DrawTexture(new Rect(x, y, width, height), trackingTexture);
}

Scribe