Results 1 to 5 of 5

Thread: Moving object allong its own axes

  1. #1
    Junior Member
    Join Date
    Apr 2011
    Posts
    4

    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

  2. #2
    Senior Member
    Join Date
    May 2010
    Posts
    207

    Re: Moving object allong its own axes

    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

  3. #3
    Junior Member
    Join Date
    Apr 2011
    Posts
    4

    Re: Moving object allong its own axes

    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?

  4. #4

    Re: Moving object allong its own axes

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

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

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

  5. #5

    Re: Moving object allong its own axes

    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[0].xyz;
    mat.column[3].xyz += moveVec.normalize() * moveLength;

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

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

Similar Threads

  1. Moving object with mouse
    By xrew in forum WebGL - General
    Replies: 3
    Last Post: 03-31-2011, 05:25 AM
  2. Moving object allong its own axes
    By freddy50 in forum WebGL - General
    Replies: 4
    Last Post: 01-01-1970, 12:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •