Sunday 25 October 2009

Nearly there, perhaps...

Phew, so thats officially the end of my weekend coding session. Incidentally its also the end of my weekend, so I didn't really have much say in the matter. A recent screencap of my creation:

Things that have happened:

  • Spaceship: hardcoded; weighs in at 16 polys and 24 lines. Gently bobs and rotates. 
  • 2D mouse point projected onto plane in 3D. The cursor has been replaced by a translucent square, the centre of this square is projected onto the 'visually accurate' position on the plane that is the ground (fps style). The position is used to move the spaceship, so that is it hovering above it. Essentially, mouse moves in 2D world across screen: spaceship moves in 3D above ground.
  • I got the formula for this by re-arranging the 3D-to-2D one, look at the previous post if you're havin a confuz, it looks like this:

_3dPoint._y = yPlane;
_3dPoint._z = (yPlane * FOCAL_LENGTH)/(_2dPoint.Y - VP_Y) - FOCAL_LENGTH;
_3dPoint._x = (_2dPoint.X - VP_X)/(FOCAL_LENGTH/(FOCAL_LENGTH + _3dPoint._z));

  • Tree animation! Re-engineered the algorithm so its prettier to look at. Individual branches move independently while the entire tree sways left and right, also the amount of movement increases towards the top, like a normal tree (it still looks like seaweed though).
  • Lightning! Click/Hold the Left button to strike the ground beneath the spaceship with a lightning bolt. Its pretty much just 2 lines each made of 5-6 points which get a new random x and z value each frame (y values preserved). Simple enough but it works ok.
  • Fire! Wherever the lightning strikes, burns. If it hits the bottom of a tree, the fire will spread up the tree. If it hits a yucky little spidery squit, that burns too (the fire travels with it on its back). Each fire burns for 5 sec.
  • Game-ish elements.... Every time you burn something you get a point :) As if you really needed the motivation.

At the moment there are some performance issues with the fire since it involves drawing a great many shapes and Gdi+ is slow. However there is one optimization that I haven't got round to working in yet, and it is very closely tied to a memory leak which took about a million trillion years to find:

Using Gdi+'s graphics.fillPoly(...) function, you need to provide it with a Gdiplus::Brush (which contains info like what colour to use). This was an unexpected turn of events when I was coding that particular section, and as such I only had a Gdiplus::Pen available. 'Ahh, not to worry' I thought, 'I can simply use the pen.GetBrush() function to retrieve a brush from the pen!'. Well it worked, but I didn't realise that it created a new brush each time, and I had written the GetBrush() directly into the arguments for the the fillPoly function. Every screen drawn was costing me memory!

Anyways, the final goal for this project now is for burnt things to die and new ones to spawn. Trees will grow to replace burnt ones, spiders will spawn very little and grow to replace their dead too. An ongoing simulation of burning strange creepy icky horrid little messes of a creature called spider, of burning peculiar wiggly fronds of seaweed, and of their subsequent rebirth. Great!


Toodles

 

No comments:

Post a Comment