Today I went in and revamping the rendering engine. I changed all of the canvas paths so that they are defined on a scale of -0.5 to 0.5 in both the X and Y planes. I did this for two reasons:
- it means that everything is constantly defined at a scale of 1.
- by going from -0.5 to 0.5 instead of 0 to 1, it makes the translation code much easier to calculate. When you start drawing from the top left corner of the object you have to do additional translations to make sure the object lines up with its proper position. By having the image defined with (0,0) in the center, you can just draw it at the correct location.
Of course, making this improvement broke a bunch of things.
- I had to fix the algorithms that determine the starting position of lasers and thrusters.
- I had to tweak the collision detection code.
- I had to change the translation and scaling for everything to scale up the object from 1 to X.
There were a few other changes but I’m happy with the result. I feel like the rendering is a lot more predictable now and all measurements of distance are now based on the same base unit, 1 Meter. The raw path instructions all draw the objects to be 1 meter by 1 meter and then they are scaled up to the correct size.
The way I was doing it sucked because every object was scaled differently and had to be transformed differently. Not very maintainable!