19 #include <grass/config.h>
21 #if defined(OPENGL_X11) || defined(OPENGL_WINDOWS)
24 #elif defined(OPENGL_AQUA)
25 #include <OpenGL/gl.h>
26 #include <OpenGL/glu.h>
29 #include <grass/gstypes.h>
42 double fx, fy, fz, tx, ty, tz;
43 GLdouble modelMatrix[16], projMatrix[16];
50 glGetDoublev(GL_MODELVIEW_MATRIX, modelMatrix);
51 glGetDoublev(GL_PROJECTION_MATRIX, projMatrix);
52 glGetIntegerv(GL_VIEWPORT, viewport);
57 gluUnProject((GLdouble) sx, (GLdouble) sy, 0.0, modelMatrix,
58 projMatrix, viewport, &fx, &fy, &fz);
59 gluUnProject((GLdouble) sx, (GLdouble) sy, 1.0, modelMatrix,
60 projMatrix, viewport, &tx, &ty, &tz);
70 glDrawBuffer((1) ? GL_FRONT : GL_BACK);
77 glBegin(GL_LINE_STRIP);
78 glVertex3fv(vect[
FROM]);
79 glVertex3fv(vect[TO]);
86 glDrawBuffer((0) ? GL_FRONT : GL_BACK);
112 glGetIntegerv(GL_MATRIX_MODE, &mm);
113 glMatrixMode(GL_PROJECTION);
115 gluPerspective((
double).1 * (gv->fov), (
double)gd->aspect,
116 (
double)gd->nearclip, (
double)gd->farclip);
123 glRotatef((
float)(gv->twist / 10.), 0.0, 0.0, 1.0);
126 gluLookAt((
double)gv->from_to[
FROM][
X], (
double)gv->from_to[
FROM][
Y],
127 (
double)gv->from_to[
FROM][Z], (
double)gv->from_to[TO][X],
128 (
double)gv->from_to[TO][Y], (
double)gv->from_to[TO][Z],
129 (
double)up[X], (
double)up[Y], (
double)up[Z]);
151 GLdouble modelMatrix[16];
161 glGetIntegerv(GL_MATRIX_MODE, &mm);
162 glMatrixMode(GL_PROJECTION);
164 gluPerspective((
double).1 * (gv->fov), (
double)gd->aspect,
165 (
double)gd->nearclip, (
double)gd->farclip);
172 glRotatef((
float)(gv->twist / 10.), 0.0, 0.0, 1.0);
175 gluLookAt((
double)gv->from_to[
FROM][
X], (
double)gv->from_to[
FROM][
Y],
176 (
double)gv->from_to[
FROM][Z], (
double)gv->from_to[TO][X],
177 (
double)gv->from_to[TO][Y], (
double)gv->from_to[TO][Z],
178 (
double)up[X], (
double)up[Y], (
double)up[Z]);
181 if (gv->rotate.do_rot) {
184 glLoadMatrixd(gv->rotate.rotMatrix);
186 glRotated(gv->rotate.rot_angle, gv->rotate.rot_axes[0],
187 gv->rotate.rot_axes[1], gv->rotate.rot_axes[2]);
188 glGetDoublev(GL_MODELVIEW_MATRIX, modelMatrix);
190 for (i = 0; i < 16; i++) {
191 gv->rotate.rotMatrix[i] = modelMatrix[i];
200 glTranslatef(pos[0], pos[1], pos[2]);
201 glMultMatrixd(gv->rotate.rotMatrix);
202 glTranslatef(-pos[0], -pos[1], -pos[2]);
222 GS_v3eq(gv->from_to[TO], gv->real_to);
223 gv->from_to[TO][Z] -= zmin;
225 gv->from_to[TO][Z] *= gv->vert_exag;
242 float zup[3], fup[3];
246 (2.0 * atan(1.0)) - acos(gv->from_to[
FROM][Z] - gv->from_to[TO][Z]);
248 zup[
X] = gv->from_to[TO][
X];
249 zup[
Y] = gv->from_to[TO][
Y];
252 zup[Z] = gv->from_to[TO][Z] + 1 / sin(alpha);
255 zup[Z] = gv->from_to[
FROM][Z] + 1.0;
277 float look_theta, pi;
279 float zup[3], yup[3], zupmag, yupmag;
281 pi = 4.0 * atan(1.0);
292 GS_v3eq(fr_to[TO], gv->from_to[TO]);
295 alpha = pi / 2.0 - acos(fr_to[FROM][Z] - fr_to[TO][Z]);
297 zup[
X] = fr_to[TO][
X];
298 zup[
Y] = fr_to[TO][
Y];
301 zup[Z] = fr_to[TO][Z] + 1 / sin(alpha);
304 zup[Z] = fr_to[
FROM][Z] + 1.0;
309 yup[
X] = fr_to[TO][
X];
310 yup[Z] = fr_to[TO][Z];
313 beta = pi / 2.0 - acos(fr_to[TO][
Y] - fr_to[FROM][
Y]);
316 yup[
Y] = fr_to[TO][
Y] - 1 / sin(beta);
319 yup[
Y] = fr_to[
FROM][
Y] + 1.0;
324 look_theta = (1800.0 / pi) *
325 acos(((zup[
X] - fr_to[FROM][
X]) * (yup[X] - fr_to[FROM][X])
326 + (zup[Y] - fr_to[FROM][Y]) * (yup[Y] - fr_to[FROM][Y])
327 + (zup[Z] - fr_to[FROM][Z]) * (yup[Z] - fr_to[FROM][Z])) /
330 if (fr_to[TO][X] - fr_to[FROM][X] < 0.0) {
331 look_theta = -look_theta;
334 if (fr_to[TO][Z] - fr_to[FROM][Z] < 0.0) {
336 if (fr_to[TO][Y] - fr_to[FROM][Y] < 0.0) {
337 look_theta = 1800 - look_theta;
342 if (fr_to[TO][Y] - fr_to[FROM][Y] > 0.0) {
343 look_theta = 1800 - look_theta;
347 return ((
int)(gv->twist + 1800 + look_theta));
381 point[
X] = (point[
X] -
w) * sx;
382 point[
Y] = (point[
Y] -
s) * sy;
383 point[Z] = (point[Z] -
min) * sz;
401 point[
X] = (sx ? point[
X] / sx : 0.0) +
w;
402 point[
Y] = (sy ? point[
Y] / sy : 0.0) +
s;
403 point[Z] = (sz ? point[Z] / sz : 0.0) +
min;
416 float min,
max, sx, sy, sz;
427 point[Z] = (sz ? point[Z] / sz : 0.0) +
min;
430 point[
X] = (sx ? point[
X] / sx : 0.0);
431 point[
Y] = (sy ? point[
Y] / sy : 0.0);
443 float min,
max, sx, sy, sz;
449 point[Z] = (sz ? (point[Z] -
min) * sz : 0.0);
452 point[
X] = (sx ? point[
X] * sx : 0.0);
453 point[
Y] = (sy ? point[
Y] * sy : 0.0);
int GS_v3normalize(float *v1, float *v2)
Change v2 so that v1v2 is a unit vector.
int gs_get_datacenter(float *cen)
Get data center point.
void gsd_get_zup(geoview *gv, double *up)
Get z-up vector (z-direction)
void gsd_do_scale(int doexag)
Set current scale.
int GS_v3dir(float *v1, float *v2, float *v3)
Get a normalized direction from v1 to v2, store in v3.
void gsd_surf2real(geosurf *gs, Point3 point)
Convert surface to real coordinates.
void gsd_color_func(unsigned int col)
Set current color.
int GS_get_region(float *n, float *s, float *w, float *e)
Get 2D region extent.
void gsd_translate(float dx, float dy, float dz)
Multiply the current matrix by a translation matrix.
void gsd_check_focus(geoview *gv)
Check focus.
void gsd_update_cplanes(void)
Update cplaces.
void gsd_real2surf(geosurf *gs, Point3 point)
Convert real to surface coordinates.
void gsd_real2model(Point3 point)
Convert real to model coordinates.
int GS_get_zrange(float *min, float *max, int doexag)
Get z-extent for all loaded surfaces.
double GS_get_aspect(void)
Get aspect value.
void GS_v3mult(float *v1, float k)
Multiple vectors.
void gsd_set_view(geoview *gv, geodisplay *gd)
Set view.
void gsd_model2surf(geosurf *gs, Point3 point)
Convert model to surface coordinates.
void gsd_model2real(Point3 point)
Convert model to real coordinates.
void GS_v3eq(float *v1, float *v2)
Copy vector values.
void gsd_linewidth(short n)
Set width of rasterized lines.
float GS_distance(float *from, float *to)
Calculate distance.
void gsd_surf2model(Point3 point)
Convert surface to model coordinates.
void gsd_scale(float xs, float ys, float zs)
Multiply the current matrix by a general scaling matrix.
int gsd_get_los(float(*vect)[3], short sx, short sy)
ADD.
int gsd_zup_twist(geoview *gv)
ADD.
void GS_get_scale(float *sx, float *sy, float *sz, int doexag)
Get axis scale.