Groups | Blog | Home
all groups > c# > august 2004 >

c# : Can I convert Page to World coordinates


phil cunningham
8/7/2004 10:26:38 PM
I am new to C# and GDI+ so I may have missed a simple way of doing this.

I am trying to use the mouse to pick object up by seeing if the mouse =
position is Inside the object.

However, I am using the Transform method as follows

float scale=3D2;
Matrix x =3D new Matrix();
x.Scale(shift,shift);
g.Transform=3Dx;
pl.Draw(g);


The objects appear twice the size on screen but the mouse position is in =
the Page system.
How can I transform the mouse position into World coordinates so that I =
can check it against the real objects


Thanks in advance for any help you can offer
Jay B. Harlow [MVP - Outlook]
8/10/2004 11:41:49 AM
Phil,
Charles Petzold's book "Program Microsoft windows with Microsoft Visual
Basic .NET" from MS Press, also available in a C# version. Has a number of
example on converting mouse coordinates to world coordinates.

I normally have a function that will initialize the Transform for me
consistently for both the Paint & the Mouse events.

Once I have a consistent Transform I use Graphics.TransformPoints to convert
to & from Page or World & Device coordinates.

The mouse is actually in Device coordinates.

I don't have a sample readily available right now, post if you would like
one.

Hope this helps
Jay


[quoted text, click to view]
I am new to C# and GDI+ so I may have missed a simple way of doing this.

I am trying to use the mouse to pick object up by seeing if the mouse
position is Inside the object.

However, I am using the Transform method as follows

float scale=2;
Matrix x = new Matrix();
x.Scale(shift,shift);
g.Transform=x;
pl.Draw(g);


The objects appear twice the size on screen but the mouse position is in the
Page system.
How can I transform the mouse position into World coordinates so that I can
check it against the real objects


Thanks in advance for any help you can offer
Phil

phil cunningham
8/12/2004 8:34:38 PM
dear jay

thanks for the reply


I think I've got something working - my problem is the Objects are measured
in Metres and the device units are mm and Mouse is in pixels but it seems to
make sense.


If you have an example this may help a lot

Many thanks
Phil


[quoted text, click to view]

AddThis Social Bookmark Button