# Web Coordinates -> QC Coordinates

Hey all,

Working on a project where I need to convert something from pixel space (origin in the upper-left, width/height in pixels) to QC space (origin in center, width/height normalized to 2). I know the CoGe Webkit plugin does the opposite (takes your mouse coords in QC space, converts to pixel space) and that the code is available (http://code.google.com/p/cogewebkit/source/browse/trunk/CoGeWebKitPlugIn...), but I figured I'd ask and see if anyone else has done this already? If not I'll go ahead and make the general purpose solution and then put it up here :)

## Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

### Re: Web Coordinates -> QC Coordinates

What do you want to do exactly? Sorry, but can't figured out what conversion you talked about :) Maybe this helps : http://code.google.com/p/cogemousecoords/ ?

### Re: Web Coordinates -> QC Coordinates

I have an algorithm for rectangle packing in 2D space, written in Javascript using pixel dimensions/coordinates. I want to use the output of that algorithm to arrange rectangles (sprites) in QC. I can go into more detail about the algorithm, but I've basically solved the problem myself as it is :) (I need to tackle aspect ratio, but that shouldn't be a problem)

### Re: Web Coordinates -> QC Coordinates

you will find my macro is very useful for interpolating coordinates. i found i needed to do this type of scale interpolation operation so much that i made a nifty macro. it works very well when you know the render dimensions or the original max and min scale. if you do not know your original max and min scale then a stock interpolation patch set to external time base should be used.

this patch takes the mouse coordinates in units, 0,0 being center and converts it to screen coordinates in pixels 0,0 being the lower left, then convertes the screen coordinates to units with 0,0 being lower left, then converts the those units to web coordinates in pixels, 0,0 being in the upper left corner, and then finally converting the web coordinates in pixels back to units with 0,0 in the center.

there are more than one way to do this..... see macro patches for details....

PreviewAttachmentSize
coordin8tr.qtz95.62 KB

### Re: Web Coordinates -> QC Coordinates

Thanks for the upload. As it turns out, we're both apparently oblivious, as QC comes with a built-in Pixels to Units and Units to Pixels patches out of the box. I'll need to do some finagling to get the coordinates right (e.g. 0,0 on the web is not 0,0 in QC), but the conversions should be taken care of :)

### Re: Web Coordinates -> QC Coordinates

I am well aware of the stock built in unit converter. if you take the time to investigate this patch you will see it only uses the width for its calculation. you would need to make another pixels to unit converter using the same formula but this time use the height. armed with this new macro and the stock one you can convert pixels to units for both x and y. this will put your x pixels in a 0 to 2 unit space which is correct but not what you asked for. you asked specifically for 0,0 to be in the center. that would be a unit space of -1 to 1.

I'm not really sure why you would ignore the macro I made that does exactly what your asking and choose to go down the stock patch route that doesn't do what you asked for. if you where hoping to solve this problem on your own I'm not sure why you asked for help but do what ever helps you learn. sometimes copy and pasting a web to unit macro someone else made isn't the best option for learning. like I said there are many solutions to this problem and I gave you my solution. all you would need to do is plug you web coordinates into the macro labeled web to units with 0,0 being on the center and you should be good to go.

now the only issue I can see with my macro is that the original min and max is set to the qc screen size. so you would need to be running full screen I order to match the web coordinates. or you could simply use the overall screen size as your min max and not the size of the qc render window. not sure if that makes sense to you. just try converting in full screen or if your screen dimensions are lets say 1024 on x then set min to 0 and max to 1024. if your web coordinates are taken from the size of the browser window then make sure the qc window is the same size as the browser window or just make sure the original min max is set to what ever range your web cords are in for the x and y dimensions respectively.