Thread View: comp.sys.next.programmer
2 messages
2 total messages
Started by Dave Griffiths
Fri, 31 Jul 1992 16:18
Bitmap Wizard
Author: Dave Griffiths
Date: Fri, 31 Jul 1992 16:18
Date: Fri, 31 Jul 1992 16:18
52 lines
2696 bytes
2696 bytes
I'm posting this for a friend:
Hi there!
I am having a problem with reading and writing bitmap images, and
thought I would poll the assembled gurus out there.
Some background:
I am writing a Pinball game which has a TIFF file background onto
which objects such as flippers, balls, bumpers and lights are
composited. These objects are initially drawn into NXImages and
then composited where needed onto the view containing the background.
I need to do "hit detection" to determine when the ball has hit an
object, and the fastest and easiest way of doing that appears to be to
have a "shadow" pinball table onto which I draw shadows of things that
the ball can hit. The background of this shadow table is white, and
walls (which balls just bounce off) are light grey. Reactive objects
like bumpers and flippers are dark grey. Whenever I draw an object on
the table (say redrawing a flipped flipper) I redraw its shadow (a
simple dark grey outline) on the shadow table. Thus whenever I move
the ball(s) I read from the point on the shadow table just ahead of
them, and if it is a wall I do a bounce, if it is a flipper etc. (dark
grey) I work out which object it is, then send a message to that
object saying it has been hit etc.
So what I am saying is that I need to be able to create a bitmap which
I can composite onto, and from which I can read pixel values, very
very fast. Reading pixel values fast means I need to know where in
memory the bitmap is stored.
Now, to use the NeXT composite methods I need to use NXImages or
Views. If I want to alter a bitmap image it MUST be an
NXCachedImageRep because if I try to alter a NXBitmapImageRep it just
changes a cached copy, and seeing as I don't know where the cached
copy is, I can't read pixels back from it. Also, with
NXCachedImageReps I cannot find out where the bitmap is stored in
memory (I can get the offscreen window it is stored in).
Help, I don't know what to do; I can lockFocus on the
NXCachedImageRep, and copy the bit into a newly allocated
NXBitmapImageRep, get the address of *that* bitmap and read the pixel,
but that takes forever. Has anyone (Ali Ozer?) got any ideas?
Thanks in advance,
Tim Bissel.
PS. This is being posted for me by a friend, but you can reply to him,
post replies or try mailing me at ...unido!portland!tim
Collision detection (was Re: Bitmap Wizard)
Author: Sam Streeper
Date: Mon, 03 Aug 1992 01:26
Date: Mon, 03 Aug 1992 01:26
61 lines
3774 bytes
3774 bytes
prim!dave@germany.eu.net (Dave Griffiths) writes: > I am writing a Pinball game which has a TIFF file background onto > which objects such as flippers, balls, bumpers and lights are > composited. > I need to do "hit detection" to determine when the ball has hit <...> Your basic idea is sound, but I think your proposed architecture is wrong. (Assuming I understood you correctly.) Remember that the Window Server (which will composite the bits between images and put them on screen) is a separate process from your application. The bitmaps ultimately reside in the window server's address space and you can't directly read data from there. You can use PostScript to send you the data back, but that's a rather expensive proposition that you don't really want to do while you're doing animation. (An interesting tidbit: the tiff files are originally interpreted in your address space (by library routines) to create the bitmaps that are shipped off to the window server.) I think what you want to do is create a collision array in your own address space, where the collision array closely resembles the bitmap of the pinball background. This collison array could be thought to resemble a Z-buffer for 3D graphics (if that helps). Because you separate collision areas from appearance, you're free to fancy up the appearance. The approach I describe above (collision table) works well for irregularly shaped bitmaps; you compare some interesting points (maybe every pixel) against the table; if you get a hit presumably the table describes the characteristics of the thing you hit. Another approach is algorithmic. This is easy for rectangular regions, simple polygons or other simple shapes, but harder for more complex shapes. Fortunately, you can often reduce complex displayed shapes to simple regions for the purpose of quick and dirty collision detection (reducing circles to squares or eight points, for example) This technique also scales well to 3 dimensional collision detection. There's a drawback to both of the above; they only tell you about a collision after it has happened. It maybe be difficult to tell how one shape entered another, and how to "back-off" to the point at which the collision actually occurred. Worse yet, things may go through each other without ever stopping at a point where you detect a collision; you must carefully optimize maximum single iteration distances to guarantee that detectable collisions will always occur. Another approach is to calculate when and where the next collision will occur. Then an animation step is the normal animation time or the time to take you to the next collision time, whichever is less. Because you have precalculated when all collisions will occur, you don't have to look for collisions on every iteration, only when parameters change. Furthermore, you never iterate past the point of collision, only to the point where it begins to happen. This technique is difficult if you have objects that have varying trajectories or speeds. However, it can be effectively combined with the other techniques. As always, I hope this makes some sense and is at least slightly helpful... -sam -- Opinions are not those of my employer. They're not even mine. They're probably wrong besides. How did they get in here, anyway?
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads