-
Notifications
You must be signed in to change notification settings - Fork 0
/
uchart.pas
executable file
·3049 lines (2292 loc) · 80.8 KB
/
uchart.pas
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
{-----------------------------------------------------------------------------
Author: Alexander Roth
Date: 04-Nov-2006
Dieses Programm ist freie Software. Sie können es unter den Bedingungen
der GNU General Public License, wie von der Free Software Foundation
veröffentlicht, weitergeben und/oder modifizieren, gemäß Version 2 der Lizenz.
Description:
-----------------------------------------------------------------------------}
unit UChart;
{$mode objfpc}{$H+}
interface
{
Die Achsen sind auf z= 0
Die folgenden Charts sind auf z= nChart
zz
}
uses
Classes, SysUtils,uanderes,lcltype, graphics, math, Messages,
LResources, Forms, Controls, Dialogs, Interfaces,
StdCtrls, ExtCtrls, gl,glu, nxGL, nxTypes, utxt,UVector;
type
TAxisKind=(YAxisKind,XAxisKind);
TAxisPosition = (apMin, apMax, ap0);
TTickPosition = (tpMin, tpMax, tpCenter);
TLabelPosition = (lpMin,lpMax,lp0,lpCenter);
TTitlePosition=record
MainPosition,
SidePosition:TLabelPosition;
AutoSidePosition:boolean;
end;
{ TOGLRect }
TOGLRect=class
private
public
r:TR2RectSimple;
Visible:boolean;
Filled:boolean;
BrushColor:Tcolor;
BrushAlpha:real;
Pen:TPen;
PenAlpha:real;
procedure Draw(Depth:TKoor1); overload;
procedure Draw(Position:TR2RectSimple; Depth:TKoor1); overload;
constructor Create;
destructor Destroy; override;
end;
{ TOGL3DNSlit }
TOGL3DNSlit=class
public
Pos, SpaceToBorder, Sizes:TKoor3; // in oglreality
beta, theta:real;
ColorGrid, Colorbeta, Colortheta:TColor;
AutoVisible,
Visible:boolean;
procedure DrawOGL;
constructor Create(aPos, aSpaceToBorder, aSizes:TKoor3);
end;
{ TOGlLabel }
TOGlLabel = class
private
DividedStrings:TStringList;
FText: string;
procedure setFText(const AValue: string);
function TextLenght:real;
function TextHeight:real;
public
pos:TKoor3;
Enabled:boolean;
Color:TColor;
PosXIs,
PosYIs:TAnchorKind;
procedure Draw; virtual;
constructor Create; virtual;
destructor Destroy; override;
property Text:string read FText write setFText;
end;
{ TOGlLabelBackground }
TOGlLabelBackground = class(TOGlLabel)
private
public
BackgroundColor:TColor;
BackgroundAlpha:real;
procedure Draw; override;
constructor Create; override;
destructor Destroy; override;
end;
{ TAxis }
TAxis = class
private
Depth:TKoor1;
FAxisPosition:TAxisPosition;
function ReadVisibleRect:TKoor1Range;
procedure writeAxisPosition(value:TAxisPosition);
procedure WriteVisibleRect(Value:TKoor1Range);
function PrettyIncrement(aMinValue, aMaxValue: real; aCountTicks:integer): real;
procedure DrawArrows(Pos1,Pos2:TKoor3; bold:real=1; ArrowSize:real=0.05; BeginningPeak:boolean=false; EndingPeak:boolean=true);
procedure DrawTicksBasic(Pos1, Pos2: TKoor3; aPos1Value, aPos2Value, aLengthTick:real; acolor:Tcolor; ShowFirstValue:boolean; PrettyIncre:real; DeepRecursion:integer=1);
procedure DrawTicks(Pos1, Pos2: TKoor3; aPos1Value, aPos2Value, aLengthTick:real; aCountTicks:integer; acolor:Tcolor; CenterTicks:boolean=true);
procedure DrawTitle(Pos1,Pos2:TKoor3);
public
CountBigTicks:integer;
CountTicks:integer;// between bigticks
Koor,
VisibleKoor,
DefaultKoor:TRealRange;
LengthAxis,
LengthBigTick, // in %
LengthTick:real; // in %
AxisKind:TAxisKind;
KoorKind:TKoorKind;
Visible:boolean;
Title:TOGlLabelBackground;
MainDescription,
DimensionDescription,
Dimension:string;
TickPosition:TTickPosition;
LabelPosition:TLabelPosition;
TitlePosition:TTitlePosition;
TempAxisPosition:TAxisPosition;
AxisAlwaysVisible:boolean;
LabelSpace:TKoor1; // in koor
BigTickPositions:TRealArray;
ColorAxis,
ColorBigTicks,
ColorTicks,
ColorMainGrid:TColor;
ShowMainGrid:boolean;
function KoorSize:real;
property AxisPosition:TAxisPosition read FAxisPosition write writeAxisPosition;
property VisibleRect:TKoor1Range read ReadVisibleRect write WriteVisibleRect; //in koor
procedure ResetKoor;
procedure Draw(Pos1,Pos2:TKoor3; bold:real=1; ArrowSize:real=0.02); // Pos ist immer auf der virtuellen Koor Koordinaten
procedure DrawMainGrid(Pos1,Pos2:TKoor3; OtherAxis:TAxis; bold:real=1);
constructor Create(aAxisKind:TAxisKind);
destructor Destroy; override;
end;
TTransChartFunc = function(akoor:TKoor1):TKoor1 of object;
TTransChartExtendedFunc = function(akoor:TKoor1; ReturnKoorKind:TKoorKind):TKoor1 of object;
TZoomRectEvent = Procedure(Sender: TObject; Shift: TShiftState; rect:TRect) of object;
TZoomEvent = Procedure(Sender: TObject; Shift: TShiftState; MousePos: TPoint; Factor:real; Axis:TKoorSet) of object;
{ TOGlBox }
TOGlBox = class(TPanel)
private
FQuotientLS2Image: real;
//gContextID: tsContextID;
OGLRectZoom:TOGLRect;
DepthOverlay:TKoor1;
StoredIdleDraw:boolean;
FShowCross:boolean;
OGLReality:TR2Rect;
FIsPaning,
FIsZoomingRect:boolean;
FZoomFactor:real; // in facator
FOnBeginPan:TMouseEvent;
FOnEndPan:TMouseEvent;
FOnPan:TMouseMoveEvent;
FOnZoom:TZoomEvent;
FOnUnZoom:TZoomEvent;
FOnZoomRect:TZoomRectEvent;
FOnBeginZoomRect:TZoomRectEvent;
FOnEndZoomRect:TZoomRectEvent;
FOnResetZoom:TZoomEvent;
FOnKoorChange:TNotifyEvent;
FOnXAxisPosChange:TNotifyEvent;
FOnImageAxisPosChange:TNotifyEvent;
FOnLSAxisPosChange:TNotifyEvent;
FKeyPan:TShiftState;
FKeyZoomUnZoomXAxis:TShiftState;
FKeyZoomUnZoomLSAxis:TShiftState;
FKeyResetZoom:TShiftState;
FKeyZoomRect:TShiftState;
FKeyChartInfo:TShiftState;
FWriteQuotientLS2Image: real;
function readXAxisPosition:TAxisPosition;
function readImageAxisPosition:TAxisPosition;
function readLSAxisPosition:TAxisPosition;
function readXAxisAlwaysVisible:boolean;
function readImageAxisAlwaysVisible:boolean;
function readLSAxisAlwaysVisible:boolean;
procedure writeXAxisPosition(value:TAxisPosition);
procedure writeImageAxisPosition(value:TAxisPosition);
procedure writeLSAxisPosition(value:TAxisPosition);
procedure writeXAxisAlwaysVisible(value:boolean);
procedure writeImageAxisAlwaysVisible(value:boolean);
procedure writeLSAxisAlwaysVisible(value:boolean);
procedure WriteQuotientLS2Image(value:real);
Procedure Paint; override;
procedure DoEnter; override;
procedure DoExit; override;
procedure DoBeginPan(Button: TMouseButton; Shift:TShiftState; X,Y:Integer);
procedure DoEndPan(Button: TMouseButton; Shift:TShiftState; X,Y:Integer);
procedure DoPan(Shift: TShiftState; X,Y: Integer);
procedure DoZoom(Sender: TObject; Shift: TShiftState; MousePos: TPoint; Factor:real; Axis:TKoorSet);
procedure DoUnZoom(Sender: TObject; Shift: TShiftState; MousePos: TPoint; Factor:real; Axis:TKoorSet);
procedure DoResetZoom(Sender: TObject; Shift: TShiftState; MousePos: TPoint; Factor:real; Axis:TKoorSet);
procedure DoZoomRect(Sender: TObject; Shift: TShiftState; rect:TRect);
procedure DoBeginZoomRect(Sender: TObject; Shift: TShiftState; rect:TRect);
procedure DoEndZoomRect(Sender: TObject; Shift: TShiftState; rect:TRect);
procedure MouseDown(Sender: TObject; Button: TMouseButton; Shift:TShiftState; X,Y:Integer);
procedure MouseMove(Sender: TObject; Shift: TShiftState; X,Y: Integer);
procedure MouseUp(Sender: TObject; Button: TMouseButton; Shift:TShiftState; X,Y:Integer);
procedure MouseWheel(Sender: TObject; Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint; var result:Boolean);
procedure MouseEnter(Sender: TObject);
procedure DrawAxis;
procedure DrawAllCharts;
procedure DrawRect;
function MouseButtonOnly(Shift: TShiftState):TMouseButton;
function MouseButtonDelete(Shift: TShiftState):TShiftState;
//muss nicht öffentlich sein, da es ja nur die speziellen Funktionen sind
function TransOGL2OGLReality(akoor:TKoor1):TKoor1;
function TransOGLReality2OGL(akoor:TKoor1):TKoor1;
function TransDeltaOGL2OGLReality(akoor:TKoor1):TKoor1;
function TransDeltaOGLReality2OGL(akoor:TKoor1):TKoor1;
function TransKoor2OGL(akoor:TKoor1):TKoor1;
function TransKoor2OGLReality(akoor:TKoor1):TKoor1;
function TransPixel2OGLReality(akoor:TKoor1):TKoor1;
function TransOGLReality2Pixel(akoor:TKoor1):TKoor1;
function TransDeltaKoor2OGLReality(akoor:TKoor1):TKoor1;
function TransDeltaKoor2Pixel(akoor:TKoor1):TKoor1;
function TransDeltaOGLReality2Pixel(akoor:TKoor1):TKoor1;
function TransDeltaPixel2OGLReality(akoor:TKoor1):TKoor1;
function TransOGL2Koor(akoor:TKoor1; ReturnKoorKind:TKoorKind):TKoor1;
function TransOGLReality2Koor(akoor:TKoor1; ReturnKoorKind:TKoorKind):TKoor1;
function TransDeltaOGLReality2Koor(akoor:TKoor1; ReturnKoorKind:TKoorKind):TKoor1;
function TransPixel2Koor(akoor:TKoor1; ReturnKoorKind:TKoorKind):TKoor1;
function TransDeltaPixel2Koor(akoor:TKoor1; ReturnKoorKind:TKoorKind):TKoor1;
public
RectPen:TPen;
RectStart,
LastMouseMovePos:TPoint;
xAxis,
ImageAxis,
LSAxis:TAxis;
Header:TOGlLabelBackground;
MiniSlit:TOGL3DNSlit;
HelpBoxZoom:TOGlLabelBackground;
property QuotientLS2Image:real read FQuotientLS2Image write WriteQuotientLS2Image;
property IsPaning:boolean read FIsPaning;
property IsZoomingRect:boolean read FIsZoomingRect;
function KoorIsVisible(akoor:TKoor3; tolerance:real=0.02):boolean;
function KoorIsVisible(x,y,z:real; tolerance:real=0.02):boolean;
procedure glWrite(textstr: String; Font_index:integer=0; Centering:boolean=False);
procedure Resize; override;
procedure WriteFShowCross(ShowCross:boolean);
function ratio:real; //width/height
procedure ResetView;
function TransAll(akoor:TKoor3; func:TTransChartFunc):TKoor3; overload;
function TransAll(akoor:TKoor3; ReturnAxisX, ReturnAxisY, ReturnAxisZ:TKoorKind; func:TTransChartExtendedFunc):TKoor3; overload;
function Trans2Koor(akoor:TKoor1; ReturnKoorKind:TKoorKind):TKoor1;
function Trans2OGL(akoor:TKoor1):TKoor1;
function Trans2OGLReality(akoor:TKoor1):TKoor1;
function Trans2Pixel(akoor:TKoor1):TKoor1;
function TransDelta2Koor(akoor:TKoor1; ReturnKoorKind:TKoorKind):TKoor1;
function TransDelta2OGL(akoor:TKoor1):TKoor1;
function TransDelta2OGLReality(akoor:TKoor1):TKoor1;
function TransDelta2Pixel(akoor:TKoor1):TKoor1;
procedure OGLVertex3f2OGL(akoor:TKoor3);overload; // NOT OGLReality
procedure OGLVertex3f2OGL(x,y,z:real; Kindx,Kindy,Kindz:TKoorKind);overload; // NOT OGLReality
procedure OGLRasterPos3f(akoor:TKoor3);overload;
procedure OGLRasterPos3f(x,y,z:TKoor1); overload;
procedure OGLRasterPos3f(x,y,z:real; Kindx, Kindy, Kindz:TKoorKind); overload;
procedure OGLVertex3f(akoor:TKoor3);overload;
procedure OGLVertex3f(x,y,z:TKoor1);overload;
procedure OGLVertex3f(x,y,z:real; Kindx, Kindy, Kindz:TKoorKind); overload;
procedure OGLTranslate3f(akoor:TKoor3);overload;
procedure OGLTranslate3f(x,y,z:real; Kindx, Kindy, Kindz:TKoorKind); overload;
procedure OGLColor(aColor:TColor); overload;
procedure OGLColor(aColor:TColor; Alpha:real); overload;
procedure DrawOGL;
procedure Initnx;
procedure Enable2D;
procedure Disable2D;
procedure DrawTestTriangle(scale:integer=30);
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
published
property ZoomFactor:real read FZoomFactor write FZoomFactor;
property ShowCross:boolean read FShowCross write WriteFShowCross;
property LSAxisPosition:TAxisPosition read ReadLSAxisPosition write writeLSAxisPosition;
property ImageAxisPosition:TAxisPosition read ReadImageAxisPosition write writeImageAxisPosition;
property XAxisPosition:TAxisPosition read ReadXAxisPosition write writeXAxisPosition;
property XAxisAlwaysVisible:boolean read ReadXAxisAlwaysVisible write writeXAxisAlwaysVisible;
property LSAxisAlwaysVisible:boolean read ReadLSAxisAlwaysVisible write writeLSAxisAlwaysVisible;
property ImageAxisAlwaysVisible:boolean read ReadImageAxisAlwaysVisible write writeImageAxisAlwaysVisible;
property OnXAxisPosChange:TNotifyEvent read FOnXAxisPosChange write FOnXAxisPosChange;
property OnImageAxisPosChange:TNotifyEvent read FOnImageAxisPosChange write FOnImageAxisPosChange;
property OnLSAxisPosChange:TNotifyEvent read FOnLSAxisPosChange write FOnLSAxisPosChange;
property OnPan:TMouseMoveEvent read FOnPan write FOnPan;
property OnBeginPan:TMouseEvent read FOnBeginPan write FOnBeginPan;
property OnEndPan:TMouseEvent read FOnEndPan write FOnEndPan;
property OnZoom:TZoomEvent read FOnZoom write FOnZoom;
property OnUnZoom:TZoomEvent read FOnUnZoom write FOnUnZoom;
property OnResetZoom:TZoomEvent read FOnResetZoom write FOnResetZoom;
property OnZoomRect:TZoomRectEvent read FOnZoomRect write FOnZoomRect;
property OnBeginZoomRect:TZoomRectEvent read FOnBeginZoomRect write FOnBeginZoomRect;
property OnEndZoomRect:TZoomRectEvent read FOnEndZoomRect write FOnEndZoomRect;
property KeyPan:TShiftState read FKeyPan write FKeyPan;
property KeyZoomUnZoomXAxis:TShiftState read FKeyZoomUnZoomXAxis write FKeyZoomUnZoomXAxis;
property KeyZoomUnZoomLSAxis:TShiftState read FKeyZoomUnZoomLSAxis write FKeyZoomUnZoomLSAxis;
property KeyResetZoom:TShiftState read FKeyResetZoom write FKeyResetZoom;
property KeyZoomRect:TShiftState read FKeyZoomRect write FKeyZoomRect;
property KeyChartInfo:TShiftState read FKeyChartInfo write FKeyChartInfo;
end;
{ TChart }
TChart = class(TComponent)
private
procedure OGLColor(aColor: TColor);
public
Visible:boolean;
Color:TColor;
Box:TOGlBox;
Pen:TPen;
UseIntensityColor:Boolean;
IntensityColorFactor:real;
WhatIsXValue,
WhatIsYValue,
WhatIsColorIntensityValue:TXYZKind;
Depth:TKoor1;
ValuePointer:TChartValueArray;
constructor Create(OGLBox:TOGlBox; aValuePointer:TChartValueArray); virtual;
destructor Destroy; override;
end;
{ TLineChart }
TLineChart = class(TChart)
private
public
procedure DrawOGL; virtual;
end;
{ TBackgroundChart }
TBackgroundChart = class(TChart)
private
public
procedure DrawOGL; virtual;
constructor Create(OGLBox:TOGlBox; aValuePointer:TChartValueArray); override;
end;
{ TBorderdBackgroundChart }
TBorderdBackgroundChart = class(TBackgroundChart)
private
public
procedure DrawOGL; override;
end;
{ TGradientBackgroundChart }
TGradientBackgroundChart = class(TChart)
private
public
LeftTop,
LeftBottom,
RightTop,
RightBottom:TColor;
procedure DrawOGL; virtual; // call this after everything else has finnished!!! For blending!
constructor Create(OGLBox:TOGlBox); virtual;
destructor Destroy; override;
end;
{ TPointChart }
TPointChart = class(TChart)
private
public
procedure DrawOGL; virtual;
end;
//function InitTextSuite:boolean;
//procedure TSCheckError;
const
znear=-100000;
zfar=1000000;
var
OGLBox:TOGlBox;
amrechnen:boolean;
implementation
uses unit1,Uapparatus;
{ TOGlBox }
procedure TOGlBox.DrawOGL;
begin
if not nx.AllOK then exit;
nx.Clear(true,true);
Enable2D;
//nx.rs.AddBlend:=true;
glBlendFunc(GL_One, GL_ONE);
//glPushMatrix;
//glTranslatef(0,0, -10000);
DrawAllCharts;
DrawAxis;
Header.Draw;
//if Form1.CheckViewLittleHelp2.Checked then
// HelpBoxZoom.Draw;
//glPopMatrix;
if IsZoomingRect then
DrawRect;
Disable2D;
MiniSlit.DrawOGL;
nx.Flip;
end;
procedure TOGlBox.Initnx;
begin
nx.CreateGlWindow(self);
nx.CreateFont('Courier',Font.Size,256);
//nx.CreateBasicFont;
nx.window.OnMouseMove:=@MouseMove;
nx.window.OnMouseDown:=@MouseDown;
nx.window.OnMouseUp:=@MouseUp;
nx.window.OnMouseWheel:=@MouseWheel;
nx.window.OnMouseEnter:=@MouseEnter;
if nx.LastError<>'' then showmessage(nx.LastError);
glDepthRange(0,-1000000000000);
end;
procedure TOGlBox.Enable2D;
begin
//nx.Enable2D;
glMatrixMode(GL_PROJECTION); { prepare for and then }
glLoadIdentity (); { define the projection }
//glOrtho(OGLReality.Left, OGLReality.Right, OGLReality.Bottom, OGLReality.Top, znear, zfar);
glOrtho(OGLReality.Left, OGLReality.Right, OGLReality.Bottom, OGLReality.Top, znear, zfar);
glMatrixMode (GL_MODELVIEW); { back to modelview matrix }
glViewport(0,0, Width, Height); { define the viewport }
//glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
//glLoadIdentity;
nx.rs.CullBack:=False;
nx.rs.CullFront:=False;
//nx.rs.AddBlend:=True;
end;
procedure TOGlBox.Disable2D;
begin
//nx.Disable2D;
end;
procedure TOGlBox.DrawTestTriangle(scale: integer);
begin
//paint test triangle
glPushMatrix;
//glTranslatef(0,0,0);
glScalef(scale,scale,1);
glBegin(GL_TRIANGLES);
glColor3f(1, 0, 0);
glVertex3f(-1, -1, 0);
glColor3f(0, 1, 0);
glVertex3f(1, -1, 0);
glColor3f(0, 0, 1);
glVertex3f(0, 1, 0);
glEnd;
glPopMatrix;
end;
function TOGlBox.TransOGL2OGLReality(akoor: TKoor1): TKoor1;
begin
Result:=akoor;
case akoor.Kind of
kkOGLx: result:=Koor1( akoor.v - xAxis.Koor.Min*OGLReality.Width/xAxis.KoorSize +OGLReality.Left , Change2OGLReality(akoor.Kind)) ;
kkOGLy: Result:=Koor1( akoor.v - LSAxis.Koor.Min*OGLReality.Height/LSAxis.KoorSize +OGLReality.Bottom , Change2OGLReality(akoor.Kind)) ;
kkOGLz: Result:=Koor1(akoor.v , kkOGLRealityz);
end;
end;
function TOGlBox.TransOGLReality2OGL(akoor: TKoor1): TKoor1;
begin
Result:=akoor;
case akoor.Kind of
kkOGLRealityx: Result:=Koor1( akoor.v + xAxis.Koor.Min*OGLReality.Width/xAxis.KoorSize -OGLReality.Left , Change2OGL(akoor.Kind)) ;
kkOGLRealityy: Result:=Koor1( akoor.v + LSAxis.Koor.Min*OGLReality.Height/LSAxis.KoorSize -OGLReality.Bottom , Change2OGL(akoor.Kind)) ;
kkOGLRealityz: Result:=Koor1(akoor.v , kkOGLRealityz);
end;
end;
function TOGlBox.TransDeltaOGL2OGLReality(akoor: TKoor1): TKoor1;
begin
Result:=akoor;
end;
function TOGlBox.TransDeltaOGLReality2OGL(akoor: TKoor1): TKoor1;
begin
Result:=akoor;
end;
function TOGlBox.TransKoor2OGL(akoor:TKoor1): TKoor1;
begin
Result:=TransOGLReality2OGL(TransKoor2OGLReality(akoor));
//result:=akoor;
//case akoor.Kind of
//kkx: Result:=Koor1(akoor.v* OGLReality.Width/ xAxis.KoorSize , Change2OGL(akoor.Kind));
//kkImage: Result:=Koor1(akoor.v* OGLReality.Height/ ImageAxis.KoorSize , Change2OGL(akoor.Kind));
//kkLS: Result:=Koor1(akoor.v* OGLReality.Height/ LSAxis.KoorSize , Change2OGL(akoor.Kind));
//kkz: Result:=Koor1(akoor.v , Change2OGL(akoor.Kind));
//end;
end;
function TOGlBox.TransKoor2OGLReality(akoor:TKoor1): TKoor1;
begin
Result:=akoor;
case akoor.Kind of
kkx: Result:=Koor1((akoor.v-xAxis.Koor.Min)* OGLReality.Width/ xAxis.KoorSize + OGLReality.Left , Change2OGLReality(akoor.Kind));
kkImage: Result:=Koor1((akoor.v-ImageAxis.Koor.Min)* OGLReality.Height/ ImageAxis.KoorSize + OGLReality.Bottom , Change2OGLReality(akoor.Kind));
kkLS: Result:=Koor1((akoor.v-LSAxis.Koor.Min)* OGLReality.Height/ LSAxis.KoorSize + OGLReality.Bottom , Change2OGLReality(akoor.Kind));
kkz: Result:=Koor1(akoor.v , kkOGLRealityz);
end;
end;
function TOGlBox.TransDeltaKoor2OGLReality(akoor:TKoor1): TKoor1;
begin
result:=akoor;
case akoor.Kind of
kkx: Result:=Koor1(akoor.v* OGLReality.Width/ xAxis.KoorSize , Change2OGLReality(akoor.Kind));
kkImage: Result:=Koor1(akoor.v* OGLReality.Height/ ImageAxis.KoorSize , Change2OGLReality(akoor.Kind));
kkLS: Result:=Koor1(akoor.v* OGLReality.Height/ LSAxis.KoorSize , Change2OGLReality(akoor.Kind));
kkz: Result:=Koor1(akoor.v , kkOGLRealityz);
end;
end;
function TOGlBox.TransDeltaKoor2Pixel(akoor:TKoor1): TKoor1;
begin
result:=TransDeltaOGLReality2Pixel(TransDeltaKoor2OGLReality(akoor));
end;
function TOGlBox.TransOGL2Koor(akoor: TKoor1; ReturnKoorKind:TKoorKind): TKoor1;
begin
Result:=TransOGLReality2Koor(TransOGL2OGLReality(akoor), ReturnKoorKind);
end;
function TOGlBox.TransOGLReality2Koor(akoor:TKoor1; ReturnKoorKind:TKoorKind): TKoor1;
begin
//es wird erwartet dass returnkoorkind mit dem ankommenden akoor.kind zusammenpasst (d.h. NOT: akoor=kkOGLRealityx and ReturnKoorKind =kkLS)
result:=akoor;
case akoor.Kind of
kkOGLRealityx: Result:=Koor1((akoor.v - OGLReality.Left) * xAxis.KoorSize/OGLReality.Width + xAxis.Koor.Min , ReturnKoorKind);
kkOGLRealityy:
case ReturnKoorKind of
kkLS: Result:=Koor1((akoor.v - OGLReality.Bottom) * LSAxis.KoorSize/ OGLReality.Height + LSAxis.Koor.Min , ReturnKoorKind);
kkImage: Result:=Koor1((akoor.v - OGLReality.Bottom) * ImageAxis.KoorSize/ OGLReality.Height + ImageAxis.Koor.Min , ReturnKoorKind);
end;
kkOGLRealityz: Result:=Koor1(akoor.v , ReturnKoorKind);
end;
//case akoor.Kind of
//kkx: Result:=Koor1(akoor.v/ OGLReality.Width* Koor.Width;
//kkLS: Result:=Koor1(akoor.v/ OGLReality.Height* Koor.Height;
//kkz: Result:=Koor1(akoor.v;
//end;
end;
function TOGlBox.TransDeltaOGLReality2Koor(akoor:TKoor1; ReturnKoorKind:TKoorKind): TKoor1;
begin
result:=akoor;
case akoor.Kind of
kkOGLRealityx: Result:=Koor1(akoor.v * xAxis.KoorSize/OGLReality.Width , ReturnKoorKind);
kkOGLRealityy:
case ReturnKoorKind of
kkLS: Result:=Koor1(akoor.v * LSAxis.KoorSize/ OGLReality.Height , ReturnKoorKind);
kkImage: Result:=Koor1(akoor.v * ImageAxis.KoorSize/ OGLReality.Height , ReturnKoorKind);
end;
kkOGLRealityz: Result:=Koor1(akoor.v , ReturnKoorKind);
end;
end;
function TOGlBox.TransPixel2Koor(akoor:TKoor1; ReturnKoorKind:TKoorKind): TKoor1;
begin
result:= TransOGLReality2Koor( TransPixel2OGLReality(akoor) , ReturnKoorKind);
end;
function TOGlBox.TransDeltaPixel2Koor(akoor:TKoor1; ReturnKoorKind:TKoorKind): TKoor1;
begin
result:= TransDeltaOGLReality2Koor(TransDeltaPixel2OGLReality(akoor),ReturnKoorKind);
end;
procedure TOGlBox.glWrite(textstr: String; Font_index: integer; Centering:boolean=False);
begin
tex.Enable;
glPushMatrix;
glScalef(1,-1,1);
//glScalef(10/Font.,10/Font.Size,1);
nx.SetFont(Font_index);
if Centering then
nx.Font[Font_index].DrawC(0, -nx.Font[0].height div 2, textstr)
else
nx.Font[Font_index].Draw(0, -nx.Font[0].height div 2, textstr);
glPopMatrix;
tex.Disable;
end;
function TOGlBox.TransPixel2OGLReality(akoor:TKoor1): TKoor1;
begin
result:=akoor;
case akoor.Kind of
kkPixelx: Result:=Koor1(akoor.v+ OGLReality.Left , Change2OGLReality(akoor.Kind));
kkPixely: Result:=Koor1(-akoor.v-OGLReality.Bottom , Change2OGLReality(akoor.Kind));
kkPixelz: Result:=Koor1(akoor.v , Change2OGLReality(akoor.Kind));
end;
end;
function TOGlBox.TransDeltaPixel2OGLReality(akoor:TKoor1): TKoor1;
begin
result:=Koor1(akoor.v, Change2OGLReality(akoor.Kind));
end;
function TOGlBox.TransOGLReality2Pixel(akoor:TKoor1): TKoor1;
begin
result:=akoor;
case akoor.Kind of
kkOGLRealityx: Result:=Koor1(akoor.v- OGLReality.Left , Change2Pixel(akoor.Kind));
// kkImage: Result:=Koor1(aOGLReality-OGLReality.Bottom , Change2Pixel(akoor.Kind));
kkOGLRealityy: Result:=Koor1(akoor.v-OGLReality.Bottom , Change2Pixel(akoor.Kind));
kkOGLRealityz: Result:=Koor1(akoor.v , Change2Pixel(akoor.Kind));
end;
end;
function TOGlBox.TransDeltaOGLReality2Pixel(akoor:TKoor1): TKoor1;
begin
result:=Koor1(akoor.v, Change2Pixel(akoor.Kind));
end;
procedure TOGlBox.OGLVertex3f2OGL(akoor: TKoor3);
var temp:TKoor3;
begin
temp:=TransAll(akoor, @Trans2OGL);
glVertex3f(temp.x.v,temp.y.v,temp.z.v);
end;
procedure TOGlBox.OGLVertex3f2OGL(x, y, z: real; Kindx, Kindy, Kindz: TKoorKind);
begin
OGLVertex3f2OGL(Koor3(x,y,z, Kindx, Kindy, Kindz));
end;
procedure TOGlBox.OGLRasterPos3f(akoor: TKoor3);
var temp:TKoor3;
begin
temp:=TransAll(akoor, @Trans2OGLReality);
glRasterPos3f(temp.x.v,temp.y.v,temp.z.v);
end;
procedure TOGlBox.OGLRasterPos3f(x, y, z: TKoor1);
begin
OGLRasterPos3f(Koor3(x,y,z));
end;
procedure TOGlBox.OGLRasterPos3f(x, y, z: real; Kindx, Kindy, Kindz: TKoorKind);
begin
OGLRasterPos3f(Koor3(x, y, z, Kindx, Kindy, Kindz));
end;
procedure TOGlBox.OGLVertex3f(akoor: TKoor3);
var temp:TKoor3;
begin
temp:=TransAll(akoor, @Trans2OGLReality);
glVertex3f(temp.x.v,temp.y.v,temp.z.v);
end;
procedure TOGlBox.OGLVertex3f(x, y, z: TKoor1);
begin
OGLVertex3f(Koor3(x,y,z));
end;
procedure TOGlBox.OGLVertex3f(x, y, z: real; Kindx, Kindy, Kindz:TKoorKind);
begin
OGLVertex3f(Koor3(x,y,z,Kindx,Kindy,Kindz));
end;
procedure TOGlBox.OGLTranslate3f(akoor: TKoor3);
var temp:TKoor3;
begin
temp:=TransAll(akoor, @Trans2OGLReality);
glTranslatef(temp.x.v,temp.y.v,temp.z.v);
end;
procedure TOGlBox.OGLTranslate3f(x, y, z: real; Kindx, Kindy, Kindz: TKoorKind);
begin
OGLTranslate3f(Koor3(x,y,z,Kindx,Kindy,Kindz));
end;
procedure TOGlBox.OGLColor(aColor: TColor);
var r,g,b:byte;
begin
ColorValues(aColor,r,g,b);
glColor3f(r/255,g/255,b/255);
end;
procedure TOGlBox.OGLColor(aColor: TColor; Alpha: real);
var r,g,b:byte;
begin
ColorValues(aColor,r,g,b);
glColor4f(r/255,g/255,b/255, Alpha);
end;
procedure TOGlBox.Resize;
begin
inherited;
if ([csLoading,csDestroying]*ComponentState<>[]) then exit;
if Parent=nil then
exit;
OGLReality.R2Rect(-self.Width/2, -self.Height/2, self.Width, self.Height);
Header.pos.y.v:= OGLReality.Top-OGLReality.Height/50;
Header.pos.y.Kind:=kkOGLy;
Header.pos.x.v:= OGLReality.Left+OGLReality.Width/2 - Length(Header.Text)/2*5;
Header.pos.x.Kind:=kkOGLx;
MiniSlit.Pos:=Koor3(OGLReality.Left, OGLReality.Bottom, DepthOverlay.v, kkOGLRealityx, kkOGLRealityy, kkOGLRealityz);
//nx.window.MakeCurrent();
//if Form1.Active then
// OGLBox.SetFocus;
end;
procedure TOGlBox.Paint;
begin
inherited Paint;
DrawOGL;
end;
procedure TOGlBox.DoEnter;
begin
self.SetFocus;
inherited DoEnter;
end;
procedure TOGlBox.DoExit;
begin
inherited DoExit;
end;
procedure TOGlBox.DoBeginPan(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
StoredIdleDraw:=Form1.EnableIdleDraw;
Form1.EnableIdleDraw:=true;
end;
procedure TOGlBox.DoEndPan(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
Form1.EnableIdleDraw := StoredIdleDraw;
end;
procedure TOGlBox.DoPan(Shift: TShiftState; X, Y: Integer);
var delta:real;
begin
delta:=TransDelta2Koor(Koor1(-X +LastMouseMovePos.X , kkPixelx), kkX).v;
xAxis.Koor.Min:=xAxis.Koor.Min + delta;
xAxis.Koor.Max:=xAxis.Koor.Max + delta;
delta:=TransDelta2Koor(Koor1(+y -LastMouseMovePos.y , kkPixely), kkLS).v;
LSAxis.Koor.Min:=LSAxis.Koor.Min + delta;
LSAxis.Koor.Max:=LSAxis.Koor.Max + delta;
delta:=TransDelta2Koor(Koor1(+y -LastMouseMovePos.y , kkPixely), kkImage).v;
ImageAxis.Koor.Min:=ImageAxis.Koor.Min + delta;
ImageAxis.Koor.Max:=ImageAxis.Koor.Max + delta;
end;
procedure TOGlBox.DoZoom(Sender: TObject; Shift: TShiftState; MousePos: TPoint; Factor: real; Axis:TKoorSet);
begin
if kkX in Axis then
AZoom(xAxis.Koor.Min, xAxis.Koor.Max, Trans2Koor(Koor1(MousePos.x, kkPixelx), kkX).v, ZoomFactor, xAxis.Koor.Min, xAxis.Koor.Max);
if kkLS in Axis then
AZoom(LSAxis.Koor.Min, LSAxis.Koor.Max, Trans2Koor(Koor1(MousePos.y, kkPixely), kkLS).v, ZoomFactor, LSAxis.Koor.Min, LSAxis.Koor.Max);
if kkImage in Axis then
AZoom(ImageAxis.Koor.Min, ImageAxis.Koor.Max, Trans2Koor(Koor1(MousePos.y, kkPixely), kkImage).v, ZoomFactor, ImageAxis.Koor.Min, ImageAxis.Koor.Max);
DrawOGL;
end;
procedure TOGlBox.DoUnZoom(Sender: TObject; Shift: TShiftState; MousePos: TPoint; Factor: real; Axis:TKoorSet);
begin
if kkX in Axis then
AZoom(xAxis.Koor.Min, xAxis.Koor.Max, Trans2Koor(Koor1(MousePos.x, kkPixelx), kkX).v, -ZoomFactor, xAxis.Koor.Min, xAxis.Koor.Max);
if kkLS in Axis then
AZoom(LSAxis.Koor.Min, LSAxis.Koor.Max, Trans2Koor(Koor1(MousePos.y, kkPixely), kkLS).v, -ZoomFactor, LSAxis.Koor.Min, LSAxis.Koor.Max);
if kkLS in Axis then
AZoom(ImageAxis.Koor.Min, ImageAxis.Koor.Max, Trans2Koor(Koor1(MousePos.y, kkPixely), kkImage).v, -ZoomFactor, ImageAxis.Koor.Min, ImageAxis.Koor.Max);
DrawOGL;
end;
procedure TOGlBox.DoResetZoom(Sender: TObject; Shift: TShiftState; MousePos: TPoint; Factor: real; Axis:TKoorSet);
begin
ResetView;
//with Koor do
//begin
//if Axis= xAxisKind then
//begin
//Left:=-95 ;
//Right:=95 ;
//end
//else if Axis= YAxisKind then
//begin
//Top:=1.1 ;
//Bottom:=-1.1 ;
//end
//end;
DrawOGL;
end;
procedure TOGlBox.DoZoomRect(Sender: TObject; Shift: TShiftState; rect: TRect);
begin
end;