GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
lights.c
Go to the documentation of this file.
1 
15 #include <grass/glocale.h>
16 #include <grass/nviz.h>
17 
27 int Nviz_set_light_position(nv_data * data, int num,
28  double x, double y, double z, double w)
29 {
30  /*
31  double xpos, ypos;
32  xpos = x;
33  xpos = (xpos < 0) ? 0 : (xpos > 1.0) ? 1.0 : xpos;
34  ypos = 1.0 - y;
35  ypos = (ypos < 0) ? 0 : (ypos > 1.0) ? 1.0 : ypos;
36 
37  if (x < 0.0 || x > 1.0 || y < 0.0 || y > 1.0) {
38  G_debug(1, "Invalid light position coordinates (%f,%f), using %f,%f",
39  x, y, xpos, 1.0 - ypos);
40  }
41  */
42 
43  data->light[num].id = num;
44  data->light[num].x = x;
45  data->light[num].y = y;
46  data->light[num].z = z;
47  data->light[num].w = w;
48 
49  G_debug(1, "Nviz_set_light_position(): num = %d x = %f y = %f z = %f w = %f",
50  num, x, y, z, w);
51  GS_setlight_position(num, x, y, z, w);
52 
53  return 1;
54 }
55 
63 int Nviz_set_light_bright(nv_data * data, int num, double value)
64 {
65  double r, g, b;
66 
67  data->light[num].brt = value;
68 
69  r = data->light[num].r * data->light[num].brt;
70  g = data->light[num].g * data->light[num].brt;
71  b = data->light[num].b * data->light[num].brt;
72 
73  G_debug(1, "Nviz_set_light_bright(): num = %d value = %f r = %f g = %f b = %f",
74  num, value, r, g, b);
75  GS_setlight_color(num, r, g, b);
76 
77  return 1;
78 }
79 
87 int Nviz_set_light_color(nv_data * data, int num,
88  int red, int green, int blue)
89 {
90  double r, g, b;
91 
92  data->light[num].r = red / 255.;
93  data->light[num].g = green / 255.;
94  data->light[num].b = blue / 255.;
95 
96  r = data->light[num].r * data->light[num].brt;
97  g = data->light[num].g * data->light[num].brt;
98  b = data->light[num].b * data->light[num].brt;
99 
100  G_debug(1, "Nviz_set_light_color(): num = %d r = %d/%f g = %d/%f b = %d/%f",
101  num, red, r, green, g, blue, b);
102  GS_setlight_color(num, r, g, b);
103 
104  return 1;
105 }
106 
114 int Nviz_set_light_ambient(nv_data * data, int num, double value)
115 {
116  data->light[num].ar = value;
117  data->light[num].ag = value;
118  data->light[num].ab = value;
119 
120  G_debug(1, "Nviz_set_light_ambient(): num = %d value = %f",
121  num, value);
122  GS_setlight_ambient(num, value, value, value);
123 
124  return 1;
125 }
126 
133 int Nviz_init_light(nv_data * data, int num)
134 {
135  G_debug(1, "Nviz_init_light(): num = %d", num);
136  if (num > MAX_LIGHTS) {
137  return 0;
138  }
139 
140  data->light[num].id = 0;
141  data->light[num].brt = 0.8;
142  data->light[num].ar = 0.3;
143  data->light[num].ag = 0.3;
144  data->light[num].ab = 0.3;
145  data->light[num].r = 1.0;
146  data->light[num].b = 1.0;
147  data->light[num].g = 1.0;
148  data->light[num].x = 1.0;
149  data->light[num].y = 1.0;
150  data->light[num].z = 1.0;
151  data->light[num].w = 1.0;
152 
153  return 1;
154 }
155 
164 int Nviz_new_light(nv_data * data)
165 {
166  int num;
167 
168  num = GS_new_light();
169 
170  if (num < 1) {
171  G_warning(_("Unable to define new light"));
172  return 0;
173  }
174 
175  Nviz_init_light(data, num);
176 
177  return 1;
178 }
179 
185 void Nviz_draw_model(nv_data * data)
186 {
187  GS_set_draw(GSD_FRONT);
188  GS_ready_draw();
190  GS_done_draw();
191  GS_set_draw(GSD_BACK);
192 }
void GS_setlight_ambient(int num, float red, float green, float blue)
Set light ambient.
Definition: GS2.c:402
void Nviz_draw_model(nv_data *data)
Draw lighting model.
Definition: lights.c:185
float b
Definition: named_colr.c:8
void GS_setlight_color(int num, float red, float green, float blue)
Set light color.
Definition: GS2.c:358
float r
Definition: named_colr.c:8
void GS_done_draw(void)
Draw done, swap buffers.
Definition: GS2.c:2499
long num
Definition: g3dcats.c:93
int Nviz_init_light(nv_data *data, int num)
Init new light.
Definition: lights.c:133
int y
Definition: plot.c:34
int Nviz_set_light_color(nv_data *data, int num, int red, int green, int blue)
Set light color.
Definition: lights.c:87
int Nviz_set_light_bright(nv_data *data, int num, double value)
Set light brightness.
Definition: lights.c:63
int Nviz_set_light_ambient(nv_data *data, int num, double value)
Set light ambient.
Definition: lights.c:114
tuple data
float g
Definition: named_colr.c:8
char * value
Definition: env.c:30
G_warning("category support for [%s] in mapset [%s] %s", name, mapset, type)
int Nviz_set_light_position(nv_data *data, int num, double x, double y, double z, double w)
Set light position.
Definition: lights.c:27
int G_debug(int level, const char *msg,...)
Print debugging message.
Definition: gis/debug.c:51
int GS_new_light(void)
Add new model light.
Definition: GS2.c:268
void GS_ready_draw(void)
Definition: GS2.c:2486
int Nviz_new_light(nv_data *data)
Define new light.
Definition: lights.c:164
void GS_set_draw(int where)
Sets which buffer to draw to.
Definition: GS2.c:2457
void GS_setlight_position(int num, float xpos, float ypos, float zpos, int local)
Set light position.
Definition: GS2.c:309
void GS_draw_lighting_model(void)
Draw lighting model.
Definition: GS2.c:938