[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: opengl question
amc45@cornell.edu wrote:
> 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.
Cool!
> 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)?
I would NOT recommend using the OpenGL selection mechanism for a
fast interactive game - but for a turn-based game which doesn't
(presumably) have so many realtime penalties, it would be acceptable.
The examples in the OpenGL RedBook (see 'Picking') explain what
you need to do. It's essentially no different from drawing the
scene twice, once for rendering and once for picking. Since
most games are geometry-limited on a reasonable 3D card, you
certainly don't want to do that since it'll probably halve
your frame-rate!
It's much faster to shoot a ray from the eye into the dataset
using OpenGL - but there is some reasonably complex code to
write to do that.
Since you (hopefully) already have code to cull the terrain to the
field of view, you can probably re-use that code with small modifications
to accept a zero sized field of view - and thus return the set of
objects along the line of the ray.
Of course if you were using my PLIB scene-graph library, you
could use the library functions to do that and it would be easy.
> if i do use an nxn level map, and i choose not to use the opengl
> selection features, does anyone know of a good way to find the
> corresponding position of the mouse click on the level map that doesn't
> take order n time?
(where 'n' is the number of triangles?)
You basically need to treat the terrain as a heirarchy of objects,
with each object surrounded by a simple bounding shape (I use
spheres - some people prefer AABB's (Axially Aligned Bounding Boxes).
This lets you toss out large numbers of triangles with a very simple
test - if the bounding shape is intersected by the ray from the eye
through the mouse pointer then you look inside it and (because this
is a heirarchical description), find more bounding shapes inside.
In the limit, you find just a handful of triangles that are close
enough to the ray that their approximated bounding shapes touch
it - and those have to be tested one by one.
Since the ray is a line, and the terrain is a 2D grid, and the
time taken to check a simple bounding shape is *tiny* compared
to the time to test a triangle, this test runs in about sqrt(n)
time.
> thank you,
> abram connelly
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: linuxgames-unsubscribe@sunsite.auc.dk
> For additional commands, e-mail: linuxgames-help@sunsite.auc.dk
--
Steve Baker http://web2.airmail.net/sjbaker1
sjbaker1@airmail.net (home) http://www.woodsoup.org/~sbaker
sjbaker@hti.com (work)