Rendering complete

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
master
sigonasr2 2 years ago
parent 7ca1d96bf1
commit bc094bebdc
  1. BIN
      C++ProjectTemplate
  2. 137
      input
  3. 174
      main.cpp

Binary file not shown.

137
input

@ -0,0 +1,137 @@
476,63 -> 481,63
478,93 -> 478,87 -> 478,93 -> 480,93 -> 480,90 -> 480,93 -> 482,93 -> 482,83 -> 482,93 -> 484,93 -> 484,88 -> 484,93 -> 486,93 -> 486,83 -> 486,93 -> 488,93 -> 488,90 -> 488,93 -> 490,93 -> 490,87 -> 490,93
489,96 -> 489,98 -> 482,98 -> 482,101 -> 496,101 -> 496,98 -> 494,98 -> 494,96
489,96 -> 489,98 -> 482,98 -> 482,101 -> 496,101 -> 496,98 -> 494,98 -> 494,96
478,93 -> 478,87 -> 478,93 -> 480,93 -> 480,90 -> 480,93 -> 482,93 -> 482,83 -> 482,93 -> 484,93 -> 484,88 -> 484,93 -> 486,93 -> 486,83 -> 486,93 -> 488,93 -> 488,90 -> 488,93 -> 490,93 -> 490,87 -> 490,93
500,146 -> 505,146
478,93 -> 478,87 -> 478,93 -> 480,93 -> 480,90 -> 480,93 -> 482,93 -> 482,83 -> 482,93 -> 484,93 -> 484,88 -> 484,93 -> 486,93 -> 486,83 -> 486,93 -> 488,93 -> 488,90 -> 488,93 -> 490,93 -> 490,87 -> 490,93
474,50 -> 474,42 -> 474,50 -> 476,50 -> 476,42 -> 476,50 -> 478,50 -> 478,46 -> 478,50 -> 480,50 -> 480,45 -> 480,50 -> 482,50 -> 482,44 -> 482,50
510,165 -> 510,155 -> 510,165 -> 512,165 -> 512,160 -> 512,165 -> 514,165 -> 514,161 -> 514,165 -> 516,165 -> 516,158 -> 516,165 -> 518,165 -> 518,157 -> 518,165
487,29 -> 487,33 -> 480,33 -> 480,37 -> 499,37 -> 499,33 -> 491,33 -> 491,29
487,29 -> 487,33 -> 480,33 -> 480,37 -> 499,37 -> 499,33 -> 491,33 -> 491,29
498,68 -> 502,68
495,104 -> 495,108 -> 488,108 -> 488,112 -> 500,112 -> 500,108 -> 498,108 -> 498,104
510,165 -> 510,155 -> 510,165 -> 512,165 -> 512,160 -> 512,165 -> 514,165 -> 514,161 -> 514,165 -> 516,165 -> 516,158 -> 516,165 -> 518,165 -> 518,157 -> 518,165
487,29 -> 487,33 -> 480,33 -> 480,37 -> 499,37 -> 499,33 -> 491,33 -> 491,29
494,65 -> 499,65
495,71 -> 499,71
474,50 -> 474,42 -> 474,50 -> 476,50 -> 476,42 -> 476,50 -> 478,50 -> 478,46 -> 478,50 -> 480,50 -> 480,45 -> 480,50 -> 482,50 -> 482,44 -> 482,50
510,165 -> 510,155 -> 510,165 -> 512,165 -> 512,160 -> 512,165 -> 514,165 -> 514,161 -> 514,165 -> 516,165 -> 516,158 -> 516,165 -> 518,165 -> 518,157 -> 518,165
496,125 -> 496,117 -> 496,125 -> 498,125 -> 498,119 -> 498,125 -> 500,125 -> 500,120 -> 500,125 -> 502,125 -> 502,118 -> 502,125 -> 504,125 -> 504,124 -> 504,125
487,65 -> 492,65
496,125 -> 496,117 -> 496,125 -> 498,125 -> 498,119 -> 498,125 -> 500,125 -> 500,120 -> 500,125 -> 502,125 -> 502,118 -> 502,125 -> 504,125 -> 504,124 -> 504,125
506,142 -> 511,142
510,165 -> 510,155 -> 510,165 -> 512,165 -> 512,160 -> 512,165 -> 514,165 -> 514,161 -> 514,165 -> 516,165 -> 516,158 -> 516,165 -> 518,165 -> 518,157 -> 518,165
483,63 -> 488,63
478,93 -> 478,87 -> 478,93 -> 480,93 -> 480,90 -> 480,93 -> 482,93 -> 482,83 -> 482,93 -> 484,93 -> 484,88 -> 484,93 -> 486,93 -> 486,83 -> 486,93 -> 488,93 -> 488,90 -> 488,93 -> 490,93 -> 490,87 -> 490,93
517,139 -> 522,139
495,77 -> 499,77
489,96 -> 489,98 -> 482,98 -> 482,101 -> 496,101 -> 496,98 -> 494,98 -> 494,96
498,74 -> 502,74
478,93 -> 478,87 -> 478,93 -> 480,93 -> 480,90 -> 480,93 -> 482,93 -> 482,83 -> 482,93 -> 484,93 -> 484,88 -> 484,93 -> 486,93 -> 486,83 -> 486,93 -> 488,93 -> 488,90 -> 488,93 -> 490,93 -> 490,87 -> 490,93
504,74 -> 508,74
478,93 -> 478,87 -> 478,93 -> 480,93 -> 480,90 -> 480,93 -> 482,93 -> 482,83 -> 482,93 -> 484,93 -> 484,88 -> 484,93 -> 486,93 -> 486,83 -> 486,93 -> 488,93 -> 488,90 -> 488,93 -> 490,93 -> 490,87 -> 490,93
486,80 -> 490,80
497,13 -> 497,17 -> 495,17 -> 495,21 -> 509,21 -> 509,17 -> 501,17 -> 501,13
510,165 -> 510,155 -> 510,165 -> 512,165 -> 512,160 -> 512,165 -> 514,165 -> 514,161 -> 514,165 -> 516,165 -> 516,158 -> 516,165 -> 518,165 -> 518,157 -> 518,165
474,50 -> 474,42 -> 474,50 -> 476,50 -> 476,42 -> 476,50 -> 478,50 -> 478,46 -> 478,50 -> 480,50 -> 480,45 -> 480,50 -> 482,50 -> 482,44 -> 482,50
510,139 -> 515,139
489,96 -> 489,98 -> 482,98 -> 482,101 -> 496,101 -> 496,98 -> 494,98 -> 494,96
496,125 -> 496,117 -> 496,125 -> 498,125 -> 498,119 -> 498,125 -> 500,125 -> 500,120 -> 500,125 -> 502,125 -> 502,118 -> 502,125 -> 504,125 -> 504,124 -> 504,125
490,63 -> 495,63
516,151 -> 516,152 -> 527,152 -> 527,151
474,50 -> 474,42 -> 474,50 -> 476,50 -> 476,42 -> 476,50 -> 478,50 -> 478,46 -> 478,50 -> 480,50 -> 480,45 -> 480,50 -> 482,50 -> 482,44 -> 482,50
513,136 -> 518,136
489,96 -> 489,98 -> 482,98 -> 482,101 -> 496,101 -> 496,98 -> 494,98 -> 494,96
474,50 -> 474,42 -> 474,50 -> 476,50 -> 476,42 -> 476,50 -> 478,50 -> 478,46 -> 478,50 -> 480,50 -> 480,45 -> 480,50 -> 482,50 -> 482,44 -> 482,50
492,74 -> 496,74
489,96 -> 489,98 -> 482,98 -> 482,101 -> 496,101 -> 496,98 -> 494,98 -> 494,96
478,93 -> 478,87 -> 478,93 -> 480,93 -> 480,90 -> 480,93 -> 482,93 -> 482,83 -> 482,93 -> 484,93 -> 484,88 -> 484,93 -> 486,93 -> 486,83 -> 486,93 -> 488,93 -> 488,90 -> 488,93 -> 490,93 -> 490,87 -> 490,93
492,80 -> 496,80
497,13 -> 497,17 -> 495,17 -> 495,21 -> 509,21 -> 509,17 -> 501,17 -> 501,13
487,29 -> 487,33 -> 480,33 -> 480,37 -> 499,37 -> 499,33 -> 491,33 -> 491,29
474,50 -> 474,42 -> 474,50 -> 476,50 -> 476,42 -> 476,50 -> 478,50 -> 478,46 -> 478,50 -> 480,50 -> 480,45 -> 480,50 -> 482,50 -> 482,44 -> 482,50
478,93 -> 478,87 -> 478,93 -> 480,93 -> 480,90 -> 480,93 -> 482,93 -> 482,83 -> 482,93 -> 484,93 -> 484,88 -> 484,93 -> 486,93 -> 486,83 -> 486,93 -> 488,93 -> 488,90 -> 488,93 -> 490,93 -> 490,87 -> 490,93
474,55 -> 474,56 -> 484,56
482,59 -> 487,59
480,65 -> 485,65
510,165 -> 510,155 -> 510,165 -> 512,165 -> 512,160 -> 512,165 -> 514,165 -> 514,161 -> 514,165 -> 516,165 -> 516,158 -> 516,165 -> 518,165 -> 518,157 -> 518,165
487,29 -> 487,33 -> 480,33 -> 480,37 -> 499,37 -> 499,33 -> 491,33 -> 491,29
473,65 -> 478,65
495,104 -> 495,108 -> 488,108 -> 488,112 -> 500,112 -> 500,108 -> 498,108 -> 498,104
506,136 -> 511,136
498,80 -> 502,80
496,125 -> 496,117 -> 496,125 -> 498,125 -> 498,119 -> 498,125 -> 500,125 -> 500,120 -> 500,125 -> 502,125 -> 502,118 -> 502,125 -> 504,125 -> 504,124 -> 504,125
496,125 -> 496,117 -> 496,125 -> 498,125 -> 498,119 -> 498,125 -> 500,125 -> 500,120 -> 500,125 -> 502,125 -> 502,118 -> 502,125 -> 504,125 -> 504,124 -> 504,125
496,125 -> 496,117 -> 496,125 -> 498,125 -> 498,119 -> 498,125 -> 500,125 -> 500,120 -> 500,125 -> 502,125 -> 502,118 -> 502,125 -> 504,125 -> 504,124 -> 504,125
510,165 -> 510,155 -> 510,165 -> 512,165 -> 512,160 -> 512,165 -> 514,165 -> 514,161 -> 514,165 -> 516,165 -> 516,158 -> 516,165 -> 518,165 -> 518,157 -> 518,165
510,165 -> 510,155 -> 510,165 -> 512,165 -> 512,160 -> 512,165 -> 514,165 -> 514,161 -> 514,165 -> 516,165 -> 516,158 -> 516,165 -> 518,165 -> 518,157 -> 518,165
478,93 -> 478,87 -> 478,93 -> 480,93 -> 480,90 -> 480,93 -> 482,93 -> 482,83 -> 482,93 -> 484,93 -> 484,88 -> 484,93 -> 486,93 -> 486,83 -> 486,93 -> 488,93 -> 488,90 -> 488,93 -> 490,93 -> 490,87 -> 490,93
478,93 -> 478,87 -> 478,93 -> 480,93 -> 480,90 -> 480,93 -> 482,93 -> 482,83 -> 482,93 -> 484,93 -> 484,88 -> 484,93 -> 486,93 -> 486,83 -> 486,93 -> 488,93 -> 488,90 -> 488,93 -> 490,93 -> 490,87 -> 490,93
516,151 -> 516,152 -> 527,152 -> 527,151
478,93 -> 478,87 -> 478,93 -> 480,93 -> 480,90 -> 480,93 -> 482,93 -> 482,83 -> 482,93 -> 484,93 -> 484,88 -> 484,93 -> 486,93 -> 486,83 -> 486,93 -> 488,93 -> 488,90 -> 488,93 -> 490,93 -> 490,87 -> 490,93
474,50 -> 474,42 -> 474,50 -> 476,50 -> 476,42 -> 476,50 -> 478,50 -> 478,46 -> 478,50 -> 480,50 -> 480,45 -> 480,50 -> 482,50 -> 482,44 -> 482,50
510,144 -> 515,144
478,93 -> 478,87 -> 478,93 -> 480,93 -> 480,90 -> 480,93 -> 482,93 -> 482,83 -> 482,93 -> 484,93 -> 484,88 -> 484,93 -> 486,93 -> 486,83 -> 486,93 -> 488,93 -> 488,90 -> 488,93 -> 490,93 -> 490,87 -> 490,93
495,104 -> 495,108 -> 488,108 -> 488,112 -> 500,112 -> 500,108 -> 498,108 -> 498,104
514,146 -> 519,146
478,93 -> 478,87 -> 478,93 -> 480,93 -> 480,90 -> 480,93 -> 482,93 -> 482,83 -> 482,93 -> 484,93 -> 484,88 -> 484,93 -> 486,93 -> 486,83 -> 486,93 -> 488,93 -> 488,90 -> 488,93 -> 490,93 -> 490,87 -> 490,93
489,25 -> 489,26 -> 504,26 -> 504,25
474,50 -> 474,42 -> 474,50 -> 476,50 -> 476,42 -> 476,50 -> 478,50 -> 478,46 -> 478,50 -> 480,50 -> 480,45 -> 480,50 -> 482,50 -> 482,44 -> 482,50
496,125 -> 496,117 -> 496,125 -> 498,125 -> 498,119 -> 498,125 -> 500,125 -> 500,120 -> 500,125 -> 502,125 -> 502,118 -> 502,125 -> 504,125 -> 504,124 -> 504,125
474,50 -> 474,42 -> 474,50 -> 476,50 -> 476,42 -> 476,50 -> 478,50 -> 478,46 -> 478,50 -> 480,50 -> 480,45 -> 480,50 -> 482,50 -> 482,44 -> 482,50
495,104 -> 495,108 -> 488,108 -> 488,112 -> 500,112 -> 500,108 -> 498,108 -> 498,104
501,71 -> 505,71
497,13 -> 497,17 -> 495,17 -> 495,21 -> 509,21 -> 509,17 -> 501,17 -> 501,13
495,104 -> 495,108 -> 488,108 -> 488,112 -> 500,112 -> 500,108 -> 498,108 -> 498,104
496,125 -> 496,117 -> 496,125 -> 498,125 -> 498,119 -> 498,125 -> 500,125 -> 500,120 -> 500,125 -> 502,125 -> 502,118 -> 502,125 -> 504,125 -> 504,124 -> 504,125
495,104 -> 495,108 -> 488,108 -> 488,112 -> 500,112 -> 500,108 -> 498,108 -> 498,104
474,55 -> 474,56 -> 484,56
489,25 -> 489,26 -> 504,26 -> 504,25
510,165 -> 510,155 -> 510,165 -> 512,165 -> 512,160 -> 512,165 -> 514,165 -> 514,161 -> 514,165 -> 516,165 -> 516,158 -> 516,165 -> 518,165 -> 518,157 -> 518,165
496,125 -> 496,117 -> 496,125 -> 498,125 -> 498,119 -> 498,125 -> 500,125 -> 500,120 -> 500,125 -> 502,125 -> 502,118 -> 502,125 -> 504,125 -> 504,124 -> 504,125
478,93 -> 478,87 -> 478,93 -> 480,93 -> 480,90 -> 480,93 -> 482,93 -> 482,83 -> 482,93 -> 484,93 -> 484,88 -> 484,93 -> 486,93 -> 486,83 -> 486,93 -> 488,93 -> 488,90 -> 488,93 -> 490,93 -> 490,87 -> 490,93
500,129 -> 500,130 -> 511,130
495,104 -> 495,108 -> 488,108 -> 488,112 -> 500,112 -> 500,108 -> 498,108 -> 498,104
474,50 -> 474,42 -> 474,50 -> 476,50 -> 476,42 -> 476,50 -> 478,50 -> 478,46 -> 478,50 -> 480,50 -> 480,45 -> 480,50 -> 482,50 -> 482,44 -> 482,50
496,125 -> 496,117 -> 496,125 -> 498,125 -> 498,119 -> 498,125 -> 500,125 -> 500,120 -> 500,125 -> 502,125 -> 502,118 -> 502,125 -> 504,125 -> 504,124 -> 504,125
509,133 -> 514,133
478,93 -> 478,87 -> 478,93 -> 480,93 -> 480,90 -> 480,93 -> 482,93 -> 482,83 -> 482,93 -> 484,93 -> 484,88 -> 484,93 -> 486,93 -> 486,83 -> 486,93 -> 488,93 -> 488,90 -> 488,93 -> 490,93 -> 490,87 -> 490,93
496,125 -> 496,117 -> 496,125 -> 498,125 -> 498,119 -> 498,125 -> 500,125 -> 500,120 -> 500,125 -> 502,125 -> 502,118 -> 502,125 -> 504,125 -> 504,124 -> 504,125
510,165 -> 510,155 -> 510,165 -> 512,165 -> 512,160 -> 512,165 -> 514,165 -> 514,161 -> 514,165 -> 516,165 -> 516,158 -> 516,165 -> 518,165 -> 518,157 -> 518,165
500,129 -> 500,130 -> 511,130
474,50 -> 474,42 -> 474,50 -> 476,50 -> 476,42 -> 476,50 -> 478,50 -> 478,46 -> 478,50 -> 480,50 -> 480,45 -> 480,50 -> 482,50 -> 482,44 -> 482,50
489,96 -> 489,98 -> 482,98 -> 482,101 -> 496,101 -> 496,98 -> 494,98 -> 494,96
516,151 -> 516,152 -> 527,152 -> 527,151
497,13 -> 497,17 -> 495,17 -> 495,21 -> 509,21 -> 509,17 -> 501,17 -> 501,13
503,139 -> 508,139
479,61 -> 484,61
503,144 -> 508,144
478,93 -> 478,87 -> 478,93 -> 480,93 -> 480,90 -> 480,93 -> 482,93 -> 482,83 -> 482,93 -> 484,93 -> 484,88 -> 484,93 -> 486,93 -> 486,83 -> 486,93 -> 488,93 -> 488,90 -> 488,93 -> 490,93 -> 490,87 -> 490,93
507,77 -> 511,77
487,29 -> 487,33 -> 480,33 -> 480,37 -> 499,37 -> 499,33 -> 491,33 -> 491,29
489,25 -> 489,26 -> 504,26 -> 504,25
510,165 -> 510,155 -> 510,165 -> 512,165 -> 512,160 -> 512,165 -> 514,165 -> 514,161 -> 514,165 -> 516,165 -> 516,158 -> 516,165 -> 518,165 -> 518,157 -> 518,165
507,146 -> 512,146
496,125 -> 496,117 -> 496,125 -> 498,125 -> 498,119 -> 498,125 -> 500,125 -> 500,120 -> 500,125 -> 502,125 -> 502,118 -> 502,125 -> 504,125 -> 504,124 -> 504,125
510,165 -> 510,155 -> 510,165 -> 512,165 -> 512,160 -> 512,165 -> 514,165 -> 514,161 -> 514,165 -> 516,165 -> 516,158 -> 516,165 -> 518,165 -> 518,157 -> 518,165
478,93 -> 478,87 -> 478,93 -> 480,93 -> 480,90 -> 480,93 -> 482,93 -> 482,83 -> 482,93 -> 484,93 -> 484,88 -> 484,93 -> 486,93 -> 486,83 -> 486,93 -> 488,93 -> 488,90 -> 488,93 -> 490,93 -> 490,87 -> 490,93
474,50 -> 474,42 -> 474,50 -> 476,50 -> 476,42 -> 476,50 -> 478,50 -> 478,46 -> 478,50 -> 480,50 -> 480,45 -> 480,50 -> 482,50 -> 482,44 -> 482,50
510,165 -> 510,155 -> 510,165 -> 512,165 -> 512,160 -> 512,165 -> 514,165 -> 514,161 -> 514,165 -> 516,165 -> 516,158 -> 516,165 -> 518,165 -> 518,157 -> 518,165
510,80 -> 514,80
478,93 -> 478,87 -> 478,93 -> 480,93 -> 480,90 -> 480,93 -> 482,93 -> 482,83 -> 482,93 -> 484,93 -> 484,88 -> 484,93 -> 486,93 -> 486,83 -> 486,93 -> 488,93 -> 488,90 -> 488,93 -> 490,93 -> 490,87 -> 490,93
486,61 -> 491,61
497,13 -> 497,17 -> 495,17 -> 495,21 -> 509,21 -> 509,17 -> 501,17 -> 501,13
501,77 -> 505,77
474,50 -> 474,42 -> 474,50 -> 476,50 -> 476,42 -> 476,50 -> 478,50 -> 478,46 -> 478,50 -> 480,50 -> 480,45 -> 480,50 -> 482,50 -> 482,44 -> 482,50
496,125 -> 496,117 -> 496,125 -> 498,125 -> 498,119 -> 498,125 -> 500,125 -> 500,120 -> 500,125 -> 502,125 -> 502,118 -> 502,125 -> 504,125 -> 504,124 -> 504,125
487,29 -> 487,33 -> 480,33 -> 480,37 -> 499,37 -> 499,33 -> 491,33 -> 491,29
497,13 -> 497,17 -> 495,17 -> 495,21 -> 509,21 -> 509,17 -> 501,17 -> 501,13
497,13 -> 497,17 -> 495,17 -> 495,21 -> 509,21 -> 509,17 -> 501,17 -> 501,13
496,125 -> 496,117 -> 496,125 -> 498,125 -> 498,119 -> 498,125 -> 500,125 -> 500,120 -> 500,125 -> 502,125 -> 502,118 -> 502,125 -> 504,125 -> 504,124 -> 504,125
504,80 -> 508,80
478,93 -> 478,87 -> 478,93 -> 480,93 -> 480,90 -> 480,93 -> 482,93 -> 482,83 -> 482,93 -> 484,93 -> 484,88 -> 484,93 -> 486,93 -> 486,83 -> 486,93 -> 488,93 -> 488,90 -> 488,93 -> 490,93 -> 490,87 -> 490,93
474,50 -> 474,42 -> 474,50 -> 476,50 -> 476,42 -> 476,50 -> 478,50 -> 478,46 -> 478,50 -> 480,50 -> 480,45 -> 480,50 -> 482,50 -> 482,44 -> 482,50
510,165 -> 510,155 -> 510,165 -> 512,165 -> 512,160 -> 512,165 -> 514,165 -> 514,161 -> 514,165 -> 516,165 -> 516,158 -> 516,165 -> 518,165 -> 518,157 -> 518,165
489,77 -> 493,77
478,93 -> 478,87 -> 478,93 -> 480,93 -> 480,90 -> 480,93 -> 482,93 -> 482,83 -> 482,93 -> 484,93 -> 484,88 -> 484,93 -> 486,93 -> 486,83 -> 486,93 -> 488,93 -> 488,90 -> 488,93 -> 490,93 -> 490,87 -> 490,93

