-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSFML_Tools.cpp
executable file
·1360 lines (1195 loc) · 36.5 KB
/
SFML_Tools.cpp
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
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <string>
#include <iostream>
//#include<GameObjects!!!!> Theyre coming, they really are!!!
#include <math.h>
#include "SFML_Tools.hpp"
Cursor_commands::Cursor_commands()
{ position.x = 0.00;
position.y = 0.00;
Right_click = false;
Left_click = false;
Middle_click = false;
}
void Cursor_commands::Set_cursor_state(float x, float y, bool right, bool left, bool middle)
{ position.x = x;
position.y = y;
Right_click = right;
Left_click = left;
Middle_click = middle;
}
Cursor_commands::~Cursor_commands()
{
}
// this whole class is horrible, but there doesnt really seem to be any
// alternatives that I can see at the moment. Its just too integral to how the
// engine handles inputs with regards to internal objects
key_commands::key_commands()
{ enter = false;
space = false;
period = false;
left = false;
right = false;
up = false;
down = false;
tilde = false;
v = false;
z= false;
x = false;
t = false;
r = false;
q = false;
w = false;
e = false;
a = false;
s = false;
d = false;
c = false;
l = false;
i = false;
comma = false;
equal = false;
dash = false;
plus = false;
numpad0 = false;
numpad1 = false;
numpad2 = false;
numpad3 = false;
numpad4 = false;
numpad5 = false;
numpad6 = false;
numpad7 = false;
numpad8 = false;
numpad9 = false;
plus = false;
minus = false;
}
// may cause burning in eyes, but it is useful
key_commands::~key_commands()
{
}
// the function for handling which keyboard input was sent //
void Log_keystroke(sf::Keyboard::Key input_event, key_commands * icommands, bool key_down)
{ // simple concept really, just pass whether the key is being held down
// as true or false to the stored value for that key, then if it is true,
// also call the function for that keypress (so things can be handled a bit
// easier in the main cpp file
// to be honest though, it might just be easier to directly store a copy
// of the sf event itself
// but I still want to store info about the keys that are up and those that
// are down
// maybe the best solution here is to create a vector of strings
// (or sf keyboard types, then let the receiving object take a look at them
// and deal with them how it sees fit
// yes, yes, I like that. The boolean wasnt really used anyways
// The Enter or Return key
if(input_event == sf::Keyboard::Return)
{ icommands->enter = key_down;
if(key_down == true)
{ icommands->Enter();
}
}
// Spacebar, space oddity, space pressme
else if(input_event == sf::Keyboard::Space)
{ icommands->space = key_down;
if(key_down == true)
{ icommands->Space();
}
}
// The Arrow Keys
else if(input_event == sf::Keyboard::Up)
{ icommands->up = key_down;
if(key_down == true)
{ icommands->Up();
}
}
else if(input_event == sf::Keyboard::Down)
{ icommands->down = key_down;
if(key_down == true)
{ icommands->Down();
}
}
else if(input_event == sf::Keyboard::Right)
{ icommands->right = key_down;
if(key_down == true)
{ icommands->Right();
}
}
else if(input_event == sf::Keyboard::Left)
{ icommands->left = key_down;
if(key_down == true)
{ icommands->Left();
}
}
// Tab Key
else if(input_event == sf::Keyboard::Tab)
{
}
// Tilde Key
else if(input_event == sf::Keyboard::Tilde)
{ icommands->tilde = key_down;
if(key_down == true)
{ icommands->Tilde();
}
}
// Alphabetical keys A-Z
else if(input_event == sf::Keyboard::A)
{ icommands->a = key_down;
if(key_down == true)
{ icommands->A();
}
}
else if(input_event == sf::Keyboard::B)
{
}
else if(input_event == sf::Keyboard::C)
{ icommands->c = key_down;
if(key_down == true)
{ icommands->C();
}
}
else if(input_event == sf::Keyboard::D)
{ icommands->d = key_down;
if(key_down == true)
{ icommands->D();
}
}
else if(input_event == sf::Keyboard::E)
{ icommands->e = key_down;
if(key_down == true)
{ icommands->E();
}
}
else if(input_event == sf::Keyboard::F)
{ icommands->f = key_down;
if(key_down == true)
{ icommands->F();
}
}
//else if(input_event == sf::Keyboard::G)
//{
//}
else if(input_event == sf::Keyboard::H)
{
}
else if(input_event == sf::Keyboard::I)
{ icommands->i = key_down;
if(key_down == true)
{ icommands->I();
}
}
else if(input_event == sf::Keyboard::J)
{
}
else if(input_event == sf::Keyboard::K)
{
}
else if(input_event == sf::Keyboard::L)
{ icommands->l = key_down;
if(key_down == true)
{ icommands->L();
}
}
else if(input_event == sf::Keyboard::M)
{
}
else if(input_event == sf::Keyboard::N)
{ icommands->n = key_down;
if(key_down == true)
{ icommands->N();
}
}
else if(input_event == sf::Keyboard::O)
{
}
else if(input_event == sf::Keyboard::P)
{
}
else if(input_event == sf::Keyboard::Q)
{ icommands->q = key_down;
if(key_down == true)
{ icommands->Q();
}
}
else if(input_event == sf::Keyboard::R)
{ icommands->r = key_down;
if(key_down == true)
{ icommands->R();
}
}
else if(input_event == sf::Keyboard::S)
{ icommands->s = key_down;
if(key_down == true)
{ icommands->S();
}
}
else if(input_event == sf::Keyboard::T)
{ icommands->t = key_down;
if(key_down == true)
{ icommands->T();
}
}
else if(input_event == sf::Keyboard::U)
{
}
else if(input_event == sf::Keyboard::V)
{ icommands->v = key_down;
if(key_down == true)
{ icommands->V();
}
}
else if(input_event == sf::Keyboard::W)
{ icommands->w = key_down;
if(key_down == true)
{ icommands->W();
}
}
else if(input_event == sf::Keyboard::X)
{ icommands->x = key_down;
if(key_down == true)
{ icommands->X();
}
}
else if(input_event == sf::Keyboard::Y)
{
}
else if(input_event == sf::Keyboard::Z)
{ icommands->z = key_down;
if(key_down == true)
{ icommands->Z();
}
} // Assorted keys, without any real category
else if(input_event == sf::Keyboard::Comma)
{ icommands->comma = key_down;
if(key_down == true)
{ icommands->Comma();
}
}
else if(input_event == sf::Keyboard::Dash)
{ icommands->dash = key_down;
if(key_down == true)
{ icommands->Dash();
}
}
else if(input_event == sf::Keyboard::Delete)
{
}
else if(input_event == sf::Keyboard::Divide)
{
}
else if(input_event == sf::Keyboard::BackSlash)
{
}
else if(input_event == sf::Keyboard::BackSpace)
{
}
else if(input_event == sf::Keyboard::Equal)
{ icommands->equal = key_down;
if(key_down == true)
{ icommands->Equal();
}
}
else if(input_event == sf::Keyboard::Escape)
{
}
else if(input_event == sf::Keyboard::LAlt)
{
}
else if(input_event == sf::Keyboard::LBracket)
{
}
else if(input_event == sf::Keyboard::RBracket)
{
}
else if(input_event == sf::Keyboard::LControl)
{
}
else if(input_event == sf::Keyboard::RControl)
{
}
else if(input_event == sf::Keyboard::LShift)
{
}
else if(input_event == sf::Keyboard::RShift)
{
}
else if(input_event == sf::Keyboard::Menu)
{
}
else if(input_event == sf::Keyboard::Multiply)
{
}
else if(input_event == sf::Keyboard::Period)
{ icommands->period = key_down;
if(key_down == true)
{ icommands->Period();
}
}
else if(input_event == sf::Keyboard::Quote)
{
}
else if(input_event == sf::Keyboard::Slash)
{
} // Pageup/Pagedown
else if(input_event == sf::Keyboard::PageDown)
{
}
else if(input_event == sf::Keyboard::PageUp)
{
} // Windows/OSX/Super key whatever you wanna call it
else if(input_event == sf::Keyboard::LSystem)
{
}
else if(input_event == sf::Keyboard::RSystem)
{
} // Numeric inputs (row beneath the F## keys)
else if(input_event == sf::Keyboard::Num0)
{
}
else if(input_event == sf::Keyboard::Num1)
{
}
else if(input_event == sf::Keyboard::Num2)
{
}
else if(input_event == sf::Keyboard::Num3)
{
}
else if(input_event == sf::Keyboard::Num4)
{
}
else if(input_event == sf::Keyboard::Num5)
{
}
else if(input_event == sf::Keyboard::Num6)
{
}
else if(input_event == sf::Keyboard::Num7)
{
}
else if(input_event == sf::Keyboard::Num8)
{
}
else if(input_event == sf::Keyboard::Num9)
{
} // The Numpad. Beware Vaughan!!!
else if(input_event == sf::Keyboard::Numpad0)
{ icommands->numpad0 = key_down;
if(key_down == true)
{ std::cout << "numpad0 keydown" << std::endl;
icommands->Numpad_0();
}
}
else if(input_event == sf::Keyboard::Numpad1)
{ std::cout << "numpad1 keyevent" << std::endl;
icommands->numpad1 = key_down;
if(key_down == true)
{ icommands->Numpad_1();
}
}
else if(input_event == sf::Keyboard::Numpad2)
{ std::cout << "numpad1 keyevent" << std::endl;
icommands->numpad2 = key_down;
if(key_down == true)
{ icommands->Numpad_2();
}
}
else if(input_event == sf::Keyboard::Numpad3)
{ icommands->numpad3 = key_down;
if(key_down == true)
{ icommands->Numpad_3();
}
}
else if(input_event == sf::Keyboard::Numpad4)
{ icommands->numpad4 = key_down;
if(key_down == true)
{ icommands->Numpad_4();
}
}
else if(input_event == sf::Keyboard::Numpad5)
{ icommands->numpad5 = key_down;
if(key_down == true)
{ icommands->Numpad_5();
}
}
else if(input_event == sf::Keyboard::Numpad6)
{ icommands->numpad6 = key_down;
if(key_down == true)
{ icommands->Numpad_6();
}
}
else if(input_event == sf::Keyboard::Numpad7)
{ icommands->numpad7 = key_down;
if(key_down == true)
{ icommands->Numpad_7();
}
}
else if(input_event == sf::Keyboard::Numpad8)
{ icommands->numpad8 = key_down;
if(key_down == true)
{ icommands->Numpad_8();
}
}
else if(input_event == sf::Keyboard::Numpad9)
{ icommands->numpad9 = key_down;
if(key_down == true)
{ icommands->Numpad_9();
}
}
else if(input_event == sf::Keyboard::Add)
{ icommands->plus = key_down;
if(key_down == true)
{ icommands->Plus();
}
} // must add minus
else if(input_event == sf::Keyboard::Subtract)
{ icommands->minus = key_down;
if(key_down == true)
{ icommands->Minus();
}
}
}
// SFML_Window Utility class ///////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// a really important part of the engine, because it stores data used throughout
// basically just a plain old wrapper for sf::RenderWindow, but it does store
// important info about the way that the window is related to the in game
// universe
SFML_Window::SFML_Window(std::string title, unsigned int h, unsigned int w)
{ Title = title;
Height = h;
Width = w;
Aperture_height = h;
Aperture_width = w;
// no real rhyme or reason behind how big the aperture should be at start
// so we just give it the same as the window itself
// this was the reason why everything appeared 10x too big
Set_origin();
// make sure it has a value
window = new sf::RenderWindow(sf::VideoMode(w, h), Title);
// set up our RenderWindow
window->setSize(sf::Vector2u(w, h));
// and size it, but.. we dont need to here, cause the videomode already
// did it.
// I think this can be removed
window->setTitle(Title);
// again think its redundant, but its a rarely used constructor, so not too
// concerning really
}
SFML_Window::SFML_Window(std::string title, unsigned int h, unsigned int w, long double initial_rotation)
{ Title = title;
Height = h;
Width = w;
Aperture_height = h;
Aperture_width = w;
// no real rhyme or reason behind how big the aperture should be at start
// so we just give it the same as the window itself
// this was the reason why everything appeared 10x too big
Set_origin();
// make sure it has a value
window = new sf::RenderWindow(sf::VideoMode(w, h), Title);
// set up our RenderWindow
window->setSize(sf::Vector2u(w, h));
// and size it, but.. we dont need to here, cause the videomode already
// did it.
// I think this can be removed
window->setTitle(Title);
// again think its redundant, but its a rarely used constructor, so not too
// concerning really
this->Set_aperture_rotation(initial_rotation);
}
void SFML_Window::Set_origin()
{ origin.x = 0;
origin.y = 0;
// If we dont know, we just say (0,0)
}
void SFML_Window::Set_origin(long double x, long double y)
{ origin.x = x;
origin.y = y;
// set our VectorVictor2 to the right value
}
void SFML_Window::Set_aperture_rotation(long double new_rotation)
{ Aperture_rotation = new_rotation;
}
void SFML_Window::Set_aperture_dimensions(long long unsigned int ap_w, long long unsigned int ap_h)
{ Aperture_width = ap_w;
Aperture_height = ap_h;
// same deal, now just for the aperture dimensions
}
bool SFML_Window::Intersection(VectorVictor::Vector2 center, long double radius, long double cam_scale)
{ // this *works* for now, but I very strongly am considering just redoing it
// as a circle with radius of the sum of the squares of the window axis.
// This is efficient for small camera views, but could prove really bad at
// large camera views...
// I dunno, but the current thing is a mess, cant just leave it like this
center -= this->origin;
// get the relative offset of the center of the circle from the window
// origin
center.Rotate_vector(-(this->Aperture_rotation));
// rotate things around so that the window is straight up and down relative
// to our coordinate system
center.y *= -1;
// now case statements, depending on the dimensions of the center vector
// at this point
if(center.x < 0)
{ if(center.x < -radius)
{ return false;
}
else
{ if((center.y >= 0)&&(center.y <= Aperture_height))
{ return true;
}
else
{ // the long method for checking if we intersect the edge anyways
// ehh screw it, why not do it right
if(center.y > this->Aperture_height)
{ center.y -= this->Aperture_height;
}
long double r_squared = (center.y*center.y) + (center.x*center.x);
if(r_squared <= (radius*radius))
{ // compare the squares so that we dont have to invoke
// pythagoras
return true;
}
else
{ return false;
}
}
}
}
else if((center.x >= 0)&&(center.x <= this->Aperture_width))
{ // the middle case, maybe easier
if(center.y > 0)
{ long double v_offset = center.y - this->Aperture_height;
if(v_offset > radius)
{ return false;
}
else
{ return true;
}
}
else
{ // center.y is negative, so the center of the circle is above the
// box
if(center.y > radius)
{ return false;
}
else
{ return true;
}
}
}
else
{ // positive and beyond the edge of the aperture
if(center.x > (radius + this->Aperture_width))
{ return false;
// too far away by definition, so false
}
else
{ // we already know from the above middle section check that this
// case must have an origin that is less than radius from the
// aperture width along the x axis
if((center.y >= 0)&&(center.y <= this->Aperture_height))
{ // identical check to the negative side of the box
return true;
}
else
{ // the long method for checking if we intersect the edge anyways
// ehh screw it, why not do it right
long double dx = center.x - this->Aperture_width;
if(center.y > this->Aperture_height)
{ center.y -= this->Aperture_height;
}
long double r_squared = (center.y*center.y) + (dx*dx);
if(r_squared <= (radius*radius))
{ // compare the squares so that we dont have to invoke
// pythagoras
return true;
}
else
{ return false;
}
}
}
}
// that was a beast
// heres hoping its more efficient than it looks...
}
bool SFML_Window::Window_intersection(sf::Vector2f window_point)
{ if((window_point.x >= 0)&&(window_point.y >= 0))
{ // we check and make sure that our point has at least positive
// coordinate values
if((window_point.x <= (float)this->Width)&&(window_point.y <= (float)this->Height))
{ // and we check that the point is within the width and height of the
// window in pixels away from the (0,0)
return true;
}
else
{ return false;
}
}
else
{ return false;
}
}
bool SFML_Window::Intersection(VectorVictor::Vector2 point, long double cam_scale)
{ // implicitly in camera view based on the double being passed
sf::Vector2f window_offset = Get_window_coordinates(point, this,cam_scale);
// get the relative offset of the given point relative to the window given
// the stuff we passed
return this->Window_intersection(window_offset);
// and return whatever Window_intersection thinks of that...
}
bool SFML_Window::Intersection(VectorVictor::Vector2 point, int zoom_factor)
{ // implicitly in map view based on the int being passed
sf::Vector2f window_offset = Get_window_coordinates(point, this, zoom_factor);
std::cout << "Window coordinates of point: " << window_offset.x << "," << window_offset.y << std::endl;
// get the relative offset of the given point relative to the window given
// the stuff we passed
return this->Window_intersection(window_offset);
// and return whatever Window_intersection thinks of that...
}
SFML_Window::~SFML_Window()
{ delete window;
// cant forget this ;D
}
// Utility functions to transform between window relative coordinates to ///////
// ignition universe coordinates and back again ////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
sf::Vector2f Get_window_coordinates(VectorVictor::Vector2 sim_point, SFML_Window * iwindow, int map_scale)
{ VectorVictor::Vector2 camera_origin(iwindow->origin.Get_x(), iwindow->origin.Get_y());
sim_point -= camera_origin;
// get the relative offset from the camera origin to
// the point in simulation as a VV2
sim_point.Rotate_vector(-iwindow->Aperture_rotation);
// rotate the vector around into the reference frame of
// the window box, now straight up and down relative to
// the global coordinate frame axes
sim_point.y *= -1;
// flip the y axis because SFML does things that way
sim_point.y *= pow(0.1, (map_scale));
sim_point.x *= pow(0.1, (map_scale));
// scale back the length of the vector by 10^map_scale
// so that its dimensions are in pixels instead of
// meters
sf::Vector2f camera_offset(sim_point.x, sim_point.y);
// put the vector into an sfml 2f type so we can return
// it properly
return camera_offset;
}
sf::Vector2f Get_window_coordinates(VectorVictor::Vector2 sim_point, SFML_Window * iwindow, long double cam_scale)
{
VectorVictor::Vector2 camera_origin(iwindow->origin.Get_x(), iwindow->origin.Get_y());
sim_point -= camera_origin;
// get the relative offset of the point from the window
// origin
sim_point.Rotate_vector(-iwindow->Aperture_rotation);
// rotate the vector so that the window is straight up and down
sim_point.y *= -1;
// flip the y axis so that SFML is happy
sim_point.x *= (10.00000000/(long double)cam_scale);
sim_point.y *= (10.00000000/(long double)cam_scale);
// of course! Because at cam_scale = 1 (or default), the window has
// dimensions 10x smaller in meters than its actual window dimensions
// in pixels, ie dimensions of 102.4 x 60.9 meters for a window with
// size of 1024 x 609. So thats why we have to scale it up by 10x
sf::Vector2f camera_offset(sim_point.x, sim_point.y);
// convert into an sf 2f for return
return camera_offset;
}
VectorVictor::Vector2 Get_simulation_coordinates(sf::Vector2f window_point, SFML_Window * iwindow, int map_scale)
{ VectorVictor::Vector2 sim_point(window_point.x, window_point.y);
// so we start with our relative offset of the point in the window
// in pixels
sim_point.y *= pow((long double)10, (map_scale));
sim_point.x *= pow((long double)10, (map_scale));
// and we scale it up by the zoom factor so we get the relative offset
// of the point from the camera origin in universe coordinates
sim_point.y *= -1;
// we flip the y axis, since the SFML coordinates will be mirrored
// vertically compared to the VV2 coordinate system that the engine
// uses
sim_point.Rotate_vector(iwindow->Aperture_rotation);
sim_point += iwindow->origin;
// we add the main windows origin point to transform the point to the sim
// sessions global origin point (0,0)
return sim_point;
// actually wasnt that complex I guess, just the previous operations in
// reverse
}
VectorVictor::Vector2 Get_simulation_coordinates(sf::Vector2f window_point, SFML_Window * iwindow, double cam_scale)
{ VectorVictor::Vector2 sim_point(window_point.x, window_point.y);
sim_point.x /= (10.00000000/(long double)cam_scale);
sim_point.y /= (10.00000000/(long double)cam_scale);
// here we now shrink it back, since the pixel coordinates are bigger
// than the actual universe coordinates by a factor of 10/cam_scale
sim_point.y *= -1;
// again, flip the y axis because SFML has down as positive y, for reasons
// that are its own
sim_point.Rotate_vector(iwindow->Aperture_rotation);
// rotate the vector back into the correct orientation of the window
sim_point += iwindow->origin;
// we add the main windows origin point to transform the point to the sim
// sessions global origin point (0,0)
return sim_point;
// and we return the vector point now in universe coordinates
}
// gonna probably need to write at least one of these from scratch methinks
// Ignition Drawables //////////////////////////////////////////////////////////
// wrapper classes for stuff that needs to be drawn to the window like text ////
// displays & other infographics that the vessel instance draws as ui //////////
// displays and things like that ///////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
void Ignition_drawable::Draw_element(SFML_Window * iwindow)
{ Talkback("Bad call to Ignition_drawable::Draw_element(SFML_Window * iwindow)");
}
void Ignition_drawable::Center_element()
{ Talkback("Ignition_drawable::Center_element()");
}
// Ignition text type //////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Ignition_text::Ignition_text(std::string text_font, sf::Vector2f initial_position, std::string initial_text, sf::Color initial_colour, unsigned int character_size, bool center_origin)
{ this->Init_object(text_font, initial_position, initial_text, initial_colour, character_size, center_origin);
}
Ignition_text::Ignition_text(sf::Font text_font, sf::Vector2f initial_position, std::string initial_text, sf::Color initial_colour, unsigned int character_size, bool center_origin)
{ this->Init_object(text_font, initial_position, initial_text, initial_colour, character_size, center_origin);
}
Ignition_text::Ignition_text()
{ // uhhh.
// just try not to call this very often
}
bool Ignition_text::Init_object(std::string text_font, sf::Vector2f initial_position, std::string initial_text, sf::Color initial_colour, unsigned int character_size, bool center_origin)
{ font.loadFromFile(text_font);
text.setFont(font);
text.setPosition(initial_position);
text.setString(initial_text);
text.setColor(initial_colour);
text.setCharacterSize(character_size);
if(center_origin == true)
{ this->Center_element();
}
return true;
// just to let everybody know that nothing went wrong
}
bool Ignition_text::Init_object(sf::Font text_font, sf::Vector2f initial_position, std::string initial_text, sf::Color initial_colour, unsigned int character_size, bool center_origin)
{ font = text_font;
// hopefully this works, we might have to pass by reference if not
text.setFont(font);
text.setPosition(initial_position);
text.setString(initial_text);
text.setColor(initial_colour);
text.setCharacterSize(character_size);
if(center_origin == true)
{ this->Center_element();
}
return true;
// just to let everybody know that nothing went wrong
}
void Ignition_text::Set_element(std::string text_string)
{ text.setString(text_string);
}
void Ignition_text::Set_element(sf::Vector2f new_position)
{ text.setPosition(new_position);
}
void Ignition_text::Set_element(sf::Color new_colour)
{ text.setColor(new_colour);
}
void Ignition_text::Set_element(unsigned int character_size)
{ text.setCharacterSize(character_size);
}
void Ignition_text::Set_element(std::string text_string, sf::Vector2f new_position)
{ this->Set_element(text_string);
this->Set_element(new_position);
}
void Ignition_text::Set_element(std::string text_string, sf::Vector2f new_position, sf::Color new_colour)
{ this->Set_element(text_string);
this->Set_element(new_position);
this->Set_element(new_colour);
}
void Ignition_text::Set_element(std::string text_string, sf::Color new_colour)
{ this->Set_element(text_string);
this->Set_element(new_colour);
}
void Ignition_text::Set_element(sf::Vector2f new_position, sf::Color new_colour)
{ this->Set_element(new_position);
this->Set_element(new_colour);
}
void Ignition_text::Draw_element(SFML_Window * iwindow)
{ iwindow->window->draw(text);
}
void Ignition_text::Center_element()
{ if(Centered == false)
{ // do some centering
// not sure how with sf::Text really
// I mean what are the dimensions of the text strip?
// important question to get answered
Centered = true;
}
}
Ignition_text::~Ignition_text()
{
}
// Ignition Circle /////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Ignition_circle::Ignition_circle(sf::Vector2f initial_position, sf::Color initial_colour, float initial_radius, bool center_origin)
{ this->Init_object(initial_position, initial_colour, initial_radius, center_origin);
}
Ignition_circle::Ignition_circle()
{
}
bool Ignition_circle::Init_object(sf::Vector2f initial_position, sf::Color initial_colour, float initial_radius, bool center_origin)
{ circle_shape.setPosition(initial_position);
circle_shape.setFillColor(initial_colour);
circle_shape.setRadius(initial_radius);
if(center_origin == true)
{ this->Center_element();
}
return true;
}
void Ignition_circle::Set_element(float new_radius)
{ circle_shape.setRadius(new_radius);
}
void Ignition_circle::Set_element(sf::Vector2f new_position)
{ circle_shape.setPosition(new_position);
}
void Ignition_circle::Set_element(sf::Color new_colour)
{ circle_shape.setFillColor(new_colour);
}
void Ignition_circle::Set_element(float new_radius, sf::Vector2f new_position)
{ this->Set_element(new_radius);
this->Set_element(new_position);
}
void Ignition_circle::Set_element(float new_radius, sf::Vector2f new_position, sf::Color new_colour)
{ this->Set_element(new_radius);
this->Set_element(new_position);
this->Set_element(new_colour);
}
void Ignition_circle::Set_element(float new_radius, sf::Color new_colour)
{ this->Set_element(new_radius);
this->Set_element(new_colour);
}
void Ignition_circle::Set_element(sf::Vector2f new_position, sf::Color new_colour)
{ this->Set_element(new_position);
this->Set_element(new_colour);
}
void Ignition_circle::Draw_element(SFML_Window * iwindow)
{ iwindow->window->draw(circle_shape);
}
void Ignition_circle::Center_element()
{ if(Centered == false)
{ // do some centering stuffz
circle_shape.setOrigin(sf::Vector2f(circle_shape.getRadius(), circle_shape.getRadius()));
Centered = true;
}
}
Ignition_circle::~Ignition_circle()
{ // no pointers, no problems
}