Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
StRiKeR

How to map level object coordinates to Canvas coordinates?

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?

Thanks in advance..

Share this post


Link to post

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.)

Share this post


Link to post
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!

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×