Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Drawing a infinite zoom-able smooth circle

Discussion in 'Scripting' started by Brockoala, Aug 16, 2017.

  1. Brockoala

    Brockoala

    Joined:
    Feb 18, 2013
    Posts:
    13
    Hi, I want to draw a circle in 3D space, which can be smooth at any distance from the camera, like vector circle in Adobe Illustrator or planet orbit line in Elite Dangerous, and has good performance on mobile devices. Please guide me into the right direction to achieve this, thank you very much!

    I did some searching and read about drawing circle with LineRenderer, but there is a problem, that it requires a fixed number of segments, so I have to re-render the circle with a new number of segments every time the camera moves or zooms, to maintain a consistent level of smoothness on the circle. Re-rendering it every frame might be a bit expensive on mobiles I think, and if I zoom in too close to the circle, that requires a huge number of segments to keep it smooth, this is also expensive.
     
    Last edited: Aug 16, 2017
  2. bigmisterb

    bigmisterb

    Joined:
    Nov 6, 2010
    Posts:
    4,221
    You need a 2 pronged solution.

    1) a solution where knots are placed closer together the closer the camera is to the knot.

    2) a solution where knots are omitted if they are not in the view.

    to accomplish 1, you would start with the knot at 0 degrees. and calculate the distance to the camera. This will define the number of degrees to the next knot. (I would have a minimum degree distance as well, we dont want a circle with 3 knots simply because it is far away.) You simply add the next knot and draw a line between the two. Then, use that knot for distance, and so on.

    For 2) use knot A and B (as you create them) if both A and B are not in the visible.

    http://answers.unity3d.com/questions/8003/how-can-i-know-if-a-gameobject-is-seen-by-a-partic.html

    The only big part to 2 is, that if you skip a knot, you are going to have to add Knot A back to the list.

    so, consider you have knots A, B, C, D, E, F, G, H, I, J, K, L, M

    you skip knots C and D because they are not visible. So in the end, your knots look like this: A, B, D, E, F, G, H, I, J, K, L, M

    Oh, and you have to do this in the late update, and every frame.
     
    Brockoala likes this.
  3. Brockoala

    Brockoala

    Joined:
    Feb 18, 2013
    Posts:
    13
    Thanks a lot! I didn't think about uneven knots! That's brillant, thanks again.