-
Notifications
You must be signed in to change notification settings - Fork 226
/
Copy pathDrawAPI.h
1700 lines (1465 loc) · 48.9 KB
/
DrawAPI.h
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
// Copyright (c) Martin Schweiger
// Licensed under the MIT License
// ======================================================================
// ORBITER SOFTWARE DEVELOPMENT KIT
// DrawAPI.h
// 2-D surface drawing support interface.
// This API defines an abstraction layer for providing drawing support
// for surfaces (e.g. lines and text). It is closely modelled on the
// Windows GDI, but provides an overload mechanism to insert different
// drawing systems.
// ======================================================================
/**
* \file DrawAPI.h
* \brief 2-D surface drawing support interface.
*/
#ifndef __DRAWAPI_H
#define __DRAWAPI_H
#include "OrbiterAPI.h"
#include <assert.h>
#include <xmmintrin.h>
#ifdef D3D9CLIENT_EXPORTS
#include "d3dx9.h"
#endif
/// \brief Poly object handle
typedef void* HPOLY;
namespace oapi {
/**
* \brief Integer-valued 2-D vector type.
* \note This structure is designed to be compatible with the Windows POINT type.
*/
union IVECTOR2 {
long data[2]; ///< vector data array
struct {
long x; ///< vector x coordinate
long y; ///< vector y coordinate
};
};
/**
* \brief 32-bit floating point 2D vector type.
* \note This structure is compatible with the D3DXVECTOR2 type.
*/
typedef struct FVECTOR2
{
FVECTOR2()
{
x = y = 0.0f;
}
FVECTOR2(float q)
{
x = y = q;
}
FVECTOR2(float _x, float _y)
{
x = _x;
y = _y;
}
FVECTOR2(double _x, double _y)
{
x = float(_x);
y = float(_y);
}
FVECTOR2(long _x, long _y)
{
x = float(_x);
y = float(_y);
}
FVECTOR2(DWORD _x, DWORD _y)
{
x = float(_x);
y = float(_y);
}
FVECTOR2(int _x, int _y)
{
x = float(_x);
y = float(_y);
}
FVECTOR2(const POINT& p)
{
x = float(p.x);
y = float(p.y);
}
FVECTOR2(const POINT* p)
{
x = float(p->x);
y = float(p->y);
}
FVECTOR2(const IVECTOR2& p)
{
x = float(p.x);
y = float(p.y);
}
inline FVECTOR2 operator* (float f) const
{
return FVECTOR2(x * f, y * f);
}
inline FVECTOR2 operator* (FVECTOR2 f) const
{
return FVECTOR2(x * f.x, y * f.y);
}
inline FVECTOR2& operator*= (FVECTOR2& f)
{
x *= f.x; y *= f.y;
return *this;
}
inline FVECTOR2& operator+= (FVECTOR2& f)
{
x += f.x; y += f.y;
return *this;
}
inline FVECTOR2& operator-= (FVECTOR2& f)
{
x -= f.x; y -= f.y;
return *this;
}
inline FVECTOR2& operator/= (FVECTOR2& f)
{
x /= f.x; y /= f.y;
return *this;
}
inline FVECTOR2 operator/ (float f) const
{
f = 1.0f / f;
return FVECTOR2(x * f, y * f);
}
inline FVECTOR2 operator+ (float f) const
{
return FVECTOR2(x + f, y + f);
}
inline FVECTOR2 operator+ (FVECTOR2& f) const
{
return FVECTOR2(x + f.x, y + f.y);
}
inline FVECTOR2 operator- (float f) const
{
return FVECTOR2(x - f, y - f);
}
inline FVECTOR2 operator+ (const FVECTOR2& f) const
{
return FVECTOR2(x + f.x, y + f.y);
}
inline FVECTOR2 operator- (const FVECTOR2& f) const
{
return FVECTOR2(x - f.x, y - f.y);
}
float x, y;
} FVECTOR2;
/**
* \brief 32-bit floating point 3D vector type.
* \note This structure is compatible with the D3DXVECTOR3 type.
*/
typedef union FVECTOR3
{
FVECTOR3()
{
x = y = z = 0.0f;
}
FVECTOR3(float q)
{
x = y = z = q;
}
FVECTOR3(float _x, float _y, float _z)
{
x = _x;
y = _y;
z = _z;
}
FVECTOR3(const VECTOR3& v)
{
x = float(v.x);
y = float(v.y);
z = float(v.z);
}
#ifdef D3D9CLIENT_EXPORTS
FVECTOR3(const D3DXVECTOR3 &v)
{
x = float(v.x);
y = float(v.y);
z = float(v.z);
}
FVECTOR3(const D3DXCOLOR& v)
{
x = float(v.r);
y = float(v.g);
z = float(v.b);
}
#endif
float MaxRGB() const
{
return (std::max)(r, (std::max)(g, b));
}
float MinRGB() const
{
return (std::min)(r, (std::min)(g, b));
}
float sql() const
{
return x * x + y * y + z * z;
}
inline VECTOR3 _V() const
{
VECTOR3 v = { x,y,z };
return v;
}
inline FVECTOR3& operator*= (float f)
{
x *= f; y *= f; z *= f;
return *this;
}
inline FVECTOR3& operator*= (const FVECTOR3 &f)
{
x *= f.x; y *= f.y; z *= f.z;
return *this;
}
inline FVECTOR3& operator/= (float f)
{
// return *this *= (1.0f / f); // nicer?
f = 1.0f / f;
x *= f; y *= f; z *= f;
return *this;
}
inline FVECTOR3& operator+= (float f)
{
x += f; y += f; z += f;
return *this;
}
inline FVECTOR3& operator+= (const FVECTOR3& f)
{
x += f.x; y += f.y; z += f.z;
return *this;
}
inline FVECTOR3& operator-= (float f)
{
x -= f; y -= f; z -= f;
return *this;
}
inline FVECTOR3& operator-= (const FVECTOR3 &f)
{
x -= f.x; y -= f.y; z -= f.z;
return *this;
}
inline FVECTOR3 operator* (float f) const
{
return FVECTOR3(x * f, y * f, z * f);
}
inline FVECTOR3 operator* (const FVECTOR3 &f) const
{
return FVECTOR3(x * f.x, y * f.y, z * f.z);
}
inline FVECTOR3 operator/ (float f) const
{
f = 1.0f / f;
return FVECTOR3(x * f, y * f, z * f);
}
inline FVECTOR3 operator/ (const FVECTOR3 &f) const
{
return FVECTOR3(x / f.x, y / f.y, z / f.z);
}
inline FVECTOR3 operator+ (float f) const
{
return FVECTOR3(x + f, y + f, z + f);
}
inline FVECTOR3 operator- (float f) const
{
return FVECTOR3(x - f, y - f, z - f);
}
inline FVECTOR3 operator+ (const FVECTOR3& f) const
{
return FVECTOR3(x + f.x, y + f.y, z + f.z);
}
inline FVECTOR3 operator- (const FVECTOR3& f) const
{
return FVECTOR3(x - f.x, y - f.y, z - f.z);
}
inline FVECTOR3 operator-() const
{
return FVECTOR3(-x, -y, -z);
}
#ifdef D3D9CLIENT_EXPORTS
inline operator D3DXVECTOR3() const
{
return D3DXVECTOR3(x, y, z);
}
inline operator D3DXCOLOR() const
{
return D3DXCOLOR(x, y, z, 1);
}
#endif
struct { float x, y, z; };
struct { float r, g, b; };
FVECTOR2 xy;
} FVECTOR3;
/**
* \brief 32-bit floating point 4D vector type.
* \note This structure is compatible with the D3DXVECTOR4 type.
*/
typedef union __declspec(align(16)) FVECTOR4
{
DWORD dword_abgr() const
{
DWORD dr = DWORD((std::max)(0.0f, r) * 255.0f + 0.5f);
DWORD dg = DWORD((std::max)(0.0f, g) * 255.0f + 0.5f);
DWORD db = DWORD((std::max)(0.0f, b) * 255.0f + 0.5f);
DWORD da = DWORD((std::max)(0.0f, a) * 255.0f + 0.5f);
if (dr > 0xFF) dr = 0xFF;
if (dg > 0xFF) dg = 0xFF;
if (db > 0xFF) db = 0xFF;
if (da > 0xFF) da = 0xFF;
return (da << 24) | (db << 16) | (dg << 8) | dr;
}
DWORD dword_argb() const
{
DWORD dr = DWORD((std::max)(0.0f, r) * 255.0f + 0.5f);
DWORD dg = DWORD((std::max)(0.0f, g) * 255.0f + 0.5f);
DWORD db = DWORD((std::max)(0.0f, b) * 255.0f + 0.5f);
DWORD da = DWORD((std::max)(0.0f, a) * 255.0f + 0.5f);
if (dr > 0xFF) dr = 0xFF;
if (dg > 0xFF) dg = 0xFF;
if (db > 0xFF) db = 0xFF;
if (da > 0xFF) da = 0xFF;
return (da << 24) | (dr << 16) | (dg << 8) | db;
}
COLOUR4 Colour4() const
{
COLOUR4 clr = { r,g,b,a };
return clr;
}
float MaxRGB() const
{
return (std::max)(r, (std::max)(g, b));
}
FVECTOR4()
{
r = g = b = a = 0.0f;
}
FVECTOR4(float q)
{
x = y = z = w = q;
}
FVECTOR4(const COLOUR4& c)
{
r = c.r;
g = c.g;
b = c.b;
a = c.a;
}
FVECTOR4(DWORD abgr)
{
DWORD dr = (abgr & 0xFF); abgr >>= 8;
DWORD dg = (abgr & 0xFF); abgr >>= 8;
DWORD db = (abgr & 0xFF); abgr >>= 8;
DWORD da = (abgr & 0xFF);
//if (da == 0) da = 255;
float q = 3.92156862e-3f;
r = float(dr) * q;
g = float(dg) * q;
b = float(db) * q;
a = float(da) * q;
}
FVECTOR4(const VECTOR4& v)
{
x = float(v.x);
y = float(v.y);
z = float(v.z);
w = float(v.w);
}
FVECTOR4(const VECTOR3& v, float _w)
{
x = float(v.x);
y = float(v.y);
z = float(v.z);
w = _w;
}
FVECTOR4(const FVECTOR3& v, float _w)
{
rgb = v;
w = _w;
}
FVECTOR4(float _x, float _y, float _z, float _w)
{
x = float(_x);
y = float(_y);
z = float(_z);
w = float(_w);
}
FVECTOR4(int _x, int _y, int _z, int _w)
{
x = float(_x);
y = float(_y);
z = float(_z);
w = float(_w);
}
FVECTOR4(double _x, double _y, double _z, double _w)
{
x = float(_x);
y = float(_y);
z = float(_z);
w = float(_w);
}
#ifdef D3D9CLIENT_EXPORTS
FVECTOR4(const D3DXVECTOR4& v)
{
x = float(v.x);
y = float(v.y);
z = float(v.z);
w = float(v.w);
}
FVECTOR4(const D3DXCOLOR& v)
{
x = float(v.r);
y = float(v.g);
z = float(v.b);
w = float(v.a);
}
#endif
inline FVECTOR4 operator* (float f) const
{
return FVECTOR4(x * f, y * f, z * f, w * f);
}
inline FVECTOR4& operator*= (float f)
{
x *= f; y *= f; z *= f; w *= f;
return *this;
}
inline FVECTOR4& operator/= (float f)
{
// return *this *= (1.0f / f); // nicer?
f = 1.0f / f;
x *= f; y *= f; z *= f; w *= f;
return *this;
}
inline FVECTOR4& operator+= (float f)
{
x += f; y += f; z += f; w += f;
return *this;
}
inline FVECTOR4& operator-= (float f)
{
x -= f; y -= f; z -= f; w -= f;
return *this;
}
inline FVECTOR4 operator/ (float f) const
{
f = 1.0f / f;
return FVECTOR4(x * f, y * f, z * f, w * f);
}
inline FVECTOR4 operator+ (float f) const
{
return FVECTOR4(x + f, y + f, z + f, w + f);
}
inline FVECTOR4 operator- (float f) const
{
return FVECTOR4(x - f, y - f, z - f, w - f);
}
inline FVECTOR4 operator+ (const FVECTOR4& f) const
{
return FVECTOR4(x + f.x, y + f.y, z + f.z, w + f.w);
}
inline FVECTOR4 operator- (const FVECTOR4& f) const
{
return FVECTOR4(x - f.x, y - f.y, z - f.z, w - f.w);
}
inline FVECTOR4 operator-() const
{
return FVECTOR4(-x, -y, -z, -w);
}
#ifdef D3D9CLIENT_EXPORTS
inline operator D3DXVECTOR4() const
{
return D3DXVECTOR4(x, y, z, w);
}
#endif
__m128 xm;
float data[4];
struct { float x, y, z, w; };
struct { float r, g, b, a; };
FVECTOR3 xyz; // , w; };
FVECTOR3 rgb; // , a; };
} FVECTOR4;
typedef union DRECT
{
DRECT()
{
left = right = top = bottom = 0.0;
}
DRECT(double l, double t, double r, double b)
{
left = l; top = t; right = r; bottom = b;
}
DRECT(float l, float t, float r, float b)
{
left = double(l); top = double(t); right = double(r); bottom = double(b);
}
DRECT(const DRECT& x)
{
left = x.left;
top = x.top;
right = x.right;
bottom = x.bottom;
}
VECTOR4 vec;
struct {
double left, top, right, bottom;
};
} DRECT;
/**
* \brief Float-valued 4x4 matrix.
* \note This structure is compatible with the D3DXMATRIX.
*/
typedef union __declspec(align(16)) FMATRIX4
{
FMATRIX4() {
m11 = m12 = m13, m14 = m21 = m22 = m23 = m24 = m31 = m32 = m33 = m34 = m41 = m42 = m43 = m44 = 0;
}
FMATRIX4(float m11, float m12, float m13, float m14,
float m21, float m22, float m23, float m24,
float m31, float m32, float m33, float m34,
float m41, float m42, float m43, float m44) :
m11(m11), m12(m12), m13(m13), m14(m14),
m21(m21), m22(m22), m23(m23), m24(m24),
m31(m31), m32(m32), m33(m33), m34(m34),
m41(m41), m42(m42), m43(m43), m44(m44)
{
}
FMATRIX4(const float* pSrc) {
for (int i = 0; i < 16; i++) data[i] = pSrc[i];
}
#ifdef D3D9CLIENT_EXPORTS
FMATRIX4(const D3DXMATRIX& m)
{
memcpy_s(data, sizeof(FMATRIX4), &m, sizeof(m));
}
FMATRIX4(const LPD3DXMATRIX m)
{
memcpy_s(data, sizeof(FMATRIX4), m, sizeof(FMATRIX4));
}
inline operator LPD3DXMATRIX()
{
return (LPD3DXMATRIX)this;
}
#endif
void Zero()
{
for (int i = 0; i < 16; i++) data[i] = 0.0;
}
void Ident()
{
for (int i = 0; i < 16; i++) data[i] = 0.0;
m11 = m22 = m33 = m44 = 1.0f;
}
void _swap(float& a, float& b) { float c = a; a = b; b = c; }
void Transpose()
{
_swap(m12, m21); _swap(m13, m31);
_swap(m14, m41); _swap(m23, m32);
_swap(m24, m42); _swap(m34, m43);
}
float data[16];
struct { FVECTOR4 _x, _y, _z, _p; };
struct { float m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44; };
} FMATRIX4;
/**
* \brief Vector Matrix multiplication
*/
inline FVECTOR4 mul(const FVECTOR4& V, const FMATRIX4& M)
{
float x = V.x * M.m11 + V.y * M.m21 + V.z * M.m31 + V.w * M.m41;
float y = V.x * M.m12 + V.y * M.m22 + V.z * M.m32 + V.w * M.m42;
float z = V.x * M.m13 + V.y * M.m23 + V.z * M.m33 + V.w * M.m43;
float w = V.x * M.m14 + V.y * M.m24 + V.z * M.m34 + V.w * M.m44;
return FVECTOR4(x, y, z, w);
}
inline FVECTOR4 tmul(const FVECTOR4& V, const FMATRIX4& M)
{
float x = V.x * M.m11 + V.y * M.m12 + V.z * M.m13 + V.w * M.m14;
float y = V.x * M.m21 + V.y * M.m22 + V.z * M.m23 + V.w * M.m24;
float z = V.x * M.m31 + V.y * M.m32 + V.z * M.m33 + V.w * M.m34;
float w = V.x * M.m41 + V.y * M.m42 + V.z * M.m43 + V.w * M.m44;
return FVECTOR4(x, y, z, w);
}
/**
* \brief Transform a position by matrix
*/
inline FVECTOR3 TransformCoord(const FVECTOR3& V, const FMATRIX4& M)
{
float x = V.x * M.m11 + V.y * M.m21 + V.z * M.m31 + M.m41;
float y = V.x * M.m12 + V.y * M.m22 + V.z * M.m32 + M.m42;
float z = V.x * M.m13 + V.y * M.m23 + V.z * M.m33 + M.m43;
float w = V.x * M.m14 + V.y * M.m24 + V.z * M.m34 + M.m44;
w = 1.0f / w;
return FVECTOR3(x * w, y * w, z * w);
}
/**
* \brief Transform a normal or direction by matrix
*/
inline FVECTOR3 TransformNormal(const FVECTOR3& V, const FMATRIX4& M)
{
float x = V.x * M.m11 + V.y * M.m21 + V.z * M.m31;
float y = V.x * M.m12 + V.y * M.m22 + V.z * M.m32;
float z = V.x * M.m13 + V.y * M.m23 + V.z * M.m33;
return FVECTOR3(x, y, z);
}
inline FVECTOR2 unit(const FVECTOR2& v)
{
float f = 1.0f / ::sqrt(v.x * v.x + v.y * v.y);
return FVECTOR2(v.x * f, v.y * f);
}
inline FVECTOR3 unit(const FVECTOR3& v)
{
float d = v.x * v.x + v.y * v.y + v.z * v.z;
return d > 0 ? FVECTOR3(v.x, v.y, v.z) / ::sqrt(d) : 0.0f;
}
inline FVECTOR3 normalize(const FVECTOR3& v)
{
float d = v.x * v.x + v.y * v.y + v.z * v.z;
return d > 0 ? FVECTOR3(v.x, v.y, v.z) / ::sqrt(d) : 0.0f;
}
inline float dot(const FVECTOR2& v, const FVECTOR2& w)
{
return v.x * w.x + v.y * w.y;
}
inline float dot(const FVECTOR3& v, const FVECTOR3& w)
{
return v.x * w.x + v.y * w.y + v.z * w.z;
}
inline float dot(const FVECTOR4& v, const FVECTOR4& w)
{
return v.x * w.x + v.y * w.y + v.z * w.z + v.w * w.w;
}
inline float length(const FVECTOR2& v)
{
return ::sqrt(v.x * v.x + v.y * v.y);
}
inline float length(const FVECTOR3& v)
{
return ::sqrt(v.x * v.x + v.y * v.y + v.z * v.z);
}
inline FVECTOR3 cross(const FVECTOR3& a, const FVECTOR3& b)
{
return FVECTOR3(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x);
}
inline float saturate(float x)
{
//sadly std::clamp produces garbage assembly on both gcc and MSVC
//this version makes MSVC produce good code
x = (x < 0.0f) ? 0.0f : x;
x = (x > 1.0f) ? 1.0f : x;
return x;
}
inline FVECTOR3 saturate(const FVECTOR3& v)
{
return FVECTOR3(saturate(v.x), saturate(v.y), saturate(v.z));
}
inline FVECTOR4 saturate(const FVECTOR4& v)
{
return FVECTOR4(saturate(v.x), saturate(v.y), saturate(v.z), saturate(v.w));
}
inline FVECTOR2 lerp(const FVECTOR2& a, const FVECTOR2& b, float x)
{
return a + (b - a) * x;
}
inline FVECTOR3 lerp(const FVECTOR3& a, const FVECTOR3& b, float x)
{
return a + (b - a) * x;
}
inline FVECTOR4 lerp(const FVECTOR4& a, const FVECTOR4& b, float x)
{
return a + (b - a) * x;
}
inline FVECTOR3 pow(const FVECTOR3& x, float y)
{
return FVECTOR3(::pow(x.x, y), ::pow(x.y, y), ::pow(x.z, y));
}
inline FVECTOR4 pow(const FVECTOR4& x, float y)
{
return FVECTOR4(::pow(x.x, y), ::pow(x.y, y), ::pow(x.z, y), ::pow(x.w, y));
}
inline FVECTOR3 pow(const FVECTOR3& x, const FVECTOR3 &y)
{
return FVECTOR3(::pow(x.x, y.x), ::pow(x.y, y.y), ::pow(x.z, y.z));
}
inline FVECTOR4 pow(const FVECTOR4& x, const FVECTOR4 &y)
{
return FVECTOR4(::pow(x.x, y.x), ::pow(x.y, y.y), ::pow(x.z, y.z), ::pow(x.w, y.w));
}
inline FVECTOR3 exp(const FVECTOR3& x)
{
return FVECTOR3(::exp(x.x), ::exp(x.y), ::exp(x.z));
}
inline FVECTOR4 exp(const FVECTOR4& x)
{
return FVECTOR4(::exp(x.x), ::exp(x.y), ::exp(x.z), ::exp(x.w));
}
inline FVECTOR3 sqrt(const FVECTOR3& x)
{
return FVECTOR3(::sqrt(x.x), ::sqrt(x.y), ::sqrt(x.z));
}
inline FVECTOR4 sqrt(const FVECTOR4& x)
{
return FVECTOR4(::sqrt(x.x), ::sqrt(x.y), ::sqrt(x.z), ::sqrt(x.w));
}
// ======================================================================
// class oapi::DrawingTool
// ======================================================================
/**
* \brief Base class for various 2-D drawing resources (fonts, pens,
* brushes, etc.)
*/
class OAPIFUNC DrawingTool {
public:
/**
* \brief Drawing tool constructor.
*/
DrawingTool () {}
/**
* \brief Drawing tool destructor.
*/
virtual ~DrawingTool () {}
};
// ======================================================================
// class oapi::Font
// ======================================================================
/**
* \brief A font resource for drawing text. A font has a defined size,
* typeface, slant, weight, etc. Fonts can be selected into a Sketchpad
* and then apply to all subsequent Text calls.
*/
class OAPIFUNC Font : public DrawingTool
{
protected:
/**
* \brief Font constructor.
* \param height cell or character height [pixel]
* \param prop proportional/fixed width flag
* \param face font face name
* \param style font decoration
* \param orientation text orientation [1/10 deg]
* \note If \e height > 0, it represents the font cell height. If height < 0,
* its absolute value represents the character height.
* \note The \e style parameter can be any combination of the \ref Style
* enumeration items.
* \note Overloaded font implementations should understand at least the
* following generic face names: "Fixed" (fixed pitch font), "Sans"
* (sans-serif font, and "Serif" (serif font) and translate them to
* appropriate specific fonts, e.g. "Courier" or "Courier New" for "Fixed",
* "Helvetica" or "Arial" for "Sans", and "Times" or "Times New Roman" for
* "Serif".
* \note If a font name is not recognised, the \e prop value should be
* checked. If prop==true, the default "Sans" font should be used. If
* false, the default "Fixed" font should be used.
*/
Font(int height, bool prop, const char* face, FontStyle style = FontStyle::FONT_NORMAL, int orientation = 0) { }
Font(int height, const char* face, int width = 0, int weight = 400, FontStyle style = FontStyle::FONT_NORMAL, float spacing = 0.0f);
public:
/**
* \brief Font destructor.
*/
virtual ~Font () {}
/**
* \brief Return the GDI handle for the font, if available.
* \return GDI font handle
* \note Non-GDI clients should not overload this method.
*/
virtual HFONT GetGDIFont () const { return 0; }
};
// ======================================================================
// class oapi::Pen
// ======================================================================
/**
* \brief A pen is a resource used for drawing lines and the outlines of
* closed figures such as retangles, ellipses and polygons.
*/
class OAPIFUNC Pen: public DrawingTool {
protected:
/**
* \brief Pen constructor.
* \param style line style (0=invisible, 1=solid, 2=dashed)
* \param width line width [pixel]
* \param col line colour (format: 0xBBGGRR)
*/
Pen (int style, int width, DWORD col) {}
public:
/**
* \brief Pen destructor.
*/
virtual ~Pen () {}
};
// ======================================================================
// class oapi::Brush
// ======================================================================
/**
* \brief A brush is a drawing resource for filling closed figures
* (rectangles, ellipses, polygons).
*/
class OAPIFUNC Brush: public DrawingTool {
protected:
/**
* \brief Brush constructor.
* \param col brush colour (format: 0xBBGGRR)
*/
Brush (DWORD col) {};
public:
/**
* \brief Brush destructor.
*/
virtual ~Brush () {}
};
// ======================================================================
// class oapi::Sketchpad
// ======================================================================
/**
* \brief A %Sketchpad object defines an environment for drawing onto 2-D
* surfaces.
*
* It defines drawing primitives (lines, text, etc.) that can be used for
* preparing MFD surfaces, panel elements or vessel markings.
*
* The drawing object is an abstract class which must be implemented by
* derived graphics clients. An example for a DrawingObject implementation
* is via the Windows GDI (graphics device interface).
*/
class OAPIFUNC Sketchpad
{
public:
enum SkpView {
ORTHO = 0, ///< Default orthographic projection
USER = 1 ///< User defined setup via ViewMatrix() and ProjectionMatrix()
};
enum BlendState {
ALPHABLEND = 0x1, ///< AlphaBlend source.color to destination.color, will retain destination alpha unchanged (if exists).
COPY = 0x2, ///< Copy source color and alpha to destination
COPY_ALPHA = 0x3, ///< Copy source.alpha to destination.alpha, will retain destination color unchanged
COPY_COLOR = 0x4, ///< Copy source.color to destination.color, will retain destination alpha unchanged
FILTER_LINEAR = 0x00, ///< Use "linear" filter in CopyRect and similar functions
FILTER_POINT = 0x10, ///< Use "point" filter in CopyRect and similar functions
FILTER_ANISOTROPIC = 0x20
};
enum RenderParam {
PRM_GAMMA = 1, ///< Enable/Setup Gamma correction
PRM_NOISE = 2 ///< Enable/Setup Noise generation
};
enum MeshFlags {
SMOOTH_SHADE = 0x01, ///< Perform smooth shading (i.e. shallow angles gets darkened)
CULL_NONE = 0x02, ///< Do not perform front/back face culling