Quantcast
Channel: VBForums - CodeBank - Visual Basic 6 and earlier
Viewing all articles
Browse latest Browse all 1529

[VB6] GDI+ Matrix For Rotation/Scale/Shear and Hit Testing

$
0
0
GDI+ offers a matrix object that can be applied to various other GDI+ objects. One of those is the Graphics object (similar to GDI's hDC). With a matrix, we can simultaneously scale, rotate, shear & offset/translate a rendering in basically one call.

The attached offers such options in a simple sample project. The matrix is created and can be cached for all future rendering, unless of course something changes and the matrix should be recreated. What's kind of neat is that an inverted copy of the matrix can be used for hit testing on the rotated, scaled, sheared, translated rendering relative to the original object, un-rotated, un-scaled, un-sheared, un-translated.

Please read the comments included in the code, especially within the pvCreateDisplayMatrix routine, before asking questions about the code

Name:  Untitled.jpg
Views: 96
Size:  44.6 KB


Just some notes. When rotating and not choosing both horizontal & vertical center alignment, keep in mind that you are rotating around a specific point on the edge of the picturebox. The top/left pixel of the image is where rotation begins within the image, not the center of the image. Should anyone want to rotate this way, obviously, the edges of the viewing area would not be a good point to begin rotation from, therefore the pvCreateDisplayMatrix allows an optional point to be passed. But since the sample project uses the edges of the viewing area if not centering rotation, the following is provided:

- Alignment determines point of rotation
- Point of rotation is optional passed parameters to function or, if no parameters passed, relative to display area

Center/Center :: rotation is from center of image over the point of rotation
any other combination :: rotation is from top/left pixel of image around the the point of rotation

So, let's say you have horizontal alignment on right edge & vertical alignment on bottom edge, ok? Well, the picturebox is now only displaying the northwest quadrant of the 360 degree rotation area. The other 3 quadrants are off the picturebox. If you try to rotate image at 45 degrees around the bottom/right corner, the rendering would fall in the southeast quadrant and not viewable. Angles from 180 to 269 would be the northwest quadrant.
Attached Images
 
Attached Files

Viewing all articles
Browse latest Browse all 1529

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>