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 Jordan Miller 2 · Aug 09, 2010 at 10:17 PM · cameramovementzoomfieldofviewprojection-matrix

Camera Zoom/custom projection having trouble.

I'm having a hard time with a program I'm making. in my program there is a frame - a window I want my camera to look out of no matter where the camera is. this means when the camera strife's left it has to look right, when the camera moves along the y axis it has to look down, and when the camera moves backwards it has to zoom in. I have the x axis and the y axis working fine enough for now but the zoom in and out isn't working so well at all.

if you're gonna help me with this its going to take work, thanks so so so much:

Here's the set up I have:

1 camera at x = 0 y = 0 z = 0

a terrain at x =-100 y = -1.080001 z = -445.7925

4 boxes forming a visual frame in the camera's view so I can see if its working

the camera has these two scripts attached:

FPSWalker.js which make the camera have a character controller and lets it move around

Stereoscript.js which makes the camera have the correct angles to look at the same window no matter where it travels. (this is the script i need help writing.)

here are the proceedures in the StereoScript.js that I know are working perfectly:

@script ExecuteInEditMode

var left = -0.5; var right = 0.5; var top = 0.5; var bottom = -0.5; var rr2 : float ; var ll2: float ; var tt2: float ; var bb2: float ; function LateUpdate () { var cam = camera; var m = PerspectiveOffCenter( left, right, bottom, top, cam.nearClipPlane, cam.farClipPlane ); cam.projectionMatrix = m;

}

static function PerspectiveOffCenter( left : float, right : float, bottom : float, top : float, near : float, far : float ) : Matrix4x4 { var x = (2.0 near) / (right - left); var y = (2.0 near) / (top - bottom); var a = (right + left) / (right - left); var b = (top + bottom) / (top - bottom); var c = -(far + near) / (far - near); var d = -(2.0 far near) / (far - near); var e = -1.0;

var m : 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; }

here's the proceedure on the stereo script I'm having trouble with: complete with comments of whats going on and the troubles I have:

function Update(){

//this is my attempt to implement an equation to calculate the angle of a right triangle. //as my character moves backwards his camera makes a right triangle. to keep the edges of //my view aligned with the edges of the frame I'm looking through I have to calculate that //right angle.

myAngle = (Mathf.Atan(2.761007 / Camera.main.transform.position.z))*(-1);//Mathf.Rad2Deg)(-1); print (myAngle);

//the following if statements calculate where the sides of my camera view must be in order //to keep looking at the frame while we're traveling left or right, up or down. but it //doesn't help us when we're moving forward and back.

if (Camera.main.transform.position.x>0) { ll2 = Camera.main.transform.position.x*(.175)(-1); ll= (ll2)-.5; rr2 = Camera.main.transform.position.x(.175)(-1); rr= (rr2)+.5; } else if (Camera.main.transform.position.x<0) { ll2 = Camera.main.transform.position.x(.175)(-1); ll= (ll2)-.5; rr2 = Camera.main.transform.position.x(.175)*(-1); rr= (rr2)+.5; } else if (Camera.main.transform.position.x==0) { ll= -0.5; rr= 0.5; }

if (Camera.main.transform.position.y>0) { bb2 = Camera.main.transform.position.y*(.175)(-1); bb= (bb2)-.5; tt2 = Camera.main.transform.position.y(.175)(-1); tt= (tt2)+.5; } else if (Camera.main.transform.position.y<0) { bb2 = Camera.main.transform.position.y(.175)(-1); bb= (bb2)-.5; tt2 = Camera.main.transform.position.y(.175)*(-1); tt= (tt2)+.5; } else if (Camera.main.transform.position.y==0) { bb= -0.5; tt= 0.5; }

//this is my pathetic attempt to implement the earlier equation: //angle = Tangent("opposite side/adjacent side") //this is supposed to help me with my zoom.

lll = ll*myAngle; ttt = tt*myAngle; bbb = bb*myAngle; rrr= rr*myAngle;

//these set the right, left, up, down to what they should be given my calculations are //correct. those variables get used by the above (working) procedures to create the affect.

left = lll; right = rrr; top = ttt; bottom = bbb;

}

now I'll include some pictures of what I mean. the Yellow lines were drawn on top of the screen prints to show where I want the camera angles to be.

good straight on is good

bad but when I move back I get this

and here are some other views that are right and wrong:

good good left

good good right

bad back bad right

bad back bad left

this is what I'm trying to recreate:

what I'm trying to recreate what I'm trying to recreate 2

Even if you just have pointers of ideas please respond I've spent hours and hours, well days really on this project and I need to make head way or drop it. please please help! thanks!

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by jooki-2 · Feb 13, 2011 at 11:41 PM

hey jordan, i'm working on such thing to FaceApi Headtracking mit unity but i can't understand the necessary steps for the asymmetric projection. have you finally finished it? greetings, jooki

Comment
Add comment · Show 2 · 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 Jordan Miller 2 · Feb 14, 2011 at 06:34 AM 0
Share

I did finish it. and then I scrapped the whole project. if you're interested in my code I'll share it with you but I don't know if I can remember how it all works.

avatar image jooki-2 · Feb 16, 2011 at 02:58 AM 0
Share

yeah, i would like to see how you finally realized that thing! would you post a link or something? thanx alot!

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

No one has followed this question yet.

Related Questions

How to add Pinch to Zoom? 0 Answers

Change field of view over time 1 Answer

Script to constantly change FOV? 1 Answer

Camera movement and zoom bounds 0 Answers

How to make a camera zoom on a particular part of image plane? 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