What you need to do is set up your system to control the characters movement and his rotation. You than place a 3d sphere at the characters location, rotate it to your characters orientation, and than offset the sphere. Next you place your camera at the spheres location and rotate it towards your player.
You need to use a collision or physics library such Sparky's Collisions, PhysX, Newton Game Dynamics, etc to perform collision checks between your character and the game world. It is a lot harder to do, but using my method you are set up to also perform collision detection with the camera sphere and the game world, allowing you to make sure your camera can't be positioned behind the game world.
You could use rays to test the location where the camera sphere will be moved after it has been rotated, this will allow you to position the camera sphere in front of any obstacles or the game environment.
I have 200 lines of code dedicated to moving my character around the game world, I haven't implemented checking the camera sphere for collision yet. I am also using Sparky's collision and will have to rewrite my character controller when I finally implement PhysX into my code.
------------------------------------
Currently 1300+ lines of code into an "over-the-shoulder" action RPG with combat based on rag-doll physics.