-
Notifications
You must be signed in to change notification settings - Fork 1
/
draw.c
778 lines (672 loc) · 20 KB
/
draw.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include "ml6.h"
#include "display.h"
#include "draw.h"
#include "matrix.h"
#include "math.h"
#include "gmath.h"
#include "obj_reader.h"
#include "mesh.h"
/*======== void scanline_convert() ==========
Inputs: struct matrix *points
int i
screen s
zbuffer zb
Returns:
v
Fills in polygon i by drawing consecutive horizontal (or vertical) lines.
Color should be set differently for each polygon.
====================*/
void scanline_convert( struct matrix *points, int i, screen s, zbuffer zb, color c) {
int top, mid, bot, y;
int distance0, distance1, distance2;
double x0, x1, y0, y1, y2, dx0, dx1, z0, z1, dz0, dz1;
int flip = 0;
z0 = z1 = dz0 = dz1 = 0;
y0 = points->m[1][i];
y1 = points->m[1][i+1];
y2 = points->m[1][i+2];
/* color c; */
/* c.red = (23 * (i/3))%255; */
/* c.green = (109 * (i/3))%255; */
/* c.blue = (c.blue+(227 * (i/3)))%255; */
//find bot, mid, top
if ( y0 <= y1 && y0 <= y2) {
bot = i;
if (y1 <= y2) {
mid = i+1;
top = i+2;
}
else {
mid = i+2;
top = i+1;
}
}//end y0 bottom
else if (y1 <= y0 && y1 <= y2) {
bot = i+1;
if (y0 <= y2) {
mid = i;
top = i+2;
}
else {
mid = i+2;
top = i;
}
}//end y1 bottom
else {
bot = i+2;
if (y0 <= y1) {
mid = i;
top = i+1;
}
else {
mid = i+1;
top = i;
}
}//end y2 bottom
//printf("ybot: %0.2f, ymid: %0.2f, ytop: %0.2f\n", (points->m[1][bot]),(points->m[1][mid]), (points->m[1][top]));
/* printf("bot: (%0.2f, %0.2f, %0.2f) mid: (%0.2f, %0.2f, %0.2f) top: (%0.2f, %0.2f, %0.2f)\n", */
x0 = points->m[0][bot];
x1 = points->m[0][bot];
z0 = points->m[2][bot];
z1 = points->m[2][bot];
y = (int)(points->m[1][bot]);
distance0 = (int)(points->m[1][top]) - y;
distance1 = (int)(points->m[1][mid]) - y;
distance2 = (int)(points->m[1][top]) - (int)(points->m[1][mid]);
//printf("distance0: %d distance1: %d distance2: %d\n", distance0, distance1, distance2);
dx0 = distance0 > 0 ? (points->m[0][top]-points->m[0][bot])/distance0 : 0;
dx1 = distance1 > 0 ? (points->m[0][mid]-points->m[0][bot])/distance1 : 0;
dz0 = distance0 > 0 ? (points->m[2][top]-points->m[2][bot])/distance0 : 0;
dz1 = distance1 > 0 ? (points->m[2][mid]-points->m[2][bot])/distance1 : 0;
while ( y <= (int)points->m[1][top] ) {
//printf("\tx0: %0.2f x1: %0.2f y: %d\n", x0, x1, y);
draw_line(x0, y, z0, x1, y, z1, s, zb, c);
x0+= dx0;
x1+= dx1;
z0+= dz0;
z1+= dz1;
y++;
if ( !flip && y >= (int)(points->m[1][mid]) ) {
flip = 1;
dx1 = distance2 > 0 ? (points->m[0][top]-points->m[0][mid])/distance2 : 0;
dz1 = distance2 > 0 ? (points->m[2][top]-points->m[2][mid])/distance2 : 0;
x1 = points->m[0][mid];
z1 = points->m[2][mid];
}//end flip code
}//end scanline loop
}
/*======== void add_polygon() ==========
Inputs: struct matrix *surfaces
double x0
double y0
double z0
double x1
double y1
double z1
double x2
double y2
double z2
Returns:
Adds the vertices (x0, y0, z0), (x1, y1, z1)
and (x2, y2, z2) to the polygon matrix. They
define a single triangle surface.
====================*/
void add_polygon( struct matrix *polygons,
double x0, double y0, double z0,
double x1, double y1, double z1,
double x2, double y2, double z2 ) {
add_point(polygons, x0, y0, z0);
add_point(polygons, x1, y1, z1);
add_point(polygons, x2, y2, z2);
}
/*======== void draw_polygons() ==========
Inputs: struct matrix *polygons
screen s
color c
Returns:
Goes through polygons 3 points at a time, drawing
lines connecting each points to create bounding
triangles. Compatible with multiple lights.
====================*/
void draw_polygons(struct matrix *polygons, screen s, zbuffer zb,
double *view, double light[MAX_LIGHTS][2][3],
color ambient, double *areflect, double *dreflect,
double *sreflect, int num_lights) {
if ( polygons->lastcol < 3 ) {
printf("Need at least 3 points to draw a polygon!\n");
exit(0);
}
int point;
double *normal;
for (point=0; point<polygons->lastcol-2; point+=3) {
normal = calculate_normal(polygons, point);
if (dot_product(normal, view) > 0) {
color c = {0, 0, 0};
int i;
for(i=0; i<num_lights; i++) {
color new = get_lighting(normal, view, ambient, light[i], areflect, dreflect, sreflect);
c.red += new.red;
c.green += new.green;
c.blue += new.blue;
}
if(c.red > 255)
c.red = 255;
if(c.green > 255)
c.green = 255;
if(c.blue > 255)
c.blue = 255;
scanline_convert(polygons, point, s, zb, c);
draw_line( polygons->m[0][point],
polygons->m[1][point],
polygons->m[2][point],
polygons->m[0][point+1],
polygons->m[1][point+1],
polygons->m[2][point+1],
s, zb, c);
draw_line( polygons->m[0][point+2],
polygons->m[1][point+2],
polygons->m[2][point+2],
polygons->m[0][point+1],
polygons->m[1][point+1],
polygons->m[2][point+1],
s, zb, c);
draw_line( polygons->m[0][point],
polygons->m[1][point],
polygons->m[2][point],
polygons->m[0][point+2],
polygons->m[1][point+2],
polygons->m[2][point+2],
s, zb, c);
}
}
}
/*======== void add_box() ==========
Inputs: struct matrix * edges
double x
double y
double z
double width
double height
double depth
Returns:
add the points for a rectagular prism whose
upper-left corner is (x, y, z) with width,
height and depth dimensions.
====================*/
void add_box( struct matrix * polygons,
double x, double y, double z,
double width, double height, double depth ) {
double x1, y1, z1;
x1 = x+width;
y1 = y-height;
z1 = z-depth;
//front
add_polygon(polygons, x, y, z, x1, y1, z, x1, y, z);
add_polygon(polygons, x, y, z, x, y1, z, x1, y1, z);
//back
add_polygon(polygons, x1, y, z1, x, y1, z1, x, y, z1);
add_polygon(polygons, x1, y, z1, x1, y1, z1, x, y1, z1);
//right side
add_polygon(polygons, x1, y, z, x1, y1, z1, x1, y, z1);
add_polygon(polygons, x1, y, z, x1, y1, z, x1, y1, z1);
//left side
add_polygon(polygons, x, y, z1, x, y1, z, x, y, z);
add_polygon(polygons, x, y, z1, x, y1, z1, x, y1, z);
//top
add_polygon(polygons, x, y, z1, x1, y, z, x1, y, z1);
add_polygon(polygons, x, y, z1, x, y, z, x1, y, z);
//bottom
add_polygon(polygons, x, y1, z, x1, y1, z1, x1, y1, z);
add_polygon(polygons, x, y1, z, x, y1, z1, x1, y1, z1);
}//end add_box
void add_mesh(struct matrix *polygons, char *fname) {
struct mesh *mesh_conts = generate_mesh(fname);
struct matrix *pts, *face_order, *vert_norms;
pts = mesh_conts->points;
face_order = mesh_conts->face_ords;
vert_norms = mesh_conts->vert_norms;
int i1, i2, i3, i4; // indices
double v1[3], v2[3], v3[3], v4[3]; // vertices
int i;
// Iterate throughout face-order matrix and add polygons
for(i=0; i<face_order->lastcol; i++) {
i1 = (face_order->m)[0][i];
i2 = (face_order->m)[1][i];
i3 = (face_order->m)[2][i];
i4 = (face_order->m)[3][i];
int coord;
for(coord=0; coord<3; coord++) {
if(i4 > 0) {
v1[coord] = (pts->m)[coord][i1-1];
v2[coord] = (pts->m)[coord][i2-1];
v3[coord] = (pts->m)[coord][i3-1];
v4[coord] = (pts->m)[coord][i4-1];
} else {
v1[coord] = (pts->m)[coord][i1-1];
v2[coord] = (pts->m)[coord][i2-1];
v3[coord] = (pts->m)[coord][i3-1];
}
}
if(i4 > 0) {
add_polygon(polygons, v1[0], v1[1], v1[2], v2[0], v2[1], v2[2], v3[0], v3[1], v3[2]);
add_polygon(polygons, v1[0], v1[1], v1[2], v3[0], v3[1], v3[2], v4[0], v4[1], v4[2]);
} else {
add_polygon(polygons, v1[0], v1[1], v1[2], v2[0], v2[1], v2[2], v3[0], v3[1], v3[2]);
}
}
free_mesh(mesh_conts);
}
struct mesh *generate_mesh(char *fname) {
struct mesh *ret_mesh = (struct mesh *)malloc(sizeof(struct mesh));
ret_mesh->points = new_matrix(4, 100);
ret_mesh->face_ords = new_matrix(4, 100);
ret_mesh->vert_norms = new_matrix(4, 100);
read_obj_file(fname, ret_mesh);
return ret_mesh;
}
/*======== void add_sphere() ==========
Inputs: struct matrix * points
double cx
double cy
double cz
double r
double step
Returns:
adds all the points for a sphere with center
(cx, cy, cz) and radius r.
should call generate_sphere to create the
necessary points
====================*/
void add_sphere( struct matrix * edges,
double cx, double cy, double cz,
double r, int step ) {
struct matrix *points = generate_sphere(cx, cy, cz, r, step);
int p0, p1, p2, p3, lat, longt;
int latStop, longStop, latStart, longStart;
latStart = 0;
latStop = step;
longStart = 0;
longStop = step;
step++;
for ( lat = latStart; lat < latStop; lat++ ) {
for ( longt = longStart; longt < longStop; longt++ ) {
p0 = lat * (step) + longt;
p1 = p0+1;
p2 = (p1+step) % (step * (step-1));
p3 = (p0+step) % (step * (step-1));
//printf("p0: %d\tp1: %d\tp2: %d\tp3: %d\n", p0, p1, p2, p3);
if (longt < step - 2)
add_polygon( edges, points->m[0][p0],
points->m[1][p0],
points->m[2][p0],
points->m[0][p1],
points->m[1][p1],
points->m[2][p1],
points->m[0][p2],
points->m[1][p2],
points->m[2][p2]);
if (longt > 0 )
add_polygon( edges, points->m[0][p0],
points->m[1][p0],
points->m[2][p0],
points->m[0][p2],
points->m[1][p2],
points->m[2][p2],
points->m[0][p3],
points->m[1][p3],
points->m[2][p3]);
}
}
free_matrix(points);
}
/*======== void generate_sphere() ==========
Inputs: double cx
double cy
double cz
double r
int step
Returns: Generates all the points along the surface
of a sphere with center (cx, cy, cz) and
radius r.
Returns a matrix of those points
====================*/
struct matrix * generate_sphere(double cx, double cy, double cz,
double r, int step ) {
struct matrix *points = new_matrix(4, step * step);
int circle, rotation, rot_start, rot_stop, circ_start, circ_stop;
double x, y, z, rot, circ;
rot_start = 0;
rot_stop = step;
circ_start = 0;
circ_stop = step;
for (rotation = rot_start; rotation < rot_stop; rotation++) {
rot = (double)rotation / step;
for(circle = circ_start; circle <= circ_stop; circle++){
circ = (double)circle / step;
x = r * cos(M_PI * circ) + cx;
y = r * sin(M_PI * circ) *
cos(2*M_PI * rot) + cy;
z = r * sin(M_PI * circ) *
sin(2*M_PI * rot) + cz;
/* printf("rotation: %d\tcircle: %d\n", rotation, circle); */
/* printf("rot: %lf\tcirc: %lf\n", rot, circ); */
/* printf("sphere point: (%0.2f, %0.2f, %0.2f)\n\n", x, y, z); */
add_point(points, x, y, z);
}
}
return points;
}
/*======== void add_torus() ==========
Inputs: struct matrix * points
double cx
double cy
double cz
double r1
double r2
double step
Returns:
adds all the points required to make a torus
with center (cx, cy, cz) and radii r1 and r2.
should call generate_torus to create the
necessary points
====================*/
void add_torus( struct matrix * edges,
double cx, double cy, double cz,
double r1, double r2, int step ) {
struct matrix *points = generate_torus(cx, cy, cz, r1, r2, step);
int p0, p1, p2, p3, lat, longt;
int latStop, longStop, latStart, longStart;
latStart = 0;
latStop = step;
longStart = 0;
longStop = step;
//printf("points: %d\n", points->lastcol);
for ( lat = latStart; lat < latStop; lat++ ) {
for ( longt = longStart; longt < longStop; longt++ ) {
p0 = lat * step + longt;
if (longt == step - 1)
p1 = p0 - longt;
else
p1 = p0 + 1;
p2 = (p1 + step) % (step * step);
p3 = (p0 + step) % (step * step);
//printf("p0: %d\tp1: %d\tp2: %d\tp3: %d\n", p0, p1, p2, p3);
add_polygon( edges, points->m[0][p0],
points->m[1][p0],
points->m[2][p0],
points->m[0][p3],
points->m[1][p3],
points->m[2][p3],
points->m[0][p2],
points->m[1][p2],
points->m[2][p2]);
add_polygon( edges, points->m[0][p0],
points->m[1][p0],
points->m[2][p0],
points->m[0][p2],
points->m[1][p2],
points->m[2][p2],
points->m[0][p1],
points->m[1][p1],
points->m[2][p1]);
}
}
free_matrix(points);
}
/*======== void generate_torus() ==========
Inputs: struct matrix * points
double cx
double cy
double cz
double r
int step
Returns: Generates all the points along the surface
of a torus with center (cx, cy, cz) and
radii r1 and r2.
Returns a matrix of those points
====================*/
struct matrix * generate_torus( double cx, double cy, double cz,
double r1, double r2, int step ) {
struct matrix *points = new_matrix(4, step * step);
int circle, rotation, rot_start, rot_stop, circ_start, circ_stop;
double x, y, z, rot, circ;
rot_start = 0;
rot_stop = step;
circ_start = 0;
circ_stop = step;
for (rotation = rot_start; rotation < rot_stop; rotation++) {
rot = (double)rotation / step;
for(circle = circ_start; circle < circ_stop; circle++){
circ = (double)circle / step;
x = cos(2*M_PI * rot) *
(r1 * cos(2*M_PI * circ) + r2) + cx;
y = r1 * sin(2*M_PI * circ) + cy;
z = -1*sin(2*M_PI * rot) *
(r1 * cos(2*M_PI * circ) + r2) + cz;
//printf("rotation: %d\tcircle: %d\n", rotation, circle);
//printf("torus point: (%0.2f, %0.2f, %0.2f)\n", x, y, z);
add_point(points, x, y, z);
}
}
return points;
}
/*======== void add_circle() ==========
Inputs: struct matrix * points
double cx
double cy
double r
double step
Returns:
Adds the circle at (cx, cy) with radius r to edges
====================*/
void add_circle( struct matrix * edges,
double cx, double cy, double cz,
double r, int step ) {
double x0, y0, x1, y1, t;
int i;
x0 = r + cx;
y0 = cy;
for (i=1; i<=step; i++) {
t = (double)i/step;
x1 = r * cos(2 * M_PI * t) + cx;
y1 = r * sin(2 * M_PI * t) + cy;
add_edge(edges, x0, y0, cz, x1, y1, cz);
x0 = x1;
y0 = y1;
}
}
/*======== void add_curve() ==========
Inputs: struct matrix *points
double x0
double y0
double x1
double y1
double x2
double y2
double x3
double y3
double step
int type
Returns:
Adds the curve bounded by the 4 points passsed as parameters
of type specified in type (see matrix.h for curve type constants)
to the matrix points
====================*/
void add_curve( struct matrix *edges,
double x0, double y0,
double x1, double y1,
double x2, double y2,
double x3, double y3,
int step, int type ) {
double t, x, y;
struct matrix *xcoefs;
struct matrix *ycoefs;
int i;
xcoefs = generate_curve_coefs(x0, x1, x2, x3, type);
ycoefs = generate_curve_coefs(y0, y1, y2, y3, type);
/* print_matrix(xcoefs); */
/* printf("\n"); */
/* print_matrix(ycoefs); */
for (i=1; i<=step; i++) {
t = (double)i/step;
x = xcoefs->m[0][0] *t*t*t + xcoefs->m[1][0] *t*t+
xcoefs->m[2][0] *t + xcoefs->m[3][0];
y = ycoefs->m[0][0] *t*t*t + ycoefs->m[1][0] *t*t+
ycoefs->m[2][0] *t + ycoefs->m[3][0];
add_edge(edges, x0, y0, 0, x, y, 0);
x0 = x;
y0 = y;
}
free_matrix(xcoefs);
free_matrix(ycoefs);
}
/*======== void add_point() ==========
Inputs: struct matrix * points
int x
int y
int z
Returns:
adds point (x, y, z) to points and increment points.lastcol
if points is full, should call grow on points
====================*/
void add_point( struct matrix * points, double x, double y, double z) {
if ( points->lastcol == points->cols )
grow_matrix( points, points->lastcol + 100 );
points->m[0][ points->lastcol ] = x;
points->m[1][ points->lastcol ] = y;
points->m[2][ points->lastcol ] = z;
points->m[3][ points->lastcol ] = 1;
points->lastcol++;
} //end add_point
/*======== void add_edge() ==========
Inputs: struct matrix * points
int x0, int y0, int z0, int x1, int y1, int z1
Returns:
add the line connecting (x0, y0, z0) to (x1, y1, z1) to points
should use add_point
====================*/
void add_edge( struct matrix * points,
double x0, double y0, double z0,
double x1, double y1, double z1) {
add_point( points, x0, y0, z0 );
add_point( points, x1, y1, z1 );
}
/*======== void draw_lines() ==========
Inputs: struct matrix * points
screen s
color c
Returns:
Go through points 2 at a time and call draw_line to add that line
to the screen
====================*/
void draw_lines( struct matrix * points, screen s, zbuffer zb, color c) {
if ( points->lastcol < 2 ) {
printf("Need at least 2 points to draw a line!\n");
return;
}
int point;
for (point=0; point < points->lastcol-1; point+=2)
draw_line( points->m[0][point],
points->m[1][point],
points->m[2][point],
points->m[0][point+1],
points->m[1][point+1],
points->m[2][point+1],
s, zb, c);
}// end draw_lines
void draw_line(int x0, int y0, double z0,
int x1, int y1, double z1,
screen s, zbuffer zb, color c) {
int x, y, d, A, B;
int dy_east, dy_northeast, dx_east, dx_northeast, d_east, d_northeast;
int loop_start, loop_end;
double distance;
double z, dz;
//swap points if going right -> left
int xt, yt;
if (x0 > x1) {
xt = x0;
yt = y0;
z = z0;
x0 = x1;
y0 = y1;
z0 = z1;
x1 = xt;
y1 = yt;
z1 = z;
}
x = x0;
y = y0;
A = 2 * (y1 - y0);
B = -2 * (x1 - x0);
int wide = 0;
int tall = 0;
//octants 1 and 8
if ( abs(x1 - x0) >= abs(y1 - y0) ) { //octant 1/8
wide = 1;
loop_start = x;
loop_end = x1;
dx_east = dx_northeast = 1;
dy_east = 0;
d_east = A;
distance = x1 - x;
if ( A > 0 ) { //octant 1
d = A + B/2;
dy_northeast = 1;
d_northeast = A + B;
}
else { //octant 8
d = A - B/2;
dy_northeast = -1;
d_northeast = A - B;
}
}//end octant 1/8
else { //octant 2/7
tall = 1;
dx_east = 0;
dx_northeast = 1;
distance = abs(y1 - y);
if ( A > 0 ) { //octant 2
d = A/2 + B;
dy_east = dy_northeast = 1;
d_northeast = A + B;
d_east = B;
loop_start = y;
loop_end = y1;
}
else { //octant 7
d = A/2 - B;
dy_east = dy_northeast = -1;
d_northeast = A - B;
d_east = -1 * B;
loop_start = y1;
loop_end = y;
}
}
z = z0;
dz = (z1 - z0) / distance;
//printf("\t(%d, %d) -> (%d, %d)\tdistance: %0.2f\tdz: %0.2f\tz: %0.2f\n", x0, y0, x1, y1, distance, dz, z);
while ( loop_start < loop_end ) {
plot( s, zb, c, x, y, z );
if ( (wide && ((A > 0 && d > 0) ||
(A < 0 && d < 0)))
||
(tall && ((A > 0 && d < 0 ) ||
(A < 0 && d > 0) ))) {
y+= dy_northeast;
d+= d_northeast;
x+= dx_northeast;
}
else {
x+= dx_east;
y+= dy_east;
d+= d_east;
}
z+= dz;
loop_start++;
} //end drawing loop
plot( s, zb, c, x1, y1, z );
} //end draw_line