Rendering Engine Revamp

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:

  1. it means that everything is constantly defined at a scale of 1.
  2. 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!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s