[comp.graphics] Hexagonal bit maps

jdb@reef.cis.ufl.edu (Brian K. W. Hook) (01/12/91)

I am writing an app that uses an hexagonal map...each hex in the map has
its own bit map.  I am running into the problem of how to use the Borland
Graphics interface (actually, ANY graphics library with a getimage/putimage
type function set) to write the hex bit map on the screen without writing
into the area of the rectangular bit map outside of the hex....e.g.


       0011111100
       0111111110
       1111111111
       0111111110
       0011111100

I don't want ANYTHING written into the region with zeros.  This wouldn't be
so hard if it was just black and white, but I am using 4-bit color.  Does
anyone know of an easy method of overlay this rectangular block on the
screen but with only the hex part showing up?

thanks for the help,

Brian

orpheus@reed.UUCP (P. Hawthorne) (01/13/91)

  jdb@reef.cis.ufl.edu (Brian K. W. Hook) writes:

| I am running into the problem of how to use the Borland Graphics interface
| (actually, ANY graphics library with a getimage/putimage type function set)
| to write the hex bit map on the screen without writing into the area of the
| rectangular bit map outside of the hex....e.g.
|
|       0011111100
|       0111111110
|       1111111111
|       0111111110
|       0011111100

  QuickDraw on the Macintosh has a procedure to allow you to copy one bitmap
  or pixmap to another, through a mask. It's a lot like a stencil, in that you
  can use a region to stop an image from being transfered outside that region.
  If I was going to try to do the same thing as the procedure I mentioned,
  without using it, I might try two methods first off.

1 Copy each pixel, from left to right and top to bottom, only if it is inside
  the area that you want to obliterate. Given that you are working with hexes,
  you might be able to develop an efficient algorithm to determine whether a
  given point is in or out of the hex. Alternately, if your graphics interface
  has the ability to define regions, you could define a hex at the appropriate
  scale when you began writing hexes, and use the mod operator and the
  interface call to see if the point was in the region.

2 Save the areas that you do not want to be obliterated, and replace them when
  you are done filling in the hex. If memory is an important consideration,
  you might be able to store the areas outside of the hex in a rectangle, by
  placing the upper left first, the lower right second, the lower left third,
  and the upper right fourth. Of course, that leave you in the position of 
  having to solve the problem again....

  I was implementing a Z Buffer the other day, which is a problem a lot like
  this one. The idea being that you step through each point on a surface, and
  only write the color of the surface onto pixels that are inside the area
  of the surface, and are closest to the eye. I had no problem determining
  if the point was closest to the eye. I had to use regions the determine if
  the point was inside the area of the surface. It was fortunate that the 
  inside/outside test for regions in QuickDraw seems relatively quick.

  I'd be very interest to see any other solutions that are posted.

joe@proto.COM (Joe Huffman) (01/14/91)

In article <26275@uflorida.cis.ufl.EDU>, jdb@reef.cis.ufl.edu (Brian K. W. Hook) writes:
> I am writing an app that uses an hexagonal map...each hex in the map has
> its own bit map.  I am running into the problem of how to use the Borland
> Graphics interface (actually, ANY graphics library with a getimage/putimage
> type function set) to write the hex bit map on the screen without writing
> into the area of the rectangular bit map outside of the hex....e.g.

[...example deleted...]

This can be done with the graphics library that comes with the Zortech C/C++
compiler for the PC, under DOS, OS/2, and a couple DOS extenders.

Use the fg_drawmatrix() function call.

Further explaination available on request.

disclaimer... I wrote the package.

-- 
joe@proto.com

mcastle@mcs213f.cs.umr.edu (Mike Castle (Nexus)) (01/14/91)

In article <26275@uflorida.cis.ufl.EDU> jdb@reef.cis.ufl.edu (Brian K. W. Hook) writes:
>
>       0011111100
>       0111111110
>       1111111111
>       0111111110
>       0011111100

Clip you image to the hexagonal shape (such as by ANDing it with the above
sample image).

Using the same above sample image, do a PUTIMAGE with the NOTPut option.
    
Now do a PUTIMAGE with the clipped image with the ORPut option.

This may cause a slight flicker at the spot you are changing, but it should
work. 

The hardest part will probably be clipping the image.  If your pulling stuff
off the screen to be moved, you might be able to clip it on a separate
graphics page (not the current one).  I haven't done much graphics programming
yet, so I don't know how difficult that would be.

If your creating a bunch a images for later use, then it will probably be no
problem clipping it nicely.

Hope this helps.

BTW, anyone no how to access the 320x200x256 mode on a VGA?  or is that SVGA 
only?  I've seen lots of programs that use it, but can't seem to find any
mention of it in either TPascal or TC++ manuals.  I've picked up a couple of
.BGI drivers, but I haven't had a chance to look at them.  All my graphics
programming will probably have to wait until summer.  :-<

Tanx.
-- 
Mike Castle (Nexus) S087891@UMRVMA.UMR.EDU (preferred)       | ERROR:  Invalid
                mcastle@mcs213k.cs.umr.edu (unix mail-YEACH!)| command 'HELP'
Life is like a clock:  You can work constantly, and be right | try 'HELP'
all the time, or not work at all, and be right twice a day.  |

jpenne@ee.ualberta.ca (Jerry Penner) (01/14/91)

In article <26275@uflorida.cis.ufl.EDU> jdb@reef.cis.ufl.edu (Brian K. W. Hook) writes:
>
>       0011111100
>       0111111110
>       1111111111
>       0111111110
>       0011111100

[ How to draw hexagonal bitmaps? ]

Well, What you do is make a bitmap that has 1 bits everywhere you
want your hexagonal pattern to show through (ie. just like your
example hexagon.)  This I will call MASK.  Your image I will call
IMAGE.  The data already on the screen I will call SCREEN.

    for each screen byte to modify
	get SCREEN
	xor IMAGE
	and MASK
	xor SCREEN	now the screen data is put where mask == 0 and
			image data goes where mask == 1
	put SCREEN

Have fun.
-- 
-------------
    Jerry Penner	alberta!bode!jpenne	Edmonton, Alberta, Canada