@ -4,86 +4,124 @@
using namespace olc;
class Example : public olc::PixelGameEngine
{
public:
Example()
{
sAppName = "Example";
}
public:
bool RayVsRect(const vf2d ray_origin, const vf2d ray_dir, const olc::utils::geom2d::rect<float> target, vf2d&contact_point, vf2d&contact_normal, float&t_hit_near){
contact_normal = { 0, 0 };
contact_point = { 0, 0 };
vf2d t_near = {(target.pos.x - ray_origin.x) / ray_dir.x, (target.pos.y - ray_origin.y) / ray_dir.y};
vf2d t_far = {(target.pos.x + target.size.x - ray_origin.x) / ray_dir.x, (target.pos.y + target.size.y - ray_origin.y) / ray_dir.y};
vi2d upperLeftCoords={500,0};
vi2d lowerRightCoords={500,0};
std::vector<std::vector<char>>board;
if (t_near.x > t_far.x) {float b; b = t_near.x; t_near.x = t_far.x; t_far.x = b;};
if (t_near.y > t_far.y) {float b; b = t_near.y; t_near.y = t_far.y; t_far.y = b;};
if (t_near.x > t_far.y || t_near.y > t_far.x) return false;
t_hit_near = fmax(t_near.x, t_near.y);
float t_hit_far = fmin(t_far.x, t_far.y);
struct Connection{
std::vector<vi2d>coords;
};
if (t_hit_far < 0) return false;
enum ReadState{
READX,
READY,
WAIT
};
contact_point.x = ray_origin.x + t_hit_near * ray_dir.x;
contact_point.y = ray_origin.y + t_hit_near * ray_dir.y;
vi2d getArrayCoords(vi2d pos){
return pos-upperLeftCoords;
}
if (t_near.x > t_near.y)
if ( 1.0f / ray_dir.x < 0)
contact_normal = { 1, 0 };
else
contact_normal = { -1, 0};
else
if ( t_near.x < t_near.y)
if ( 1.0f / ray_dir.y < 0)
contact_normal = { 0, 1 };
else
contact_normal = { 0, -1 };
return true;
void modifyBoard(vi2d pos,char val){
vi2d actualCoords=getArrayCoords(pos);
board[actualCoords.y][actualCoords.x]=val;
}
int main()
{
std::vector<Connection>connections;
std::ifstream file("input");
ReadState state=READX;
while (file.good()){
std::string line;
std::getline(file,line);
std::string num1;
std::string num2;
if (line.length()>0){
state=READX;
Connection c;
for (int i=0;i<line.length();i++){
switch (state){
case READX:{
if (line[i]==','){
state=READY;
break;
}
num1+=line[i];
}break;
case READY:{
if (line[i]==' '){
state=WAIT;
int numb1=std::atoi(num1.c_str());
int numb2=std::atoi(num2.c_str());
c.coords.push_back({numb1,numb2});
upperLeftCoords.x=std::min(numb1,upperLeftCoords.x);
upperLeftCoords.y=std::min(numb2,upperLeftCoords.y);
lowerRightCoords.x=std::max(numb1,lowerRightCoords.x);
lowerRightCoords.y=std::max(numb2,lowerRightCoords.y);
std::cout<<"read "<<num1<<"//"<<num2<<std::endl;
num1="";
num2="";
break;
}
num2+=line[i];
}break;
case WAIT:{
if (line[i]==' '){
state=READX;
break;
}
}break;
}
}
connections.push_back(c);
}
std::cout<<line<<std::endl;
}
vf2d originPoint={16,16};
bool OnUserCreate() override
{
// Called once at the start, so create things here
return true;
}
std::cout<<"Upper-Left Bounds: "<<upperLeftCoords<<std::endl;
std::cout<<"Lower-Right Bounds: "<<lowerRightCoords<<std::endl;
bool OnUserUpdate(float fElapsedTime) override
{
vf2d velocity={(GetKey(D).bHeld-GetKey(A).bHeld)*20*fElapsedTime,(GetKey(S).bHeld-GetKey(W).bHeld)*20*fElapsedTime};
vf2d contact_point;
vf2d contact_normal;
float t_hit_near;
Clear(Pixel(64,64,255));
if (!olc::utils::geom2d::overlaps(olc::utils::geom2d::circle<float>{originPoint+velocity,5},olc::utils::geom2d::rect<float>{{32,32},{64,32}})) {
originPoint+=velocity;
DrawCircle(originPoint,5);
} else {
DrawCircle(originPoint,5,RED);
for (int y=upperLeftCoords.y;y<=lowerRightCoords.y;y++){
std::vector<char>b;
for (int x=upperLeftCoords.x;x<=lowerRightCoords.x;x++){
b.push_back(' ');
}
DrawLine(originPoint,GetMousePos());
DrawRect({32,32},{64,32},RayVsRect(originPoint, GetMousePos()-originPoint, olc::utils::geom2d::rect<float>{{32,32},{64,32}},contact_point,contact_normal,t_hit_near)&&t_hit_near<1?YELLOW:WHITE);
return true;
}
};
board.push_back(b);
}
for(int i=0;i<connections.size();i++){
Connection&c=connections[i];
vi2d&startPos=c.coords[0];
for (int j=1;j<c.coords.size();j++){
vi2d&endPos=c.coords[j];
while (startPos!=endPos){
modifyBoard(startPos,'#');
if (startPos.x!=endPos.x){
startPos.x+=(endPos.x-startPos.x)/std::abs(startPos.x-endPos.x);
}
if (startPos.y!=endPos.y){
startPos.y+=(endPos.y-startPos.y)/std::abs(startPos.y-endPos.y);
}
}
}
}
int main()
{
Example demo;
if (demo.Construct(128, 120, 8, 8))
demo.Start();
for (int y=0;y<board.size();y++){
for (int x=0;x<board[y].size();x++){
if (board[y][x]!=' '){
std::cout<<board[y][x];
} else
if (x+upperLeftCoords.x==500){
std::cout<<'|';
} else {
std::cout<<board[y][x];
}
}
std::cout<<std::endl;
}
return 0;
}

Loading…
Cancel
Save