3d tile game | |
"gappy" <fake@email.com> wrote in message
news:3efda3c1$0$45180$65c69314@mercury.nildram.net ...
> pretty simple question for anyone who knows the answer i guess.
>
> I'm making a 3d game which is tile based. I've basically got loads of
tiles
> set out as the floor, they're all completely flat so y = 1.
>
> What i want to do is have the user click somewhere on the screen (using a
> normal 2d screen cursor) and have it select that tile.
>
> The old way of doing this would be dividing the mousey and y by the size
of
> the tiles then rounding it. This can't be dont in this case because of the
> perspective.
>
>
> I figure that i've got to do something with vectors, probably from the
> camera vector to the point that was clicked.. but i'm not sure.
>
> The tiles are generated using a simple 2 triangle vector then drawn over
and
> over again to create the landscape.
>
>
> I figure that if i can get the 'impact' vector from the point clicked i
can
> work it out the old way by dividing by the tile size to get which tile was
> clicked.
>
> I didn't really concentrate in maths when we were doing all the triangle
> stuff - and I'm regretting it now. I'm really trying though - so if anyone
> can suggest some resources I would be really grateful.
Depends on the language and platform you are using, but here are a few ideas
for you. The first is mapping, so that you basically have each pixel equal
1 unit. That way, if the mouse is loacted at pixel (85, 192), it will know
exactely what is there. The faults of this are major problems when changing
resolution and it can slow down the game if not done right. So languages
have built in code in their library that can automatically retrieve the
color where you are clicking or know if you are on an object or not. Also,
you could start the mouse at center and record the movements, so if the
mouse went 3cm to the right, you would know what is there. |