1 /*****************************************************************************
2   FILE           : $Source: /projects/higgs1/SNNS/CVS/SNNS/xgui/sources/d3_draw.c,v $
3   SHORTNAME      : draw.c
4   SNNS VERSION   : 4.2
5 
6   PURPOSE        : routines for cube and line drawing
7   NOTES          :
8 
9   AUTHOR         : Ralf Huebner
10   DATE           : 1.12.1991
11 
12   CHANGED BY     : Sven Doering
13   RCS VERSION    : $Revision: 2.9 $
14   LAST CHANGE    : $Date: 1998/03/03 14:09:50 $
15 
16     Copyright (c) 1990-1995  SNNS Group, IPVR, Univ. Stuttgart, FRG
17     Copyright (c) 1996-1998  SNNS Group, WSI, Univ. Tuebingen, FRG
18 
19 ******************************************************************************/
20 #include <config.h>
21 
22 
23 #include <stdio.h>
24 #include <math.h>
25 #include <X11/Xlib.h>
26 #include <X11/X.h>
27 #include <X11/Xutil.h>
28 #include <X11/Xos.h>
29 
30 #include "glob_typ.h"	/*  Kernel constant and type definitions  */
31 #include "kr_ui.h"	/*  Kernel interface functions	*/
32 
33 
34 #include "d3_global.h"
35 #include "d3_anageo.h"
36 #include "d3_shade.h"
37 #include "d3_zgraph.h"
38 #include "d3_graph.h"
39 #include "d3_point.h"
40 #include "d3_main.h"
41 
42 #include "d3_draw.ph"
43 
44 /*****************************************************************************
45   FUNCTION : d3_draw_wireframeLine
46 
47   PURPOSE  : draws a link for the wireframe model
48   RETURNS  :
49   NOTES    :
50 
51 ******************************************************************************/
52 
53 
d3_draw_wireframeLine(float * v1,float * v2)54 void d3_draw_wireframeLine (float *v1, float *v2)
55 {
56     int xp1, yp1, xp2, yp2;
57 
58     xp1 = floor (v1[0] + 0.5);
59     yp1 = floor (v1[1] + 0.5);
60     xp2 = floor (v2[0] + 0.5);
61     yp2 = floor (v2[1] + 0.5);
62     d3_drawLine (xp1, yp1, xp2, yp2);
63 }
64 
65 
66 
67 
68 /*****************************************************************************
69   FUNCTION : d3_draw_wireframeCube
70 
71   PURPOSE  : draws a unit for the wireframe model
72   RETURNS  :
73   NOTES    :
74 
75 ******************************************************************************/
76 
77 
78 
79 /* void d3_draw_wireframeCube (float (*c)[4]) */
d3_draw_wireframeCube(cube c)80 void d3_draw_wireframeCube (cube c)
81 {
82     int i, xp1, yp1, xp2, yp2;
83 
84     for (i=0; i<ANZ_LINES; i++) {
85          xp1 = c [d3_cube_lines [i][0]][0];
86          yp1 = c [d3_cube_lines [i][0]][1];
87          xp2 = c [d3_cube_lines [i][1]][0];
88          yp2 = c [d3_cube_lines [i][1]][1];
89          d3_drawLine (xp1, yp1, xp2, yp2);
90     }
91 }
92 
93 
94 
95 
96 
97 /*****************************************************************************
98   FUNCTION : d3_draw_solidLine
99 
100   PURPOSE  : draws a link for the solid model
101   RETURNS  :
102   NOTES    :
103 
104 ******************************************************************************/
105 
106 
d3_draw_solidLine(vector v1,vector v2)107 void d3_draw_solidLine (vector v1, vector v2)
108 {
109     int xp, yp, i;
110     float my, my_step, dx, dy, zp;
111     vector v, w;
112 
113 
114     dx = fabs (v2[0] - v1[0]);
115     dy = fabs (v2[1] - v1[1]);
116     if (dx > dy)
117         my_step = (dx==0)? 1.0 : 1.0/dx;
118     else
119         my_step = (dy==0)? 1.0 : 1.0/dy;
120     for (i=0; i<4; i++)
121         w[i] = v2[i] - v1[i];
122     my = 0.0;
123     while (fabs (my) <= 1.0) {
124         for (i=0; i<4; i++)
125             v[i] = v1[i] + my * w[i];
126         xp = (int) (v[0]+0.5);
127         yp = (int) (v[1]+0.5);
128         if ((xp >= d3_clipWindow.x0) && (yp >= d3_clipWindow.y0)
129           && (yp < d3_clipWindow.y1) && (xp < d3_clipWindow.x1)) {
130             d3_readZbuffer (xp, yp, &zp);
131             if (v[2] < zp) {
132                 d3_putPixel (xp, yp);
133                 d3_writeZbuffer (xp, yp, v[2]);
134 	    }
135         }
136         my += my_step;
137     }
138 }
139 
140 
141 
142 
143 /*****************************************************************************
144   FUNCTION : d3_draw_solidCube
145 
146   PURPOSE  : draws a unit for the solid model
147   RETURNS  :
148   NOTES    :
149   UPDATE   : 3.3.93  shading for activation
150 
151 ******************************************************************************/
152 
153 
154 
d3_draw_solidCube(cube c,vector vp,vector lp,int unit_no)155 void d3_draw_solidCube (cube c, vector vp, vector lp, int unit_no)
156 {
157     int pi, vi;
158     d3_polygon_type p;
159     unsigned long color;
160     vector normal;
161     float col_val;
162     static long shades[6] = {0, -2, 2, 0, -2, 2};
163 
164     for (pi=0; pi<6; pi++) {
165         d3_normalVector (normal, c[d3_vertex_index[pi][0]],
166                                  c[d3_vertex_index[pi][1]],
167                                  c[d3_vertex_index[pi][2]]);
168 
169         if (d3_state.unit_mode.color == nothing_on) {
170             d3_shadeIntens (&d3_intens, c[d3_vertex_index[pi][0]], normal, lp);
171             color = d3_intens_to_grayval (d3_intens);
172         } else {
173             d3_getColorValue (d3_state.unit_mode.color, unit_no, &col_val);
174             color = (long) d3_value_to_color (col_val) + 3 + shades[pi];
175         }
176         d3_setColor (color);
177         p.n = 4;
178         for (vi=0; vi<4; vi++) {
179             p.vert[vi][0] = c[d3_vertex_index[pi][vi]] [0];
180             p.vert[vi][1] = c[d3_vertex_index[pi][vi]] [1];
181             p.vert[vi][2] = c[d3_vertex_index[pi][vi]] [2];
182         }
183         d3_drawPoly (&p);
184         d3_flushPixels ();
185     }
186 }
187 
188 
189 /* end of file */
190 /* lines:*/
191 
192 
193 
194 
195 
196 
197