SbrLgt.cc 2.67 KB
Newer Older
Ken Martin's avatar
Ken Martin committed
1
2
/*=========================================================================

Ken Martin's avatar
Ken Martin committed
3
  Program:   Visualization Toolkit
Ken Martin's avatar
Ken Martin committed
4
5
6
7
8
  Module:    SbrLgt.cc
  Language:  C++
  Date:      $Date$
  Version:   $Revision$

Ken Martin's avatar
Ken Martin committed
9
This file is part of the Visualization Toolkit. No part of this file or its
Ken Martin's avatar
Ken Martin committed
10
11
12
13
14
15
16
17
contents may be copied, reproduced or altered in any way without the express
written consent of the authors.

Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994

=========================================================================*/
#include <math.h>
#include "SbrRen.hh"
18
#include "SbrLgt.hh"
Ken Martin's avatar
Ken Martin committed
19
#include "Light.hh"
Ken Martin's avatar
Ken Martin committed
20

Will Schroeder's avatar
Will Schroeder committed
21
22
// Description:
// Implement base class method.
Ken Martin's avatar
Ken Martin committed
23
void vtkSbrLight::Render(vtkLight *lgt, vtkRenderer *ren,int light_index)
Ken Martin's avatar
Ken Martin committed
24
{
Ken Martin's avatar
Ken Martin committed
25
  this->Render(lgt, (vtkSbrRenderer *)ren,light_index);
Ken Martin's avatar
Ken Martin committed
26
27
}

Will Schroeder's avatar
Will Schroeder committed
28
29
// Description:
// Actual light render method.
Ken Martin's avatar
Ken Martin committed
30
void vtkSbrLight::Render(vtkLight *lgt, vtkSbrRenderer *ren,int light_index)
Ken Martin's avatar
Ken Martin committed
31
32
33
34
35
{
  float	dx, dy, dz;
  float	color[3];
  int light_flag;
  int fd;
Ken Martin's avatar
Ken Martin committed
36
37
  float *Color, *Position, *FocalPoint;
  float Intensity;
Ken Martin's avatar
Ken Martin committed
38
39
40
41
42

  light_flag = ren->GetLightSwitch();
  fd = ren->GetFd();
  
  // get required info from light
Ken Martin's avatar
Ken Martin committed
43
44
45
46
47
  Intensity = lgt->GetIntensity();
  Color = lgt->GetColor();
  color[0] = Intensity * Color[0];
  color[1] = Intensity * Color[1];
  color[2] = Intensity * Color[2];
Ken Martin's avatar
Ken Martin committed
48
  
Ken Martin's avatar
Ken Martin committed
49
50
51
52
53
  FocalPoint = lgt->GetFocalPoint();
  Position   = lgt->GetPosition();
  dx = FocalPoint[0] - Position[0];
  dy = FocalPoint[1] - Position[1];
  dz = FocalPoint[2] - Position[2];
Ken Martin's avatar
Ken Martin committed
54
55
  
  // define the light source
Ken Martin's avatar
Ken Martin committed
56
  if (!lgt->GetPositional())
Ken Martin's avatar
Ken Martin committed
57
58
59
60
61
62
63
    {
    light_source(fd, light_index, DIRECTIONAL,
		 color[0], color[1], color[2],
		 -dx, -dy, -dz);
    }
  else
    {
Ken Martin's avatar
Ken Martin committed
64
65
    float *AttenuationValues = lgt->GetAttenuationValues();

Ken Martin's avatar
Ken Martin committed
66
67
    light_source(fd, light_index, POSITIONAL,
		 color[0], color[1], color[2],
Ken Martin's avatar
Ken Martin committed
68
		 Position[0], Position[1], Position[2]);
Ken Martin's avatar
Ken Martin committed
69
    light_model(fd, light_index, ATTEN_LIGHT | SPOT_LIGHT | CONE_LIGHT,
Ken Martin's avatar
Ken Martin committed
70
		(int)lgt->GetExponent(), 1.0, lgt->GetConeAngle(),
Ken Martin's avatar
Ken Martin committed
71
72
		dx, dy, dz);
    light_attenuation(fd, light_index, 1, 
Ken Martin's avatar
Ken Martin committed
73
74
75
		      AttenuationValues[0],
		      AttenuationValues[1],
		      AttenuationValues[2]);
Ken Martin's avatar
Ken Martin committed
76
77
    }
  
Ken Martin's avatar
Ken Martin committed
78
  light_flag |= (0x0001 << light_index);
Ken Martin's avatar
Ken Martin committed
79
  vtkDebugMacro(<< "Defining front light\n");
Ken Martin's avatar
Ken Martin committed
80
  
Ken Martin's avatar
Ken Martin committed
81
  // define another mirror light if backlit is on and not positional
Ken Martin's avatar
Ken Martin committed
82
  if (ren->GetBackLight() && !lgt->GetPositional()) 
Ken Martin's avatar
Ken Martin committed
83
84
85
86
    {
    light_index++;
    light_source(fd, light_index, DIRECTIONAL,
		 color[0], color[1], color[2],
Ken Martin's avatar
Ken Martin committed
87
		 dx, dy, dz);
Ken Martin's avatar
Ken Martin committed
88
    vtkDebugMacro(<< "Defining back light\n");
Ken Martin's avatar
Ken Martin committed
89
90
91
92
93
    light_flag |= (0x0001 << light_index);
    }

  // update the light switch
  light_switch(fd, light_flag);
94
95
  ren->SetLightSwitch(light_flag);
  
Ken Martin's avatar
Ken Martin committed
96
  vtkDebugMacro(<< "SB_light_switch: " << light_flag << "\n");
Ken Martin's avatar
Ken Martin committed
97
98
}