Forums > MaxMSP

Has anyone got any suggestions on how to improve my collision detection algo?

February 6, 2008 | 10:03 pm

max v2;
#N vpatcher 395 197 1014 511;
#P window setfont "Sans Serif" 20.;
#P window linecount 1;
#P comment 21 60 30 196628 1);
#P window linecount 2;
#P comment 51 228 268 196628 My collision detection algo is a bit naff can you help?;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#N vpatcher 271 157 896 445;
#P origin -66 0;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 210 44 41 196617 r BallY;
#P newex 33 47 41 196617 r BallX;
#P comment 299 66 100 196617 Up = 0 Down =1;
#P comment 298 90 100 196617 Left = 0 Right = 1;
#N vpatcher 614 324 1213 769;
#P origin 29 0;
#P window setfont "Sans Serif" 9.;
#N vpatcher 576 46 1055 399;
#P origin 122 0;
#P window setfont "Sans Serif" 9.;
#P newex 351 226 48 196617 togedge;
#B color 5;
#P newex 240 226 48 196617 togedge;
#B color 5;
#P newex 118 225 48 196617 togedge;
#B color 5;
#P toggle 15 197 15 0;
#P newex 15 222 48 196617 togedge;
#B color 5;
#P toggle 351 198 15 0;
#P button 376 115 15 0;
#P toggle 240 200 15 0;
#P button 265 114 15 0;
#P button 143 114 15 0;
#P toggle 118 196 15 0;
#P button 40 114 15 0;
#P button 351 114 15 0;
#P button 240 114 15 0;
#P button 118 114 15 0;
#P button 15 114 15 0;
#P newex 351 171 30 196617 > 40;
#P newex 351 141 35 196617 timer;
#P comment 7 300 100 196617 X;
#P newex 240 171 30 196617 > 40;
#P newex 240 141 35 196617 timer;
#P outlet 15 279 15 0;
#P outlet 118 280 15 0;
#P newex 118 171 30 196617 > 40;
#P newex 118 141 35 196617 timer;
#P newex 15 171 30 196617 > 40;
#P newex 15 141 35 196617 timer;
#P comment 347 38 20 196617 BR;
#P comment 237 37 20 196617 BL;
#P comment 114 38 20 196617 TR;
#P comment 18 39 20 196617 TL;
#P inlet 350 66 15 0;
#P inlet 240 66 15 0;
#P inlet 118 62 15 0;
#P inlet 15 63 15 0;
#P comment 120 299 100 196617 Y;
#P connect 1 0 20 0;
#P connect 20 0 9 0;
#P connect 9 0 10 0;
#P connect 10 0 32 0;
#P connect 32 0 31 0;
#P connect 31 0 14 0;
#P connect 34 0 14 0;
#P connect 3 0 24 0;
#P connect 24 0 9 1;
#P connect 1 0 21 0;
#P connect 21 0 11 0;
#P connect 11 0 12 0;
#P connect 12 0 25 0;
#P connect 25 0 33 0;
#P connect 33 0 13 0;
#P connect 35 0 13 0;
#P connect 2 0 26 0;
#P connect 26 0 11 1;
#P connect 2 0 22 0;
#P connect 22 0 15 0;
#P connect 15 0 16 0;
#P connect 16 0 28 0;
#P connect 28 0 34 0;
#P connect 4 0 27 0;
#P connect 27 0 15 1;
#P connect 3 0 23 0;
#P connect 23 0 18 0;
#P connect 18 0 19 0;
#P connect 19 0 30 0;
#P connect 30 0 35 0;
#P connect 4 0 29 0;
#P connect 29 0 18 1;
#P pop;
#P newobj 385 222 179 196617 p Shape1CollisonPoint-ORIGINAL IDEA;
#P window setfont "Sans Serif" 20.;
#P comment 350 336 31 196628 h;
#P comment 299 335 31 196628 g;
#P comment 260 338 31 196628 f;
#P comment 209 336 31 196628 e;
#P comment 166 338 31 196628 d;
#P comment 107 336 31 196628 c;
#P comment 62 338 31 196628 b;
#P button 1 289 38 0;
#P button 355 285 38 0;
#P button 53 291 38 0;
#P button 108 292 38 0;
#P button 253 289 38 0;
#P button 297 289 38 0;
#P button 205 286 38 0;
#P button 158 287 38 0;
#P window setfont "Sans Serif" 9.;
#P newex 120 253 87 196617 s X-BallDirection;
#P newex 230 253 87 196617 s Y-BallDirection;
#N vpatcher 247 152 1228 569;
#P origin 15 0;
#P outlet 1 321 15 0;
#P outlet 423 321 15 0;
#P outlet 119 321 15 0;
#P inlet 469 38 15 0;
#P inlet 313 38 15 0;
#P inlet 157 38 15 0;
#P inlet 1 38 15 0;
#P window setfont "Sans Serif" 9.;
#P newex 1 93 480 196617 if ($i1+15) < = ($i2+30) && ($i1+15) >= $i2 && ($i3+15) < = ($i4+30) && ($i3+15) >= $i4 then bang;
#P comment 74 114 256 196617 BOTTOM RIGHT BALL PIXEL (Collision Detection);
#P comment 236 215 178 196617 BOTTOM RIGHT AT TOP CORNER (Left);
#P comment 231 293 186 196617 BOTTOM RIGHT AT TOP CORNER (Top);
#P newex 440 217 510 196617 if ($i1+15) >= $i2 && ($i1+15) < = ($i2+3) && ($i3+15) <= ($i4+15) && ($i3+15) >= $i4 then bang;
#P newex 423 290 496 196617 if ($i1+15) < = ($i2+15) && ($i1+15) >= $i2 && ($i3+15) < = ($i4+3) && ($i3+15) >= $i4 then bang;
#P connect 6 0 5 0;
#P connect 5 0 12 0;
#P fasten 1 0 10 0 445 258 124 258;
#P connect 7 0 5 1;
#P connect 8 0 5 2;
#P fasten 6 0 0 0 6 79 428 79;
#P connect 0 0 11 0;
#P fasten 6 0 1 0 6 82 445 82;
#P connect 9 0 5 3;
#P fasten 7 0 0 1 162 73 590 73;
#P fasten 7 0 1 1 162 84 611 84;
#P fasten 8 0 0 2 318 67 752 67;
#P fasten 8 0 1 2 318 86 777 86;
#P fasten 9 0 0 3 474 62 914 62;
#P fasten 9 0 1 3 474 89 943 89;
#P pop;
#P newobj 300 169 95 196617 p Ball-BottomRight;
#N vpatcher 69 85 1006 473;
#P outlet 16 319 15 0;
#P outlet 435 320 15 0;
#P outlet 134 321 15 0;
#P inlet 427 38 15 0;
#P inlet 290 38 15 0;
#P inlet 153 38 15 0;
#P inlet 16 38 15 0;
#P window setfont "Sans Serif" 9.;
#P newex 16 93 423 196617 if $i1 < = ($i2+30) && $i1 >= $i2 && ($i3+15) < = ($i4+30) && ($i3+15) >= $i4 then bang;
#P comment 89 114 256 196617 BOTTOM LEFT BALL PIXEL (Collision Detection);
#P comment 252 279 178 196617 BOTTOM LEFT AT TOP CORNER (Top);
#P comment 247 217 186 196617 BOTTOM LEFT AT TOP CORNER (Right);
#P newex 445 213 457 196617 if $i1 < = ($i2+30) && $i1 >= ($i2+27) && ($i3+15) < = ($i4+15) && ($i3+15) >= $i4 then bang;
#P newex 435 283 442 196617 if $i1 < = ($i2+30) && $i1 >= ($i2+15) && ($i3+15) >= $i4 && ($i3+15) < = ($i4+3) then bang;
#P connect 6 0 5 0;
#P connect 5 0 12 0;
#P fasten 1 0 10 0 450 251 139 251;
#P connect 7 0 5 1;
#P connect 8 0 5 2;
#P connect 9 0 5 3;
#P fasten 6 0 0 0 21 79 440 79;
#P connect 0 0 11 0;
#P fasten 6 0 1 0 21 82 450 82;
#P fasten 7 0 0 1 158 73 584 73;
#P fasten 7 0 1 1 158 84 599 84;
#P fasten 8 0 0 2 295 67 728 67;
#P fasten 8 0 1 2 295 86 748 86;
#P fasten 9 0 0 3 432 62 872 62;
#P fasten 9 0 1 3 432 89 897 89;
#P pop;
#P newobj 201 169 90 196617 p Ball-BottomLeft;
#N vpatcher 119 168 1056 556;
#P outlet 16 323 15 0;
#P outlet 438 321 15 0;
#P outlet 134 321 15 0;
#P inlet 427 38 15 0;
#P inlet 290 38 15 0;
#P inlet 153 38 15 0;
#P inlet 16 38 15 0;
#P window setfont "Sans Serif" 9.;
#P newex 16 93 422 196617 if ($i1+15) < = ($i2+30) && ($i1+15) >= $i2 && $i3 < = ($i4+30) && $i3 >= $i4 then bang;
#P comment 89 114 256 196617 TOP RIGHT BALL PIXEL (Collision Detection);
#P comment 246 214 178 196617 TOP RIGHT AT BOTTOM CORNER (Left);
#P comment 241 334 200 196617 TOP RIGHT AT BOTTOM CORNER (Bottom);
#P newex 438 294 460 196617 if ($i1+15) < = ($i2+15) && ($i1+15) >= $i2 && $i3 >= ($i4+27) && $i3 < = ($i4+30) then bang;
#P newex 438 212 445 196617 if ($i1+15) >= $i2 && ($i1+15) < = ($i2+3) && $i3 <= ($i4+30) && $i3 >= ($i4+15) then bang;
#P connect 6 0 5 0;
#P connect 5 0 12 0;
#P fasten 0 0 10 0 443 246 139 246;
#P connect 7 0 5 1;
#P connect 8 0 5 2;
#P connect 9 0 5 3;
#P fasten 6 0 0 0 21 79 443 79;
#P fasten 6 0 1 0 21 82 443 82;
#P connect 1 0 11 0;
#P fasten 7 0 0 1 158 73 588 73;
#P fasten 7 0 1 1 158 84 593 84;
#P fasten 8 0 0 2 295 67 733 67;
#P fasten 8 0 1 2 295 86 743 86;
#P fasten 9 0 0 3 432 62 878 62;
#P fasten 9 0 1 3 432 89 893 89;
#P pop;
#P newobj 113 169 79 196617 p Ball-TopRight;
#N vpatcher 16 76 899 449;
#P outlet 16 321 15 0;
#P outlet 426 321 15 0;
#P outlet 134 321 15 0;
#P inlet 376 38 15 0;
#P inlet 256 38 15 0;
#P inlet 136 38 15 0;
#P inlet 16 38 15 0;
#P window setfont "Sans Serif" 9.;
#P newex 16 93 371 196617 if $i1 < = ($i2+30) && $i1 >= $i2 && $i3 < = ($i4+30) && $i3 >= $i4 then bang;
#P comment 89 114 198 196617 TOP LEFT BALL PIXEL (Collision Detection);
#P comment 246 214 178 196617 TOP LEFT AT BOTTOM CORNER (Right);
#P comment 242 296 186 196617 TOP LEFT AT BOTTOM CORNER (Bottom);
#P newex 426 276 431 196617 if $i1 < = ($i2+30) && $i1 >= ($i2+15) && $i3 >= ($i4+27) && $i3 < = ($i4+30) then bang;
#P newex 426 212 425 196617 if $i1 >= ($i2+27) && $i1 < = ($i2+30) && $i3 <= ($i4+30) && $i3 >= ($i4+15) then bang;
#P connect 6 0 5 0;
#P connect 5 0 12 0;
#P fasten 0 0 10 0 431 247 139 247;
#P connect 7 0 5 1;
#P connect 8 0 5 2;
#P connect 9 0 5 3;
#P fasten 6 0 0 0 21 74 431 74;
#P fasten 6 0 1 0 21 85 431 85;
#P connect 1 0 11 0;
#P fasten 7 0 0 1 141 70 569 70;
#P fasten 7 0 1 1 141 83 571 83;
#P fasten 8 0 0 2 261 64 707 64;
#P fasten 8 0 1 2 261 80 711 80;
#P fasten 9 0 0 3 381 59 845 59;
#P fasten 9 0 1 3 381 77 851 77;
#P pop;
#P newobj 30 169 74 196617 p Ball-TopLeft;
#P comment 201 64 32 196617 Ball Y;
#P inlet 201 81 15 0;
#P inlet 30 80 15 0;
#P newex 300 79 56 196617 r Shape1Y;
#P newex 113 81 56 196617 r Shape1X;
#P comment 30 63 36 196617 Ball X;
#P window setfont "Sans Serif" 20.;
#P comment 8 341 27 196628 A;
#P connect 10 2 20 0;
#P connect 4 0 7 0;
#P fasten 2 0 7 1 118 146 56 146;
#P connect 9 2 18 0;
#P fasten 5 0 7 2 206 124 77 124;
#P fasten 3 0 7 3 305 108 98 108;
#P connect 9 1 17 0;
#P fasten 4 0 8 0 35 160 118 160;
#P connect 8 1 12 0;
#P connect 7 1 12 0;
#P connect 9 1 12 0;
#P connect 28 0 12 0;
#P fasten 2 0 8 1 118 141 141 141;
#P connect 7 1 13 0;
#P fasten 5 0 8 2 206 120 164 120;
#P fasten 3 0 8 3 305 104 187 104;
#P fasten 4 0 9 0 35 156 206 156;
#P connect 7 2 14 0;
#P fasten 2 0 9 1 118 137 232 137;
#P connect 10 1 11 0;
#P connect 8 2 11 0;
#P connect 10 2 11 0;
#P connect 9 2 11 0;
#P connect 7 2 11 0;
#P connect 28 1 11 0;
#P fasten 5 0 9 2 206 117 258 117;
#P connect 8 2 16 0;
#P fasten 3 0 9 3 305 101 284 101;
#P connect 8 1 15 0;
#P fasten 4 0 10 0 35 151 305 151;
#P fasten 2 0 10 1 118 132 333 132;
#P connect 10 1 19 0;
#P fasten 5 0 10 2 206 113 361 113;
#P fasten 3 0 10 3 305 99 389 99;
#P connect 7 0 28 0;
#P connect 8 0 28 1;
#P connect 9 0 28 2;
#P connect 10 0 28 3;
#P pop;
#P newobj 33 82 187 196617 p Shape1Collision;
#P window linecount 0;
#P comment 264 47 225 196617 HOW COUNTER DIRECTION RELATES TO BALL;
#P connect 4 0 1 0;
#P connect 5 0 1 1;
#P pop;
#P newobj 377 207 101 196617 p Collision Detection;
#P window setfont "Sans Serif" 20.;
#P comment 325 173 268 196628 Collision detection in here!;
#P window setfont "Sans Serif" 9.;
#P newex 529 76 56 196617 s loadbang;
#P newex 529 49 48 196617 loadbang;
#P newex 202 43 59 196617 r StartBall;
#P newex 376 47 55 196617 r StopBall;
#P message 376 71 50 196617 Stop Ball;
#P message 53 69 54 196617 Start Ball;
#N vpatcher 451 202 1201 691;
#P window setfont "Sans Serif" 9.;
#P newex 404 221 41 196617 r BallY;
#P newex 263 221 41 196617 r BallX;
#N vpatcher 173 315 1449 1071;
#P window setfont "Sans Serif" 9.;
#P message 386 78 79 196617 enablesprites 1;
#P newex 590 217 56 196617 s Shape1Y;
#P newex 531 217 56 196617 s Shape1X;
#P message 910 219 65 196617 recordsprite;
#P newex 640 155 74 196617 t 100 20 b b b;
#P newex 173 89 40 196617 t b b b;
#P message 658 219 94 196617 closesprite shape1;
#P newex 121 64 118 196617 t b b b b b b b b b;
#P message 753 219 156 196617 paintrect 0 0 30 30 15 200 200;
#P comment 146 165 195 196617 left , top , right , bottom , red , green , blue;
#P newex 175 32 72 196617 r DrawUpdate;
#P message 455 115 42 196617 getsize;
#P message 34 117 75 196617 closesprite ball;
#P message 115 137 162 196617 paintrect 0 0 15 15 255 255 255;
#P message 229 117 65 196617 recordsprite;
#P outlet 233 401 15 0;
#P newex 115 32 56 196617 r loadbang;
#P message 308 114 33 196617 clear;
#P message 344 114 109 196617 brgb 0 0 0;
#P connect 13 0 6 0;
#P connect 13 1 5 0;
#P connect 8 0 11 0;
#P connect 2 0 11 0;
#P connect 11 4 13 0;
#P connect 13 2 4 0;
#P connect 15 0 3 0;
#P connect 0 0 3 0;
#P connect 6 0 3 0;
#P connect 5 0 3 0;
#P connect 4 0 3 0;
#P connect 1 0 3 0;
#P connect 10 0 3 0;
#P connect 12 0 3 0;
#P connect 7 0 3 0;
#P connect 18 0 3 0;
#P connect 11 5 1 0;
#P connect 11 6 0 0;
#P connect 11 8 18 0;
#P connect 11 7 7 0;
#P connect 14 0 16 0;
#P connect 14 1 17 0;
#P connect 11 3 14 0;
#P connect 14 2 12 0;
#P connect 14 3 10 0;
#P connect 14 4 15 0;
#P pop;
#P newobj 38 242 98 196617 p DrawEnvironment;
#N vpatcher 251 381 851 781;
#P window setfont "Sans Serif" 9.;
#P window linecount 0;
#P newex 141 147 54 196617 send~ dac;
#P newex 17 54 20 196617 t b;
#P newex 17 29 56 196617 r loadbang;
#P window linecount 1;
#P newex 194 53 87 196617 r X-BallDirection;
#P newex 287 53 87 196617 r Y-BallDirection;
#P newex 141 72 38 196617 sig~ 1;
#P message 194 89 49 196617 startloop;
#P newex 141 117 88 196617 groove~ Collision;
#P message 17 90 89 196617 replace jongly.aif;
#P newex 17 114 85 196617 buffer~ Collision;
#P connect 7 0 8 0;
#P connect 8 0 1 0;
#P connect 1 0 0 0;
#P connect 4 0 2 0;
#P fasten 3 0 2 0 199 111 146 111;
#P connect 2 0 9 0;
#P connect 6 0 3 0;
#P fasten 5 0 3 0 292 78 199 78;
#P pop;
#P newobj 32 32 76 196617 p Shape1Sound;
#N vpatcher 447 370 798 555;
#P window setfont "Sans Serif" 9.;
#P newex 112 51 44 196617 del 100;
#P newex 112 72 53 196617 t 100 20;
#P newex 112 31 56 196617 r loadbang;
#P newex 179 42 84 196617 r Shape1YMouse;
#P newex 21 43 84 196617 r Shape1XMouse;
#P newex 251 108 56 196617 s Shape1Y;
#P newex 192 108 56 196617 s Shape1X;
#P outlet 21 132 15 0;
#P newex 21 108 168 196617 sprintf drawsprite shape1 %ld %ld;
#P connect 4 0 0 0;
#P connect 7 0 0 0;
#P connect 0 0 1 0;
#P connect 6 0 8 0;
#P connect 8 0 7 0;
#P connect 5 0 0 1;
#P connect 7 1 0 1;
#P fasten 4 0 2 0 26 97 197 97;
#P fasten 5 0 3 0 184 89 256 89;
#P pop;
#P newobj 141 242 111 196617 p Shape1MouseControl;
#P inlet 616 40 15 0;
#P inlet 494 40 15 0;
#N comlet;
#P outlet 263 303 15 0;
#N vpatcher 635 175 1228 662;
#P origin 34 0;
#P window setfont "Sans Serif" 9.;
#P window linecount 0;
#P message 322 50 33 196617 clear;
#P window linecount 15;
#P message 446 58 50 196617 1 3 , 2 4 , 3 5 , 4 7 , 5 9 , 6 12 , 7 16 , 8 20 , 9 25 , 10 32 , 11 40 , 12 50 , 13 70 , 14 100 , 15 150 ,;
#P flonum 23 212 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P newex 306 206 27 196617 + 1;
#P message 306 181 13 196617 1;
#P message 267 206 13 196617 2;
#P newex 267 183 22 196617 b 1;
#P newex 267 125 27 196617 + 1;
#P message 40 57 14 196617 5;
#P newex 267 106 40 196617 change;
#P newex 64 279 40 196617 gate 3;
#P message 64 311 135 196617 150 , $1 1250;
#P message 94 343 60 196617 3 , $1 1250;
#P newex 64 375 52 196617 line;
#N comlet;
#P outlet 64 431 13 0;
#N comlet;
#P inlet 50 120 13 0;
#N comlet;
#P inlet 144 49 13 0;
#N comlet;
#P inlet 109 49 13 0;
#P newex 40 30 107 196617 r loadbang;
#P message 94 74 13 196617 1;
#P message 128 74 13 196617 1;
#P message 129 220 13 196617 0;
#P message 112 220 13 196617 0;
#P newex 128 117 26 196617 gate;
#P newex 94 118 25 196617 gate;
#P newex 112 198 45 196617 sel 1 15;
#P message 128 138 29 196617 prev;
#P message 94 139 26 196617 next;
#N coll Angles;
#P newobj 94 172 65 196617 coll Angles;
#P comment 162 173 100 196617 Ball Bounce Angles;
#P connect 1 0 27 0;
#P connect 11 0 21 0;
#P fasten 26 0 19 0 311 257 69 257;
#P fasten 24 0 19 0 272 248 69 248;
#P connect 19 0 18 0;
#P fasten 17 0 16 0 99 367 69 367;
#P connect 18 0 16 0;
#P fasten 19 1 15 0 84 302 221 302 221 418 69 418;
#P connect 16 0 15 0;
#P connect 11 0 10 0;
#P connect 13 0 10 0;
#P fasten 8 0 5 0 134 242 190 242 190 107 99 107;
#P connect 10 0 5 0;
#P connect 5 0 2 0;
#P connect 29 0 1 0;
#P connect 28 0 1 0;
#P connect 14 0 1 0;
#P connect 2 0 1 0;
#P connect 3 0 1 0;
#P connect 1 0 19 1;
#P fasten 19 2 17 0 99 304 207 304 207 339 99 339;
#P connect 12 0 5 1;
#P connect 1 1 4 0;
#P connect 4 0 7 0;
#P connect 11 0 9 0;
#P connect 12 0 9 0;
#P fasten 7 0 6 0 117 244 177 244 177 100 133 100;
#P connect 9 0 6 0;
#P connect 6 0 3 0;
#P connect 4 1 8 0;
#P connect 13 0 6 1;
#P fasten 21 0 20 0 45 94 272 94;
#P connect 20 0 22 0;
#P connect 22 0 23 0;
#P connect 23 0 24 0;
#P fasten 22 0 25 0 272 158 311 158;
#P connect 25 0 26 0;
#P connect 11 0 28 0;
#P pop;
#P newobj 555 94 65 196617 p BallAngles;
#N vpatcher 343 44 992 705;
#P window setfont "Sans Serif" 9.;
#P window linecount 0;
#P newex 147 64 27 196617 t i i;
#P newex 91 172 87 196617 r X-BallDirection;
#P newex 401 172 87 196617 r Y-BallDirection;
#P newex 383 583 106 196617 v Y-CounterDirection;
#P newex 73 587 106 196617 v X-CounterDirection;
#P newex 73 558 29 196617 > 0;
#P newex 73 534 29 196617 -;
#P newex 73 508 29 196617 t i i;
#P newex 383 556 29 196617 > 0;
#P newex 383 532 29 196617 -;
#P newex 383 506 29 196617 t i i;
#P newex 412 193 69 196617 r BallYMouse;
#P newex 110 193 69 196617 r BallXMouse;
#P comment 427 376 100 196617 Ball Y Position;
#P comment 115 376 100 196617 Ball X Position;
#P number 437 290 35 9 -14 64 3 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P message 437 266 44 196617 max $1;
#P message 127 266 44 196617 max $1;
#P number 127 290 35 9 -7 243 3 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 437 216 71 196617 r Y-Boundary;
#P newex 127 216 71 196617 r X-Boundary;
#P newex 437 238 30 196617 – 15;
#P newex 127 238 30 196617 – 15;
#P newex 147 43 61 196617 r BallSpeed;
#P flonum 107 118 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P comment 425 444 100 196617 UP boundary;
#P comment 450 468 100 196617 DOWN boundary;
#P button 431 468 15 0;
#P button 407 444 15 0;
#P button 97 444 15 0;
#P button 121 468 15 0;
#P flonum 440 118 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#N comlet;
#P inlet 475 61 24 0;
#N comlet;
#P inlet 73 61 29 0;
#N counter 2 0 64;
#X flags 0 0;
#P newobj 383 311 82 196617 counter 2 0 64;
#P window linecount 1;
#P newex 383 142 67 196617 metro 250;
#N counter 2 0 243;
#X flags 0 0;
#P newobj 73 311 83 196617 counter 2 0 243;
#P newex 73 142 44 196617 metro 7;
#P comment 115 444 100 196617 LEFT boundary;
#P comment 139 468 100 196617 RIGHT boundary;
#P comment 178 238 227 196617 < - Number Here Depends On BALL/BLOCK SIZE;
#P comment 495 585 100 196617 Up = 0 Down =1;
#P comment 183 589 100 196617 Left = 0 Right = 1;
#P newex 383 376 41 196617 s BallY;
#P newex 73 376 41 196617 s BallX;
#P connect 11 0 7 0;
#P connect 7 0 8 0;
#P connect 8 0 0 0;
#P connect 8 0 37 0;
#P connect 37 1 38 0;
#P connect 38 0 39 0;
#P connect 39 0 40 0;
#P connect 43 0 8 1;
#P connect 37 0 38 1;
#P connect 8 1 15 0;
#P fasten 44 0 20 0 152 88 112 88;
#P connect 20 0 7 1;
#P connect 8 2 14 0;
#P connect 24 0 22 0;
#P connect 22 0 27 0;
#P fasten 32 0 26 0 115 285 132 285;
#P connect 27 0 26 0;
#P connect 26 0 8 3;
#P fasten 22 0 8 4 132 261 150 261;
#P connect 21 0 44 0;
#P fasten 11 0 9 0 78 108 388 108;
#P connect 9 0 10 0;
#P connect 10 0 1 0;
#P connect 10 0 34 0;
#P connect 34 1 35 0;
#P connect 35 0 36 0;
#P connect 36 0 41 0;
#P connect 42 0 10 1;
#P connect 34 0 35 1;
#P connect 10 1 16 0;
#P connect 10 2 17 0;
#P connect 25 0 23 0;
#P connect 23 0 28 0;
#P fasten 33 0 29 0 417 286 442 286;
#P connect 28 0 29 0;
#P connect 29 0 10 3;
#P fasten 44 1 13 0 169 88 445 88;
#P fasten 12 0 9 1 480 139 445 139;
#P connect 13 0 9 1;
#P fasten 23 0 10 4 442 260 460 260;
#P pop;
#P newobj 484 116 81 196617 p BallMovement;
#N vpatcher 444 343 795 605;
#P button 292 67 15 0;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P comment 236 67 50 196617 Stop Ball;
#P message 292 90 14 196617 0;
#P outlet 292 196 15 0;
#P inlet 292 34 15 0;
#P message 30 164 13 196617 1;
#P newex 30 137 44 196617 del 200;
#P comment 45 114 58 196617 Start Ball;
#P button 30 112 16 0;
#N comlet;
#P outlet 30 187 26 0;
#P window linecount 0;
#P newex 74 68 40 196617 t b b b;
#P newex 89 162 82 196617 uzi 4;
#N comlet;
#P outlet 89 187 26 0;
#N comlet;
#P inlet 74 33 21 0;
#P newex 161 138 120 196617 + 3;
#P newex 161 112 107 196617 random 8;
#P fasten 5 0 7 0 79 104 35 104;
#P connect 7 0 9 0;
#P connect 9 0 10 0;
#P connect 10 0 6 0;
#P connect 2 0 5 0;
#P connect 5 1 4 0;
#P connect 4 0 3 0;
#P fasten 5 2 0 0 109 102 166 102;
#P connect 0 0 1 0;
#P connect 1 0 4 1;
#P connect 11 0 15 0;
#P connect 15 0 13 0;
#P connect 13 0 12 0;
#P pop;
#P newobj 494 64 132 196617 p BallStartStop;
#P newex 263 243 151 196617 sprintf drawsprite ball %ld %ld;
#P connect 10 0 0 0;
#P connect 7 0 4 0;
#P connect 0 0 4 0;
#P connect 9 0 4 0;
#P connect 11 0 0 1;
#P fasten 1 0 2 0 499 91 489 91;
#P fasten 1 2 2 0 621 85 489 85;
#P connect 5 0 1 0;
#P connect 1 1 3 0;
#P connect 3 0 2 1;
#P connect 6 0 1 1;
#P pop;
#P newobj 53 97 333 196617 p LCDControl;
#P user lcd 53 141 258 79 0 1 0 0 1;
#P connect 2 0 1 0;
#P connect 1 0 0 0;
#P connect 4 0 3 0;
#P connect 3 0 1 1;
#P connect 6 0 7 0;
#P pop;

