qwazimoto
Active member
- Joined
- Oct 20, 2006
- Messages
- 39
- Programming Experience
- Beginner
Hi
I am creating a program where I have to simulate people moving around an entertainment complex. The user must be able to draw the complex's floor layout, then add any objects to the layout, eg tables, gardens ect.
I feel competant enough to tackle these problems
(except the AI for the people moving around but that will be in another thread I guess).
What I would like help with is after the user has drawn an image they are happy with to be the birds eye floor layout. I need to find the walls of this layout. I have already got this working but not in a verry appropriate way (I think). So heres what im doing now.
All outlines of anything drawn will be red.
this code gets the position of all red pixels starting from left down to right down
The layout will almost always be an odd shape (consisting of squares, poly's, ellipses), and these red lines that are used for walls, may not just be the outline of this image as there will usualy be walls inside the building...
All I want is a fast way to find wether a person is going to collide with a wall? but I need to know how to arrange the point array/ array's of where the walls are, in a way that can be checked fast...
A good way I think of looking at this is as if it were a maze.
Where I go from here depends on the best Idea i guess so thanks.
Im pretty blank and I appolagise if I cant be more specific but thanks in advance for any suggestions
I am creating a program where I have to simulate people moving around an entertainment complex. The user must be able to draw the complex's floor layout, then add any objects to the layout, eg tables, gardens ect.
I feel competant enough to tackle these problems
(except the AI for the people moving around but that will be in another thread I guess).
What I would like help with is after the user has drawn an image they are happy with to be the birds eye floor layout. I need to find the walls of this layout. I have already got this working but not in a verry appropriate way (I think). So heres what im doing now.
All outlines of anything drawn will be red.
this code gets the position of all red pixels starting from left down to right down
VB.NET:
[COLOR=#008000]'declare the rectangle to get image from[/COLOR]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] rect [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Rectangle([/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].Panel1.Location.X, [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].Panel1.Location.Y, [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].Panel1.Width, [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].Panel1.Height)[/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] pnlBMP [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Bitmap [COLOR=#008000]'Declare a bitmap[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]'"Copyrect" returns the image and applies it to pnlBMP[/COLOR][/SIZE]
[SIZE=2]pnlBMP = [/SIZE][SIZE=2][COLOR=#0000ff]CType[/COLOR][/SIZE][SIZE=2](copyRect(Panel1, [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] RectangleF(Panel1.Location.X, [/SIZE]
[SIZE=2] _Panel1.Location.Y, Panel1.Width, Panel1.Height)), Bitmap).Clone[/SIZE]
[SIZE=2]pnlBMP.Save([/SIZE][SIZE=2][COLOR=#800000]"testimage.bmp"[/COLOR][/SIZE][SIZE=2]) [COLOR=#008000]'Save a copy of this image[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] pnts(0) [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Point [COLOR=#008000]'Decalre a point array[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] x, y, count [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer = 0[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]For[/COLOR][/SIZE][SIZE=2] x = 1 [/SIZE][SIZE=2][COLOR=#0000ff]To[/COLOR][/SIZE][SIZE=2] pnlBMP.Width [COLOR=#008000]'For each pixel on X axis[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff] For[/COLOR][/SIZE][SIZE=2] y = 1 [/SIZE][SIZE=2][COLOR=#0000ff]To[/COLOR][/SIZE][SIZE=2] pnlBMP.Height [COLOR=#008000]'check all pixels on Y axis [/COLOR][/SIZE]
[COLOR=#008000] 'if the pixels color = red then add its location to array[/COLOR]
[SIZE=2][COLOR=#0000ff] If[/COLOR][/SIZE][SIZE=2] pnlBMP.GetPixel(x, y).ToArgb = Color.Red.ToArgb [/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE]
[SIZE=2] pnts(count) = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Point(x, y - 1)[/SIZE]
[SIZE=2][COLOR=#0000ff] ReDim[/COLOR][SIZE=2][COLOR=#0000ff]Preserve[/COLOR][/SIZE][SIZE=2] pnts(count)[/SIZE]
count += 1
[/SIZE][SIZE=2][COLOR=#0000ff] End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff] Next[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Next[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]'Write the points of each red pixel to text file[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] w [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] IO.StreamWriter([/SIZE][SIZE=2][COLOR=#800000]"points.txt"[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] i [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]For[/COLOR][/SIZE][SIZE=2] i = 0 [/SIZE][SIZE=2][COLOR=#0000ff]To[/COLOR][/SIZE][SIZE=2] pnts.Length - 1[/SIZE]
[SIZE=2]w.WriteLine(pnts(i).ToString)[/SIZE]
[SIZE=2][COLOR=#0000ff]Next[/COLOR][/SIZE]
[SIZE=2]w.Close()[/SIZE]
The layout will almost always be an odd shape (consisting of squares, poly's, ellipses), and these red lines that are used for walls, may not just be the outline of this image as there will usualy be walls inside the building...
All I want is a fast way to find wether a person is going to collide with a wall? but I need to know how to arrange the point array/ array's of where the walls are, in a way that can be checked fast...
A good way I think of looking at this is as if it were a maze.
Where I go from here depends on the best Idea i guess so thanks.
Im pretty blank and I appolagise if I cant be more specific but thanks in advance for any suggestions
Last edited: