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
|
/*=========================================================================
Program: Visualization Toolkit
Module: vtkOpenGLLight.cxx
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 "vtkOpenGLLight.h"
#include "vtkOpenGLRenderer.h"
#include "vtkObjectFactory.h"
#include "vtkMatrix4x4.h"
#include "vtkOpenGLError.h"
#include "vtkOpenGL.h"
#include <math.h>
vtkStandardNewMacro(vtkOpenGLLight);
// Implement base class method.
void vtkOpenGLLight::Render(vtkRenderer *vtkNotUsed(ren), int light_index)
{
vtkOpenGLClearErrorMacro();
float color[4];
float info[4];
// get required info from light
float dx = this->FocalPoint[0] - this->Position[0];
float dy = this->FocalPoint[1] - this->Position[1];
float dz = this->FocalPoint[2] - this->Position[2];
if (this->TransformMatrix)
{
double mat[16];
vtkMatrix4x4::Transpose(*this->TransformMatrix->Element, mat);
// code assumes that we're already in GL_MODELVIEW matrix mode
glPushMatrix();
glMultMatrixd(mat);
}
color[0] = this->Intensity * this->AmbientColor[0];
color[1] = this->Intensity * this->AmbientColor[1];
color[2] = this->Intensity * this->AmbientColor[2];
color[3] = 1.f;
glLightfv(static_cast<GLenum>(light_index), GL_AMBIENT, color);
color[0] = this->Intensity * this->DiffuseColor[0];
color[1] = this->Intensity * this->DiffuseColor[1];
color[2] = this->Intensity * this->DiffuseColor[2];
glLightfv(static_cast<GLenum>(light_index), GL_DIFFUSE, color);
color[0] = this->Intensity * this->SpecularColor[0];
color[1] = this->Intensity * this->SpecularColor[1];
color[2] = this->Intensity * this->SpecularColor[2];
glLightfv(static_cast<GLenum>(light_index), GL_SPECULAR, color);
// define the light source
if (!this->Positional)
{
info[0] = -dx;
info[1] = -dy;
info[2] = -dz;
info[3] = 0.f;
glLightf(static_cast<GLenum>(light_index), GL_SPOT_EXPONENT, 0.f);
glLightf(static_cast<GLenum>(light_index), GL_SPOT_CUTOFF, 180.f);
glLightfv(static_cast<GLenum>(light_index), GL_POSITION, info);
}
else
{
// specify position and attenuation
info[0] = this->Position[0];
info[1] = this->Position[1];
info[2] = this->Position[2];
info[3] = 1.f;
glLightfv(static_cast<GLenum>(light_index), GL_POSITION, info);
glLightf(static_cast<GLenum>(light_index),
GL_CONSTANT_ATTENUATION, this->AttenuationValues[0]);
glLightf(static_cast<GLenum>(light_index),
GL_LINEAR_ATTENUATION, this->AttenuationValues[1]);
glLightf(static_cast<GLenum>(light_index),
GL_QUADRATIC_ATTENUATION, this->AttenuationValues[2]);
// set up spot parameters if necessary
if (this->ConeAngle < 180.0)
{
info[0] = dx;
info[1] = dy;
info[2] = dz;
glLightfv(static_cast<GLenum>(light_index), GL_SPOT_DIRECTION, info);
glLightf(static_cast<GLenum>(light_index), GL_SPOT_EXPONENT,
this->Exponent);
glLightf(static_cast<GLenum>(light_index), GL_SPOT_CUTOFF,
this->ConeAngle);
}
else
{
glLighti(static_cast<GLenum>(light_index), GL_SPOT_CUTOFF, 180);
}
}
if (this->TransformMatrix)
{
glPopMatrix();
}
vtkOpenGLCheckErrorMacro("failed after Render");
}
//----------------------------------------------------------------------------
void vtkOpenGLLight::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}
|