rotate an 8byte array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • adam johnson
    New Member
    • Dec 2011
    • 4

    rotate an 8byte array

    Hi guys/Gals.
    I want to rotate an 8 byte array, to create a spinning effect, i.e.

    char_buff[0] = 0x81;
    char_buff[1] = 0x42;
    char_buff[2] = 0x24;
    char_buff[3] = 0x18;
    char_buff[4] = 0x18;
    char_buff[5] = 0x24;
    char_buff[6] = 0x42;
    char_buff[7] = 0x81;

    this makes up a "character" , any ideas as how I can rotate it. not just 90 degrees, 180, 270. that bits easy. but a full 'spin'?

    Thanks guys.
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    What, exactly, is a full spin?

    Comment

    • adam johnson
      New Member
      • Dec 2011
      • 4

      #3
      i would like to rotate this 8x8 character array around its center point. so it look like the character is turning round.

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        You will need a graphic O/S for that.

        You don't say what you are using but a console C app can't do what you want.

        Comment

        • lspxy
          New Member
          • Nov 2011
          • 12

          #5
          Code:
          char swap = '\0';
          for (i = 0; (i < 8, j = 7 - i) && (i <= j); i++)
          {
              swap = char_buff[i];
              char_buff[i] = char_buff[j];
              char_buff[j] = swap;
          }

          Comment

          • adam johnson
            New Member
            • Dec 2011
            • 4

            #6
            thankyou. I can already do the easy rotates as i said earlier. I was thinking more along te lines of of a 0-360 degree rotate. Tried a few ways and although i do get a rotation "of sorts" its not good.
            I was thinking along the lines of plotting an 8x8 square at a given angle and then filling the area in with my 8x8 array. I think i must be getting some weird rounding problems ans stuff. Just about given up now. Heres what ive got so far:-

            rotate_array ( 30,30, 'A', angle );

            void rotate_array( int xpos, int ypos, int character, int angle )
            {
            double newX, newY;
            double radians = (double)angle; // radians = angle * (PI/180);
            double pX=3, pY=3; // centre of character
            int x, y, index=character *8; // index character in my array
            int char_width = 7; // character height in bits
            int char_height = 7; // character width in bits
            int row, mask;

            // characters are held in 8x8 array. However, the character data
            // is really only 7x6, thats removing spacing for printing etc.
            // so we will ignore row 7, column 0

            for (y=0; y<char_height; y++)
            {
            row = char_buff[ index+y ]; /* first byte of character */

            for (x=char_width; x>=1; x--)
            {
            // rotate a point (x,y) angle around (pX, pY)
            // NOTE: we are using the angle NOT radians.

            newX = 0.5 + ((x-pX)*cos(radians ) - (y-pY)*sin(radians ) + pX);
            newY = 0.5 + ((x-pX)*sin(radians ) + (y-pY)*cos(radians ) + pY);

            SET_CURSOR( xpos+newX, ypos+newY );
            mask = 1 << x;
            if (row & mask) printf("%c", 219 );
            else printf(".");
            }
            }
            }

            Comment

            • adam johnson
              New Member
              • Dec 2011
              • 4

              #7
              the problem seem to be plotting the square. Holes are left by the newX,newY points.And some points are used twice. Anyideas anyone? I do use radian instead of angle now too.

              newX = ((x-pX)*cos(radians ) - (y-pY)*sin(radians )) + pX;
              newY = ((x-pX)*sin(radians ) + (y-pY)*cos(radians )) + pY;

              Comment

              Working...