My way of thinking about this is to think of the eye-and-camera system as a vector going from the camera to the eye. So when I’m trying to work out what’s going on, or how I want to turn the camera, then I try to visualise what’s happening to this vector.

But there are lots of ways to move a vector. If we assume, for simplicity, that it is of fixed length, then still we get 5 degrees of freedom: the position of the anchor (the camera in this case) and the direction of the vector (the displacement of the eye from the camera).

For example, in the roller coaster program then I want the camera to be looking at the person in the cart (this is in the newer version of the code, not the one included with Codea). So I work out the position of the cart, and that’s my eye vector. Then I want the camera looking at that point along the line of the track so I work out the tangent to the path at that point and move back in that direction by a fixed distance. This becomes my camera position. Finally, I use the normal to the track for the “up”.

I’m not completely clear as to what you want to achieve. In particular, should moving in the y-direction move the camera along the line it is currently looking along, or along some line fixed for all time? I’ll assume the former.

So we have a camera at a position **c** looking at a position **e**. These are in the xz-plane so I’ll write them as 2-vectors. The “up” direction is always assumed to be the y-direction. The user moves the controller by (x,y) and we want to interpret the x as an adjustment to the angle and the y as a forward/backward.

The first question is whether the adjustment to the angle should move the camera or move the eye. In the latter, we regard the camera as fixed but can rotate. In the former, we keep looking at the same point but move around it. I think that the latter makes most sense. So **c** doesn’t change, but **e** should transform by a rotation with angle x. Thus

```
e.x,e.z = math.cos(x)*e.x + math.sin(x)e.z, -math.sin(x)*e.x + math.cos(x)*e.z
```

If that’s rotating stuff the wrong way, change the signs of the sines. If you decide to do the assignments in two statements then you’ll need to use dummy variables as you must be sure to use the *old* values for `e.x`

and `e.z`

in the computations for the new ones.

The y-value is to be used to move the camera forward or backward along its current line of sight. Again, there’s a choice to be made. We could keep the eye fixed, or translate that as well. I’ll do the code for the latter. To do the translation, we need to add a vector to both the camera and eye position that is in the direction of the eye from the camera. Thus

```
e,c = e + y*(e - c),c + y*(e - c)
```

Again, if doing this in two statements then use dummy variables. To just move the camera then only update c.

I hope I’ve interpreted what you want correctly.