Hello everyone;
I had a bit of trouble deciding where this needed to be posted; although there is quite a bit of math involved, in the end this is about graphics, and some aesthetic concerns need to be taken into account. If this is in the wrong place, I apologize. There's quite a bit to this topic and quite a few questions, so please forgive the length.
So, what I am attempting to do is take a 3D rotation represented as a quaternion and use that to pick an appropriate sprite from a sheet. Think of it as a more complicated form of what was done in the original DOOM: I want to use the y rotation and x rotation to pick the corresponding sprite, then use the remaining z rotation to orient that sprite appropriately. I'm not sure if this has been done before, but if someone has, I'd love to see it.
I currently have a system that works, but I think it could be better. I currently have a simple sprite that is rotated in the x and y axes in 45 degree increments. I calculate the appropriate quaternion, and rotate the unit Z vector by it, and store this away. When I render the sprite in question, I get its current rotation, rotate the unit Z vector by it and compare the dot products of it and the vectors I stored away. I use the texture coordinates corresponding the the vector with the highest dot product. I then take the difference between the closest rotation quaternion and the actual rotation and find the component around the respective stored vector using swing twist decomposition. I extract the angle of this quaternion from its w component, giving me the z rotation of the sprite.
As I said, I think it could be better; it seems kind of silly to me to need to store those rotated Z vectors when I should just be able to compare the quaternions directly. There is a reason for them however; certain rotations are completely equivalent barring a rotation around z, which I'm hoping to extract separately regardless. Thus, I actually want to find the closest rotation irrespective of Z. However, I am struggling to find a way to make this work with only quaternions, as different rotations could wind up with the same orientation. I'm sure I just need to take the portion of the actual rotation around a certain axis before comparing with the stored ones, but I'm struggling to know what axis that is. No matter what I seem to do, it seems to pick the wrong sprite at certain times.
Another concern I have is smoothness. Obviously, 45 degree angle changes, even with a completely fluid Z axis, would still look a little jarring in motion. My game runs at a 60 Hz timestep, so my rendering rate would be at least that high. How small a rotation angle would I need to have an appealing turnaround at that rate? Or, perhaps better, is there some clever math or perspective trick I can do to fake it? I render with orthographic projection, but maybe I can pull a clever math trick?
The reason I'm doing this at all is because I was hoping to combine this with skeletal animation. Typical 2D skeletal animations look sort of like paper dolls, mostly because the bones can only turn on a single axis. I was thinking I could leverage the bone animation in something like Blender and use those rotations with this sort of sprite high resolution character sprites that animate fairly smoothly and look good from literally any angle.
But my fundamental question, at the end of the day, is this: is this actually worth my time to pursue further, given how much of a headache it has already been?
I mean, I still think its a neat idea, but I might just be better off modelling everything in Blender in the first place. Even if I were to reduce the number of orientations to the bare minimum, removing symmetrical cases and orientations in which a sprite would never be seen, that would still be a lot of sprites for a single character. My time might be better used elsewhere.
I've been thinking about these issues in a vacuum, so I was hoping to get input from other people before I drive myself to the brink of insanity trying to do something that may not be as clever as I thought.
Hopefully I explained everything satisfactorily.
Thanks for your help.