Clustering of galaxies in a hierarchical universe - I. Methods and results at z=0