GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: src/limn/light.c Lines: 0 30 0.0 %
Date: 2017-05-26 Branches: 0 20 0.0 %

Line Branch Exec Source
1
/*
2
  Teem: Tools to process and visualize scientific data and images             .
3
  Copyright (C) 2013, 2012, 2011, 2010, 2009  University of Chicago
4
  Copyright (C) 2008, 2007, 2006, 2005  Gordon Kindlmann
5
  Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998  University of Utah
6
7
  This library is free software; you can redistribute it and/or
8
  modify it under the terms of the GNU Lesser General Public License
9
  (LGPL) as published by the Free Software Foundation; either
10
  version 2.1 of the License, or (at your option) any later version.
11
  The terms of redistributing and/or modifying this software also
12
  include exceptions to the LGPL that facilitate static linking.
13
14
  This library is distributed in the hope that it will be useful,
15
  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17
  Lesser General Public License for more details.
18
19
  You should have received a copy of the GNU Lesser General Public License
20
  along with this library; if not, write to Free Software Foundation, Inc.,
21
  51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22
*/
23
24
25
#include "limn.h"
26
27
28
/*
29
******** limnLightSet()
30
**
31
** turns on a light
32
**
33
*/
34
void
35
limnLightSet(limnLight *lit, int which, int vsp,
36
             float r, float g, float b,
37
             float x, float y, float z) {
38
39
  if (lit && AIR_IN_CL(0, which, LIMN_LIGHT_NUM-1)) {
40
    lit->on[which] = 1;
41
    lit->vsp[which] = vsp;
42
    ELL_4V_SET(lit->col[which], r, g, b, 1.0);
43
    ELL_4V_SET(lit->_dir[which], x, y, z, 0.0);
44
  }
45
}
46
47
/*
48
******** limnLightAmbientSet()
49
**
50
** sets the ambient light color
51
*/
52
void
53
limnLightAmbientSet(limnLight *lit, float r, float g, float b) {
54
55
  if (lit) {
56
    ELL_4V_SET(lit->amb, r, g, b, 1.0);
57
  }
58
}
59
60
/*
61
******** limnLightUpdate()
62
**
63
** copies information from the _dir vectors to the dir vectors. This
64
** needs to be called even if there are no viewspace lights, so that
65
** the dir vectors are set and normalized.  If there are no viewspace
66
** lights, "cam" can actually be passed as NULL, but don't get carried
67
** away...
68
**
69
** returns 1 if there was a problem in the camera, otherwise 0.
70
*/
71
int
72
limnLightUpdate(limnLight *lit, limnCamera *cam) {
73
  static const char me[]="limnLightUpdate";
74
  double dir[3], _dir[3], uvn[9]={0,0,0,0,0,0,0,0,0}, norm;
75
  int i;
76
77
  if (cam) {
78
    if (limnCameraUpdate(cam)) {
79
      biffAddf(LIMN, "%s: trouble in camera", me);
80
      return 1;
81
    }
82
    ELL_34M_EXTRACT(uvn, cam->V2W);
83
  }
84
  for (i=0; i<LIMN_LIGHT_NUM; i++) {
85
    ELL_3V_COPY(_dir, lit->_dir[i]);
86
    if (cam && lit->vsp[i]) {
87
      ELL_3MV_MUL(dir, uvn, _dir);
88
    } else {
89
      ELL_3V_COPY(dir, _dir);
90
    }
91
    ELL_3V_NORM(dir, dir, norm);
92
    ELL_4V_SET_TT(lit->dir[i], float, dir[0], dir[1], dir[2], 0.0);
93
  }
94
  return 0;
95
}
96
97
/*
98
******** limnLightSwitch
99
**
100
** can toggle a light on/off
101
**
102
** returns 1 on error, 0 if okay
103
*/
104
void
105
limnLightSwitch(limnLight *lit, int which, int on) {
106
107
  if (lit && AIR_IN_CL(0, which, LIMN_LIGHT_NUM-1)) {
108
    lit->on[which] = on;
109
  }
110
}
111
112
void
113
limnLightReset(limnLight *lit) {
114
  int i;
115
116
  if (lit) {
117
    ELL_4V_SET(lit->amb, 0, 0, 0, 1);
118
    for (i=0; i<LIMN_LIGHT_NUM; i++) {
119
      ELL_4V_SET(lit->_dir[i], 0, 0, 0, 0);
120
      ELL_4V_SET(lit->dir[i], 0, 0, 0, 0);
121
      ELL_4V_SET(lit->col[i], 0, 0, 0, 1);
122
      lit->on[i] = AIR_FALSE;
123
      lit->vsp[i] = AIR_FALSE;
124
    }
125
  }
126
}