Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 TheDylonFive · Mar 10, 2017 at 07:04 AM · rotationmatrix2.5dperspective camerafrustum

Calculating the viewing area corners in world space of a perspective camera that is NOT perpendicular to the viewing surface

Hey all!

So I have a game that is 2.5d, so its basically a top down game map, in which I want to keep the camera's frustum/viewing area from ever going outside of the edge of the map image, which is working right now for me, but now i want to add in slight amounts of rotation so that the camera isnt perpendicular to the map.


This is currently working for me and here's how I'm doing it:

1) With the height and width of the camera frustum, I am currently find the maximum distance for the camera to be positioned so that the viewing area never goes out of the map using the formulas given by Unity:

https://docs.unity3d.com/Manual/FrustumSizeAtDistance.html

2) Given the Height and Width of my screen I scaled down the target frustrum which i determined from finding the largest ratio of map.sizeDelta.x/screen.x and same with y, and then found the max distance from that

3) Then I have a target position at which the camera is going to be centered at, and with the center position and the target frustum width and height you can know how far off the camera that is going to be centered on this target object will be outside of the world space corners of the map (basically checking if centerPos.x > mapMinX + (frustrumWidth/2) and so on for each side)

4) If the position is too far in one direction, I change the target position to so that it doesn't spill out over the map, basically:

newPosition.x = mapMinX + (frustumWidth / 2);

3) Then I pass that target to my camera controller and it lerps its way to that position


Here's my question:

This is all just being calculated from a top down, exactly perpendicular to the map, like every example on google has discussed so far..

I want to be able to calculate these world corners of the viewing area from an angled camera (aka a camera not perpendicular to the map)


In Review:

Given a Vector3 position of a target on the map I would like to look at, and potentially given a distance, I want to calculate ahead of time what angle and position of the camera would be best so that i could get that target in view of the camera, but also but not have the camera see off of the map.

I guess my real problem with my current way is how do I take the top down rect that I have:

(xPos: targetPosition.x, yPos: targetPosition.y, Width: frustumWidth, Height: frustumHeight)

and skew the corners to get the four world point corners of the transformed "quadrilateral" because its not a rectangle anymore, as it would appear in rotated version of the camera

I am willing to concede potentially keeping all rotation to a maximum of 5 or 10 degrees about the x or z axes but I am still lacking a calculation that can even give me the skewed rect of what the camera will see if its rotated

So whether that is using a projection matrix perhaps to skew the top down view by an amount, or perhaps there is a formula for a perspective camera to determine this, or even if the way you might suggest has me redo the entire system I've created so far, I would very much appreciate any help, and I'm sure there will be other people down the road that would appreciate it as well! (:


What I Don't Want To Do (but will if there is a compelling reason to)

I don't want to set my camera and then make calculations and set it again and so on and so on, I want to calculate it ahead of time so I can just have my camera lerp there!


Here are a few links that are very close to what I've been looking for but I haven't been able to find anything about how to calculate ahead of time:

http://answers.unity3d.com/questions/486035/how-to-find-world-coordinates-of-screen-corners-wi.html

http://mathforum.org/library/drmath/view/55344.html

http://answers.unity3d.com/questions/564276/adjusting-returned-worldtoscreenpoint-for-perspect.html


Thanks again all!

Comment
Add comment
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

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to rotatate an array of points(x,z) around origin point(x,z)? 1 Answer

Can I make a camera render specified layer with specified script?(My English is too bad.Don't know what to ask correctly) 0 Answers

Point an arrow at the mouse position, 2.5D 1 Answer

How to Decompose a TRS Matrix? 3 Answers

How to achieve Luftrauser like airplane gameplay in 2.5D 1 Answer


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