Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

Rendering/vtkgluPickMatrix.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkgluPickMatrix.h,v $
00005   Language:  C++
00006 
00007   Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen 
00008   All rights reserved.
00009   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00010 
00011      This software is distributed WITHOUT ANY WARRANTY; without even 
00012      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00013      PURPOSE.  See the above copyright notice for more information.
00014 
00015 =========================================================================*/
00026 #ifndef vtkgluPickMatrix_h
00027 #define vtkgluPickMatrix_h
00028 
00029 #ifndef VTK_IMPLEMENT_MESA_CXX
00030 # if defined(__APPLE__) && (defined(VTK_USE_CARBON) || defined(VTK_USE_COCOA))
00031 #  include <OpenGL/gl.h>
00032 # else
00033 #  include <GL/gl.h>
00034 # endif
00035 #endif
00036 
00037 // This function was copied from Mesa and sets up the pick matrix
00038 inline void vtkgluPickMatrix( GLdouble x, GLdouble y,
00039                               GLdouble width, GLdouble height,
00040                               int *origin, int *size )
00041 {
00042   GLfloat m[16];
00043   GLfloat sx, sy;
00044   GLfloat tx, ty;
00045   
00046   sx = size[0] / width;
00047   sy = size[1] / height;
00048   tx = (size[0] + 2.0 * (origin[0] - x)) / width;
00049   ty = (size[1] + 2.0 * (origin[1] - y)) / height;
00050 
00051 #define M(row,col)  m[col*4+row]
00052    M(0,0) = sx;   M(0,1) = 0.0;  M(0,2) = 0.0;  M(0,3) = tx;
00053    M(1,0) = 0.0;  M(1,1) = sy;   M(1,2) = 0.0;  M(1,3) = ty;
00054    M(2,0) = 0.0;  M(2,1) = 0.0;  M(2,2) = 1.0;  M(2,3) = 0.0;
00055    M(3,0) = 0.0;  M(3,1) = 0.0;  M(3,2) = 0.0;  M(3,3) = 1.0;
00056 #undef M
00057 
00058    glMultMatrixf( m );
00059 }
00060 
00061 #endif