|Zombie simulator: sprites ahoy!|
|Saturday, 09 January 2010 14:23|
I had a productive morning and was able to write both the sprite importer class and the sprite class and here's the first output.
One hundred sprites randomly generated and dotted around the top left corner of the map.
Because I want to animate the sprites, I used the TextureMatrix feature of the material assigned to each one to limit the texture applied to the two triangles that the sprites are rendered on. I had to jump through some hoops to get it work though since the texture was inverted when loaded. I found that if I used negative texture coords when creating the vertices, the texture would vanish altogether.
In the end, it was a series of changes made to the texture matrix that solved the problem, using the following code, where x and y identify the sprite by it's index into the texture, not it's pixel location.
vector2df scale(spriteSize / texture->getSize());
This has meant that each sprite needed to be a unique scene node object as in addition to each needing it's own material, they also have to have their own locations. In the long run, I think it may be more efficient to write a custom sprite scene node and generate the triangles and texture coords as needed only for those sprites that are on-screen during each frame. I suspect it will be faster to render this way as there could be thousands of scene nodes otherwise, each one of which is being culled, and transformed individually by Irrlicht's engine.blog comments powered by Disqus