How do I have to take into account the direction in which the camera is facing when creating a first person strafe (left/right) movement
- by Chris
This is the code I am currently using, and it works great, except for the strafe always causes the camera to move along the X axis which is not relative to the direction in which the camera is actually facing. As you can see currently only the x location is updated: [delta * -1, 0, 0]
How should I take into account the direction in which the camera is facing (I have the camera's target x,y,z) when creating a first person strafe (left/right) movement?
case 'a':
var eyeOriginal = g_eye;
var targetOriginal = g_target;
var viewEye = g_math.subVector(g_eye, g_target);
var viewTarget = g_math.subVector(g_target, g_eye);
viewEye = g_math.addVector([delta * -1, 0, 0], viewEye);
viewTarget = g_math.addVector([delta * -1, 0, 0], viewTarget);
g_eye = g_math.addVector(viewEye, targetOriginal);
g_target = g_math.addVector(viewTarget, eyeOriginal);
break;
case 'd':
var eyeOriginal = g_eye;
var targetOriginal = g_target;
var viewEye = g_math.subVector(g_eye, g_target);
var viewTarget = g_math.subVector(g_target, g_eye);
viewEye = g_math.addVector([delta, 0, 0], viewEye);
viewTarget = g_math.addVector([delta, 0, 0], viewTarget);
g_eye = g_math.addVector(viewEye, targetOriginal);
g_target = g_math.addVector(viewTarget, eyeOriginal);
break;