PDA

View Full Version : translation of the coordinate system



anubis79
24-09-2003, 09:23 PM
As you know Screen coordinate system origin is located on upper-left corner of the screen and DxDraw component or others are referenced there. It means that DXDraw.surface.Draw and primary.Draw takes their reference on that point.
Could you know a way to translate origin (DXDraw or screen or Form orgin) lower-left corner of the screen and make y axis orientation up. It's essential for me to drawing on Surface or primary. (Not Canvas property coordinate system changing.) Thank you...
:D

Alimonster
24-09-2003, 09:50 PM
It's possible in the GDI to change the mapping mode to what you want. See the following link for info about that, although it's unlikely to help in DelphiX: http://www.efg2.com/Lab/Library/UseNet/1999/0805.txt It may be possible to use GDI functions with the dx surface (see the GetDC and ReleaseDC functions that are undoubtedly hidden somewhere in the dx surface), in which case the above code may help -- but that will be slow since the GDI isn't built for speed.

Note that it's possible to use a subtraction to turn the y axis upside-down. For example, if you had a screen ranging from [0..319] then under the standard computer axis system, 0 in the y axis is the top. However, if you think about the y value of (319 - y) then it will always be what you need mathematically. In general, if you have a known maximum value then just do (max - y) and you're all set.

However, it does depend on whether you want the drawing to be flipped as well: for example, drawing an image at (0, 0) being the screen bottom left, starting as the image's bottom-left corner instead of its top-left corner. If you need that then you'd want to draw the image at a slightly different location, at (max - y - image.height).

Have you considered using OpenGL? OpenGL follows the conventional "y axis is up". If you don't need 3d then you can use an orthographic projection (i.e., no perspective squashing) using glOrtho, and that'll leave you with a few gl functions to wrap up (drawing lines with glBegin/glEnd, loading images, et cetera). It could definitely be handy for you, although I'm not sure of your target hardware or other issues.

I'm probably overlooking something obvious and simple because I'm in a rush. Anyway, hope this helps.

anubis79
25-09-2003, 09:55 AM
It's possible in the GDI to change the mapping mode to what you want. See the following ]http://www.efg2.com/Lab/Library/UseNet/1999/0805.txt[/url] It may be possible to use GDI functions with the dx surface (see the GetDC and ReleaseDC functions that are undoubtedly hidden somewhere in the dx surface), in which case the above code may help -- but that will be slow since the GDI isn't built for speed.

Note that it's possible to use a subtraction to turn the y axis upside-down. For example, if you had a screen ranging from [0..319] then under the standard computer axis system, 0 in the y axis is the top. However, if you think about the y value of (319 - y) then it will always be what you need mathematically. In general, if you have a known maximum value then just do (max - y) and you're all set.

However, it does depend on whether you want the drawing to be flipped as well: for example, drawing an image at (0, 0) being the screen bottom left, starting as the image's bottom-left corner instead of its top-left corner. If you need that then you'd want to draw the image at a slightly different location, at (max - y - image.height).

Have you considered using OpenGL? OpenGL follows the conventional "y axis is up". If you don't need 3d then you can use an orthographic projection (i.e., no perspective squashing) using glOrtho, and that'll leave you with a few gl functions to wrap up (drawing lines with glBegin/glEnd, loading images, et cetera). It could definitely be handy for you, although I'm not sure of your target hardware or other issues.

I'm probably overlooking something obvious and simple because I'm in a rush. Anyway, hope this helps.


First I specify that my project is a drawing project. I' m using DelphiX for some drawing routines and benefiting from Video memory and faster access. At that time I don't need to run in Fullscreen mode. Window mode is enough for me.
At video memory the DirectDrawSurface which I created is referenced upper-left corner of the screen and when I draw it on Primary (with DXDraw.Primary.Draw method) it' s referenced from the same point. You said taking the image (or DXdraw component) bottom-left corner will be solution. I agree but I use a special scrooling for this image and so it doesn't work. (Because of using different corners)
I can try an other concept: Using same corners(Video memory and Screen). But this time main matter is how I can translate or create the DirectDrawSurface from +x, +y region to +x, -y region in memory.
I hope this message is much clear. I wait for your comments.

Alimonster
29-09-2003, 08:39 AM
Sorry about the delay in replying but I totally forgot about this thread! I wish people would hassle me more! :x

Anyway, I'm not sure if you quite caught my meaning the last time.

The final displaying-to-screen (flipping, or whatever method you use) doesn't matter: it can be seen as a generic "show it to the user" method that's the equivalent of a black box. We don't need to touch that part at all.

No, what I was suggesting is that _when composing each frame_, you work with translated coordinates. So, for example, if you had something like the following in pseudo-code, given a max screen height of 480 pixels:

(move to 10, 10)
(draw line to 100, 100)
(draw line to 100, 300)
(draw line to 10, 300)
(draw line to 10, 10)
(draw image at 400, 200)

...then you'd translate the y coordinates of each:

(move to 10, [479 - 10])
(draw line to 100, [479 - 100])
(draw line to 100, [479 - 300])
(draw line to 10, [479 - 300])
(draw line to 10, [479 - 10])
(draw image to 400, [479 - 200 - image.height])

Basically, you generate the frame using your own coordinate system by changing each y value. You can then flip/blit/draw/get it to the screen somehow without worry.

You may not want to subtract the image's height when drawing an image -- dunno since I've not tested the above theory out in code.

Another alternative would be to do everything upside down, including image data, then do the final draw-to-screen flipped upside-down, but that's a pretty obscene option (and I've not thought through that option, to be honest).

EDIT: just for clarification, do your _calculations_ in your "y axis is up" way, but translate the _drawing_ when showing the results. Make sense now?

anubis79
30-09-2003, 08:01 PM
Now, it's enough for me. I've realized your suggestion and tried it. It works quite well. Thank you...