View Full Version : Moving object allong its own axes

freddy50

04-02-2011, 01:45 AM

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

SteveBaker

04-02-2011, 03:53 AM

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

freddy50

04-02-2011, 04:44 AM

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?

oak3d

04-02-2011, 08:54 PM

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;

oak3d

04-02-2011, 08:58 PM

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;

Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.