In glsl this is done via matrix multiplication, on the graphics card. I think if you wanted a general purpose solution you would want to use a similar method but you would lose out in the gpu acceleration