Files |  Tutorials |  Articles |  Links |  Home |  Team |  Forum |  Wiki |  Impressum

Aktuelle Zeit: Mi Mai 29, 2024 01:27

Foren-Übersicht » English » English Programming Forum
Unbeantwortete Themen | Aktive Themen



Ein neues Thema erstellen Auf das Thema antworten  [ 3 Beiträge ] 
Autor Nachricht
 Betreff des Beitrags: GL_Select
BeitragVerfasst: Sa Jun 28, 2008 21:07 
Offline
DGL Member
Benutzeravatar

Registriert: Mi Jul 21, 2004 22:39
Beiträge: 360
Wohnort: UK, Scotland
Bild

Im trying to implement a GL_Select picker in a map editor im making but it just returns 0 hits. I have used This tutorial as a basis. Before the code below, FInSelection is filled with every face which could have been picked by the user (Based on the Bounding Box of each face), its also sorted so that the first one will be the closest to the Camera. Any help would be appreciated.

Code:
  1.  // Store our Viewport
  2.  glGetIntegerv(GL_VIEWPORT, @viewport);
  3.  // Tell OpenGL the size of our select buffer
  4.  glSelectBuffer(512, @SelectBuffer);
  5.  // Change our render mode to GL_SELECT
  6.  glRenderMode(GL_SELECT);
  7.  // Init the namestack
  8.  glInitNames;
  9.  glPushName(0);
  10.  glMatrixMode(GL_PROJECTION);
  11.  glPushMatrix;
  12.   glLoadIdentity;
  13.   // Zoom the view to one pixel around the mouse position
  14.   gluPickMatrix(x, y, 1.0, 1.0, viewport);
  15.   gluPerspective(45.0, OGLGrid.OGLWidth/OGLGrid.OGLHeight, 4, 40000);
  16.   // Now we draw our scene in the select render mode
  17.   glMatrixMode(GL_MODELVIEW);
  18.  
  19.   glPushMatrix;
  20.    OGLGrid.Prepare2D(OGLGrid.OGLWidth,OGLGrid.OGLHeight);
  21.    glTranslatef(OGLGrid.GetFWidth / 2 + OGLGrid.PosX,OGLGrid.GetFHeight / 2 + OGLGrid.PosY+15,0);
  22.  
  23.     glInitNames;
  24.     glPushName(0);
  25.     for i := 0 to FInSelection_Count-1 do
  26.     begin
  27.      glLoadName(i);
  28.      TFME_Map_Visual_Object(FInSelection[i]).Render(OGLGrid,True);
  29.     end;
  30.  
  31.    OGLGrid.End2D;
  32.   glPopMatrix;
  33.  
  34.   glMatrixMode(GL_PROJECTION);
  35.  glPopMatrix;
  36.  
  37.  Hits := glRenderMode(GL_RENDER);
  38.  glMatrixMode(GL_MODELVIEW);
  39.  
  40.  if Hits > 1 then
  41.  begin
  42.   Add(FInSelection[SelectBuffer[3]]);
  43.   OGLGrid.UpdateGrids;
  44.  end;
  45. end;

_________________
Free Map Editor - Game Requirements - Stucuk.Net
-Stu


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: So Jun 29, 2008 04:54 
Offline
DGL Member
Benutzeravatar

Registriert: Mi Jul 21, 2004 22:39
Beiträge: 360
Wohnort: UK, Scotland
Guess it helps if you enable GL_VERTEX_ARRAY before sending data using Vertex Arrays(Doh!).

_________________
Free Map Editor - Game Requirements - Stucuk.Net
-Stu


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: So Jun 29, 2008 18:51 
Offline
DGL Member
Benutzeravatar

Registriert: Mi Jul 21, 2004 22:39
Beiträge: 360
Wohnort: UK, Scotland
Ran into another problem, this one shouldn't be as simple as the first. GL_Select seems to be failing somtimes, in most cases it works fine, but iv found a map with an area where it gives no hits, yet there is face's in that area which are being passed to it. The images below shows in red the faces which are being sent to the GL_Select for Picking, the Yellow area is where its generating no hits and the green dot is where i clicked.

Bild Bild Bild

- Download ~1.36MB (EXE + Sample Map)
Note: 3D View doesn't have any picking ability, only the Grid Modes have the ability.

