flounder
flounder

Reputation: 141

WinGDI SetWorldTransform Inverse

I need an inverse transformation.

I start with a CPoint(x0, y0);

I do a rotation and translation so that in my new coordinate system, (x0, y0) becomes (0,0) and I draw everything in the new coordinate system (which may have other that right-angle rotation).

void DoMyRotation(CPoint origin, CPoint end)
   {
    XFORM transform;
    ...compute XFORM...details don't matter
    dc.ModifyWorldTransform(&transform, MWT_LEFTMULTIPLY); 
   }
   
void MyConvertToThisCoordinateSystem(CDC & dc, CPoint & pt, XFORM & oldtransform)
   {
    ... how to write this?
   }

void MyDrawSomething(CDC & dc, CPoint origin, 
                     CPoint endpoint)
   {
    int n = dc.SaveDC();
    MyDrawPlus(dc, origin);  // draws + at origin
    // find the linear distance between the origin and the
    // endpoint
    int distance = MyAskPythagoras(origin, endpoint);

    DoMyRotation(dc, origin, endpoint);
    // What I want is:
    //
    // * origin
    //  \
    //   \  ('distance' units line)
    //    \
    //     * endpoint
    

I do a bunch of drawing calls relative to the transformed coordinate system, during which I compute some new coordinate values of interest The transformation does no scaling. For example:

dc.MoveTo(0,0);
dc.LineTo(distance, 0);

//  (0,0)           (distance, 0)
//  *---------------*
// Now compute the center of the line
CPoint pt(distance / 2, 0);

//   (0,0)   (distance/2, 0)
//   *-------*-------*
//           pt      (distance, 0)

// Which translates to (on the screen)
// * origin
//  \
//   * pt
//    \
//     * endpoint
// pt coordinates are in the transformed 
// coordinate system
XFORM oldtransform;                   // ?
dc.GetWorldTransform(&oldtransform);  // ?
dc.RestoreDC(n);

// Now I need pt in the current coordinate space, so I
// can draw something there

MyConvertToThisCoordinateSystem(dc, pt, oldtransform);
MyDrawPlusSign(dc, pt); // Draws a + in the center of the line

//    * origin
//     \
//      +
//       \
//        * endpoint

There does not seem to be any way to do this. Note that the actual drawing is much more complex than this trivial example. I have several interesting points I have recorded and I need to use them in the original coordinate system. They are computable only in the drawing in the transformed system since they are a consequence of doing the drawing. Actually, the drawing is done by a virtual draw() method, so I have no idea what is actually being drawn, or how; all I know is that certain key points will be recorded, so the next object can be drawn in the correct place.

In general, the GetWorldTransform is not quite right, because I want the inverse of the transform I used, since drawings may be nested inside other. I can cause the MyRotation to update an XFORM & parameter instead of just keeping it local. But I am a bit pressed for time and am hoping there is already some well-documented method for doing this.

Upvotes: 1

Views: 184

Answers (0)

Related Questions