- Home /
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
bad
and here are some other views that are right and wrong:
good
good
bad
bad
this is what I'm trying to recreate:
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!
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
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.
yeah, i would like to see how you finally realized that thing! would you post a link or something? thanx alot!
Your answer
Follow this Question
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