[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: opengl question









>the idea is to make a good version of the mediocre warhammer 40k games
>that have been produced.  i am thinking of something that has myth-like
>graphics, but turn based.

Caution: Games Workshop are very litigious. Don;t use any of their (tm)s or
they'll crucify you. Yeah, it might well be a free game, yeah, it might well be
amateur. They'll still see you in court.

>i am using an nxn array corresponding to a level map (where each entry is
>a height value) where i could potentially sub-sample the height map to
>get a terrain of triangles (or a bez-mesh if i'm feeling masochistic)...

>so my question is this.  if i wanted to tell a particular "troop" on the
>level map to go to another position on the level map, how do i correspond
>the mouse click to a position on the potentially translated and rotated
>level map?  i know there is this concept of selection in opengl, is this
>the way to go?  is this fast enough not to be too cumbersome?  or should
>i do the level map in a completely other way to accomidate for this type
>of play better (i.e., don't use an nxn array level map, but something
>different)?

Assuming your map is a grid, assuming all the heights are above zero, and
assuming you know what the projection matrix is, this is what you do:

Find the line that connects the "pinhole" of the viewpoint - the projection
centre and the point at the depth of the screen where the cursor is.
Effectively, what you do then is the opposite of projection: You find the line
which consists of all the points which could be projected to where the cursor
is. This still isn't staggeringly useful, so what you do then is solve the
equation of that line, for where it crosses the zero Y plane. (If it doesn't, or
it crosses it behind the camera, they clicked on the sky...) Convert this co-ord
from your eye-coords, back to the universe and then to coords on the map plane.

This gives you a point. This is the LAST point at which the unit can have been
ordered to move. You could use this if your map is a close approximation to
flat. If not, you'll need to jigger about a bit. Take the line linking that
point and the eye point and lay it onto the map plane. That gives you all
possible selected map points. You then need to work along that line and find the
first point at which the ray cast from the view centre through the cursor
crosses the actual land height.

If your map is a close approximation to smooth, you could probably get away with
working out the average height of all the bits of land along that line and
finding where the ray crosses that plane rather than the Y=0 plane.


Alternatively, having now got a sub-set of land sections that might be the right
ones, you could use selection amongst them.