optimized transformation matrix generation