31
Help, Errors, FAQ / Re: Rotating around origin for framesets.
« 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.
This code either mirrors a graphic horizontally or rotates it, it resides in DrawFrame, thanks, bluemonkmn for help!
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!