vtkgluPickMatrix.h 1.72 KB
Newer Older
1 2 3 4 5
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkgluPickMatrix.h

6
  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 8
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9

10 11
     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12
     PURPOSE.  See the above copyright notice for more information.
13 14 15 16 17 18 19

=========================================================================*/
// .NAME vtkObject - implement selected glu functionality
// .SECTION Description
// This file implements selected glu functionality to avoid 
// system dependencies on glu.

20 21 22
#ifndef vtkgluPickMatrix_h
#define vtkgluPickMatrix_h

23
#ifndef VTK_IMPLEMENT_MESA_CXX
Mumit Khan's avatar
Mumit Khan committed
24
# if defined(__APPLE__) && (defined(VTK_USE_CARBON) || defined(VTK_USE_COCOA))
25 26 27 28 29 30
#  include <OpenGL/gl.h>
# else
#  include <GL/gl.h>
# endif
#endif

31 32
// This function was copied from Mesa and sets up the pick matrix
inline void vtkgluPickMatrix( GLdouble x, GLdouble y,
33 34
                              GLdouble width, GLdouble height,
                              int *origin, int *size )
35 36 37 38 39
{
  GLfloat m[16];
  GLfloat sx, sy;
  GLfloat tx, ty;
  
40 41 42 43
  sx = size[0] / width;
  sy = size[1] / height;
  tx = (size[0] + 2.0 * (origin[0] - x)) / width;
  ty = (size[1] + 2.0 * (origin[1] - y)) / height;
44 45 46 47 48 49 50 51 52 53 54 55

#define M(row,col)  m[col*4+row]
   M(0,0) = sx;   M(0,1) = 0.0;  M(0,2) = 0.0;  M(0,3) = tx;
   M(1,0) = 0.0;  M(1,1) = sy;   M(1,2) = 0.0;  M(1,3) = ty;
   M(2,0) = 0.0;  M(2,1) = 0.0;  M(2,2) = 1.0;  M(2,3) = 0.0;
   M(3,0) = 0.0;  M(3,1) = 0.0;  M(3,2) = 0.0;  M(3,3) = 1.0;
#undef M

   glMultMatrixf( m );
}

#endif