In JMonkeyEngine, given any view direction Vector3f instance, I'd like to get a new vector facing the nearest x or z axis (positive or negative), with y set to 0.
For example
[-0.99915564, -0.036672898, -0.018518358]
// -> should return [-1, 0, 0]
[-0.01313778, 0.042407744, 0.99901414]
// -> should return [0, 0, 1]
Is there a nifty math trick for this or do I need to manually check x and z and then set y to 0
?
Thanks.
Update
So far, what I do is this
dir.x = dir.x >= 0 ? Math.floor(dir.x + 0.5) : Math.ceil(dir.x - 0.5);
dir.y = 0;
dir.z = dir.z >= 0 ? Math.floor(dir.z + 0.5) : Math.ceil(dir.z - 0.5);
Which produce the desired output. I was wondering if this can be done in a more elegant fashion (i.e. through some nifty matrix operation).