Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gl_pick.cpp File Reference
#include "gl_globals.h"
#include "gfxlib.h"
#include "gl_matrix.h"
#include <GL/glu.h>
#include <assert.h>

Go to the source code of this file.

Macros

#define SELECTBUF_SIZE   MAX_PICK*4
 

Functions

void GFXBeginPick (int x, int y, int xsize, int ysize)
 
void GFXSetPickName (int name)
 
void drawRects (GLenum mode)
 
bool GFXCheckPicked ()
 
vector< PickData > * GFXEndPick ()
 

Variables

const float epsilon = 0.001
 
static vector< PickData > * picked_objects = new vector< PickData > ()
 
static unsigned selectbuf [SELECTBUF_SIZE]
 

Macro Definition Documentation

#define SELECTBUF_SIZE   MAX_PICK*4

Definition at line 10 of file gl_pick.cpp.

Referenced by GFXBeginPick().

Function Documentation

void drawRects ( GLenum  mode)

Definition at line 49 of file gl_pick.cpp.

50 {
51  glLoadName( 1 );
52  glBegin( GL_QUADS );
53  glColor3f( 1.0, 1.0, 0.0 );
54  glVertex3i( 2, 0, 0 );
55  glVertex3i( 2, 6, 0 );
56  glVertex3i( 6, 6, 0 );
57  glVertex3i( 6, 0, 0 );
58  glEnd();
59  glLoadName( 2 );
60  glBegin( GL_QUADS );
61  glColor3f( 0.0, 1.0, 1.0 );
62  glVertex3i( 3, 2, -1 );
63  glVertex3i( 3, 8, -1 );
64  glVertex3i( 8, 8, -1 );
65  glVertex3i( 8, 2, -1 );
66  glEnd();
67  glLoadName( 3 );
68  glBegin( GL_QUADS );
69  glColor3f( 1.0, 0.0, 1.0 );
70  glVertex3i( 0, 2, -2 );
71  glVertex3i( 0, 7, -2 );
72  glVertex3i( 5, 7, -2 );
73  glVertex3i( 5, 2, -2 );
74  glEnd();
75 }
void GFXBeginPick ( int  x,
int  y,
int  xsize,
int  ysize 
)

Definition at line 18 of file gl_pick.cpp.

References GFXGetFrustumVars(), picked_objects, GFXMatrices::projection, selectbuf, and SELECTBUF_SIZE.

19 {
20  //save and change gl projection matrix
21  GLint viewport[4];
22 
23  float left, right, bottom, top, fnear, ffar;
24  GFXGetFrustumVars( true, &left, &right, &bottom, &top, &fnear, &ffar );
25 
26  glMatrixMode( GL_PROJECTION );
27  glPushMatrix();
28  glLoadIdentity();
29  glGetIntegerv( GL_VIEWPORT, viewport );
30  gluPickMatrix( x, viewport[3]-y, xsize, ysize, viewport );
31  glMultMatrixf( projection );
32 
33  glSelectBuffer( SELECTBUF_SIZE, selectbuf );
34  glRenderMode( GL_SELECT );
35  glGetError();
36 
37  delete picked_objects;
38  picked_objects = new vector< PickData > ();
39 }
bool GFXCheckPicked ( )

Definition at line 78 of file gl_pick.cpp.

79 {
80  assert( 0 );
81  glFlush();
82  int num_hits = glRenderMode( GL_RENDER );
83  glRenderMode( GL_SELECT );
84  glGetError();
85  assert( num_hits >= 0 && num_hits <= 1 );
86  return num_hits > 0;
87 }
vector< PickData >* GFXEndPick ( )

Definition at line 89 of file gl_pick.cpp.

References a, picked_objects, and selectbuf.

90 {
91  int num_hits = glRenderMode( GL_RENDER );
92  assert( num_hits != -1 );
93  //num_hits could == -1, check for this case
94  unsigned *ptr = selectbuf;
95  for (int a = 0; a < num_hits; a++) {
96  picked_objects->push_back( PickData( ptr[3], ptr[1], ptr[2] ) );
97  ptr += ptr[0]+3;
98  }
99  //restore gl projection matrix
100  glMatrixMode( GL_PROJECTION );
101  glPopMatrix();
102  return picked_objects;
103 }
void GFXSetPickName ( int  name)

Definition at line 41 of file gl_pick.cpp.

42 {
43  glInitNames();
44  glPushName( name );
45  glLoadName( name );
46  glGetError();
47 }

Variable Documentation

const float epsilon = 0.001

Definition at line 11 of file gl_pick.cpp.

vector< PickData >* picked_objects = new vector< PickData > ()
static

Definition at line 13 of file gl_pick.cpp.

Referenced by GFXBeginPick(), and GFXEndPick().

unsigned selectbuf[SELECTBUF_SIZE]
static

Definition at line 14 of file gl_pick.cpp.

Referenced by GFXBeginPick(), and GFXEndPick().