Tuesday 17 May 2011

A controlled explosion is a good explosion

Finally got around to sorting the explosion of parts along more axes than just X. Taking some angles of parts from Blender helped again, but I needed to sort out some vectors. In hindsight 3D vectors were what I needed, but since I had consciously made the parts on only two planes (xy and zy) I didn't really have to solve this, just do 2D vectors and swap the planes around when needed.





Luckily I had a handy vector function from my previous assignment that takes a point, angle and magnitude and gives you back the new point (this is super handy, why do PVectors not do this?). I think I'll write a version that can handle 3D also, then put it into a nifty Utils class or module that I can import into later projects.

The motion is not properly hierarchical, because the class structure stupidly is not either (man my class structure is overly simple) but I managed to cheat a bit for that too, since only a few parts really needed to act relatively.

Oh, and the direction-based mouse code I have been proud of and using for a while now has been superceded! Turns out the normalisation of the direction information (so that it's either 1 or -1 regardless of how far you actually travelled) was a dumb thing to do. Because of frame rate, the mouse moves further than 1 pixel per frame, so the values you are modifying (like rotation of the model) because proportional to the time spent moving the mouse, rather than how far you moved it. The end result is control that feels muddy and sluggish, since moving the mouse the same distance will not always yield the same outcome. I had written a bunch more code and introduced several global variables to get around this normalisation for my current project before I realised that simply taking it out fixes everything. Facepalm.

No comments:

Post a Comment