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
0
Question by Ender2718 · Jun 08, 2013 at 02:47 AM · cameraprojection

Off-axis projection problem

I am trying to get off-axis projection working for my scene camera, and can't seem to get it working. I am on Unity 4.0.1f2.

I am using the PerspectiveOffCenter function provided here: http://docs.unity3d.com/Documentatio...ionMatrix.html

Code:

 public static Matrix4x4 PerspectiveOffCenter(float left, float right,
                                                  float bottom, float top,
                                                  float near, float far)
 {
       float x = 2.0F * near / (right - left);
       float y = 2.0F * near / (top - bottom);
       float a = (right + left) / (right - left);
       float b = (top + bottom) / (top - bottom);
       float c = -(far + near) / (far - near);
       float d = -(2.0F * far * near) / (far - near);
       float e = -1.0F;
  
       Matrix4x4 m = new Matrix4x4();
       m[0, 0] = x; m[0, 1] = 0; m[0, 2] = a; m[0, 3] = 0;
       m[1, 0] = 0; m[1, 1] = y; m[1, 2] = b; m[1, 3] = 0;
       m[2, 0] = 0; m[2, 1] = 0; m[2, 2] = c; m[2, 3] = d;
       m[3, 0] = 0; m[3, 1] = 0; m[3, 2] = e; m[3, 3] = 0;
  
       return m;
 }


My C# script is simply this, and is attached to my only scene camera: Code:

 using System.Collections;
 using UnityUtil;
  
 public class ARCamera : MonoBehaviour
 {
   private Matrix4x4 customProj;
   private float near = 0.05f;
   private float far = 30.0f;
  
   // Use this for initialization
   void Start()
   {
     float left, right, bottom, top;
  
     camera.nearClipPlane = near;
     camera.farClipPlane = far;
  
     left = -0.3f;
     right = 0.1f;
     bottom = -0.1f;
     top = 0.1f;
  
     customProj = MathUtil.PerspectiveOffCenter(left, right, bottom, top, near, far);
   }
  
   // Update is called once per frame
   void LateUpdate()
   {
     camera.projectionMatrix = customProj;
   }
 }


This seems to have no effect of my camera frustum. When the player is running, the scene view shows a perfectly symmetric frustum. Setting the projection matrix seems to have no effect.

Anyone know what I might be doing wrong?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Owen-Reynolds · Jun 08, 2013 at 03:52 PM

Works for me. In either Update or LateUpdate. Check if it's working at all with just projMat = Matrix4x4.identity;

Then try it with much larger values. You may not be getting the scale correct, so that left/right of -0.3 and 0.1 is working, but is only making a difference of a few pixels. (I set matrix[3,0]=7 which should have jerked the camera sideways, but didn't appear to do anything. Changing to =20 I could finally see it was pulling to the right, 7 just wasn't noticeable.)

Then maybe look up the formula again. This is pretty well-known, so probably lots of places to go for the original.

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

Answer by Ender2718 · Jun 10, 2013 at 05:03 PM

From what I understood left, right, top, bottom, specify the extents of the near plane.

For the number I entered: left = -0.3f; right = 0.1f; bottom = -0.1f; top = 0.1f; near=0.05

That should be a pretty off center projection, yet the frustum gizmo in scene view (while running) does not change at all, and the projection to that camera looks no different than the on-axis version, as if my projection matrix was never actually applied.

BTW, does that matrix really need to be set on ever update/lateupdate? Why can it not be set once. Does it have to be set from a script directly attach to the camera or can it be set by another script for that camera but not attached to it?

Is there anything that would cause Unity not to use the matrix?

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

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

15 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to make camera position relative to a specific target. 1 Answer

Position camera so that 3d game object fills up 100px by 100px of screen space. 0 Answers

Room scale projection from unity 0 Answers

How to Project a video from a game object? 2 Answers

How to make an Off-axis / Off-center camera ? 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