Currently I’m going by the top left, top right, bottom left and bottom right pixel on the the square ball and telling the counter to change direction should any of those areas come into contact with the area the shape is in.

This however, doesn’t work very well?!

Does any one have any ideas on how it could work, and is there a much better way of doing it than this?

Thanks,

Rhys


February 6, 2008 | 10:32 pm

maybe you would be interested in checking katsuhiro chiba’s "ref matrix" patch, it might give a couple of ideas :)

http://www.audiooo.com/jp/freestuff/index.html


February 7, 2008 | 12:40 am

That’s an excellent patch, thanks karrrlo!

I was thinking along similar lines only I didn’t want to be limited to just squares, and I would like to avoid using grid patterns, if possible.

The LCD object seems perfect as it allows for user created sprites and therefore the user’s imagination, to run riot.

I think the collision detection on that must be done by on a pixel by pixel basis though?

The algo I came up with and thought would work, unfortunately has various oddities and kinks that come with it…

Any other thoughts anyone?

Rhys


February 7, 2008 | 3:29 am



VG
February 7, 2008 | 9:57 am

Derek:
you patch seems interesting but there miss some abstractions,
which i couldn’t find on maxobjects…
Could you send them along, or give a link to get them?

Rhys:
there have been some posts on this forum on this topic,
you could check them.

