GRASS Programmer's Manual  6.4.2(2012)
change_view.c
Go to the documentation of this file.
00001 
00015 #include <grass/glocale.h>
00016 #include <grass/nviz.h>
00017 
00027 int Nviz_resize_window(int width, int height)
00028 {
00029     int ret;
00030 
00031     ret = 1;
00032 
00033     if (width < 1 || height < 1) {
00034         width = 20;
00035         height = 20;
00036         ret = 0;
00037     }
00038 
00039     G_debug(1, "Nviz_resize_window(): width = %d height = %d", width, height);
00040     GS_set_viewport(0, width, 0, height);
00041 
00042     /*   GS_clear(0x0000FF); causes red flash - debug only */
00043     GS_set_draw(GSD_BACK);
00044     GS_ready_draw();
00045     GS_alldraw_wire();
00046     GS_done_draw();
00047 
00048     return ret;
00049 }
00050 
00058 int Nviz_update_ranges(nv_data * dc)
00059 {
00060     float zmin, zmax, exag;
00061 
00062     GS_get_longdim(&(dc->xyrange));
00063 
00064     dc->zrange = 0.;
00065 
00066     /* Zrange is based on a minimum of Longdim */
00067     if (GS_global_exag()) {
00068         exag = GS_global_exag();
00069         dc->zrange = dc->xyrange / exag;
00070     }
00071     else {
00072         exag = 1.0;
00073     }
00074 
00075     GS_get_zrange_nz(&zmin, &zmax);     /* actual */
00076 
00077     zmax = zmin + (3. * dc->xyrange / exag);
00078     zmin = zmin - (2. * dc->xyrange / exag);
00079 
00080     if ((zmax - zmin) > dc->zrange)
00081         dc->zrange = zmax - zmin;
00082 
00083     return 1;
00084 }
00085 
00094 int Nviz_set_viewpoint_position(double x_pos, double y_pos)
00095 {
00096     float xpos, ypos, from[3];
00097     float tempx, tempy;
00098 
00099     xpos = x_pos;
00100     xpos = (xpos < 0) ? 0 : (xpos > 1.0) ? 1.0 : xpos;
00101     ypos = 1.0 - y_pos;
00102     ypos = (ypos < 0) ? 0 : (ypos > 1.0) ? 1.0 : ypos;
00103 
00104     if (x_pos < 0.0 || x_pos > 1.0 || y_pos < 0.0 || y_pos > 1.0) {
00105         G_debug(3, "Invalid view position coordinates, using %f,%f",
00106                   xpos, 1.0 - ypos);
00107     }
00108 
00109     G_debug(1, "Nviz_set_viewpoint_position(): x = %f y = %f", x_pos, y_pos);
00110     GS_get_from(from);
00111 
00112     tempx = xpos * RANGE - RANGE_OFFSET;
00113     tempy = ypos * RANGE - RANGE_OFFSET;
00114 
00115     if ((from[X] != tempx) || (from[Y] != tempy)) {
00116 
00117         from[X] = tempx;
00118         from[Y] = tempy;
00119 
00120         GS_moveto(from);
00121 
00122         /* Nviz_draw_quick(data); */
00123     }
00124 
00125     return 1;
00126 }
00127 
00136 int Nviz_set_viewpoint_height(double height)
00137 {
00138     float from[3];
00139 
00140     G_debug(1, "Nviz_set_viewpoint_height(): value = %f", height);
00141 
00142     GS_get_from_real(from);
00143 
00144     if (height != from[Z]) {
00145         from[Z] = height;
00146 
00147         GS_moveto_real(from);
00148 
00149         /*
00150            normalize (from);
00151            GS_setlight_position(1, from[X], from[Y], from[Z], 0);
00152          */
00153 
00154         /* Nviz_draw_quick(data); */
00155     }
00156 
00157     return 1;
00158 }
00159 
00168 int Nviz_set_viewpoint_persp(int persp)
00169 {
00170     int fov;
00171 
00172     G_debug(1, "Nviz_set_viewpoint_persp(): value = %d", persp);
00173 
00174     fov = (int)(10 * persp);
00175     GS_set_fov(fov);
00176 
00177     /* Nviz_draw_quick(data); */
00178 
00179     return 1;
00180 }
00181 
00190 int Nviz_set_viewpoint_twist(int twist)
00191 {
00192     G_debug(1, "Nviz_set_viewpoint_twist(): value = %d", twist);
00193     GS_set_twist(10 * twist);
00194 
00195     /* Nviz_draw_quick(data); */
00196 
00197     return 1;
00198 }
00199 
00208 int Nviz_change_exag(nv_data * data, double exag)
00209 {
00210     double temp;
00211 
00212     G_debug(1, "Nviz_change_exag(): value = %f", exag);
00213     temp = GS_global_exag();
00214 
00215     if (exag != temp) {
00216         GS_set_global_exag(exag);
00217         Nviz_update_ranges(data);
00218 
00219         /* Nviz_draw_quick(data); */
00220     }
00221 
00222     return 1;
00223 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines