We consider a gas of ultracold two-level atoms confined in a cavity, taking into account for atomic center-of-mass motion and cavity mode variations. We use the generalized Dicke model, and analyze separately the cases of a Gaussian, and a standing wave mode shape. Owing to the interplay between external motional energies of the atoms and internal atomic and field energies, the phase-diagrams exhibit novel features not encountered in the standard Dicke model, such as the existence of first and second order phase transitions between normal and superradiant phases. Due to the quantum description of atomic motion, internal and external atomic degrees of freedom are highly correlated leading to modified normal and superradiant phases.