Jump to content

How to map level object coordinates to Canvas coordinates?


StRiKeR

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...