Pan and zoom

189 views
Skip to first unread message

Maelvon

unread,
May 11, 2012, 4:54:54 AM5/11/12
to SceneJS
Hello,

I see in the examples that we can rotate the camera (yaw and pitch)
around an object. But I don't see example of panning and zooming. Is
that possible?

I see some threads here but nothing very clear.

Thanks,

Maelvon

Lindsay Kay

unread,
May 11, 2012, 5:02:36 AM5/11/12
to sce...@googlegroups.com
Hi Maelvon, 

sure is, you can do this by manipulating the 'eye' and 'look' properties of the camera node.

To pan, just find the vertical and horizontal vectors orthogonal to the eye->look and eye->up vectors and move the eye and look points along those.

Some pseudocode to get you started:

pan(x, y, rate) {

        // get look and eye from your camera node

        var forward = normalizeVec3(subVec3([look.x, look.y, look.z], [eye.x, eye.y, eye.z]));
        var axis = cross3Vec3(up, forward);
        up = normalizeVec3(cross3Vec3(axis, forward));
        var right = normalizeVec3(cross3Vec3(forward, up));

        var moveX = mulVec3Scalar(right, x * rate);
        var moveY = mulVec3Scalar(up, -y * rate);
        var move = addVec3(moveX, moveY);

        var newLook = addVec3([look.x, look.y, look.z], move);
        var newEye = addVec3([eye.x, eye.y, eye.z], move);
        var look2 = { x: newLook[0], y: newLook[1], z: newLook[2] };
        var eye2 = { x: newEye[0], y: newEye[1], z: newEye[2] };

       // ... now set new look2 and eye2 on camera node
Reply all
Reply to author
Forward
0 new messages