2.3 Moving a sprite within a sector

By Charles Quarra, charsquarra@hotmail.com.

Now that you have a sprite, you want to move it around. do it with either:

sprite->GetMovable()->SetPosition( csVector3(x,y,z) );
sprite->GetMovable()->UpdateMove();

which sets the position to the x,y,z point of the parent mesh where sprite is in. Remember that we set that sprite's iSector* to room, so this coordinates are room coordinates. Later we will see that a sprite could be parented easily to another sprite, in which case coordinates are relative to the parent sprite. The UpdateMove() updates the engine with the new coordinates

or:

sprite->GetMovable()->MovePosition( csVector3(x,y,z) );
sprite->GetMovable()->UpdateMove();

which adds x,y,z to the current coordinates where the sprite is. This moves relatively while SetPosition moves absolutely. The more general linear transformation is a displacement and a rotation. CS contains a struct that can handle this transformations. This structure is called csReversibleTransform. It has a csVector3 (for displacement) and a csMatrix3 (for rotation). You can create one with:

csMatrix3 ROT;
csVector3 POS;
csReversibleTransform T(ROT,POS);

This tranformation represents the change in coordinates

      x' = ROT*(x - POS)

where x and x' are old and new coords, respectively. Now, how do you tell the sprite to do the transform? Easy:

sprite->GetMovable()->SetTransform(T);
sprite->GetMovable()->UpdateMove();

(You dont have to do the UpdateMove() every time you do a change; you could do various changes and then call UpdateMove() just once.) How do you query the current transform to discover where the sprite is?

csReversibleTransform CURRENT = sprite->GetMovable()->GetTransform();