Path: chuka.playstation.co.uk!news From: James Chow Newsgroups: scee.yaroze.programming.2d_graphics Subject: Re: animation, collision detection, backgrounds Date: Sun, 18 Jul 1999 22:23:11 +0100 Organization: PlayStation Net Yaroze (SCEE) Lines: 38 Message-ID: <379245BF.76BC9046@chowfam.demon.co.uk> References: <3786FE72.1BE9@hotmail.com> <7m8sug$dq823@chuka.playstation.co.uk> NNTP-Posting-Host: chowfam.demon.co.uk Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 4.5 [en] (Win98; I) X-Accept-Language: en > > When i wrote a simple function to test two spheres colliding as they > > bounced around the screen the program slows down when the spheres are > > near the edge of the screen (but only if collision detection is being > > used). Also when if a higher res mode (640 x512) the screen flickered > > constantly and when the spheres collided they produced a static double > > image until the spheres collided again. What's wrong? > > > > Also the spheres sometimes stick together if they collide whilst moving > > towards each other. > > PASS. :o( > (I won't even bother trying to answer this one) If you get flickering in hi-res, that means one thing - the code's taking too many cpu cycles. Yellow book -> Frame Buffer Access -> Drawing Control in Interlaced Mode (p52 in mine) : "drawing must always be completed in 1/60th second (NTSC) or 1/50th second (PAL)". Given the fact that the program slows down on collision, indicates that the collision detection code may need optimising. You're not doing the pixel perfect masking routine are you? Try this instead if you are. If x1, y1 and r1 are centre and radius of sphere 1, and similarly for sphere 2 x2, y2, r2. Then, if ((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)) < ((r1 - r2) * (r1 - r2)) have collision Whatever you do - don't square root! That eats cycles like no tomorrow... If the square root of a number is bigger than another then so is its square. In general - avoid the float/double functions that need to work out fractions. They are *very poor* in terms of performance. Cheers, James.