I am not sure if I understand it correctly, as I somehow stopped thinking after the first sentence. But is this what you want? http://stackoverflow.com/questions/349050/calculating-a-lookat-matrix