# WebGL- moving an object in the line of sight

I defined my Model-View Matrix defining a function lookAt that represents the eye of the camera, the position of the object that I'm representing and the "up" vector of the camera. How can I move the object in the line of sight of the camera? Any tips? If I define the vector that points to the position of the object and starts at the eye of the camera (so if I define the line of sight) how can I use this to make the object move along this direction?

This is my lookAt function

  function lookAt( eye, at, up )
{
if ( !Array.isArray(eye) || eye.length != 3) {
throw "lookAt(): first parameter [eye] must be an a vec3";
}

if ( !Array.isArray(at) || at.length != 3) {
throw "lookAt(): first parameter [at] must be an a vec3";
}

if ( !Array.isArray(up) || up.length != 3) {
throw "lookAt(): first parameter [up] must be an a vec3";
}

if ( equal(eye, at) ) {
return mat4();
}

var v = normalize( subtract(at, eye) );  // view direction vector
var n = normalize( cross(v, up) );       // perpendicular vector
var u = normalize( cross(n, v) );        // "new" up vector

v = negate( v );

var result = mat4(
vec4( n, -dot(n, eye) ),
vec4( u, -dot(u, eye) ),
vec4( v, -dot(v, eye) ),
vec4()
);

return result;
}

• Do you mean you want the object to move directly towards or away from the eye? May 20 '17 at 0:31
• Yeah along the direction of the eye May 20 '17 at 10:06