Source:
Code:
  1.  
  2. procedure TFME_Map_Selected.ProcessClick(OGLGrid : TOGLGrid; X, Y: Integer);
  3. var
  4.  I : Cardinal;
  5.  VisualObject : TFME_Map_Visual_Object;
  6.  Viewport     : TVector4i;
  7.  SelectBuffer : array[0..512] of TGLUInt;
  8.  Hits         : Integer;
  9.  Hit          : TGLUInt;
  10. begin
  11.  if OGLGrid.FObjectsCount < 1 then exit;
  12.  
  13.  FInSelection_Count := 0;
  14.  // This bit generates the list of possible faces that could be selected based on there bounding box
  15.  for I := OGLGrid.FObjectsCount-1 downto 0 do
  16.  begin
  17.   VisualObject := OGLGrid.FObjects[OGLGrid.FObjectsOrder[I].ID];
  18.   if IsInBounds(OGLGrid,X,Y,VisualObject) then
  19.    AddInSelection(VisualObject);
  20.  end;
  21.  
  22.  if FInSelection_Count < 1 then exit; // If no face has the X,Y in there bounds then exit.
  23.  
  24.  //START OF GL_SELECT
  25.  
  26.  // Store our Viewport
  27.  glGetIntegerv(GL_VIEWPORT, @viewport);
  28.  // Tell OpenGL the size of our select buffer
  29.  FillChar(SelectBuffer,SizeOf(SelectBuffer),0);
  30.  glSelectBuffer(512, @SelectBuffer);
  31.  // Change our render mode to GL_SELECT
  32.  glRenderMode(GL_SELECT);
  33.  // Init the namestack
  34.  glInitNames;
  35.  glPushName(0);
  36.  glMatrixMode(GL_PROJECTION);
  37.  glPushMatrix;
  38.   glLoadIdentity;
  39.   // Zoom the view to one pixel around the mouse position
  40.   gluPickMatrix(x, y, 1.0, 1.0, viewport);
  41.   glOrtho(0, OGLGrid.OGLWidth, 0, OGLGrid.OGLHeight, -1, 1);
  42.   // Now we draw our scene in the select render mode
  43.   glMatrixMode(GL_MODELVIEW);
  44.    //START OF "RENDERING"
  45.  
  46.  
  47.   glClear(GL_DEPTH_BUFFER_BIT or GL_COLOR_BUFFER_BIT);
  48.   glPushMatrix;
  49.     glTranslatef(OGLGrid.GetFWidth / 2 + OGLGrid.PosX,OGLGrid.GetFHeight / 2 + OGLGrid.PosY+15,0);
  50.  
  51.     glEnableClientState(GL_VERTEX_ARRAY);
  52.  
  53.     glInitNames;
  54.     glPushName(0);
  55.  
  56.     glDisable(GL_CULL_FACE);
  57.     for i := 0 to FInSelection_Count-1 do
  58.     begin
  59.      glLoadName(i);
  60.      TFME_Map_Visual_Object(FInSelection[i]).Render(OGLGrid,True);
  61.     end;
  62.     glEnable(GL_CULL_FACE);
  63.  
  64.     glDisableClientState(GL_VERTEX_ARRAY);
  65.  
  66.   glPopMatrix;
  67.  
  68.    //END OF "RENDERING"
  69.  
  70.   glMatrixMode(GL_PROJECTION);
  71.  glPopMatrix;
  72.  
  73.  Hits := glRenderMode(GL_RENDER);
  74.  glMatrixMode(GL_MODELVIEW);
  75.  
  76.  //END OF GL_SELECT
  77.  
  78.  if Hits > 1 then
  79.  if SelectBuffer[3] < FInSelection_Count then
  80.  begin
  81.   Add(FInSelection[SelectBuffer[3]]);
  82.   OGLGrid.UpdateGrids;
  83.  end;
  84. end;

_________________
Free Map Editor - Game Requirements - Stucuk.Net
-Stu


Nach oben
 Profil  
Mit Zitat antworten  
Beiträge der letzten Zeit anzeigen:  Sortiere nach  
Ein neues Thema erstellen Auf das Thema antworten  [ 3 Beiträge ] 
Foren-Übersicht » English » English Programming Forum


Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 9 Gäste


Du darfst keine neuen Themen in diesem Forum erstellen.
Du darfst keine Antworten zu Themen in diesem Forum erstellen.
Du darfst deine Beiträge in diesem Forum nicht ändern.
Du darfst deine Beiträge in diesem Forum nicht löschen.
Du darfst keine Dateianhänge in diesem Forum erstellen.

Suche nach:
Gehe zu:  
  Powered by phpBB® Forum Software © phpBB Group
Deutsche Übersetzung durch phpBB.de
[ Time : 0.009s | 14 Queries | GZIP : On ]