Author Topic: A question for the coder of GLEST...  (Read 4343 times)

overkode

  • Guest
A question for the coder of GLEST...
« on: 26 May 2004, 20:22:26 »
Hi,
I know your game is not open source, and that's OK, but I was wondering if you could give me some advice on how you got the drag-selection working in OpenGL.

I've been trying to do group selection without much luck. Could you give me a hint?

I can do single object selection with the name stack and gluPickMatrix() but obviously that's not how to do group selection. I've got the selection rectangle being drawn in the usual RTS manner but I'm not sure how to get it to register hits with objects....

Are you drawing the selection rect in ortho mode(on the screen) or in modelview space(the world?), and how do I tell the game objects that the rect has been "dragged" over them?

It bugs me alot because I can do A* fine, but that's useless until I can select the units! (lol)

I'd appreciate any help.

If you decide to respond then you can reach me at:
ca_nehme-^-hotmail.com

Thanks.  :confused:
« Last Edit: 15 April 2016, 20:34:43 by filux »

martiño

  • Behemoth
  • *******
  • Posts: 1,095
    • View Profile
(No subject)
« Reply #1 on: 26 May 2004, 20:39:36 »
You are wrong, you can do group selection with gluPuckMatrix(), in the same manner as individual selection, but you have to pass to this funcion the size and position of the selection rectangle. Then you render your objects as usual with perspective, and check the selection buffer.

Here is the code I use for selection in glest:

Code: [Select]

void Renderer::computeSelected(Selection::UnitContainer &units){

//declarations
GLuint selectBuffer[GuiManager::maxSelBuff];
const Metrics &metrics= Metrics::getInstance();
const GuiManager *guiManager= game->getGuiManager();

//compute center and dimensions of selection rectangle
int x= (guiManager->getPosDown().x+guiManager->getPosUp().x) / 2;
int y= (guiManager->getPosDown().y+guiManager->getPosUp().y) / 2;
int w= abs(guiManager->getPosDown().x-guiManager->getPosUp().x);
int h= abs(guiManager->getPosDown().y-guiManager->getPosUp().y);
if(w<1) w=1;
if(h<1) h=1;

//setup matrices
glSelectBuffer(GuiManager::maxSelBuff, selectBuffer);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
GLint view[]= {0, 0, metrics.getVirtualW(), metrics.getVirtualH()};
glRenderMode(GL_SELECT);
glLoadIdentity();
gluPickMatrix(x, y, w, h, view);
gluPerspective(perspFov, metrics.getAspectRatio(), perspNearPlane, perspFarPlane);
loadGameCameraMatrix();

//render units
renderUnitsFast();

//pop matrices
glMatrixMode(GL_PROJECTION);
glPopMatrix();

//select units
int selCount= glRenderMode(GL_RENDER);
for(int i=1; i<=selCount; ++i){
int factionIndex= selectBuffer[i*5-2];
int unitIndex= selectBuffer[i*5-1];
const World *world= game->getWorld();
if(factionIndex<world->getFactionCount() && unitIndex<world->getFaction(factionIndex)->getUnitCount()){
Unit *unit= world->getFaction(factionIndex)->getUnit(unitIndex);
units.push_back(unit);
}
}
}
« Last Edit: 1 January 1970, 00:00:00 by martiño »

overkode

  • Guest
-
« Reply #2 on: 27 May 2004, 15:10:17 »
Nice! Some one tried to explain that to me before... A dude on the OpenGL.org forums told me to do it that way, but I tried and tried and couldn't get it to work. I think I was having a problem with the screen to world coordinates for the drag-rectangle.

One more question(if you don't mind  ^_^ )... Are you using gluProject or gluUnproject(gluUnproject4 if gl v1.3) anywhere to convert screen coordinates into world coordinates and vice versa?

Anyway, I'm definately gonna try that out.

Thanks alot! I REALLY appreciate your help. :D

P.S. Nice work on glest. I'm a HUGE Warcraft3 fan, so needless to say I like glest alot. Actually, glest is better than alot of the RTS games I've bought lately, lol.
« Last Edit: 4 April 2016, 06:00:11 by filux »

martiño

  • Behemoth
  • *******
  • Posts: 1,095
    • View Profile
(No subject)
« Reply #3 on: 27 May 2004, 16:11:20 »
Hi thanx for you words, and no, I don't use gluProject() or gluUnProject(), because you don't have do to any screen/world conversions, gluPickMatrix() receives screen coords as you can see in the code (posDown and posUp are in screen coords).
« Last Edit: 1 January 1970, 00:00:00 by martiño »

overkode

  • Guest
-
« Reply #4 on: 27 May 2004, 20:25:32 »
Aw yeah!

I'm gonna make my changes to my project tonite.

Thanks again for the code/help.  8)
« Last Edit: 4 April 2016, 06:00:40 by filux »