On Tue, 18 Dec 2007, gsteixei wrote:

> Im new with soya and im stucked with a simple task, i would like to
> know how could i know the direction of an object.

that should be simple indeed. i was a bit surprised it is not provided as 
a volumen.direction property, or something.

> For example, I have a character (actually it is Balazar :p) and i
> want to know which is its direction from north, like if he have a
> compass...

at least the orientation / rotation can be gotten from the object matrix, 
which is soya3d i guess is the common 4x4 matrix used in most computer 
graphics things. it seems a bit particular though, that all the values are 
flatted to a single dimensional matrix, but that makes no diff really..

In [1]: import soya
In [2]: v = soya.Volume()
In [16]: v.matrix
Out[16]: (+ formatting by me now, just linebreaks to make it clearer:
(1.0, 0.0, 0.0, 0.0,
  0.0, 1.0, 0.0, 0.0,
  0.0, 0.0, 1.0, 0.0,
  0.0, 0.0, 0.0, 1.0,
  1.0, 1.0, 1.0)

.. hm apparently i was wrong and it is not a 4x4 matrix, but has .. 3 
extra elements, that perhaps is the scale, which iirc is also the diagonal 
line of 1.0s there (the default position is at 0).

anyhow, the 'rotation part' in a (4x4) matrix is the first 3 values, 'the 
upper left corner', so for example in Blender the matrix.RotationPart() 
method (in source/python/api2_2x/matrix.c) just returns these values:
self->matrix[0][0];
self->matrix[0][1];
self->matrix[0][2];
self->matrix[1][0];
self->matrix[1][1];
self->matrix[1][2];
self->matrix[2][0];
self->matrix[2][1];
self->matrix[2][2];
('->' is just c for '.' (well not exactly but in this case yes) :)

and that is a normal 3d vector of the rotation iirc.

what happens when rotating in object in soya seems to be as follows:
In [21]: d = soya.Vector(None, 1, 0, 0)
In [25]: v.look_at(d)
Out[26]:
(-0.0, 0.0, 1.0, 0.0,
   0.0, 1.0,-0.0, 0.0,
  -1.0,-0.0,-0.0, 0.0,
   0.0, 0.0, 0.0, 1.0,
  1.0, 1.0, 1.0)

so what do we see here? i am not sure :)
i guess the default axis used for that looking also rotated the object 
somehow. when using a more specific call, another kind of matrix results:

In [27]: v.look_at_x(d)

In [28]: v.matrix
Out[28]:
( 1.0,  0.0,  0.0, 0.0,
   0.0, -1.0, -0.0, 0.0,
   0.0, -0.0,  1.0, 0.0,
   0.0,  0.0,  0.0, 1.0,
   1.0,  1.0,  1.0)

uh i don't actually know what is happening there - either i remember 4x4 
matrices wrong (has been a while had had to calc using them directly), or 
my guess of the soya matrix structure was all wrong to begin 
with. so am afraid that can't really help here, and must wait for the 
authors to educate us :) .. in ogre i think quaternions are used 
internally for rotation, so the GetOrientation it has just returns that, 
and there are ways to calc the dir vectors from that but that's a 
different story.

of course in games it goes vice versa, that you use look_at or such 
methods to set the direction of your objects, and that direction you can 
just keep yourself (as a vector).

> gnudoido

~Toni

_______________________________________________
Soya-user mailing list
Soya-user@gna.org
https://mail.gna.org/listinfo/soya-user

Reply via email to