Physics and applications of metamaterials and nanophotonic devices