rotation matrix for particle track

Struggling with some equations here. I've got a particle I need to track in an absolute reference frame, but each step I move/rotate it relative to its own reference frame. I need to track it's absolute position while moving it relatively.

I'm trying to figure out the proper set of rotation matrices. It propagates along the x-axis and I can describe its current direction with [ux, uy, uz], now I need to rotate it about it's own reference frame by the deflection $\theta$ (deflection from incident direction) and azimuthal rotation $\phi$ (rotation about incident direction), and then find its new position, [ux', uy', uz']. Should I multiply by the rotation matrix, ROT[y,$\theta$], then ROT[x,$\phi$] or the opposite order?

I'm just getting myself confused. By way of reference, I'm trying to derive the set of equations on (pdf) page 20 of this document.

It's a) not derived very well and b) derived for propagation along the z-axis, not the x-axis.

TL;DR - I have a vector in space pointing in an arbitrary direction, described by its projections on the world x,y,z-axis. I need to rotate the vector, in relation to its own reference frame, and find the world axis projections. Essentially this is a ray-tracing problem. Incoming ray needs to point in a new direction - what is that direction?

-
What do you mean by "It propagates along the x-axis and I can describe its current direction with [ux, uy, uz]"? If it propagates along the x axis, why isn't its current direction [1,0,0]? – joriki Feb 7 '11 at 22:45
joriki, sorry, it originates by propogating along the (world) x-axis - but after several movements, it doesn't stay there. But, deflection ($\theta$) is in reference to the local x-axis and azimuthal rotation $\phi$ is rotation about this axis. – gallamine Feb 8 '11 at 13:33

Let $R$ be the rotational matrix which has the axes of the local frame, represented in the world coordinates in its columns. This means that $R$ as a matrix maps directions from vectors expressed with projection in the local frame to world space. Let $T$ be the rotation you have to apply, which is written in the local coordinates. What you do is: you transform to the local coordinates (inverse of $R$ does that), do the rotation, and go back:
$$\vec{x}'=RTR^T\vec{x}$$