a few ideas on how to get collision done:
1) you will need to have speed stored at some point,
It helps for making objects evolution controlled by speed.
Namely : new_position = position + current_speed.
Check "advanced navigation" patch for a nice exemple
on how to do it with jit.matrix… (however you could do
with matrixes)

2) in your collision patch, check estimated next position to know if you
encounter an obstacle
and correct speed accordingly… this part may be tricky, you will find
literrature on the net
on algorithms to achieve this
for exemple :

http://www.flipcode.com/archives/Basic_Collision_Detection.shtml

3) Take into account all simplication you can get from a simple
geometry. (hint: very important point!!)

4) get some coffee and a sheet of paper for drawing these trigonometric
formulas back into mind.

It took me almost a week to get something clean and efficient.
I developped it for someone else and cannot post it for licence reason,
sorry, but I hope the lines above will help you get started.
… vincent

http://www.pucemuse.com
http://www.mazirkat.org/vincent/

Derek Franz a écrit :
> psst! hey buddy,over here. its a collision detection algo for any two
> lines in 2d space, it requires peter elsea;s l== and position by
> James McCartney…its hot, i use it whenever I can
>
> max v2;
> #N vpatcher 130 129 774 594;
> #P window setfont "Sans Serif" 9.;
> #P window linecount 1;
> #P newex 274 290 60 196617 _ paintoval;
> #P newex 276 268 27 196617 l;
> #P flonum 229 210 57 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P newex 227 165 66 196617 pack 0 0 0 0;
> #P newex 90 400 32 196617 sel 1;
> #P newex 76 352 105 196617 pack 0 0 0 0 0 0 0 0;
> #P newex 419 30 94 196617 bgcolor 30 240 23;
> #P message 356 33 59 196617 multitetris;
> #P window linecount 3;
> #P message 327 86 85 196617 A = y2-y1 B = x1-x2 C = A*x1+B*y1;
> #P window linecount 1;
> #P message 497 228 79 196617 return bang if ||;
> #P message 218 400 102 196617 return bangig collide;
> #P message 356 52 203 196617 collision detechtion between 2linesegments;
> #P button 73 424 15 0;
> #P newex 76 374 97 196617 l== 1 1 1 1 1 1 1 1;
> #P newex 239 324 27 196617 >=;
> #P newex 268 324 27 196617 < =;
> #P newex 178 324 27 196617 >=;
> #P newex 207 324 27 196617 < =;
> #P newex 58 328 27 196617 >=;
> #P newex 148 325 27 196617 < =;
> #P newex 87 325 27 196617 >=;
> #P newex 116 326 27 196617 < =;
> #P newex 197 269 76 196617 unpack 0 0 0 0;
> #P newex 91 269 76 196617 unpack 0 0 0 0;
> #P message 162 303 154 196617 min (y1 , y2) ≤ x ≤ max(y1 , y2);
> #P message 10 302 162 196617 min (x1 , x2) ≤ x ≤ max(x1 , x2);
> #P button 477 227 15 0;
> #P newex 479 206 32 196617 sel 0;
> #N vpatcher 143 219 676 650;
> #P outlet 353 238 15 0;
> #P window setfont "Sans Serif" 9.;
> #P window linecount 0;
> #P newex 354 209 66 196617 pack 0 0 0 0;
> #P newex 370 131 53 196617 maximum;
> #P newex 357 109 50 196617 minimum;
> #P newex 324 132 53 196617 maximum;
> #P newex 295 110 50 196617 minimum;
> #P window linecount 3;
> #P message 208 147 85 196617 A = y2-y1 B = x1-x2 C = A*x1+B*y1;
> #P outlet 131 219 15 0;
> #P outlet 232 217 15 0;
> #P outlet 33 204 15 0;
> #P window linecount 1;
> #P newex 156 150 27 196617 *;
> #P newex 127 186 27 196617 +;
> #P newex 86 153 27 196617 *;
> #P newex 152 111 27 196617 -;
> #P newex 143 76 67 196617 unpack 0 0 0;
> #P newex 61 83 40 196617 unpack;
> #P newex 155 50 72 196617 position 0 2 1;
> #P newex 82 50 63 196617 position 3 1;
> #P newex 65 113 27 196617 -;
> #P inlet 121 23 15 0;
> #P connect 1 0 10 0;
> #P connect 2 0 4 0;
> #P connect 4 0 1 0;
> #P connect 0 0 2 0;
> #P connect 4 1 1 1;
> #P connect 1 0 7 0;
> #P connect 5 0 7 1;
> #P connect 7 0 8 0;
> #P connect 8 0 12 0;
> #P connect 3 0 5 0;
> #P connect 9 0 8 1;
> #P connect 5 0 6 0;
> #P connect 0 0 3 0;
> #P connect 6 0 9 0;
> #P connect 5 1 6 1;
> #P connect 5 2 9 1;
> #P connect 6 0 11 0;
> #P connect 2 0 14 0;
> #P connect 2 0 15 0;
> #P connect 18 0 19 0;
> #P connect 14 0 18 0;
> #P connect 3 0 16 0;
> #P connect 3 0 17 0;
> #P connect 15 0 18 1;
> #P connect 16 0 18 2;
> #P connect 17 0 18 3;
> #P pop;
> #P newobj 171 131 64 196617 p abc;
> #P button 84 90 15 0;
> #P newex 147 105 27 196617 llist;
> #P number 162 24 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P number 187 44 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P number 219 25 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P number 228 45 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P newex 189 68 61 196617 pak 0 0 0 0;
> #P newex 85 106 27 196617 llist;
> #P number 59 35 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P number 89 50 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P number 107 28 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P number 140 48 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P newex 86 68 61 196617 pak 0 0 0 0;
> #P newex 335 130 72 196617 _ linesegment;
> #P message 318 119 33 196617 clear;
> #P user lcd 317 252 264 194 1 1 0 0 0;
> #N vpatcher 407 227 826 536;
> #P outlet 252 229 15 0;
> #P window setfont "Sans Serif" 9.;
> #P window linecount 0;
> #P newex 257 180 66 196617 pack 0 0 0 0;
> #P window linecount 1;
> #P newex 352 125 53 196617 maximum;
> #P newex 327 100 50 196617 minimum;
> #P newex 277 125 53 196617 maximum;
> #P window linecount 0;
> #P newex 247 101 50 196617 minimum;
> #P window linecount 3;
> #P message 223 47 85 196617 A = y2-y1 B = x1-x2 C = A*x1+B*y1;
> #P outlet 8 239 15 0;
> #P outlet 166 219 15 0;
> #P outlet 78 203 15 0;
> #P window linecount 1;
> #P newex 154 146 27 196617 *;
> #P newex 17 191 27 196617 +;
> #P newex 11 145 27 196617 *;
> #P newex 38 114 27 196617 -;
> #P newex 53 84 40 196617 unpack;
> #P newex 123 89 67 196617 unpack 0 0 0;
> #P newex 49 53 63 196617 position 3 1;
> #P newex 140 51 72 196617 position 0 2 1;
> #P newex 137 114 27 196617 -;
> #P inlet 82 30 15 0;
> #P connect 8 0 12 0;
> #P connect 6 0 7 0;
> #P connect 7 0 8 0;
> #P connect 4 0 7 1;
> #P connect 9 0 8 1;
> #P connect 5 0 6 0;
> #P connect 0 0 3 0;
> #P connect 3 0 5 0;
> #P connect 5 1 6 1;
> #P connect 6 0 10 0;
> #P connect 2 0 4 0;
> #P connect 4 0 1 0;
> #P connect 0 0 2 0;
> #P connect 4 1 1 1;
> #P connect 1 0 9 0;
> #P connect 1 0 11 0;
> #P connect 4 2 9 1;
> #P connect 3 0 14 0;
> #P connect 18 0 19 0;
> #P connect 14 0 18 0;
> #P connect 15 0 18 1;
> #P connect 3 0 15 0;
> #P connect 16 0 18 2;
> #P connect 17 0 18 3;
> #P connect 2 0 16 0;
> #P connect 2 0 17 0;
> #P pop;
> #P newobj 91 132 67 196617 p abc;
> #N vpatcher 20 74 620 474;
> #P window setfont "Sans Serif" 9.;
> #P newex 144 64 76 196617 unpack 0 0 0 0;
> #P newex 86 50 27 196617 *;
> #P newex 59 75 27 196617 -;
> #P newex 50 51 27 196617 *;
> #P inlet 166 29 15 0;
> #P outlet 59 97 15 0;
> #P connect 5 0 2 0;
> #P connect 2 0 3 0;
> #P connect 3 0 0 0;
> #P connect 5 1 2 1;
> #P connect 4 0 3 1;
> #P connect 5 2 4 0;
> #P connect 5 3 4 1;
> #P connect 1 0 5 0;
> #P pop;
> #P newobj 227 185 57 196617 p parrellel;
> #N vpatcher 20 74 620 474;
> #P window setfont "Sans Serif" 9.;
> #P newex 59 124 91 196617 append 40 30 233;
> #P newex 57 97 74 196617 ladd -3 -3 3 3;
> #P newex 52 50 48 196617 pack 0 0;
> #P newex 50 72 39 196617 dupe 2;
> #P inlet 52 30 15 0;
> #P inlet 90 30 15 0;
> #P outlet 64 170 15 0;
> #P connect 4 0 3 0;
> #P connect 2 0 4 0;
> #P connect 3 0 5 0;
> #P connect 5 0 6 0;
> #P connect 6 0 0 0;
> #P connect 1 0 4 1;
> #P pop;
> #P newobj 219 238 63 196617 p drawpoint;
> #P window linecount 3;
> #P message 293 209 176 196617 else{ double x = (B2*C1 – B1*C2)/det
> double y = (A1*C2 – A2*C1)/det };
> #P message 302 163 156 196617 double det = A1*B2 – A2*B1 if(det == 0){
> //Lines are parallel };
> #P window linecount 1;
> #P newex 174 214 27 196617 / 0.;
> #P newex 189 165 27 196617 *;
> #P newex 170 189 27 196617 !-;
> #P newex 161 166 27 196617 *;
> #P newex 96 217 27 196617 / 0.;
> #P newex 83 166 27 196617 *;
> #P newex 97 191 27 196617 -;
> #P newex 115 165 27 196617 *;
> #P connect 3 0 39 0;
> #P connect 53 0 45 0;
> #P connect 34 2 39 1;
> #P connect 39 0 52 0;
> #P connect 52 0 44 0;
> #P hidden connect 12 0 2 0;
> #P connect 22 0 28 0;
> #P connect 16 0 28 0;
> #P connect 28 0 21 0;
> #P connect 20 0 16 0;
> #P connect 7 0 37 0;
> #P connect 37 0 52 1;
> #P connect 44 0 53 0;
> #P connect 21 0 12 0;
> #P hidden connect 12 3 34 0;
> #P connect 1 0 3 0;
> #P connect 2 0 1 0;
> #P connect 29 2 2 1;
> #P connect 16 0 21 1;
> #P connect 36 0 52 2;
> #P connect 19 0 16 1;
> #P connect 34 0 37 1;
> #P connect 11 0 3 1;
> #P connect 0 0 1 1;
> #P hidden connect 12 2 0 0;
> #P connect 38 0 52 3;
> #P connect 7 0 36 0;
> #P connect 18 0 16 2;
> #P connect 41 0 52 4;
> #P connect 29 1 0 1;
> #P connect 34 1 36 1;
> #P connect 17 0 16 3;
> #P connect 40 0 52 5;
> #P connect 28 0 27 0;
> #P connect 3 0 38 0;
> #P connect 43 0 52 6;
> #P hidden connect 12 0 4 0;
> #P connect 22 0 27 1;
> #P connect 34 3 38 1;
> #P connect 42 0 52 7;
> #P connect 4 0 5 0;
> #P connect 27 0 29 0;
> #P connect 5 0 7 0;
> #P connect 29 0 4 1;
> #P connect 7 0 41 0;
> #P connect 6 0 5 1;
> #P connect 26 0 22 0;
> #P hidden connect 12 1 6 0;
> #P connect 11 0 7 1;
> #P fasten 35 0 41 1 200 296;
> #P connect 29 3 35 0;
> #P connect 25 0 22 1;
> #P connect 29 1 6 1;
> #P connect 7 0 40 0;
> #P connect 3 0 10 0;
> #P connect 24 0 22 2;
> #P connect 35 1 40 1;
> #P hidden connect 12 1 54 0;
> #P connect 54 0 11 0;
> #P connect 11 0 55 0;
> #P connect 3 0 43 0;
> #P connect 23 0 22 3;
> #P connect 29 2 54 1;
> #P connect 35 2 43 1;
> #P hidden connect 12 2 54 2;
> #P connect 3 0 42 0;
> #P connect 7 0 10 1;
> #P connect 56 0 57 0;
> #P connect 45 0 56 0;
> #P connect 29 0 54 3;
> #P connect 35 3 42 1;
> #P connect 10 0 56 1;
> #P connect 57 0 13 0;
> #P connect 15 0 13 0;
> #P connect 14 0 13 0;
> #P connect 28 0 14 0;
> #P connect 21 0 15 0;
> #P connect 27 0 15 0;
> #P connect 30 0 31 0;
> #P connect 11 0 30 0;
> #P pop;
>
>
> On 2/6/08, Rhys Perkins wrote:
>
>> That’s an excellent patch, thanks karrrlo!
>>
>> I was thinking along similar lines only I didn’t want to be limited to just
>> squares, and I would like to avoid using grid patterns, if possible.
>>
>> The LCD object seems perfect as it allows for user created sprites and
>> therefore the user’s imagination, to run riot.
>>
>> I think the collision detection on that must be done by on a pixel by pixel
>> basis though?
>>
>> The algo I came up with and thought would work, unfortunately has various
>> oddities and kinks that come with it…
>>
>> Any other thoughts anyone?
>>
>> Rhys
>>
>>
>
>
>
>


