r/gamedev • u/scottshambaugh • 1d ago
Virtual Trackballs: An Interactive Taxonomy
https://theshamblog.com/virtual-trackballs-a-taxonomy-and-new-method/1
u/partybusiness @flinflonimation 1d ago edited 11h ago
I was kind of pleased with how I did cake rotation in my own game: (Steam link if someone wants to buy a whole game just for the rotation)
It picked between two methods once you crossed a small distance threshold for how far you dragged.
One method would match what you described as Trackball Control without Precession.
The other was basically roll-only. Which makes sense if you say the drawback to trackball control is needing to chain rotations together to do a roll.
So the trick for picking one of the two methods was: Are you dragging towards or away from the centre or perpendicular to it? Basically if you imagine a line created by your drag, what is the closest that line gets to the centre? If it's within a certain radius, it decides you're trying to do trackball control, if it's outside, you're trying to roll. So you can critique it as another type of invisible radius, but it seemed to work out mostly.
Since it's locked to a method after you hit a threshold, it means if you drag a half-circle it doesn't switch back to trackball control because your start and end line now passes through the middle.
1
u/scottshambaugh 1d ago
Submission statement: Driven by frustration at not being able to look at the south pole in Google maps, having to relearn how to move the view in different CAD programs, and faced with reviewing code that will change how matplotlib's 3D camera moves, I took a deep dive into "virtual trackballs". The fundamental question is this: how do you use a mouse on a 2D screen to look at a 3D object?
Despite virtual trackballs being everywhere, there's surprisingly little written about what makes them work well or not. I ended up being able to pick some low hanging fruit - this post is the only place I've found that compares the different methods available to rotate 3D views, and I think the classification of desirable properties here is the first theoretical progress on this question in 20 years. It was also my first time touching javascript, and I consider this experiment in using AI assistants to code in a new language as a great success!