Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Mr_FJ · Aug 18, 2014 at 10:27 AM · 2dgui3doculusselection

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: alt text

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 :) http://stackoverflow.com/questions/9604132/how-to-project-a-point-on-to-a-sphere

selection box.png (16.2 kB)
Comment
Add comment · Show 8
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image robertbu · Aug 18, 2014 at 02:57 PM 0
Share

Why are GUI or NGUI a problem? Is a GUITexture okay? Is the rest of the Quad (outside of the selection box) transparent, translucent, or opaque?

avatar image Mr_FJ · Aug 19, 2014 at 08:53 AM 0
Share

I can't really afford NGUI right now, and I'm using ongui for other hud. I used to draw the selection box on the hud, before I implemented oculus. It's way offset, and I can't figure out why, but the real problem is, when you turn your head, the selection box turns with you. That's not acceptable :P Ideally I could project it on a mesh, because the player is sitting inside a transparent sphere, but that's not really necessary. Yes, if I use a quad, the rest should be transparent. Will GUITexture work, if I can't use OnGUI? Doesn't it rely on that?

avatar image Mr_FJ · Aug 19, 2014 at 08:56 AM 0
Share

I suppose I could move the other GUI to the same plane/quad/other, but it wouldn't be as easy to read :/ I guess that's plan F. Hmm a plan E, could be to draw a line from the selected object's position, to the top right of the screen, hmm...

avatar image robertbu · Aug 19, 2014 at 09:02 AM 0
Share

I don't know enough about what you are trying to do and Oculus to give you an answer. You can draw the selection box using any of 1) Quad in world space, 2) GUITexture, or 3) GUI.DrawTexture(). If you want it to stay aligned with the object, the code will be different for each implementation. From what you describe, you should be able to just put a quad with the box texture between the object and the camera at the camera's near clipping plane.

avatar image Mr_FJ · Aug 19, 2014 at 10:26 AM 0
Share

Yes, but how do I figure out where to put the rectangle? I was using worldtoscreenpoint before, but that won't work since I'm drawing it on a 3d object :I Worth noting, that the player will be rotating around (Including different heights) the object, and the object won't be just a box :/

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Scribe · Aug 20, 2014 at 11:40 AM

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

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Mr_FJ · Aug 25, 2014 at 08:42 AM 0
Share

Thanks for your attention, but I found another way :)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

GUI Follow RaycastHit 2 Answers

Fix a GUI's position relative to a 3D object 1 Answer

2D Arrow pointing at 3D Position 1 Answer

Plane Object as GUI - Lighting Issue 1 Answer

2d sprite bacground motion? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges