Reputation: 867
Is there anyway I can rotate my 2D Texture image rotating to a point? I've tried the glRotate function, It rotates and moves the object. I'm looking for a function/way for rotating my textures to a point by not moving them.
Here's my draw code:
static void Draw2DTexture(int textureid, float x1, float y1, float width, float height, Color color)
{
float x2 = x1 + width;
float y2 = y1 + height;
RectangleF rect;
rect = new RectangleF(0, 0, 1, 1);
GL.PushAttrib(AttribMask.ColorBufferBit);
GL.Color3(color);
GL.BindTexture(TextureTarget.Texture2D, textureid);
GL.Enable(EnableCap.Texture2D);
GL.Disable(EnableCap.DepthTest);
GL.Rotate(35, 0f, 0f, 1f);
GL.Begin(BeginMode.Quads);
GL.TexCoord2(rect.Right, rect.Bottom); GL.Vertex2(x2, y2);
GL.TexCoord2(rect.Right, rect.Top); GL.Vertex2(x2, y1);
GL.TexCoord2(rect.Left, rect.Top); GL.Vertex2(x1, y1);
GL.TexCoord2(rect.Left, rect.Bottom); GL.Vertex2(x1, y2);
GL.End();
GL.Enable(EnableCap.DepthTest);
GL.PopAttrib();
}
Draw2DTexture(5, 300f, 300f, 256f, 512f, Color.White);
Upvotes: 0
Views: 665
Reputation: 4631
"It rotates and moves the object"
I'm not sure what rotating to a point is, but the problem you mention here is about having the proper center of rotation.
Whenever you apply a rotation to an object, it rotates it about the origin. This is great, but what happens when your object isn't centered about the origin? You need to translate your object to the origin, rotate it, and translate it back to its original position.
This will rotate in place.
What about rotation around a point? Instead of translating to the origin via the rotating object's position, translate by the point around which you want to rotate
Upvotes: 1