GRASS Programmer's Manual  6.4.2(2012)
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
change_view.c
Go to the documentation of this file.
1 
15 #include <grass/glocale.h>
16 #include <grass/nviz.h>
17 
28 {
29  int ret;
30 
31  ret = 1;
32 
33  if (width < 1 || height < 1) {
34  width = 20;
35  height = 20;
36  ret = 0;
37  }
38 
39  G_debug(1, "Nviz_resize_window(): width = %d height = %d", width, height);
40  GS_set_viewport(0, width, 0, height);
41 
42  /* GS_clear(0x0000FF); causes red flash - debug only */
43  GS_set_draw(GSD_BACK);
44  GS_ready_draw();
46  GS_done_draw();
47 
48  return ret;
49 }
50 
58 int Nviz_update_ranges(nv_data * dc)
59 {
60  float zmin, zmax, exag;
61 
62  GS_get_longdim(&(dc->xyrange));
63 
64  dc->zrange = 0.;
65 
66  /* Zrange is based on a minimum of Longdim */
67  if (GS_global_exag()) {
68  exag = GS_global_exag();
69  dc->zrange = dc->xyrange / exag;
70  }
71  else {
72  exag = 1.0;
73  }
74 
75  GS_get_zrange_nz(&zmin, &zmax); /* actual */
76 
77  zmax = zmin + (3. * dc->xyrange / exag);
78  zmin = zmin - (2. * dc->xyrange / exag);
79 
80  if ((zmax - zmin) > dc->zrange)
81  dc->zrange = zmax - zmin;
82 
83  return 1;
84 }
85 
94 int Nviz_set_viewpoint_position(double x_pos, double y_pos)
95 {
96  float xpos, ypos, from[3];
97  float tempx, tempy;
98 
99  xpos = x_pos;
100  xpos = (xpos < 0) ? 0 : (xpos > 1.0) ? 1.0 : xpos;
101  ypos = 1.0 - y_pos;
102  ypos = (ypos < 0) ? 0 : (ypos > 1.0) ? 1.0 : ypos;
103 
104  if (x_pos < 0.0 || x_pos > 1.0 || y_pos < 0.0 || y_pos > 1.0) {
105  G_debug(3, "Invalid view position coordinates, using %f,%f",
106  xpos, 1.0 - ypos);
107  }
108 
109  G_debug(1, "Nviz_set_viewpoint_position(): x = %f y = %f", x_pos, y_pos);
110  GS_get_from(from);
111 
112  tempx = xpos * RANGE - RANGE_OFFSET;
113  tempy = ypos * RANGE - RANGE_OFFSET;
114 
115  if ((from[X] != tempx) || (from[Y] != tempy)) {
116 
117  from[X] = tempx;
118  from[Y] = tempy;
119 
120  GS_moveto(from);
121 
122  /* Nviz_draw_quick(data); */
123  }
124 
125  return 1;
126 }
127 
137 {
138  float from[3];
139 
140  G_debug(1, "Nviz_set_viewpoint_height(): value = %f", height);
141 
142  GS_get_from_real(from);
143 
144  if (height != from[Z]) {
145  from[Z] = height;
146 
147  GS_moveto_real(from);
148 
149  /*
150  normalize (from);
151  GS_setlight_position(1, from[X], from[Y], from[Z], 0);
152  */
153 
154  /* Nviz_draw_quick(data); */
155  }
156 
157  return 1;
158 }
159 
169 {
170  int fov;
171 
172  G_debug(1, "Nviz_set_viewpoint_persp(): value = %d", persp);
173 
174  fov = (int)(10 * persp);
175  GS_set_fov(fov);
176 
177  /* Nviz_draw_quick(data); */
178 
179  return 1;
180 }
181 
191 {
192  G_debug(1, "Nviz_set_viewpoint_twist(): value = %d", twist);
193  GS_set_twist(10 * twist);
194 
195  /* Nviz_draw_quick(data); */
196 
197  return 1;
198 }
199 
208 int Nviz_change_exag(nv_data * data, double exag)
209 {
210  double temp;
211 
212  G_debug(1, "Nviz_change_exag(): value = %f", exag);
213  temp = GS_global_exag();
214 
215  if (exag != temp) {
216  GS_set_global_exag(exag);
217  Nviz_update_ranges(data);
218 
219  /* Nviz_draw_quick(data); */
220  }
221 
222  return 1;
223 }