[gameprogrammer] Re: 3d overhead view rts games

There are several ways.  As you mention using a grid is one of the ways, but
i wouldn't use something like GL pick - I would imagine using a mouse x/y to
ray conversion like that below would be best.  This gives you a ray in world
space that you can use to intersect objects - such as an imaginary world
grid.

// Convert the screen position into camera position
g_Camera.GetProjectionMatrix(matrix);

pos.x = (((Mouse->GetPos().x * 2.0f) / ScreenSize.x) - 1.0f) /
matrix.mm[0][0];
pos.y = -(((Mouse->GetPos().y * 2.0f) / ScreenSize.y) - 1.0f) /
matrix.mm[1][1];
pos.z = 1.0f;

g_Camera.GetViewMatrix(matrix);

// Get the inverse matrix
inv = -matrix;

// Then into world position
start = inv.GetTranslation();
direction.x = (pos.x * inv.mm[0][0]) + (pos.y * inv.mm[1][0]) + (pos.z *
inv.mm[2][0]);
direction.y = (pos.x * inv.mm[0][1]) + (pos.y * inv.mm[1][1]) + (pos.z *
inv.mm[2][1]);
direction.z = (pos.x * inv.mm[0][2]) + (pos.y * inv.mm[1][2]) + (pos.z *
inv.mm[2][2]);


-----Original Message-----
From: gameprogrammer-bounce@xxxxxxxxxxxxx
[mailto:gameprogrammer-bounce@xxxxxxxxxxxxx] On Behalf Of Alan Wolfe
Sent: 25 October 2004 08:00
To: gameprogrammer@xxxxxxxxxxxxx
Subject: [gameprogrammer] 3d overhead view rts games

I was wondering, in a game like warcraft 3, how do you know how to corelate
where the mouse is on the screen with where that part is on the grid of the
map?  IE when you are building a building, how does it know, based on mouse
position, what part of the map to put that building on?
The first thing that comes to mind is to give each square it's own unique id
and use the picking ability of GL, but for a large map like 100x100, that's
10,000 id's which seems like an aweful lot.

The second thing that comes to mind is somehow using the view matrix but no
idea how you would get from point A to point B on that one.

Anybody know how they do it?


---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html






---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html


Other related posts: