Selecting

SelectingABuildingThis is a little ugly, but functional.  Today, I implemented polygon-accurate picking of buildings, players, and monsters.  That is, the cursor now moves over and reacts to these objects rather than ignoring them.  I also implemented a mechanism by which the cursor can find out not only where it’s bumped into something, but also precisely what that object is.  In this screenshot, I have just selected a quest building that’s off in the distance, while new subscribers (blue cubes) are entering the world from the starting position in the foreground.

Today I also implemented a “DrawOutline” function on the vsBox3D class, which just draws the edges of an axis aligned bounding box;  that’s what I’m using to draw the outline around the building in the distance.  I’m not really convinced that that’s the right way to hilight a building, but at least it can show you what’s currently being selected.  Actually drawing glowing lines along the vertices of the building sounds like a good idea, but it could turn into an awful lot of lines, once the buildings are being fully procedurally generated, instead of just being the simple blocks that I’m using now.  Alternately, I could change the material of the building;  draw it in a different color, or with an extra animated light or something.  Really, I suppose that’s a visual thing that I can work out later;  right now I’m trying to make the game’s UI work at all;  being pretty can come later.  :)

I always forget how tricky it is to make this sort of 3D picking code work;  particularly in a project like this one, where there are lots of different objects being expressed in a lot of different coordinate systems.  There were lots of finicky little bugs where if you pointed at a player, but there was a building somewhere behind the player, the cursor would prefer to point at the building rather than at the player, due to a subtle bug in the coordinate conversions.  Time consuming to track it all down!  But I think it’s all working properly, now.

Next thing is going to be the “Remove Building” functionality, which shouldn’t be difficult at all to hook up;  figuring out which building the mouse is pointing at in a 3D scene was the hard part.  Now that I know that, it should be pretty trivial to remove the building.  But I’m going to leave that for tomorrow.