| Zombie simulator: rooves and picking |
|
| Wednesday, 06 January 2010 07:36 |
Keeping the rain offBeen a busy couple of days, not really achieving a whole lot, but advancing nonetheless. I added floors and rooves to the buildings. This was an exercise in frustration that involved in going back and forth between Blender and C++ tweaking and changing until I had the basics setup correctly. As it stands, it looks adequate, though the texture coordinates and textures themselves need to be worked on.
I went back and broke the single multiple-building mesh down into one mesh per building, though all nodes are still positioned at the origin, with the vertices controlling where in the city the building is located. In total there are now 167 nodes in the scene, comprised of 272 mesh buffers, where each floor of each building occupies one mesh buffer. After implementing node picking (detailed below), I was able to set up the engine to highlight a building when it's clicked on and print out the building's stats on the console. In the image, the building in the green box is comprised of four floors, using a total of 1,802 vertices and 2,718 triangles. The typical single level building uses around 500 vertices and 800 triangles, so it doesn't take much to quickly exceed 30,000 triangles in the window when the camera is zoomed out at maximum as it is in the picture. Performance is still OK - it doesn't get close to dropping below 60fps until the entire city is in view, which is about 50,000 triangles, and at this stage, it's theoretically just fast enough to complete what I want to do on my mid-range hardware, but if possible I'd like to have this running on anything above a netbook. Luckily, there's room for improvement:
Node pickingThe primary reason I switched to one node per building was so that I could quickly isolate a building using Irrlicht's "node picking" functions - basically translating a mouse click into selecting an object on the screen. When setting up the orthographic viewing matrix for the camera, one of the parameters defines whether the view uses orthographic or perspective calculations. I obviously set this to orthographic, and that parameter is used by Irrlicht's collision manager to determine how to translate a 2D screen coordinate into a 3D world location, when the mouse is clicked. At first, when I tried this, I discovered that there was something amiss. The only nodes that would register a click were those in the top half of the screen, which left me thinking it was Irrlicht that was playing up. Further investigation revealed that the culprit was in fact the camera's frustum, specifically the near plane. When I first began messing around with the orthographic camera, I had to set the view frustum near and far values to huge numbers, -40,000 and +40,000 respectively. This was done to stop Irrlicht's frustum culling from being too enthusiastic - basically the frustum box was moving at a different speed to the camera which meant as the view moved away from the origin, the clipping area gradually became visible until all the buildings were clipped by the time I'd gotten to the bottom right corner of the city. Yesterday evening, after spending a number of hours trying to figure out what was wrong, I discovered the side effect of having a large, negative value for the frustum's near plane. It caused the ray casting calculations to put the camera's origin below 0 when the mouse was in the bottom half of the screen. When the imaginary ray was fired into the screen from the this negative Y coordinate, it was effectively being fired up at the city from below, which meant that the first thing it always hit was the giant road mesh. The near plane is now set to zero, the far plane to 15,000 and node picking is working perfectly! blog comments powered by Disqus |