February 7, 2008 | 8:31 pm


February 7, 2008 | 8:33 pm


February 7, 2008 | 10:42 pm

Thanks for the info guys. I figured out a dead easy way of doing it now you told me that I had to stop the counter before changing the ball direction.

The websites were very enlightening! Thanks very much for all your help.

Rhys



Ron
February 7, 2008 | 11:17 pm

so, what does it look like now? got the patch to pass along?

feeble minds wanna know

ron

Rhys Perkins wrote:
Thanks for the info guys. I figured out a dead easy way of doing it now you told me that I had to stop the counter before changing the ball direction.

The websites were very enlightening! Thanks very much for all your help.

Rhys


February 8, 2008 | 5:53 pm

I can upload a video of what I have got so far (without sound as I can’t find a screen capture program for mac with sound)

I also can’t upload the patch until it is done as it is part of a bigger project to be marked by my uni.

Come summer time if people are still interested then I can upload it.

Thanks,

Rhys


February 8, 2008 | 7:51 pm

proprietary hogwash

On 2/8/08, Rhys Perkins wrote:
>
> I can upload a video of what I have got so far (without sound as I can’t
> find a screen capture program for mac with sound)
>
> I also can’t upload the patch until it is done as it is part of a bigger
> project to be marked by my uni.
>
> Come summer time if people are still interested then I can upload it.
>
> Thanks,
>
> Rhys
>


