Dimitris,
> -----Messaggio originale-----
> Da: pli...@li...=20
> [mailto:pli...@li...] Per conto=20
> di Dimitris Mexis
> Inviato: marted=EC 24 luglio 2007 16.26
> A: pli...@li...
> Oggetto: [Plib-users] Matrices and sgCoord
>=20
> The following code has been a success in order to make the=20
> object move at a constant speed.
>=20
> sgCoord stigma;
>=20
> void GLObject::setStigma( sgMat4 & objDst){
> sgSetCoord( & stigma, objDst);
> }
>=20
> GLObject::move(){
> //The rotation matrix for moving around trireme.
> sgMat4 RotateMatrix =3D {
> 1, 0, 0, 0,
> 0, 1, 0, 0,
> 0, 0, 1, 0,
> 0,( getSpeed()), 0, 1
> };
> =20
> sgMakeCoordMat4( SHIPSRC, &trireme->getStigma()); sgMultMat4(=20
> SHIPDST, SHIPSRC, RotateMatrix); setStigma( SHIPDST);
>=20
> What I don;t understand is that I took the usual matrix and=20
> instead tweaking the last column element by the second row, I=20
> inversed it and put the getSpeed() which is <>0 in the bottom=20
> row! Why? this?
I hope to have understood correctly your perplexity.
First, SSG has a different coord reference system wrt OpenGL. Both have =
the
same handness, so x+ is along right in both, yet OpenGL is y+ -up, z+ =
-going
outside the screen, whilst SSG is z+ -up, y+ -going into the screen.
Second, SG's sgMat4 is a 4x4 homogeneous matrix for specifying =
projection,
viewing, modelling and/or object position. For old, nostalgic =
programmers,
it's a-la-IrisGL. The fourth row is the translation.
Then, when your ship moves on the sea plane, it actually moves on the =
x-y
plane (z=3D0), and hence elements of a sgMat4 ship_xform to change are
ship_xform [3][0], ship_xform[3][1] (ship_xform[3] can be pointed to by =
a
sgVec3 to set a transformation vector xyz).
That's the reason why you put getSpeed() for setting RotateMatrix[3][1]. =
In
a un-rotated viewing, you should see the ship entering/exiting into/out =
the
screen.
> I made then the matrix multiplications, and took the result=20
> to sgCoord.
> Is this right approach? Ok it works, but it worths?
You don't specify what you do with sgCoord stigma after the last set. If =
you
need to move it I assume your ship is a=20
ssgTransform *ship;
So you'll probably call
ship->setTransform( /* sgCoord* */ stigma ); // one of the several =
forms
to set a xform
Alternatively I could have done this way:
void move_ship( ssgTransform *ship )
{
sgMat4 ship_xform;
ship->getTransform( ship_xform );
sgVec3 ship_pos =3D { 0, getSpeed(), 0 }; // don't know if getSpeed =
is
directly callable, or an object method
sgAddVec3( ship_xform[3], ship_pos ); // just increment the =
position
coords, resembles sgMultMat4 for the translation part only
ship->setTransform( ship_xform ); // set the updated matrix =
back to
the object
}
Greetings,
Paolo Leoncini
|