🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: alt.msdos.programmer
1 messages
1 total messages Started by Steve Madsen Mon, 28 Sep 1992 05:07
Rotating a bitmap
#642
Author: Steve Madsen
Date: Mon, 28 Sep 1992 05:07
67 lines
2619 bytes
        First off, this deals with Turbo C++ 1.0 and 256 color VGA graphics.

        I've got a problem with some code I'm trying to develop to rotate an
image.  This is pretty basic stuff.  All I'm trying to do is have an image in
putimage() format, pass a couple of pointers to memory and an angle to rotate,
and have the destination image be the rotated version of the source.  I've got
most of the thing completed, but it just does not work right and I've spent
about 4 1/2 hours trying to debug it.

        So, if any cares to look at the code and see what's wrong, or maybe
knows where I can look for some information on this type of thing, PLEASE let
me know!

        Code follows .sig...

-- 
Steve Madsen
Miami University  Oxford, OH
Internet: sjmadsen@miavx1.acs.muohio.edu

--
/**************************************************************************
   rotateimage:
 
   Rotates an image in putimage format "angle" degrees.  The resulting
   image is stored at "dest".
**************************************************************************/
 
void rotateimage(char *src, char *dest, int angle)
{
  double hypotenuse;
  double theta;
  double radians;
  int x, y;
  int dx, dy;
  int width = src[0] + src[1] * 256;
  int height = src[2] + src[3] * 256;
  int centerx = width / 2, centery = height / 2;
 
  // First fill up the destination memory with "normal" values:
 
  dest[0] = src[0];
  dest[1] = src[1];
  dest[2] = src[2];
  dest[3] = src[3];
  for (x = 0; x < width * height; x++)
    dest[x + 4] = 0;
 
  angle = angle % 360;  // reduce & adjust for clockwise rotation
  radians = (M_PI / 180) * angle; // convert degrees -> radians
  for (y = 0; y < height; y++)
    for (x = 0; x < width; x++) {
      dx = x - centerx;
      dy = y - centery;
      hypotenuse = sqrt((double)(dx * dx) + (double)(dy * dy));
      if (hypotenuse == 0.0) {
        dx = x;
        dy = y;
      } else {
        theta = asin(dy / hypotenuse);
        dx = cos(theta + radians) * hypotenuse;
        dy = sin(theta + radians) * hypotenuse;
      }
      if (dx >= 0 && dx < width && dy >= 0 && dy < height)
        dest[dy * width + dx + 4] = src[y * width + x + 4];
    }
}
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads