If you’ve ever used 3D software you’ve probably used an orbit camera. It’s the control scheme where you drag the mouse to rotate around the target. It feels simple: just rotate around a point. But once you try to implement it yourself, the details of 3D rotations quickly get in the way.
When I first got into graphics I spent a lot of time building small demos to learn the basics of the pipeline. An orbit camera quickly rose to the top of my list because it made navigating those experiments so much easier. But back then, the explanations I found were either incomplete or jumped straight to quaternions. Some even tossed in a mysterious “clamp” to stop the camera from flipping upside down without ever explaining why it was necessary.
In this article, I’ll revisit the problem the way I wish it had been explained to me back then. I’ll show how to build an orbit camera using spherical coordinates: what they are, why they’re a natural fit, and the quirks that come with them. By the end, you’ll have a working implementation. You’ll also see why spherical coordinates aren’t the final word, and how their limits point toward more general solutions.
From Cartesian to polar coordinates
One of the simplest ways to implement orbit controls is with spherical coordinates. When I first came across them, they seemed like a somewhat abstract way of describing positions in space, but they turned out to be more intuitive than Cartesian coordinates. Spending a little time on spherical coordinates is worth it because they map directly to camera movement and appear throughout graphics. The easiest way to understand the math is to start with polar coordinates in 2D.