 Search In
• More options...
Find results that contain...
Find results in...

## Recommended Posts

I'm working on a wad tool written in Python.Mainly to pursue my interest in the
architecture of the WAD format. Secondly, to increase my programming skills.

I've parsed the infotable and I am attempting to display E1M1's VERTEXES/LINEDEFS.However, I don't know how to map a point whose X and Y coords in the level are say X:-1088 Y:3060 to a screen. Whose top-left is 0,0.

How is this mapped? Is some geometric function needed? I think I need to find the center of the map in the level to reference against the center of my canvas to map the cords?

Linguica said:

Thanks. Omgifol is a complicated library to me right now. It's structure isn't clear to me. He's importing a lot of his other modules..

I'm not familiar with Python syntax, so I'll just describe principles.

While loading vertexes, remember the very lowest x coordinate there is in the whole map and story it in a variable called for example "minX", same for the very highest x coordinate (maxX), and very lowest + very highest y coordinates too (minY, maxY).

Now, assuming you want the entire map to fit onto the canvas, define a scale factor (a floating point number) like this:

`scale = min(canvasWidth/(maxX-minX),canvasHeight/(maxY-minY));`
Where "canvasWidth" and "canvasHeight" are self-explanatory, and the function "min" kind of too (it returns the lesser one of the 2 parameters passed to it).

Now for each vertex ("v"), assuming it already has "x" and "y" properties loaded from the map's VERTEXES, compute "canvasX" and "canvasY" coordinates like this:
```v.canvasX = (v.x-minX)*scale;
v.canvasY = (v.y-minY)*scale;```
(EDIT: Ninjaed by Linguica.)

scifista42 said:

I'm not familiar with Python syntax, so I'll just describe principles.

While loading vertexes, remember the very lowest x coordinate there is in the whole map and story it in a variable called for example "minX", same for the very highest x coordinate (maxX), and very lowest + very highest y coordinates too (minY, maxY).

Now, assuming you want the entire map to fit onto the canvas, define a scale factor (a floating point number) like this:

`scale = min(canvasWidth/(maxX-minX),canvasHeight/(maxY-minY));`
Where "canvasWidth" and "canvasHeight" are self-explanatory, and the function "min" kind of too (it returns the lesser one of the 2 parameters passed to it).

Now for each vertex ("v"), assuming it already has "x" and "y" properties loaded from the map's VERTEXES, compute "canvasX" and "canvasY" coordinates like this:
```v.canvasX = (v.x-minX)*scale;
v.canvasY = (v.y-minY)*scale;```
(EDIT: Ninjaed by Linguica.)

With what you've explained to me, the Python code makes sense now! Thanks guys!