-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlot.c
1382 lines (1163 loc) · 38.2 KB
/
Plot.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
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* ---------------------------------------------------------------------- *
* Plot - 25-12-93 SSi - Zeichenroutinen *
* ---------------------------------------------------------------------- */
#include "Plot.h"
#include <proto/intuition.h>
#include <proto/graphics.h>
#include <proto/dos.h>
#include <proto/exec.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <user/functions.h>
#include <graphics/gfxmacros.h>
/* globale Zeiger etc. ------------------------------------------------- */
extern struct Screen *OurS;
extern struct Window *OurW;
extern struct Window *ApsW;
extern short Drawx,DrawX,Drawy,DrawY; /* min. und max. Koor. für die Funktion */
/* auf dem Bildschirm */
extern short BorderDrawx,BorderDrawX,BorderDrawy,BorderDrawY; /* min. und max. Koor. */
extern double Midx,Midy; /* Koordinatenmitte (veränderlich) */
extern double _Midx,_Midy; /* -"- (fest) */
extern short SpacingX,SpacingY; /* x/y - Musterabstand */
TIME *TimeEstTH; /* für OPT_Time */
extern struct TextFont *textfont;
extern struct PlotPrefs *editPrefs;
extern struct RGColSupp *RGColSupp; /* RG-3d ColorSupp - Struktur */
/* APS-System ------------------------------------------------------------- */
extern TIME *APS_TH; /* für OPT_APS */
extern LONG APS_MinIntervall;
extern char APS_Filename[];
/* Daten der Funktion *****************************************************/
extern fnctcode *FunctionCode; /* RAW-Code der Funktion */
/* extern int _FPERR; */ /* Errorstatus von EvalRaw() */
extern short Status; /* Funktion zu berechnen 0 - ja / !=0 - nein */
extern double *X; /* Zeiger auf x,y Variablen */
extern double *Y;
extern double xMin;
extern double xMax;
extern double yMin;
extern double yMax; /* Bereich der Funktion */
extern double zMin;
extern double zMax;
extern vector FuncMid; /* Funktionsmitte als Vector in Funktionskoordinaten */
vector xBase,yBase,zBase; /* Basisvektoren der transformierten Funktion */
extern short xRes; /* Berechnungsschritte */
extern short yRes;
extern double yAngle; /* Kippwinkel der Funktion */
extern double zAngle;
extern double SizeFact; /* Vergrößerungsfaktor der Funktion */
extern double Diffuse_Rfx; /* Faktoren (0-2) für diffuse und */
extern double Direct_Rfx; /* direkte Lichtreflexion */
extern double PatternCol,PatternDeltaCol; /* Funktionsfarben */
extern double BodyCol;
/*************************************************************************/
/* Globale Daten ------------------------------------------------------- */
extern short mode; /* derz. Arbeitsmodus des Hauptprogramms */
extern short submode; /* Untermodus (interessant in Editmode */
/* und Drawmode) */
extern short ConsoleState;
extern short DrawMode; /* Zeichenmodus */
extern short Options; /* gewählte Optionen */
short COLm,COLcnt; /* min. Farbe und Farbzahl für die Funktion */
double COL_CC1,COL_CC2,COL_CC3; /* Farben für DrawCCross() (0-1) */
short ModeDisplay_x; /* x/y-Koordinaten der Modus-Anzeige */
short ModeDisplay_y;
vector LightVect[MAXLIGHTS] = /* Standard-Koordinaten der Lichtquellen */
{
2.0,-5.0,5.0,
0.0,0.0,10.0,
-2.0,5.0,-5.0,
0.0,0.0,-10.0
};
double LightIntens[MAXLIGHTS] = /* Standard-Intensitäten der Lichtquellen */
{ 1.0,0.6,1.0,0.6 };
short LightsOn=1; /* welche Lichtquellen sind an ? (1 Bit / Lichtqu.) */
#define TIMEEST_SECONDS 2 /* Anzahl der Sekunden, nach denen eine neue Zeit- */
/* schätzung für das Zeichnen gemacht wird */
struct DateStamp PicLastSave; /* Datum+Zeit der letzten Bildspeicherung */
LONG PicSecWorth=-1; /* Anzahl Sekunden, die das Bild "wert" ist. */
/* (wird erst bei Beendigung des Zeichenvor- */
/* gangs gesetzt */
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* Die von DrawFunction verwendete Datenstruktur DrawingInfo - - - - - - - - */
struct DrawingInfo DI;
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* Koordinatentransformation ----------------------------------------------- */
void ComputeBaseVects(void) // errechnet die FnctMid, xBase, yBase zBase
{ // Vektoren nach x/y/zDist, y/zAngle, SizeFact
static vector xa = { 1,0,0 }, ya = { 0,1,0 }, za = { 0,0,1 };
MakeBaseVect(&xBase,xa);
MakeBaseVect(&yBase,ya);
MakeBaseVect(&zBase,za);
}
void MakeBaseVect(vector *base, vector preset) // transformiert preset
{ // und legt ihn in base ab
double dist; /* Abstand des Punkt von der Drehachse */
double w;
if (dist=sqrt(preset.x*preset.x+preset.y*preset.y)) /* Drehung in xy-Ebene */
{
if (preset.x<0.0) w=pi-asin(preset.y/dist)+zAngle;
else w=asin(preset.y/dist)+zAngle;
preset.x=cos(w)*dist;
preset.y=sin(w)*dist;
} else preset.x=preset.y=0.0;
if (dist=sqrt(preset.x*preset.x+preset.z*preset.z)) /* Drehung in xz-Ebene */
{
if (preset.x<0.0) w=pi-asin(preset.z/dist)+yAngle;
else w=asin(preset.z/dist)+yAngle;
preset.x=cos(w)*dist;
preset.z=sin(w)*dist;
} else preset.x=preset.z=0.0;
base->x=preset.x*SizeFact; /* auf Bildschirmgröße bringen */
base->y=preset.y*SizeFact;
base->z=preset.z*SizeFact; /* -> Visualkoordinaten */
}
void PreTransform(v) /* transformiert den Vector (dreht ihn und rechnet */
vector *v; /* ihn in Bildschirmkoor. (ohne Fluchtpunktpers.) um) */
{
vector buf=*v;
VSub(&buf,&buf,&FuncMid); // Funktion mitten
v->x=buf.x*xBase.x+buf.y*yBase.x+buf.z*zBase.x; // transformieren
v->y=buf.x*xBase.y+buf.y*yBase.y+buf.z*zBase.y;
v->z=buf.x*xBase.z+buf.y*yBase.z+buf.z*zBase.z;
}
point Transform(v,EyeY) /* transformiert den Vector zu bx,by */
vector *v; /* bei bx=by=ILL Punkt nicht zu berechnen */
double EyeY; /* vom angeg. Augenpunkt aus */
{
point P;
if (activePrefs->EyeScreenDist-v->x<=0.0) P.bx=P.by=ILL;
else
{ /* und Fluchtpunktperspektive */
int valx,valy;
valx=Midx+activePrefs->XAspect*(EyeY+activePrefs->EyeScreenDist*(v->y-EyeY)/(activePrefs->EyeScreenDist-v->x));
valy=Midy-activePrefs->EyeScreenDist*v->z*activePrefs->YAspect/(activePrefs->EyeScreenDist-v->x);
if (abs(valx)>20000 || abs(valy)>20000) P.bx=P.by=ILL;
else
{
P.bx=valx;
P.by=valy;
}
}
return(P);
}
/* ----------------------------------------------------------------------- */
void RetraceVect(Vect) /* transformiert einen Vektor in Visualkoord. */
vector *Vect; /* zurück in Funktions-Koordinaten */
{
double w,dist;
VSDiv(Vect,SizeFact); /* auf Funkt.Koord. Größe bringen */
if (dist=sqrt(Vect->x*Vect->x+Vect->z*Vect->z)) /* Drehung in xz-Ebene */
{
if (Vect->x<0.0) w=pi-asin(Vect->z/dist)-yAngle;
else w=asin(Vect->z/dist)-yAngle;
Vect->x=cos(w)*dist;
Vect->z=sin(w)*dist;
} else Vect->x=Vect->z=0.0;
if (dist=sqrt(Vect->x*Vect->x+Vect->y*Vect->y)) /* Drehung in xy-Ebene */
{
if (Vect->x<0.0) w=pi-asin(Vect->y/dist)-zAngle;
else w=asin(Vect->y/dist)-zAngle;
Vect->x=cos(w)*dist;
Vect->y=sin(w)*dist;
} else Vect->x=Vect->y=0.0;
VAdd(Vect,Vect,&FuncMid); /* und aus der Mitte holen */
}
/* ----------------------------------------------------------------------- */
void CompuSizeFact(void) /* gleicht den Größenfaktor an die Range- */
{ /* definitionen an. */
double Diagonal; /* Länge der Diagonale des Koordinaten- */
/* Würfels */
Diagonal=sqrt((xMax-xMin)*(xMax-xMin)+
(yMax-yMin)*(yMax-yMin)+
(zMax-zMin)*(zMax-zMin));
if (Diagonal==0.0) { Error(l[82]); }
else
{
double maxxy; /* durchschnittliche Maximalausbreitung in bx/by */
maxxy=((double)(activePrefs->DrawAreaWidth)/activePrefs->XAspect+(double)(activePrefs->DrawAreaHeight)/activePrefs->YAspect)/2.0;
SizeFact=maxxy/Diagonal;
}
ComputeBaseVects();
}
/* ----------------------------------------------------------------------- */
void DisplayMode(void) /* druckt den Modus auf das Bild */
{
char *str;
if (ConsoleState==CS_PREFS) return;
switch(mode) /* Handlung entscheiden */
{
case MODE_START:
case MODE_ENDREQ:
case MODE_TEST:
return;
case MODE_CLEAR:
case MODE_WAIT:
case MODE_DISPL:
case MODE_STARTEDIT:
str=l[48];
break;
case MODE_DRAW:
str=l[49];
break;
case MODE_EDIT:
str=l[50];
break;
case MODE_LOAD:
str=l[51];
break;
case MODE_SAVE:
str=l[52];
break;
case MODE_HELP:
str=l[55];
break;
default:
str=" ??? ...";
}
SetDrMd(OurW->RPort,JAM2);
SetAPen(OurW->RPort,(mode==MODE_SAVE || mode==MODE_LOAD)?3:1);
SetBPen(OurW->RPort,0);
Move(OurW->RPort,ModeDisplay_x,ModeDisplay_y);
Text(OurW->RPort,str,11);
}
/* ----------------------------------------------------------------------- */
void PrintTime(Time) /* druckt die in Minuten(gebrochen) angegeben Zeit */
double Time; /* ins Modusdisplay */
{
static char Buf[20];
short Hs,Mins,Secs;
if (Time>=0.0)
{
Hs=(short)(Time/3600.0); Time-=(double)Hs*3600.0;
Mins=(short)(Time/60.0); Time-=(double)Mins*60.0;
Secs=(short)(Time);
if (Hs) sprintf(Buf," %02hdh %02hdm ",Hs,Mins);
else if (Mins) sprintf(Buf," %02hdm %02hds ",Mins,Secs);
else sprintf(Buf," %02hd secs ",Secs);
Buf[11]=0;
}
else strcpy(Buf,l[56]);
SetDrMd(OurW->RPort,JAM2);
SetAPen(OurW->RPort,1);
SetBPen(OurW->RPort,0);
Move(OurW->RPort,ModeDisplay_x,ModeDisplay_y);
Text(OurW->RPort,Buf,strlen(Buf));
}
/* ----------------------------------------------------------------------- */
char CCSource[20*3+1] = /* x/y/z - Koordinaten von 20 Punkten */
{
-1,-1,-1, -1,-1,0, -1,-1,1, -1,0,-1, -1,0,1, -1,1,-1, -1,1,0, -1,1,1,
0,-1,-1, 0,-1,1, 0,1,-1, 0,1,1,
1,-1,-1, 1,-1,0, 1,-1,1, 1,0,-1, 1,0,1, 1,1,-1, 1,1,0, 1,1,1,
-2
};
point CCPoints[20]; /* bx/by - Koordinaten von 20 Punkten */
point _CCPoints[20]; /* -"- für OPT_RG3d */
char CCLines[24*2+1] = /* 24 Linienverbindungen */
{
0,2, 3,4, 5,7, 8,9, 10,11, 12,14, 15,16, 17,19,
0,5, 1,6, 2,7, 8,10, 9,11, 12,17, 13,18, 14,19,
0,12, 1,13, 2,14, 3,15, 4,16, 5,17, 6,18, 7,19,
-1
};
void DrawCCross(int m) /* Koordinatenkreuz zeichnen */
{ /* bei m=0 normale Funktion */
point p1,p2; /* =1 Zeichnung nach editPrefs (Testbild) */
short a,b,dd;
static double oxMin,oyMin,ozMin,oxMax,oyMax,ozMax,oSizeFact,
oMidx,oMidy,oXAspect,oYAspect;
static short oDrawx,oDrawy,oDrawX,oDrawY;
static vector oFuncMid;
vector tv;
double eo;
struct PlotPrefs *oactivePrefs;
if (m==1)
{
if (!editPrefs) return;
oactivePrefs=activePrefs; activePrefs=editPrefs;
oXAspect=editPrefs->XAspect;
oYAspect=editPrefs->YAspect;
editPrefs->XAspect=oactivePrefs->DisplayWidth/editPrefs->ScreenXMeasure;
editPrefs->YAspect=oactivePrefs->DisplayHeight/editPrefs->ScreenYMeasure;
oxMin=xMin; xMin=-1.0;
oyMin=yMin; yMin=-1.0;
ozMin=zMin; zMin=-1.0;
oxMax=xMax; xMax=1.0;
oyMax=yMax; yMax=1.0;
ozMax=zMax; zMax=1.0;
oFuncMid=FuncMid; FuncMid.x=FuncMid.y=FuncMid.z=0.0;
oMidx=Midx; Midx=_Midx;
oMidy=Midy; Midy=_Midy;
oSizeFact=SizeFact;
CompuSizeFact();
oDrawx=Drawx; Drawx=BorderDrawx;
oDrawy=Drawy; Drawy=BorderDrawy;
oDrawX=DrawX; DrawX=BorderDrawX;
oDrawY=DrawY; DrawY=BorderDrawY;
}
else if (Status&ST_RANGE) { Error(l[62]); return; } /* bei fehlerhafter Range -> */
for (a=b=0;CCSource[a]!=-2;b++)
{
switch (CCSource[a++])
{ case -1: tv.x=xMin; break; case 0: tv.x=0.0; break; case 1: tv.x=xMax; break; }
switch (CCSource[a++])
{ case -1: tv.y=yMin; break; case 0: tv.y=0.0; break; case 1: tv.y=yMax; break; }
switch (CCSource[a++])
{ case -1: tv.z=zMin; break; case 0: tv.z=0.0; break; case 1: tv.z=zMax; break; }
PreTransform(&tv);
CCPoints[b]=Transform(&tv,(Options&OPT_RG3d)?-(activePrefs->EyeEyeDist/2.0):0.0);
if (Options&OPT_RG3d) _CCPoints[b]=Transform(&tv,activePrefs->EyeEyeDist/2.0);
}
if (mode!=MODE_CLEAR && m==0) { short old; old=mode; Mode(MODE_DOCLEAR); mode=old; }
SetColor(COL_CC1,(Options&OPT_RG3d)?1:0);
for (a=0;CCLines[a]!=-1;)
{
DrawRawLine(CCPoints[CCLines[a++]],CCPoints[CCLines[a++]]);
}
if (Options&OPT_RG3d)
{
SetColor(COL_CC1,2);
for (a=0;CCLines[a]!=-1;)
{
DrawRawLine(_CCPoints[CCLines[a++]],_CCPoints[CCLines[a++]]);
}
}
for (dd=(Options&OPT_RG3d)?1:0;(Options&OPT_RG3d)?(dd<3):(dd<1);dd++)
{
switch (dd)
{
case 0: eo=0.0; break;
case 1: eo=activePrefs->EyeEyeDist/-2.0; break;
case 2: eo=activePrefs->EyeEyeDist/2.0; break;
}
SetColor(COL_CC2,dd);
tv.x=xMin; tv.y=0.0; tv.z=0.0; PreTransform(&tv);
p1=Transform(&tv,eo);
tv.x=xMax; tv.y=0.0; tv.z=0.0; PreTransform(&tv);
p2=Transform(&tv,eo);
if (m==0 && p2.bx>Drawx && p2.bx<DrawX-textfont->tf_XSize && p2.by>Drawy+textfont->tf_Baseline && p2.by<DrawY-textfont->tf_YSize+textfont->tf_Baseline)
{
Move(OurW->RPort,p2.bx,p2.by);
SetDrMd(OurW->RPort,JAM1);
Text(OurW->RPort,"x",1);
}
SetColor(COL_CC3,dd);
DrawRawLine(p1,p2); /* x-Achse */
SetColor(COL_CC2,dd);
tv.x=0.0; tv.y=yMin; tv.z=0.0; PreTransform(&tv);
p1=Transform(&tv,eo);
tv.x=0.0; tv.y=yMax; tv.z=0.0; PreTransform(&tv);
p2=Transform(&tv,eo);
if (m==0 && p2.bx>Drawx && p2.bx<DrawX-textfont->tf_XSize && p2.by>Drawy+textfont->tf_Baseline && p2.by<DrawY-textfont->tf_YSize+textfont->tf_Baseline)
{
Move(OurW->RPort,p2.bx,p2.by);
SetDrMd(OurW->RPort,JAM1);
Text(OurW->RPort,"y",1);
}
SetColor(COL_CC3,dd);
DrawRawLine(p1,p2); /* y-Achse */
SetColor(COL_CC2,dd);
tv.x=0.0; tv.y=0.0; tv.z=zMin; PreTransform(&tv);
p1=Transform(&tv,eo);
tv.x=0.0; tv.y=0.0; tv.z=zMax; PreTransform(&tv);
p2=Transform(&tv,eo);
if (m==0 && p2.bx>Drawx && p2.bx<DrawX-textfont->tf_XSize && p2.by>Drawy+textfont->tf_Baseline && p2.by<DrawY-textfont->tf_YSize+textfont->tf_Baseline)
{
Move(OurW->RPort,p2.bx,p2.by);
SetDrMd(OurW->RPort,JAM1);
Text(OurW->RPort,"z",1);
}
SetColor(COL_CC3,dd);
DrawRawLine(p1,p2); /* z-Achse */
/* Lichtquellen */
if (m==0 && (DrawMode&(DMF_COL|DMF_LCOL)))
{
point lp;
short a;
for (a=0;a<MAXLIGHTS;a++)
{
if (LightsOn&(1<<a))
{
memcpy(&tv,&LightVect[a],sizeof(vector));
PreTransform(&tv);
lp=Transform(&tv,eo);
if (lp.bx!=ILL || lp.by!=ILL)
{
p1.bx=lp.bx-(short)(activePrefs->ScreenXMeasure/100.0*activePrefs->XAspect);
p2.bx=lp.bx+(short)(activePrefs->ScreenXMeasure/100.0*activePrefs->XAspect);
p1.by=p2.by=lp.by;
SetColor(COL_CC3,dd); DrawRawLine(p1,p2);
p1.by=lp.by-(short)(activePrefs->ScreenXMeasure/100.0*activePrefs->YAspect);
p2.by=lp.by+(short)(activePrefs->ScreenXMeasure/100.0*activePrefs->YAspect);
p1.bx=p2.bx=lp.bx;
SetColor(COL_CC3,dd); DrawRawLine(p1,p2);
lp.bx+=4;
lp.by-=2;
if (lp.bx>Drawx && lp.bx<DrawX-textfont->tf_XSize && lp.by>Drawy+textfont->tf_Baseline && lp.by<DrawY-textfont->tf_YSize+textfont->tf_Baseline)
{
static char Buf[2]=" ";
SetColor(COL_CC2,dd);
Move(OurW->RPort,lp.bx,lp.by);
Buf[0]=a+'1';
SetDrMd(OurW->RPort,JAM1);
Text(OurW->RPort,Buf,1);
}
}
}
}
}
}
NormalColor();
/* Winkel aufs Bild drucken */
if (m==0 && DrawX-Drawx>=W(20*8) && DrawY-Drawy>=H(5*8))
{
static char yAngBuf[10], zAngBuf[10];
sprintf(yAngBuf,"y %#5.1f°",360.0-(yAngle?yAngle:2.0*pi)*(180.0/pi));
sprintf(zAngBuf,"z %#5.1f°",zAngle*(180.0/pi));
if (Options&OPT_RG3d) SetColor((double)RGColSupp->Colors[RGColSupp->ColNum/2],0);
else SetAPen(OurW->RPort,1);
SetBPen(OurW->RPort,(Options&OPT_RG3d)?RGColSupp->BGCol:3);
SetDrMd(OurW->RPort,JAM2);
Move(OurW->RPort,DrawX-(W(10*8)),DrawY-(H(2*8))); Text(OurW->RPort,yAngBuf,8);
Move(OurW->RPort,DrawX-(W(10*8)),DrawY-(H(1*8))); Text(OurW->RPort,zAngBuf,8);
}
if (m==1)
{
activePrefs=oactivePrefs;
xMin=oxMin;
yMin=oyMin;
zMin=ozMin;
xMax=oxMax;
yMax=oyMax;
zMax=ozMax;
FuncMid=oFuncMid;
Midx=oMidx;
Midy=oMidy;
Drawx=oDrawx;
Drawy=oDrawy;
DrawX=oDrawX;
DrawY=oDrawY;
editPrefs->XAspect=oXAspect;
editPrefs->YAspect=oYAspect;
SizeFact=oSizeFact;
ComputeBaseVects();
}
NormalColor();
}
/* --------------------------------------------------------------------- */
int CorrectLine(Line) /* korrigiert die Linie so, daß sie auf */
line *Line; /* dem Bildschirm liegt */
{ /* RETURN: 0 - ok / 1 - Linie nur teilw. auf */
/* dem Schrim / -1 - Linie nicht auf dem Schirm */
int state=0;
if (!Line) return(-1);
if (Line->p1.bx==ILL && Line->p1.by==ILL || Line->p2.bx==ILL && Line->p2.by==ILL) goto __NotToDraw;
if (Line->p1.bx<Drawx)
{
if (Line->p2.bx<Drawx) goto __NotToDraw;
Line->p1.by=Line->p1.by+(Drawx-Line->p1.bx)*(Line->p2.by-Line->p1.by)/(Line->p2.bx-Line->p1.bx);
Line->p1.bx=Drawx;
state=1;
}
if (Line->p1.by<Drawy)
{
if (Line->p2.by<Drawy) goto __NotToDraw;
Line->p1.bx=Line->p1.bx+(Drawy-Line->p1.by)*(Line->p2.bx-Line->p1.bx)/(Line->p2.by-Line->p1.by);
Line->p1.by=Drawy;
state=1;
}
if (Line->p1.bx>DrawX)
{
if (Line->p2.bx>DrawX) goto __NotToDraw;
Line->p1.by=Line->p1.by+(DrawX-Line->p1.bx)*(Line->p2.by-Line->p1.by)/(Line->p2.bx-Line->p1.bx);
Line->p1.bx=DrawX;
state=1;
}
if (Line->p1.by>DrawY)
{
if (Line->p2.by>DrawY) goto __NotToDraw;
Line->p1.bx=Line->p1.bx+(DrawY-Line->p1.by)*(Line->p2.bx-Line->p1.bx)/(Line->p2.by-Line->p1.by);
Line->p1.by=DrawY;
state=1;
}
if (Line->p2.bx<Drawx)
{
if (Line->p1.bx<Drawx) goto __NotToDraw;
Line->p2.by=Line->p2.by+(Drawx-Line->p2.bx)*(Line->p1.by-Line->p2.by)/(Line->p1.bx-Line->p2.bx);
Line->p2.bx=Drawx;
state=1;
}
if (Line->p2.by<Drawy)
{
if (Line->p1.by<Drawy) goto __NotToDraw;
Line->p2.bx=Line->p2.bx+(Drawy-Line->p2.by)*(Line->p1.bx-Line->p2.bx)/(Line->p1.by-Line->p2.by);
Line->p2.by=Drawy;
state=1;
}
if (Line->p2.bx>DrawX)
{
if (Line->p1.bx>DrawX) goto __NotToDraw;
Line->p2.by=Line->p2.by+(DrawX-Line->p2.bx)*(Line->p1.by-Line->p2.by)/(Line->p1.bx-Line->p2.bx);
Line->p2.bx=DrawX;
state=1;
}
if (Line->p2.by>DrawY)
{
if (Line->p1.by>DrawY) goto __NotToDraw;
Line->p2.bx=Line->p2.bx+(DrawY-Line->p2.by)*(Line->p1.bx-Line->p2.bx)/(Line->p1.by-Line->p2.by);
Line->p2.by=DrawY;
state=1;
}
return(state);
__NotToDraw:
Line->p1.bx=Line->p1.by=Line->p2.bx=Line->p2.by=ILL;
return(-1);
}
/* ----------------------------------------------------------------------- */
int DrawLine(p1,p2,c) /* Linie in Farbe c zeichnen (mit Grenztest) */
point p1,p2; /* RETURN: 0 - ok / 1 - Linie nur teilw. auf */
short c; /* dem Schrim / -1 - Linie nicht auf dem Schirm */
{
int state;
line Line;
Line.p1=p1;
Line.p2=p2;
state=CorrectLine(&Line);
if (state>=0) FastDrawLine(&Line,c);
return(state);
}
int DrawRawLine(p1,p2) /* Linie zeichnen (mit Grenztest) */
point p1,p2; /* RETURN: 0 - ok / 1 - Linie nur teilw. auf */
/* dem Schrim / -1 - Linie nicht auf dem Schirm */
{ /* es werden die akt. eingestellten Zeichen- */
int state; /* parameter verwender (APEN/BPEN/PATTERN) */
line Line;
Line.p1=p1;
Line.p2=p2;
state=CorrectLine(&Line);
if (state>=0)
{
Move(OurW->RPort,Line.p1.bx,Line.p1.by);
Draw(OurW->RPort,Line.p2.bx,Line.p2.by);
}
return(state);
}
void FastDrawLine(Line,c) /* Linie in Farbe c zeichnen (ohne Grenztest) */
line *Line;
short c;
{
SetAPen(OurW->RPort,c);
Move(OurW->RPort,Line->p1.bx,Line->p1.by);
Draw(OurW->RPort,Line->p2.bx,Line->p2.by);
}
/* --------------------------------------------------------------------- */
void DrawTriangle(p1,p2,p3) /* zeichnet ein Dreieck */
point p1,p2,p3; /* mit der derz. Farbe und Muster */
{
short lawbreak=0;
point zp; /* Punkt-Zwischenspeicher */
short a,count;
line l[3];
point p[3]; /* Punkte des Dreiecks */
short EdgesInTri=0;/* Eckpunkte, die im Viereck liegen */
/* Eckp. von l.o. gegen den Uhrzs. 0-2 nummeriert */
l[2].p2=l[0].p1=p[0]=p1; /* Linien übertragen */
l[0].p2=l[1].p1=p[1]=p2;
l[1].p2=l[2].p1=p[2]=p3;
if (CorrectLine(&l[0])) lawbreak++;
if (CorrectLine(&l[1])) lawbreak++;
if (CorrectLine(&l[2])) lawbreak++;
if (lawbreak) /* festst., welche Bildschirmeckp. im Dreieck liegen */
{
zp.bx=Drawx;
zp.by=Drawy;
if (IsPointInTri(zp,p)) EdgesInTri|=0x1;
zp.by=DrawY;
if (IsPointInTri(zp,p)) EdgesInTri|=0x2;
zp.bx=DrawX;
if (IsPointInTri(zp,p)) EdgesInTri|=0x4;
zp.by=Drawy;
if (IsPointInTri(zp,p)) EdgesInTri|=0x8;
}
if (EdgesInTri==0xf) RectFill(OurW->RPort,Drawx,Drawy,DrawX,DrawY);
else
{
zp.bx=zp.by=ILL;
for(a=0,count=0;a<3;a++) /* Punkte an Graphics übergeben */
{
if ((l[a].p1.bx!=ILL || l[a].p1.by!=ILL) && l[a].p1!=zp)
{
zp=l[a].p1;
if (count++) AreaDraw(OurW->RPort,zp.bx,zp.by);
else AreaMove(OurW->RPort,zp.bx,zp.by);
}
if ((l[a].p2.bx!=ILL || l[a].p2.by!=ILL) && l[a].p2!=zp)
{
zp=l[a].p2;
if (count++) AreaDraw(OurW->RPort,zp.bx,zp.by);
else AreaMove(OurW->RPort,zp.bx,zp.by);
}
if (EdgesInTri) /* gegf. Bilschirmecke in Zeichnung */
{ /* einfügen */
for (;;)
{
short is_to_draw;
is_to_draw=0;
if (zp.bx==Drawx)
{
if (!is_to_draw && EdgesInTri&0x1) { zp.by=Drawy; is_to_draw=1; EdgesInTri&=~0x1; }
if (!is_to_draw && EdgesInTri&0x2) { zp.by=DrawY; is_to_draw=1; EdgesInTri&=~0x2; }
}
if (zp.bx==DrawX)
{
if (!is_to_draw && EdgesInTri&0x4) { zp.by=DrawY; is_to_draw=1; EdgesInTri&=~0x4; }
if (!is_to_draw && EdgesInTri&0x8) { zp.by=Drawy; is_to_draw=1; EdgesInTri&=~0x8; }
}
if (zp.by==Drawy)
{
if (!is_to_draw && EdgesInTri&0x1) { zp.bx=Drawx; is_to_draw=1; EdgesInTri&=~0x1; }
if (!is_to_draw && EdgesInTri&0x8) { zp.bx=DrawX; is_to_draw=1; EdgesInTri&=~0x8; }
}
if (zp.by==DrawY)
{
if (!is_to_draw && EdgesInTri&0x2) { zp.bx=Drawx; is_to_draw=1; EdgesInTri&=~0x2; }
if (!is_to_draw && EdgesInTri&0x4) { zp.bx=DrawX; is_to_draw=1; EdgesInTri&=~0x4; }
}
if (is_to_draw)
{
if (count++) AreaDraw(OurW->RPort,zp.bx,zp.by);
else AreaMove(OurW->RPort,zp.bx,zp.by);
}
else break;
}
}
}
AreaEnd(OurW->RPort); /* und zeichnen */
}
}
/* --------------------------------------------------------------------- */
void SetColor(double col,short RG) /* setzt Farbe und Muster nach geg. Farbwert(0-1) */
{ /* oder nach direkter Farbnummer (Farbwert>1) */
/* legt fest, ob normal (RG=0), rot (RG=1) oder grün (RG=2) gez. */
/* wird */
static USHORT __chip ditherdata[4][2] = { 0x0000, 0x0000,
0x2222, 0x8888,
0x5555, 0xaaaa,
0x7777, 0xdddd };
UWORD colornum;
UWORD maxcol;
if (!RGColSupp) RG=0;
if (RG)
{
SetWrMsk(OurW->RPort,(RG==1)?(RGColSupp->RedMask):(RGColSupp->GreenMask));
}
else SetWrMsk(OurW->RPort,0xff);
if (col<=1.0)
{
maxcol=RG?RGColSupp->ColNum:COLcnt;
/* Zwischenfarben erlaubt ? */
if ((Options&OPT_DitherCol) && (!RG || RGColSupp->ColNum>1))
{
maxcol=maxcol*4-3;
colornum=(UWORD)(col*(double)maxcol);
if (colornum>=maxcol) colornum=maxcol-1;
SetDrMd(OurW->RPort,JAM2);
SetAfPt(OurW->RPort,ditherdata[colornum&3],1);
SetDrPt(OurW->RPort,ditherdata[colornum&3][0]);
colornum/=4;
maxcol/=4;
if (RG) /* Rot-Grün-Modus ? */
{
SetBPen(OurW->RPort,RGColSupp->Colors[colornum++]);
SetAPen(OurW->RPort,RGColSupp->Colors[min(maxcol,colornum)]);
}
else
{
colornum+=COLm;
maxcol+=COLm;
SetBPen(OurW->RPort,colornum++);
SetAPen(OurW->RPort,min(maxcol,colornum));
}
}
else /* keine Zwischenfarben erlaubt */
{
colornum=(UWORD)(col*(double)maxcol);
if (colornum>=maxcol) colornum=maxcol-1;
SetAfPt(OurW->RPort,0,0);
SetDrPt(OurW->RPort,0xffff);
SetDrMd(OurW->RPort,JAM1);
if (RG) SetAPen(OurW->RPort,RGColSupp->Colors[colornum]);
else SetAPen(OurW->RPort,colornum+COLm);
}
}
else /* col Wert >1.0 */
{
if (RG && col==3.0) /* RG Hintergrund */
{
SetAfPt(OurW->RPort,0,0);
SetDrPt(OurW->RPort,0xffff);
SetAPen(OurW->RPort,RGColSupp->BGCol);
SetDrMd(OurW->RPort,JAM1);
}
else
{
NormalColor();
SetAPen(OurW->RPort,(UWORD)col);
}
}
}
void NormalColor(void) /* setzt Farb u. Zeichenregister (Muster) zurück */
{
SetAfPt(OurW->RPort,0,0);
SetDrPt(OurW->RPort,0xffff);
SetBPen(OurW->RPort,3);
SetDrMd(OurW->RPort,JAM1);
SetWrMsk(OurW->RPort,0xff);
}
/****************************************************************************/
double _stdcol; /* Standardfarbe für DMF_FL ... */
void DrawFunction(void) /* Zeichnet die Funktion */
{ /* bei submode=0 wird alles zuert initiali- */
/* siert, dann wird bei jedem weiteren Aufruf */
/* gezeichnet, bis DrawFunction() dann */
/* mode=MODE_WAIT setzt, */
/* submode wird autom. -1 -> Zws. freigeben */
/* Datenstrukt DI unter starker Verwendung */
complex _Z; /* errechneter Z-Wert */
double Z; /* zu benutzender Z-Wert */
point p1,_p1; /* Punkt-Zws. */
vector v1; /* xyz-Zws. */
vector tv; /* Transform-Vector (für Zwischenergebnisse) */
point *pp1,*pp2; /* ^p1/p2 */ /* für OPT_RG3d */
point *pP; /* ^P[] */
vector *eye;
short dd;
double c1,c2; /* Farben für DMF_COL */
double lc1,lc2; /* Farben für DMF_LCOL */
if (submode>=0 && (Status || !(DrawMode&(DMF_FL|DMF_PAT)))) /* Etwas nicht ok. ? */
{
Error(l[83]);
Mode(MODE_WAIT);
return;
}
if (!submode) /* bei erstem Aufruf, testen, ob zeichenbar */
{
if (DrawMode&(DMF_LCOL|DMF_COL))
{
short light=0;
short a;
for (a=0;a<MAXLIGHTS;a++)
{
if (LightsOn&(1<<a)) if (LightIntens[a]) light++;
}
if (!(Diffuse_Rfx+Direct_Rfx)) light=0;
if (!light)
{
Error(l[83]);
Mode(MODE_WAIT);
return;
}
}
}
if (submode<=0) /* 1. Aufruf von DrawFunction() ? */
{
if (DI.P) /* gegf. P-Zws. freigeben */
{
FreeMem(DI.P,DI.PSize*sizeof(point));
DI.P=0;
}
if (DI._P) /* gegf. P-Zws. freigeben */
{
FreeMem(DI._P,DI.PSize*sizeof(point));
DI._P=0;
}
if (DI.V) /* gegf. V-Zws. freigeben */
{
FreeMem(DI.V,DI.PSize*sizeof(vector));
DI.V=0;
}
if (submode==-1) /* bei Ende Zeichenzeit errechnen */
{
struct DateStamp Date;
if (PicSecWorth>0)
{
DateStamp(&Date);
PicSecWorth=(Date.ds_Days-PicLastSave.ds_Days)*(24*60*60);
PicSecWorth+=(Date.ds_Minute-PicLastSave.ds_Minute)*60;
PicSecWorth+=(Date.ds_Tick-PicLastSave.ds_Tick)/50;
if (!PicSecWorth) PicSecWorth=1;
}
/* und APS schließen */
WindowToBack(ApsW);
return;
}
submode=1;
MakeDrawingInfo(); /* DI-Struktur initialisieren */
DateStamp(&PicLastSave); /* letzte Bildspeicherung festlegen */
PicSecWorth=1;
GetAPSFilename(); /* APS ggf. einblenden */
StartTime(APS_TH,APS_MinIntervall*60);
}
/* - - - - Schleifensteuerung 1 - - - - */
if (++DI.PatX2Cnt>DI.SpacingX2) DI.PatX2Cnt=0;
if (DI.SX2==DI.EndX2)
{
DI.P[DI.SX2+1]=DI.p2;
if (DI._P) DI._P[DI.SX2+1]=DI._p2;
if (DI.V) DI.V[DI.SX2+1]=DI.v2;
if (DI.SX1==DI.EndX1) { submode=-1; Mode(MODE_WAIT); return; }
DI.SX2=DI.BeginX2;
DI.SX1+=DI.DirX1;
DI.p2.bx=DI.p2.by=ILL;
DI._p2.bx=DI._p2.by=ILL;
if (++DI.PatX1Cnt>DI.SpacingX1) DI.PatX1Cnt=0;
DI.PatX2Cnt=-1;
}
DI.SX2+=DI.DirX2;
if (Options&OPT_Time)
{
if (DI.LastSec || DI.LastMic)
{
if (CheckTime(TimeEstTH)) /* Zeit ist jetzt zu schätzen*/
{
ULONG NewSec,NewMic;
double TimeNeeded;
DI.PointsToDo-=DI.PointCnt;
DI.PointsMeasured+=DI.PointCnt;