February 9, 2008 | 12:40 am

Not really. I’m just being cautious.

I wrote it using all the standard max objects which are coded by people other than myself, along with some personal thought and development/manipulation of these objects.

I can’t claim ownership for this but I would rather release a more complete version after I have handed it in.

Seeing as you asked so nicely though:

The collision detection is done by this expression:

if $i1 < = ($i2+30) && ($i1+15) >= $i2 && $i3 < = ($i4+30) && ($i3+15) >= $i4 then bang

where:

$i1 is the x co-ordinate of the moving ball on the LCD object
$i2 is the x co-ordinate of the shape it collides with
$i3 is the y co-ordinate of the moving ball
$i4 is the y co-ordinate of the shape it collides with

If the ball comes into contact with the shape then a bang is sent out (at which point the ball will rebound in the opposite direction)

$i1 to ($i1+15) and $i3 to ($i3+15) means that the ball is 15 x 15

$i2 to ($i2+30) and $i4 to ($i4+30) means that the ball is 30 x 30

Hope that helps,

Rhys


February 9, 2008 | 12:44 am

Sorry that should read the shape is 30×30 not the ball for the second one.

$i2 to ($i2+30) and $i4 to ($i4+30) means that the shape is 30 x 30


Viewing 13 posts - 1 through 13 (of 13 total)