home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 7098 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.9 KB

  1. Path: mail2news.demon.co.uk!ns.unibol.com
  2. From: John Girvin <jgirvin@bfs.unibol.com>
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: Collision Detects !!!!
  5. Date: Tue, 9 Apr 1996 14:06:01 GMT
  6. Message-ID: <199604091406.OAA00456@mailhost.unibol.com>
  7. X-NNTP-Posting-Host: ns.unibol.com
  8. X-Newsreader: TIN [version 1.2 PL2]
  9. X-Mail2News-Path: ns.unibol.com
  10.  
  11. On Sun, 7 Apr 1996 11:19:56 GMT, breese@imada.ou.dk (Bjorn Reese) wrote:
  12. :>John Girvin (jgirvin@bfs.unibol.com) wrote:
  13.  
  14. :>> if ( (px2 - bullet[i]->x) < (bullet[i]->width + player->width) &&
  15. :>>       ^^^   ^^^^^^^^^^^^
  16. :>>        swapped!
  17. :>Ok, makes sense now. I simply love it!
  18.  
  19. Yeah, I thought it was pretty clever too! I didnt invent it mind, I
  20. just saw it somewhere and saved it for posterity. 
  21. Glad you like it anyway :)
  22.  
  23. :>On a second look it would be fatal to remove player->width from the
  24. :>inequality. I was initially puzzled by it's appearence, but now I've
  25. :>realized that it's the principal cause why the unsigned comparison works.
  26.  
  27. I realised this also when I tried to further optimise my collision 
  28. detection this way! Normal algebraic rules do not apply with unsigned 
  29. arithmetic, something they never taught me at school :)
  30.  
  31. You can make the comparison into:
  32.  
  33.     if ( (bullet[i]->x2 - player->x) > -(bullet[i]->width + player->width) )
  34.              ^^           ^  ^ ^
  35.                       |            \ | /
  36.                      NB!            NB!
  37. if its easier to calculate bx2 than px2, or you want to keep px2 in a
  38. register (seeing as its a constant ;) and not change it with a 
  39. sub bxreg,px2reg. Check that expression though ;)
  40.  
  41. cya,
  42. /John.
  43. __________________________________________________________________________
  44. |/\John Girvin : developing software for Unibol Inc., speaking for myself|
  45. |\/jgirvin@bfs.unibol.com | Amiga,!PC,net,Trek,SF,MTB,C2H50H,house,techno|
  46. |girv@girvnet.demon.co.uk | Youll never take me alive, Macro$loth fiends!|
  47. \A1200/030-40/10M/3.0 A500/000-7/2M/2.04 464/Z80-4/0.0625M/1.0 Team AMIGA/
  48.