Subversion Repositories gelsvn

Rev

Rev 630 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 630 Rev 656
Line 187... Line 187...
187
            glEnd();
187
            glEnd();
188
        }
188
        }
189
    }
189
    }
190
    
190
    
191
    
191
    
-
 
192
    bool depth_pick(int x, int y, float& depth)
-
 
193
    {
-
 
194
        float new_depth;
-
 
195
        
-
 
196
        // Get the minimum and maximum depth values.
-
 
197
        float minmax_depth[2];
-
 
198
        glGetFloatv(GL_DEPTH_RANGE, minmax_depth);
-
 
199
        glPushAttrib(GL_PIXEL_MODE_BIT);
-
 
200
        glReadBuffer(GL_FRONT);
-
 
201
        // Read a single pixel at the position of the mouse cursor.
-
 
202
        glReadPixels(x, y, 1,1, GL_DEPTH_COMPONENT,
-
 
203
                     GL_FLOAT, (void*) &new_depth);
-
 
204
        glPopAttrib();
-
 
205
        
-
 
206
        // If the depth corresponds to the far plane, we clicked on the
-
 
207
        // background.
-
 
208
        if(new_depth == minmax_depth[1])
-
 
209
            return false;
-
 
210
        
-
 
211
        depth = new_depth;
-
 
212
        return true;
-
 
213
    }
-
 
214
    
-
 
215
    Vec3d screen2world(int x, int y, float depth)
-
 
216
    {
-
 
217
        // Enquire about the viewport dimensions
-
 
218
        GLint viewport[4];
-
 
219
        glGetIntegerv(GL_VIEWPORT, viewport);
-
 
220
        // Copy modelview matrix.
-
 
221
        double mvmat[16];
-
 
222
        glGetDoublev(GL_MODELVIEW_MATRIX, mvmat);
-
 
223
        
-
 
224
        // Copy the projection matrix. We assume it is unchanged.
-
 
225
        double prjmat[16];
-
 
226
        glGetDoublev(GL_PROJECTION_MATRIX, prjmat);
-
 
227
        
-
 
228
        // Now unproject the point from screen to world coordinates.
-
 
229
        double ox, oy, oz;
-
 
230
        gluUnProject(x, y,depth,
-
 
231
                     mvmat,prjmat,viewport,
-
 
232
                     &ox, &oy, &oz);
-
 
233
        
-
 
234
        return Vec3d(ox,oy,oz);
-
 
235
    }
-
 
236
 
-
 
237
    
192
    
238
    
193
    void draw(const Geometry::AABox& box)
239
    void draw(const Geometry::AABox& box)
194
    {
240
    {
195
        glBegin(GL_QUADS);
241
        glBegin(GL_QUADS);
196
        Vec3f norm_neg[] = {Vec3f(0,0,-1), Vec3f(-1,0,0), Vec3f(0,-1,0)};
242
        Vec3f norm_neg[] = {Vec3f(0,0,-1), Vec3f(-1,0,0), Vec3f(0,-1,0)};