Author Topic: Rotating around origin for framesets.  (Read 6441 times)

v6v

  • Clever
  • Fanatic
  • ***
  • Posts: 500
  • Has renamed his project to Galaxy!
    • View Profile
    • My Developer Page!
    • Email
Rotating around origin for framesets.
« on: 2013-03-16, 06:30:22 PM »
Simple question:

Is there a way to use the FrameSet Tweening Wizard to rotate around the origin point 0, 0? I need to get 360 frames of a graphic rotated around the origin point I the frameset editor, (0, 0)

When I use the frameset tweening wizard now, it rotates around a point that seems to change, I need a point that is constantly 0, 0.

The only way I see to do this is to manually do it (This can't be the only way, right??)

This is what I want.

« Last Edit: 2013-03-16, 10:08:24 PM by v6v »

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Rotating around origin for framesets.
« Reply #1 on: 2013-03-18, 05:20:15 AM »
Like any wizard, this wizard has its limitations compared to what you can do manually, and you may be encountering one. I couldn't think of a reason to rotate around a constant point, I guess, and I figured the most useful point around which to rotate (for the purposes of the wizards at least) was a frame's center.

Maybe if you offset all the frames you're going to want to rotate by the appropriate amount, you can indirectly cause the wizard to rotate around a constant point by dealing with offset frames instead of the originals. I only have 3 minutes left and that's not enough time to investigate this this morning.

v6v

  • Clever
  • Fanatic
  • ***
  • Posts: 500
  • Has renamed his project to Galaxy!
    • View Profile
    • My Developer Page!
    • Email
Re: Rotating around origin for framesets.
« Reply #2 on: 2013-03-18, 02:06:53 PM »
You've answered my question nicely. If the rotation point is the center of a frame, then I can manually just rotate around the center of the sprite using the frame editor and the Around Center checkbox while specifying the degree, this actually gives me much greater control of rotation, thank you bluemonkmn.

Time to break my game apart for the 23'rd time now, *chuckle. This might actually be the last time though, and it seems to be my last major hurdle. I've somehow figured out how to manually set the graphic sheet for a frameset at runtime, and this should cut my frameset count from 434 to 28, and I think my EXE is mainly embedded framesets.
« Last Edit: 2013-03-18, 02:10:13 PM by v6v »

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Rotating around origin for framesets.
« Reply #3 on: 2013-03-19, 04:54:58 AM »
If the frameset tweening wizard already rotates around the center, why do you need to use the Frame Editor and manually rotate with "Around center"? Why not just use the wizard?

v6v

  • Clever
  • Fanatic
  • ***
  • Posts: 500
  • Has renamed his project to Galaxy!
    • View Profile
    • My Developer Page!
    • Email
Re: Rotating around origin for framesets.
« Reply #4 on: 2013-03-19, 09:38:23 PM »
It does, missed that! *chuckle*

v6v

  • Clever
  • Fanatic
  • ***
  • Posts: 500
  • Has renamed his project to Galaxy!
    • View Profile
    • My Developer Page!
    • Email
Re: Rotating around origin for framesets.
« Reply #5 on: 2013-04-26, 12:45:22 PM »
Let me continue my question.

I have this code in DrawFrame

It's right before GL.Vertices,I use cornerstrig in my GL.Vertices call in DrawFrame

I'm trying to handle rotation inside of DrawFrame.

Code: [Select]
  PointF Center = new PointF(((((corners[3].X))) + (((corners[0].X))/2)), ((((corners[1].Y))) + ((corners[0].Y))/2));
       float radius = (float)(Math.Sqrt(Math.Pow(((((corners[3].X)) + ((corners[0].X)))/2) , 2) +  Math.Pow(((((corners[1].Y)) + ((corners[0].Y)))/2), 2)));


  

      PointF[] cornerstrig = new PointF[4];

      cornerstrig[0].X = (float)(Center.X - (radius*Math.Cos((3*Math.PI)/4)));
      cornerstrig[0].Y = (float)(Center.Y - (radius*Math.Sin((3*Math.PI)/4)));

      cornerstrig[1].X = (float)(Center.X - (radius*Math.Cos((5*Math.PI)/4)));
      cornerstrig[1].Y = (float)(Center.Y - (radius*Math.Sin((5*Math.PI)/4)));

      cornerstrig[2].X = (float)(Center.X - (radius*Math.Cos((7*Math.PI)/4)));
      cornerstrig[2].Y = (float)(Center.Y - (radius*Math.Sin((7*Math.PI)/4)));

      cornerstrig[3].X = (float)(Center.X - (radius*Math.Cos((1*Math.PI)/4)));
      cornerstrig[3].Y = (float)(Center.Y - (radius*Math.Sin((1*Math.PI)/4)));


It seems right but it's as if the frame expands and shrinks in size randomly, I'm not sure what I'm doing wrong..

I'm trying to get the Center, radius, and calculate the points as Rcos(theta) Rsin(Theta from center, using the 4 angles 3pi/4 5pi/4 7pi/4 1pi/4

Maybe I should handle Rotation before corners[] is passed to DrawFrame?
« Last Edit: 2013-04-26, 12:50:39 PM by Galaxy »

v6v

  • Clever
  • Fanatic
  • ***
  • Posts: 500
  • Has renamed his project to Galaxy!
    • View Profile
    • My Developer Page!
    • Email
Re: Rotating around origin for framesets.
« Reply #6 on: 2013-04-26, 05:09:36 PM »
Hey, I got it working! It works only for square graphics, but that's all I need it for.

Code: [Select]
 PointF Center = new PointF(((((corners[0].X))) + (((corners[3].X))/2)), ((((corners[0].Y))) + ((corners[1].Y))/2));
       float radius = (float)(Math.Sqrt(Math.Pow(((((corners[3].X)) + ((corners[0].X)))/2) , 2) +  Math.Pow(((((corners[1].Y)) + ((corners[0].Y)))/2), 2)));


  



      PointF[] cornerstrig = new PointF[4];
      
if (phi != 0)
{
      cornerstrig[0].X = (float)(Center.X - (radius*Math.Cos(((3*Math.PI)/4)+phi)));
      cornerstrig[0].Y = (float)(Center.Y - (radius*Math.Sin(((3*Math.PI)/4)+phi)));

      cornerstrig[1].X = (float)(Center.X - (radius*Math.Cos(((5*Math.PI)/4)+phi)));
      cornerstrig[1].Y = (float)(Center.Y - (radius*Math.Sin(((5*Math.PI)/4)+phi)));

      cornerstrig[2].X = (float)(Center.X - (radius*Math.Cos(((7*Math.PI)/4)+phi)));
      cornerstrig[2].Y = (float)(Center.Y - (radius*Math.Sin(((7*Math.PI)/4)+phi)));

      cornerstrig[3].X = (float)(Center.X - (radius*Math.Cos(((1*Math.PI)/4)+phi)));
      cornerstrig[3].Y = (float)(Center.Y - (radius*Math.Sin(((1*Math.PI)/4)+phi)));
}
else
{
   cornerstrig[0] = corners[0];
cornerstrig[1] = corners[1];
cornerstrig[2] = corners[2];
cornerstrig[3] = corners[3];
}

      


            if (!Flipped)
      {      
      GL.TexCoord2((float)sourceRect.Left / texture.Width, (float)sourceRect.Top / texture.Height);
      GL.Vertex3((cornerstrig[3].X + offsetX)/scaledown, (cornerstrig[3].Y + offsetY)/scaledown, pos);
      GL.TexCoord2((float)sourceRect.Left / texture.Width, (float)(sourceRect.Top + sourceRect.Height) / texture.Height);
      GL.Vertex3((cornerstrig[2].X + offsetX)/scaledown , (cornerstrig[2].Y + offsetY)/scaledown , pos );
      GL.TexCoord2((float)(sourceRect.Left + sourceRect.Width) / texture.Width, (float)(sourceRect.Top + sourceRect.Height) / texture.Height);
      GL.Vertex3((cornerstrig[1].X + offsetX)/scaledown, (cornerstrig[1].Y + offsetY)/scaledown , pos );
      GL.TexCoord2((float)(sourceRect.Left + sourceRect.Width) / texture.Width, (float)sourceRect.Top / texture.Height);
      GL.Vertex3((cornerstrig[0].X + offsetX)/scaledown , (cornerstrig[0].Y + offsetY)/scaledown , pos );
      }

            if (Flipped)
      {
      GL.TexCoord2((float)sourceRect.Left / texture.Width, (float)sourceRect.Top / texture.Height);
      GL.Vertex3((cornerstrig[0].X + offsetX)/scaledown , (cornerstrig[0].Y + offsetY)/scaledown , pos );
      GL.TexCoord2((float)sourceRect.Left / texture.Width, (float)(sourceRect.Top + sourceRect.Height) / texture.Height);
      GL.Vertex3((cornerstrig[1].X + offsetX)/scaledown, (cornerstrig[1].Y + offsetY)/scaledown , pos );
      GL.TexCoord2((float)(sourceRect.Left + sourceRect.Width) / texture.Width, (float)(sourceRect.Top + sourceRect.Height) / texture.Height);
      GL.Vertex3((cornerstrig[2].X + offsetX)/scaledown , (cornerstrig[2].Y + offsetY)/scaledown , pos );
      GL.TexCoord2((float)(sourceRect.Left + sourceRect.Width) / texture.Width, (float)sourceRect.Top / texture.Height);
      GL.Vertex3((cornerstrig[3].X + offsetX)/scaledown, (cornerstrig[3].Y + offsetY)/scaledown, pos);
  
      }



This code either mirrors a graphic horizontally or rotates it, it resides in DrawFrame, thanks, bluemonkmn for help!