Transforming to arbitrary coordinate space

   3929   4   1
User Avatar
Member
22 posts
Joined: June 2008
Offline
Hello,

Have three vectors X,Y,Z in camera space that form an orthonormal basis.
And vector V also in camera space.

Just need to convert V from camera space to X,Y,Z space.

Tried to do it like this:


vector av = array(X,Y,Z);
matrix A = set(av);
vector res = vtransform(V, A );


but result is wrong.

How can one transform V from camera space to coordinate system defined by X,Y,Z?
TD @ Mr.X Inc
User Avatar
Member
519 posts
Joined:
Offline
Try this piece of code:


vector av = array(X, Y, Z);
matrix A = maketransform(0, 0, av, av, av2]);
vector res = vtransform(V, A);
User Avatar
Member
22 posts
Joined: June 2008
Offline
Pagefan
Try this piece of code:

Thanks for reply, unfortunately result seems to be wrong.

matrix maketransform(int trs, int xyz, vector t, vector r, vector s)

From the docs:
maketransform builds a general 4×4 transform matrix given an order of transformations (trs), an order for rotations (xyz), a vector representing the translation (t), rotation (r), scale (s)

In my case X,Y,Z are not vectors that represent rotation or scale.
This are just three vectors that form a basis.
TD @ Mr.X Inc
User Avatar
Member
519 posts
Joined:
Offline
Ah I missed that about the X,Y,Z being a custom space…

My matrix math is a bit rusty but give this a shot:


vector V = set(your_x, your_y, your_z);
vector av = array(X,Y,Z);
vector cur_space = ({1,0,0}, {0,1,0}, {0,0,-1});
vector cam_space = (normalize(vtransform(“space:camera”, cur_space)),
normalize(vtransform(“space:camera”, cur_space)),
normalize(vtransform(“space:camera”, cur_space)));
/*since both the vectors are orthonormal you only need to retrieve one rotation*/
matrix3 mat = dhideral(cam_space, av);
vector Vnew = vtransform(V, mat);

If it doesn't work, could you post your hip file?
  • Quick Links