1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
|
/*=========================================================================
Program: Visualization Toolkit
Module: $RCSfile: vtkOpenGLCamera.cxx,v $
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkOpenGLCamera.h"
#include "vtkMatrix4x4.h"
#include "vtkObjectFactory.h"
#include "vtkOpenGLRenderer.h"
#include "vtkOutputWindow.h"
#include "vtkRenderWindow.h"
#include "vtkgluPickMatrix.h"
#include "vtkOpenGL.h"
#include <math.h>
#ifndef VTK_IMPLEMENT_MESA_CXX
vtkCxxRevisionMacro(vtkOpenGLCamera, "$Revision: 1.63 $");
vtkStandardNewMacro(vtkOpenGLCamera);
#endif
// Implement base class method.
void vtkOpenGLCamera::Render(vtkRenderer *ren)
{
double aspect[2];
int lowerLeft[2];
int usize, vsize;
vtkMatrix4x4 *matrix = vtkMatrix4x4::New();
// find out if we should stereo render
this->Stereo = (ren->GetRenderWindow())->GetStereoRender();
ren->GetTiledSizeAndOrigin(&usize,&vsize,lowerLeft,lowerLeft+1);
// if were on a stereo renderer draw to special parts of screen
if (this->Stereo)
{
switch ((ren->GetRenderWindow())->GetStereoType())
{
case VTK_STEREO_CRYSTAL_EYES:
if (this->LeftEye)
{
glDrawBuffer(GL_BACK_LEFT);
}
else
{
glDrawBuffer(GL_BACK_RIGHT);
}
break;
case VTK_STEREO_LEFT:
this->LeftEye = 1;
break;
case VTK_STEREO_RIGHT:
this->LeftEye = 0;
break;
default:
break;
}
}
else
{
if (ren->GetRenderWindow()->GetDoubleBuffer())
{
glDrawBuffer(GL_BACK);
}
else
{
glDrawBuffer(GL_FRONT);
}
}
glViewport(lowerLeft[0],lowerLeft[1], usize, vsize);
glEnable( GL_SCISSOR_TEST );
glScissor(lowerLeft[0],lowerLeft[1], usize, vsize);
// some renderer subclasses may have more complicated computations for the
// aspect ratio. SO take that into account by computing the difference
// between our simple aspect ratio and what the actual renderer is
// reporting.
ren->ComputeAspect();
ren->GetAspect(aspect);
double aspect2[2];
ren->vtkViewport::ComputeAspect();
ren->vtkViewport::GetAspect(aspect2);
double aspectModification = aspect[0]*aspect2[1]/(aspect[1]*aspect2[0]);
glMatrixMode( GL_PROJECTION);
if(usize && vsize)
{
matrix->DeepCopy(this->GetPerspectiveTransformMatrix(
aspectModification*usize/vsize, -1,1));
matrix->Transpose();
}
if(ren->GetIsPicking())
{
int size[2]; size[0] = usize; size[1] = vsize;
glLoadIdentity();
vtkgluPickMatrix(ren->GetPickX(), ren->GetPickY(), 1, 1, lowerLeft, size);
glMultMatrixd(matrix->Element[0]);
}
else
{
// insert camera view transformation
glLoadMatrixd(matrix->Element[0]);
}
// push the model view matrix onto the stack, make sure we
// adjust the mode first
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
matrix->DeepCopy(this->GetViewTransformMatrix());
matrix->Transpose();
// insert camera view transformation
glMultMatrixd(matrix->Element[0]);
if ((ren->GetRenderWindow())->GetErase() && ren->GetErase())
{
ren->Clear();
}
// if we have a stereo renderer, draw other eye next time
if (this->Stereo)
{
if (this->LeftEye)
{
this->LeftEye = 0;
}
else
{
this->LeftEye = 1;
}
}
matrix->Delete();
}
void vtkOpenGLCamera::UpdateViewport(vtkRenderer *ren)
{
int lowerLeft[2];
int usize, vsize;
ren->GetTiledSizeAndOrigin(&usize,&vsize,lowerLeft,lowerLeft+1);
glViewport(lowerLeft[0],lowerLeft[1], usize, vsize);
glEnable( GL_SCISSOR_TEST );
glScissor(lowerLeft[0],lowerLeft[1], usize, vsize);
}
//----------------------------------------------------------------------------
void vtkOpenGLCamera::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
}
|