Design and optimization of control primitives for simulated characters