JohnG
Ex Member
Re: how do i get the rotations of a camera?
Reply #3 - Mar 29th , 2010, 6:25am
One bit of info that will probably be useful, is that by default the view angle is 60degrees. I believe this is 60' on whichever screen-dimension is largest, so if your width is greater than height, the angle is 60' across and the height angle is 60/width*height. If you take those angles, and some assume distance from the camera to the drawing plane, and some vector from the camera towards it (and an up-vector), then it becomes just some trigonometry to work out what screen x/y position. It won't be the easiest trig, but should be doable. The "left" vector (that is going from the centre of the screen towards the left) will be the cross-product of the camera direction vector, and the camera up-vector. The "width" of the canvas is simple too, if it's 200 units away, and the FOV is 60' horizontally, then split it into two right angled triangles, you have 200 on the adjacent edge, and an angle of 30', so you the half-width is arctan(30' in radians)*200. Double that and you have the total width. Normalise your "left" vector.. that's now one unit along the width of the canvas. Find out what one pixel on screen means in terms of canvas width (e.g. if the canvas width is 800, and your screen width is 400, then 1 pixel = 2 canvas width units) The camera position plus the distance*camera look-at vector = middle of canvas. Work out how many pixels left (or right) of centre the cursor is, and add that *left vector (or that *(-left) ) to the middle of the canvas and voila, you have the world co-ordinates of the mouse's left/right position. Repeat the same for the up/down position and you have it all in world coordinates.