Mouse Control On A 3D Map

Hi there,

Since my last topic in this forum on openGL, my game project progressed quite far. It didn’t have any… well, game mechanics, as such, but you could place and destroy buildings, and character placed on the map could path find around the place fairly efficently. The problem is, as I didn’t really have any kind of plan when I started the project, the code is pretty hacked up. I decided to start again from scratch, this time with a much better design and a better idea of what I wanted the game to do. I also decided to make it 3d.

The game is a city builder game, so the “3d” aspect is going to be purely visual, the mechanics are going to be more or less the same. I might have a pop at doing interesting fractal generated terrain, but there is essentially only going to be one Z level for the purpose of game mechanics. I think I’ll be able to handle the graphical side of it with a bit of work, but there is one problem to which I have no solution: How to deal with mouse input.

More precisely, how to work out where the cursor is relative to the map. It was pretty easy with the isometric system I had before - I just added the mouse position to a couple of variables that represented the view area’s relation to the map. For a 3d map though, where the user is going to be able to rotate, zoom in and out (etc) the view, I don’t really have any idea how to get the mouse’s position, and thus I won’t be able to have the player manipulate stuff with the mouse.

Could anyone give a hint on this subject?

Basically what you do is plot out a ray trace that is dependent upon the current camera viewpoint. Say, for example, the camera is pointing directly downwards. That means, when the user clicks the mouse, you’re going to see if the mouse at that X and Y position intercepts anything in a line along the Z axis that goes directly downwards. In other words, you’re plotting collision along a line using the axis that you don’t have, and the line’s equation is determined by the camera position. Make sense?

are you using openGL? or something else? can you show a demo/screenshot of your app, so i can get a visual of what you are doing.

it shouldnt be that hard to do.