# "Inverted" Coordinate Conversions (mpxi, pxmi)?

## Recommended Posts

What is the point of the "inverted" (in the sense of negated) coordinate conversion methods in the P2 subsystem? Isn't the direction of coordinate system essentially arbitrary, such that multiplying by -1 for conversions in both directions is equivalent to not doing so at all? For example, a sprite with position (100, 200) and velocity (60, -20) in Phaser is to the right of and below the origin and moving to the right and up. Don't you get the same physics whether P2 represents than internally as (5,10) and (3,-1) or as (-5,-10) and (-3,1)? As long as the mirroring is done (or not done) consistently, why does it matter?

##### Share on other sites

the mpxi/pxmi conversions are precisely what allows you to work that way.

##### Share on other sites

the mpxi/pxmi conversions are precisely what allows you to work that way.

I don't really follow. There are inverted (mpxi/pxmi) and non-inverted (mpx/pxm) versions of these functions. Phaser appears to use the inverted versions internally. Why? And doesn't that force any code that interacts with the Phaser P2 subsystem to use the inverted subsystem as well?

##### Share on other sites

Yes it does, and the reason is that internally, p2 uses different units than Phaser. The non-inverted versions are used for stuff like circle radii, where the orientation really doesn't matter. But every time you interact with p2 from Phaser you need to apply the mpxi/pxmi unit conversion.

##### Share on other sites

Yes it does, and the reason is that internally, p2 uses different units than Phaser. The non-inverted versions are used for stuff like circle radii, where the orientation really doesn't matter. But every time you interact with p2 from Phaser you need to apply the mpxi/pxmi unit conversion.

Ok, using the non-inverted versions for non-signed values make sense. But I still don't understand why the negative factor is necessary for position/velocity coordinates. What does it matter if Phaser and P2's notions of up/down and left/right are reversed as long as that reversal is consistent?

##### Share on other sites

That's actually a very good question. I guess you have to do it either in every conversion, or in not a single one—and that's a choice that's been made by the framework, to have it everywhere. I wonder if it were possible to build a, perhaps leaner, but perhaps also more opaque implementation of p2 without any unit conversions whatsoever.

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

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