forums

TNT Basic Forums > Programming Q&A
Polygon problem!
< Last Thread     Next Thread >
Author
Thread        Post A Reply

09-07-2002 21:59

Posted by:
Holmes

Click Here to Email Holmes   Find more posts by Holmes

okay, so I've got polygons in my map that sort of act as guides to tell vehicles what direction to move on roads. The problem is that the program never thinks the vehicles are in any of the polygons. Here's the section of code:

Procedure rotatevehicle(int vx,int vy)
int m
float rotation
for m = 0 to map polygon count-1
if in map polygon (m,vx,vy,0) = true
rotation = 270
print vx;",";vy;" is in Polygon ";m; " of Type ";Map Polygon Name(m); " at ";map polygon x(m); "," ; map polygon y(m); " to " ; map polygon x(m) + map polygon width(m) ; "," ; map polygon y(m) + map polygon height(m)
else if in map polygon (m,vx,vy,0) = false
print vx;",";vy;" is NOT in Polygon ";m; " of Type ";Map Polygon Name(m); " at ";map polygon x(m); "," ; map polygon y(m); " to " ; map polygon x(m) + map polygon width(m) ; "," ; map polygon y(m) + map polygon height(m)
end if
next m
end Proc (rotation)

The result is that it prints stuff that SHOULD satisfy the conditions, but it doesn't. Here's an example from the output console:

3,73 is NOT in Polygon 2 of type left at 0,0 to 7,83

Now how exactly does 3,73 not lie between 0,0 and 7,83?

P.S. The print statement takes up several lines in this field so sorry if the code isn't very readable.

09-08-2002 16:56

Posted by:
Mark Tully

Find more posts by Mark Tully

Holmes,

How are you drawing your map, are you using map viewports?

Thanks

Mark

09-08-2002 22:08

Posted by:
Holmes

Click Here to Email Holmes   Find more posts by Holmes

Yes, I am using map viewports.

09-10-2002 19:35

Posted by:
Mark Tully

Find more posts by Mark Tully

Polygons

Polygons are more like bitmasks that can either be set for a tile or not. They aren't filled rectangles. The rectangle formed from the results of 'map polygon x/y' and 'map polygon width/height' are the bounding box around the polygon - it doesn't mean that every tile inside those bounds are in the polygon, just that all tiles outside of these bounds are outside the polygon.

Basically, by using these bounds, you can limit the number of tiles to check against when trying to find all tiles in a polygon. By only checking the ones inside the polygon bounds, this saves checking every tile in the map.

Are you sure that the 3,73 has the polygon set for it? Make sure the polygon isn't just a hollow rectangle on your map, only the coloured tiles in the polygon editor are 'in' the polygon.

Thanks,

Mark

All times are GMT        Post A Reply

Forum Jump:
< Last Thread     Next Thread >

< Contact Us - TNT Basic >

Powered by: vBulletin Lite Version 1.0.1 Lite
Copyright © Jelsoft Enterprises Limited 2000.