BRL-CAD
dm_util.c
Go to the documentation of this file.
1 /* D M _ U T I L . C
2  * BRL-CAD
3  *
4  * Copyright (c) 1988-2014 United States Government as represented by
5  * the U.S. Army Research Laboratory.
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  * version 2.1 as published by the Free Software Foundation.
10  *
11  * This library is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this file; see the file named COPYING for more
18  * information.
19  */
20 /** @file libdm/dm_util.c
21  */
22 
23 #include "bn.h"
24 #include "dm.h"
25 
26 #include "./dm_private.h"
27 
28 # ifdef HAVE_GL_GL_H
29 # include <GL/gl.h>
30 # endif
31 
32 #if defined(DM_OGL) || defined(DM_WGL) || defined(DM_RTGL)
33 int
34 drawLine3D(struct dm_internal *dmp, point_t pt1, point_t pt2, const char *log_bu, float *wireColor)
35 {
36  static float black[4] = {0.0, 0.0, 0.0, 0.0};
37  GLdouble pt[3];
38 
39  if (dmp->dm_debugLevel)
40  bu_log(log_bu);
41 
42  if (dmp->dm_debugLevel) {
43  GLfloat pmat[16];
44 
45  glGetFloatv(GL_PROJECTION_MATRIX, pmat);
46  bu_log("projection matrix:\n");
47  bu_log("%g %g %g %g\n", pmat[0], pmat[4], pmat[8], pmat[12]);
48  bu_log("%g %g %g %g\n", pmat[1], pmat[5], pmat[9], pmat[13]);
49  bu_log("%g %g %g %g\n", pmat[2], pmat[6], pmat[10], pmat[14]);
50  bu_log("%g %g %g %g\n", pmat[3], pmat[7], pmat[11], pmat[15]);
51  glGetFloatv(GL_MODELVIEW_MATRIX, pmat);
52  bu_log("modelview matrix:\n");
53  bu_log("%g %g %g %g\n", pmat[0], pmat[4], pmat[8], pmat[12]);
54  bu_log("%g %g %g %g\n", pmat[1], pmat[5], pmat[9], pmat[13]);
55  bu_log("%g %g %g %g\n", pmat[2], pmat[6], pmat[10], pmat[14]);
56  bu_log("%g %g %g %g\n", pmat[3], pmat[7], pmat[11], pmat[15]);
57  }
58 
59  if (dmp->dm_light) {
60  glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, wireColor);
61  glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, black);
62  glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, black);
63  glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, black);
64 
65  if (dmp->dm_transparency)
66  glDisable(GL_BLEND);
67  }
68 
69  glBegin(GL_LINES);
70  VMOVE(pt, pt1); /* fastf_t to GLdouble */
71  glVertex3dv(pt);
72  VMOVE(pt, pt2); /* fastf_t to GLdouble */
73  glVertex3dv(pt);
74  glEnd();
75 
76  return TCL_OK;
77 }
78 
79 int
80 drawLines3D(struct dm_internal *dmp, int npoints, point_t *points, int lflag, const char *log_bu, float *wireColor)
81 {
82  register int i;
83  static float black[4] = {0.0, 0.0, 0.0, 0.0};
84 
85  if (dmp->dm_debugLevel)
86  bu_log(log_bu);
87 
88  if (dmp->dm_debugLevel) {
89  GLfloat pmat[16];
90 
91  glGetFloatv(GL_PROJECTION_MATRIX, pmat);
92  bu_log("projection matrix:\n");
93  bu_log("%g %g %g %g\n", pmat[0], pmat[4], pmat[8], pmat[12]);
94  bu_log("%g %g %g %g\n", pmat[1], pmat[5], pmat[9], pmat[13]);
95  bu_log("%g %g %g %g\n", pmat[2], pmat[6], pmat[10], pmat[14]);
96  bu_log("%g %g %g %g\n", pmat[3], pmat[7], pmat[11], pmat[15]);
97  glGetFloatv(GL_MODELVIEW_MATRIX, pmat);
98  bu_log("modelview matrix:\n");
99  bu_log("%g %g %g %g\n", pmat[0], pmat[4], pmat[8], pmat[12]);
100  bu_log("%g %g %g %g\n", pmat[1], pmat[5], pmat[9], pmat[13]);
101  bu_log("%g %g %g %g\n", pmat[2], pmat[6], pmat[10], pmat[14]);
102  bu_log("%g %g %g %g\n", pmat[3], pmat[7], pmat[11], pmat[15]);
103  }
104 
105  if (npoints < 2 || (!lflag && npoints%2))
106  return TCL_OK;
107 
108  if (dmp->dm_light) {
109  glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, wireColor);
110  glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, black);
111  glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, black);
112  glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, black);
113 
114  if (dmp->dm_transparency)
115  glDisable(GL_BLEND);
116  }
117 
118  if (lflag)
119  glBegin(GL_LINE_LOOP);
120  else
121  glBegin(GL_LINES);
122 
123  for (i = 0; i < npoints; ++i) {
124  GLdouble pt[3];
125  VMOVE(pt, points[i]); /* fastf_t to GLdouble */
126  glVertex3dv(pt);
127  }
128 
129  glEnd();
130 
131  return TCL_OK;
132 }
133 
134 int
135 drawLine2D(struct dm_internal *dmp, fastf_t X1, fastf_t Y1, fastf_t X2, fastf_t Y2, const char *log_bu)
136 {
137  if (dmp->dm_debugLevel)
138  bu_log(log_bu);
139 
140  if (dmp->dm_debugLevel) {
141  GLfloat pmat[16];
142 
143  glGetFloatv(GL_PROJECTION_MATRIX, pmat);
144  bu_log("projection matrix:\n");
145  bu_log("%g %g %g %g\n", pmat[0], pmat[4], pmat[8], pmat[12]);
146  bu_log("%g %g %g %g\n", pmat[1], pmat[5], pmat[9], pmat[13]);
147  bu_log("%g %g %g %g\n", pmat[2], pmat[6], pmat[10], pmat[14]);
148  bu_log("%g %g %g %g\n", pmat[3], pmat[7], pmat[11], pmat[15]);
149  glGetFloatv(GL_MODELVIEW_MATRIX, pmat);
150  bu_log("modelview matrix:\n");
151  bu_log("%g %g %g %g\n", pmat[0], pmat[4], pmat[8], pmat[12]);
152  bu_log("%g %g %g %g\n", pmat[1], pmat[5], pmat[9], pmat[13]);
153  bu_log("%g %g %g %g\n", pmat[2], pmat[6], pmat[10], pmat[14]);
154  bu_log("%g %g %g %g\n", pmat[3], pmat[7], pmat[11], pmat[15]);
155  }
156 
157  glBegin(GL_LINES);
158  glVertex2f(X1, Y1);
159  glVertex2f(X2, Y2);
160  glEnd();
161 
162  return TCL_OK;
163 }
164 #endif
165 
166 int
167 draw_Line3D(struct dm_internal *dmp, point_t pt1, point_t pt2)
168 {
169  if (!dmp)
170  return TCL_ERROR;
171 
172  if (bn_pt3_pt3_equal(pt1, pt2, NULL)) {
173  /* nothing to do for a singular point */
174  return TCL_OK;
175  }
176 
177  return TCL_OK;
178 }
179 
180 /*
181  * Local Variables:
182  * mode: C
183  * tab-width: 8
184  * indent-tabs-mode: t
185  * c-file-style: "stroustrup"
186  * End:
187  * ex: shiftwidth=4 tabstop=8
188  */
void bu_log(const char *,...) _BU_ATTR_PRINTF12
Definition: log.c:176
int draw_Line3D(struct dm_internal *dmp, point_t pt1, point_t pt2)
Definition: dm_util.c:167
int dm_light
!0 means lighting on
Definition: dm_private.h:112
int drawLine2D(struct dm_internal *dmp, fastf_t X1, fastf_t Y1, fastf_t X2, fastf_t Y2, const char *log_bu)
int drawLines3D(struct dm_internal *dmp, int npoints, point_t *points, int sflag, const char *log_bu, float *wireColor)
int drawLine3D(struct dm_internal *dmp, point_t pt1, point_t pt2, const char *log_bu, float *wireColor)
int dm_transparency
!0 means transparency on
Definition: dm_private.h:113
Definition: human.c:197
int bn_pt3_pt3_equal(const point_t a, const point_t b, const struct bn_tol *tol)
int dm_debugLevel
!0 means debugging
Definition: dm_private.h:109
double fastf_t
Definition: defines.h:300