Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

How create orthographic view to fit a square

Discussion in 'Editor & General Support' started by sirival, Feb 28, 2013.

  1. sirival

    sirival

    Joined:
    Sep 14, 2011
    Posts:
    146
    Hello,

    I can't seem to do this.. I have a square area defined by 4 world space corners. What I want is to automatically position an orthographic camera on top of the square, adjust the camera's orthographic size to just fit that square and take a screenshot.

    Can someone give me a little insight on this? ( this is to create a minimap )

    Thank you
     
  2. FuzzyNori

    FuzzyNori

    Joined:
    Dec 6, 2012
    Posts:
    47
    A camera has as many corners as a square.

    A camera also has a transform.

    So if you set the cameras transform.x and transform.y, its width and its height to the same of the square and also its rotation, the camera will be "pointing" at that square. You then just adjust one of the axis so that its not right on top of the square but a little above/bellow it as you need.
     
  3. sirival

    sirival

    Joined:
    Sep 14, 2011
    Posts:
    146
    Actually stupid as that may be I hadn't tried just setting the corner coordinates directly to Matrix4x4.Ortho... People are so stupid sometimes...
     
  4. FuzzyNori

    FuzzyNori

    Joined:
    Dec 6, 2012
    Posts:
    47
    Does that mean your problem is solved ? :)
     
  5. sirival

    sirival

    Joined:
    Sep 14, 2011
    Posts:
    146
    The problem that I asked about has been solved.

    I still have a related problem that I can work around but it'd be nice if I knew why it happens.. The method I used to create a minimap before was to cast rays from the bottom left corner of that square until the top right, and render the color of the hit point to a texture.

    Then that texture is used as a minimap where various world positions are rendered on top of it as minimap icons etc.

    The problem that I'm having right now is that the image produced with raycasting vs the image that is rendered using the orthographic camera is offseted by a slight amount. I don't know why and I don't expect you to know why, I'm just mentioning it in case you had an idea why this happens. Theoritically the two images should be identical ( of course the screenshot would have more detail ).
     
  6. FuzzyNori

    FuzzyNori

    Joined:
    Dec 6, 2012
    Posts:
    47
    I'm not experienced enough with raycasting so you are right on the money, I can't help there.

    I, however, have followed a tutorial for a minimap and got it working easy.

    Are you doing it your way for any reason or would you be open to other ways to do it?
     
  7. sirival

    sirival

    Joined:
    Sep 14, 2011
    Posts:
    146
    That's alright thanks anyway :) . Well I am doing it with a texture instead of a second camera that renders a top-down view, because of the number of draw calls that the second camera would add. Unfortunately I can't afford to double the number of draw calls ...
     
  8. Deleted User

    Deleted User

    Guest

    Hi, you can also checkout the popular KGFMapSystem:

    - It took us more than 4 month to develop it so we have solved nearly most of all possible minimap problems out there. :)
    We have a very big user base, and it seems that all of them are very happy with the system.

    Just have a look:

    homepage-> http://www.kolmich.at/kolmich/index.php?option=com_content&view=article&id=116&catid=86&Itemid=475〈=en

    webdemo-> http://www.kolmich.at/kolmich/demo/kgf/KGFMinimap/KGFMinimap.html

    assetstore->http://u3d.as/content/kolmich-creations/kgfmap-system/3bf

    documentation->http://www.kolmich.at/documentation/

    If you have any questions just contact me at support@kolmich.at or use our forum www.kolmich.at/forum

    Best wishes

    Michal
     
  9. sirival

    sirival

    Joined:
    Sep 14, 2011
    Posts:
    146
    Thanks I'll check that out :)