# Moving object allong its own axes

Hi,

I’m trying to do the following: I want to move an object along its own axes. The translate function moves it around the original xyz axes, is it possible to move an object independent from this?
(I searched the webgl forum, but didn’t find a solution to this problem)

Thanks,
Fred

Sounds like you need a refresher on matrix math! Create a 4x4 matrix for the motion in the coordinate system of the object and multiply that by the 4x4 matrix for the location of the object in the virtual world. The result becomes the new matrix for the location of the object in the world.

Seriously: If you want to do 3D graphics, it is utterly essential that you become highly familiar with how matrix and vector math works. There is no way to dodge that. If you have to actually ask this question - then probably my answer above doesn’t help you much.

– Steve

Thanks for you reply. But I’m afraid I’ve posted this thread in the wrong section, it’s supposed to be in the webgl beginners section. :? But I understand your comment (partially) and I think I can search from this point to a solution. Are there any basic webgl/opengl books which I can read to boost my understanding?

In a typical opengl coordinate system, this can be done as following:
//move along local x direction
vec3 moveVec = mat.column.xyz;
mat.column += moveVec * moveLength;

//move along local y direction
vec3 moveVec = mat.column.xyz;
mat.column += moveVec * moveLength;

//move along local z direction
vec3 moveVec = mat.column.xyz;
mat.column += moveVec * moveLength;

The upper solution assumes no scaling is applied on the matrix.
Take scaling into account then we got:

//move along local x direction
vec3 moveVec = mat.column.xyz;
mat.column.xyz += moveVec.normalize() * moveLength;

//move along local y direction
vec3 moveVec = mat.column.xyz;
mat.column.xyz += moveVec.normalize() * moveLength;

//move along local z direction
vec3 moveVec = mat.column.xyz;
mat.column.xyz += moveVec.normalize() * moveLength;