Re: Nearest point to the mouse cursor?
From: Niels Jensen (NielsJensen_at_discussions.microsoft.com)
Date: 10/06/04
- Next message: Vjay77: "How can I find out memory free and used using vb.net?"
- Previous message: Bonj: "Re: Intellisense"
- In reply to: Larry Serflaten: "Re: Nearest point to the mouse cursor?"
- Next in thread: Niels Jensen: "Re: Nearest point to the mouse cursor?"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 6 Oct 2004 03:55:29 -0700
I'd just like to thank averyone who helped me out on this - I'm getting
there..... slowly and you've all been a great help holding my hand as I go
Thanks guys
Niels
"Larry Serflaten" wrote:
>
> "Niels Jensen" <NielsJensen@discussions.microsoft.com> wrote
> > Thanks for this code Larry it's *yet* another was that I can draw a hexmap...
> >
> > Is there any chance you could be so kind and explain what the complicated
> > mathematical sections do (and how they do it?)
>
> It is very easy to get X and Y coordinates when the cells are rectangles:
>
> > > ' Get red grid cell x and y
> > > x = e.X \ SX
> > > y = e.Y \ SY
>
> SX and SY are the size values of the red cells, so that, dividing the
> current X or Y mouse position by the size of the cell give the cell's
> X or Y values.
>
> It is not so easy when there are angled lines or other such polygons.
> In your case, I first set out to identify where the angled lines are, you
> can see by the displayed grid they do follow a repeating pattern and
> that pattern is represented in the Rows array. Second, the angle the
> slopes are at is constant so one formula (based on the ratio of X to Y)
> can be used to tell when the mouse crosses the angled line. When it
> does, the horizontal position has to be adjusted. There is one formula
> for the forward slash, and another for the backward slash. With the
> correct X position, there is one other thing to address and that is that
> alternating hex columns are offset by one cell difference and that is
> found and altered as the last part of the process.
>
>
> > I've been trying to figure
> > out how the 1st section works:
> >
> > > Rows(0) = New Integer() {-1, 0, 0, -2, 1, 1, -1}
> > > Rows(1) = New Integer() {-2, 0, 0, -1, 1, 1, -2}
>
> It is an array of arrays.
>
> These statements assign arrays of Integers to the elements of the Rows
> array. "New Integer()" tells VB you're creating a new array and the values
> inside the brackets initialize that array with those values. In this case, a -1
> represents the forward slash (angle cell) and -2 represents the backward
> slash (angle cell). 0 and 1 were only used during the draw process to help
> determine if the horizontal line of the hex cell should be at the top or
> bottom of that group of cells.
>
> > I'm also drawing the hexcells in a panel, not a form and although I've
> > successfully managed to do this within my program using your code, the
> > graphics are only drawn within the initial visible part of the panel, as soon
> > as I use the scrollbars I get one of two things hapening. If the drawimage
> > is in the "paint" sub then it re-draws all over the screen eventually drawing
> > a nice big red block on the panel screen. how can I make your hexmap draw a
> > 50hex by 50hex board and then maintain the image so that the scrollbars on
> > the panel display the image correctly. I'll be overlaying the Hexes that
> > have information with small .bmp graphical images such as trees or towns, the
> > idea being that the end user can click on a hex containing a town image and
> > get the information for the town.
>
> You will probably want to back up that panel with a memory bitmap such that
> you draw your 50X50 board to the bitmap, and then copy it over to the panel
> (in its Paint event) depending on the scroll position.
>
> While doing your drawing in the paint event is a low impact method, it gets a
> bit useless when you have several items to draw and are erasing the screen to
> reposition them all. In that case it is better to draw to memory and then copy
> the finished image in one go.
>
> Take a look at what I did, I gave the form a public Image property that was
> my memory bitmap. It is such a common methodology that I did it by habit!
> In the form's Paint event I simply copied over the image in one go. Doing it
> that way (and even that can be improved) allows for automatic repainting when
> the form is restored from being minimized, or when some other window covers
> and then exposes that form.
>
> Where I have 0, 0 you'd add in values from your scroll control....
>
> HTH
> LFS
>
>
>
>
>
>
>
- Next message: Vjay77: "How can I find out memory free and used using vb.net?"
- Previous message: Bonj: "Re: Intellisense"
- In reply to: Larry Serflaten: "Re: Nearest point to the mouse cursor?"
- Next in thread: Niels Jensen: "Re: Nearest point to the mouse cursor?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|