0

I need to be able to transform one of my own objects along with some GraphicsPath objects in .Net. I need any scaling, translation, rotation operations that are performed on the GraphicsPath objects to also occur on my own object.

For example, here is some scaling code:

using (Matrix ScaleTransform = new Matrix(1, 0, 0, 1, 0, 0)) // scale matrix
{
    ScaleTransform.Scale(ScaleX, ScaleY);
    moPath.Transform(ScaleTransform);
    moBoundingBox.Transform(ScaleTransform);

    MyObject.Transform(ScaleTranform);
}


//In "MyObject":
public void Transform(Matrix m)
{
    //How is this implemented?  Is there a built-in .Net method?
}

The question is: What is the best way to implement the "Transform" method in MyObject. I did quite a bit of searching, but couldn't find any references for the best way to do this.

Thanks!

Flipster
  • 4,373
  • 4
  • 28
  • 36

1 Answers1

1

Implementing the transform yourself is not very hard, take a look at:

http://en.wikipedia.org/wiki/Transformation_matrix

So is your object a bitmap or something? Then this might be some of the way:

http://en.csharp-online.net/GDIplus_Graphics_Transformation%E2%80%94Image_Transformation

Or you could leave your object and push the transformation to a stack and use it when you make it into graphics.

Hey - it looks like the Matrix class can do a lot for you:

http://msdn.microsoft.com/en-us/library/system.drawing.drawing2d.matrix.aspx

For example

TransformPoints(Point[]) or TransformVectors(Point[])
Rune Andersen
  • 1,650
  • 12
  • 15
  • Hi Rune, I appreciate the response. The last example you gave is the one I actually implemented. I simply made all of my coordinates into "points", and passed the point array into the built-in matrix transform. So, great idea! +1 and accepted. – Flipster Jul 01 '11 at 21:26