Zombie simulator: lots more props E-mail
Monday, 25 January 2010 18:45

I started putting in props yesterday and I had a lot of trouble positioning the sprites on the map purely by X,Y and Z coordinates, having to tweak everything by 20 or 30 pixels in various directions.

I tracked the problem back to the fact that the sprites are actually drawn onto two triangles arranged in a square to face directly at the camera. This means that the "quad" has been rotated in two dimensions, so the X,Y and Z coordinates of the top left corner of the mesh have moved. I settled on a method of positioning all sprites by an imaginary centre point located, between the feet of the human model, at the base of the stop sign's pole, etc, and worked a rule for all sprites no matter the size. Now it's easy to put something on the map, right where I want it.

Once I'd begun trying to generate sprites from the new models, I encountered a further "simple" problem that was a real pain. Sprites are generated by loading the models into Irrlicht and then rotating them against a transparent background, eight times to make a full circle. After each rotation, a snapshot is taken from the world camera's perspective, trimmed and added to a group texture. The latest problem only affected street lights because of their shape - tall and thin, with an arm sticking out one side. The street light wasn't rotating centred around the central shaft, which made it off-centre, leading to evil fudgery in Irrlicht, of the sort "if sprite x and facing direction y then position = position + offset Z". Totally unacceptable because it makes everything that much harder to get right.

The reaons for this problem is that the B3D exporter loses the object centre point, as defined in Blender, and simply repositions all the vertices around the center of the model extents. I was thinking of some elaborate code to try and figure out the rotational centre of an object when I came up with a quick fix.

The solution was to add a disc to the base of the street light model to force the extents of the model to be the same on all sides. To stop the disc appearing in the rendered result, I simply flipped the normals and turned on backface culling in Irrlicht. It saved a lot of time.

The new models are all pretty basic, but at the scale they appear in the zombie world, they'll probably be fine with maybe a little tweaking down the line.

With the props created, I made up some basic rules for the number and locations of everything, and added a few lines of code to the class that constructs the roads:

  • The street lights appear mid way down every straight bit of road.
  • Stop signs appear only at three way intersections, facing the direction of the traffic that is approaching the intersection, on the correct side of the road.
  • Traffic lights are at four way intersections
  • Rubbish bins and bus stops appear three quarters of the way down 20% of streets that are longer than 3 map units in length (256 pixels per map unit). It's always one or the other, but never both on a street.
  • Fire hydrants appear 1/4 of the way down 10% of streets

I'm also thinking about including speed limits on streets rather than have cars travel at the same speed on every street. The rule for that would be the uninterrupted stretch of road, the higher the speed limit. This isn't really necessary, but it's a nice idea nonetheless. I'll have to have some sort of speed limit built into the road class anyway to control the traffic, so I might as well make it a variable feature.

It's getting close to time to animate the human model and adding some vehicles to the roads.

blog comments powered by Disqus