OK, so I mentioned that I was intending to work some on DirectQ's interpolation code. The original plan was to gut the current code and then start bringing on the QII interpolation code, but that didn't quite work out. Turns out that the old QER code is so deeply embedded into the engine that there would be some major surgery involved, so Plan B swung into action.
This involved dredging up the old QER tutorial from The Wayback Machine, reading it again with a fresh pair of eyes, going "meh" cos the code is really and truly quite horrific, then going into full-on experimental mode with what I've already got.
Step 1 was to make sense of the variable names. The QER guys used "pose1" and "pose2", for example, which doesn't really help with determining which pose number is the current one and which was the previous one. All well and good when you're writing the code in the heat of the moment, but not good at all when you come back to years later and try to bugfix it or add functionality. They also did the same with origin and angles, so good old-fashioned "try it one way and if it doesn't work try it the other" came to the rescue and provided me with sensible variable names.
From there I've cleaned it up a lot and generally made it more easy on the eyes.
All this is well and good, but it's nice to include a bonus feature for anyone using the engine, so I switched the interpolation from linear to cubic. This came with minimal CPU overhead and will give a smooth curve between points instead of a straight line. It's quite subtle, but once you do notice the difference (smoother and more even animations) it's hard to go back.
Of course it's not as perfect as spline interpolation, but that involves quite a bit of extra overhead on top of cubic, and I don't think right now that the difference would be as worthwhile as the step from linear to cubic was.
From here the next steps are to find places where I've front-loaded code into the renderer and move them back to the client where possible. I had already done this as long ago as MHQuake with orientation and position interpolation (which very cleanly fixed some issues that QER had messy code in the renderer for), but now I think there's scope for some of the animation code to also move.
The end result will be cleaner, more maintainable and give you a better visual result too. All nice.
Sunday, March 28, 2010
DirectQ Interpolation Work
Posted by
mhquake
at
8:14 PM
Subscribe to:
Post Comments (Atom)
2 comments:
Any chance that this will be tutorialised for use in other engines? Or will it be pretty obvious how it fits together once the source for the next version is released?
Cheers, kempie
It should be obvious, cubic interpolation was only a 2-line code change.
I'm not too certain about tutorializing it as every engine I've ever looked at has different code, so it would be quite useless to do so.
Post a Comment