I am trying to oscillate a 2D object about a point, while the object has already been drawn then later I want to oscillate it by specifying the pivot point, how to proceed, please help me.It is for a mini project.I am using codeblocks and using c programing language along with OpenGL to do this, I have attached main .c file and .cpb file below (For reference I have attached the code for that object also below .) I have attached a .png file as what is my 2D image looks like.I want to oscillate that image about its top point(i.e cap tip).
#include <GL/glut.h>
#include <math.h>
#define PI 3.14159265358979324
void myinit()
{
glClearColor(1.0,1.0,1.0,0.0);
glMatrixMode (GL_PROJECTION);
gluOrtho2D(0.0, 200.0, 0.0, 150.0);
//glutPostRedisplay();
}
void display(void)
{
float r3 = 4.0; // Radius of circle.
float x3 = 80.0; // X-coordinate of center of circle.
float y3 = 67.0;
float r1 = 1.0; // Radius of circle.
float x1 = 77.0; // X-coordinate of center of circle.
float y1 = 73.0;
float r2 = 1.0; // Radius of circle.
float x2 = 83.0; // X-coordinate of center of circle.
float y2 = 73.0;
float R = 3.0; // Radius of circle.
float X = 80.0; // X-coordinate of center of circle.
float Y = 103.0; // Y-coordinate of center of circle.
int numVertices = 25; // Number of vertices on circle.
float t = 0; // Angle parameter.
int i;
glClear(GL_COLOR_BUFFER_BIT);
//glColor3f(0.5, 0.5, 0.5);
glLineWidth(2.0);
glEnable(GL_LINE_STIPPLE);
//glLineStipple(1,0x00ff);
//draw a line
glBegin(GL_LINES);
glColor3f(0.92, 0.78, 0.62);
glVertex2f(80.0,60.0);
glVertex2f(90.0,65.0);
glVertex2f(90.0,65.0);
glVertex2f(90.0,75.0);
glColor3f(0.137255, 0.556863, 0.137255);//0.0, 0.5, 0.0);
glVertex2f(90.0,75.0);
glVertex2f(80.0,80.0);
glVertex2f(80.0,80.0);
glVertex2f(70.0,75.0);
glColor3f(0.92, 0.78, 0.62);
glVertex2f(70.0,75.0);
glVertex2f(70.0,65.0);
glVertex2f(70.0,65.0);
glVertex2f(80.0,60.0);
glColor3f( 0.137255, 0.556863, 0.137255);
glVertex2f(90.0,75.0);
glVertex2f(80.0,100.0);
glVertex2f(80.0,100.0);
glVertex2f(70.0,75.0);
glEnd();
glFlush();
glBegin(GL_POLYGON);
glColor3f(0.1, 0.9, 0.0);
for(int i = 0; i < numVertices; ++i)
{
//glColor3ub(rand()%256, rand()%256, rand()%256);
glVertex3f(X + R * cos(t), Y + R * sin(t), 0.0);
t += 2 * PI / numVertices;
}
glEnd();
glFlush();
glBegin(GL_POLYGON);
glColor3f(0.647059, 0.164706, 0.164706);
for(int i = 0; i < numVertices; ++i)
{
glVertex3f(x1 + r1 * cos(t), y1 + r1 * sin(t), 0.0);
t += 2 * PI / numVertices;
}
glEnd();
glFlush();
glBegin(GL_POLYGON);
glColor3f(0.647059, 0.164706, 0.164706);
for(int i = 0; i < numVertices; ++i)
{
glVertex3f(x2 + r2 * cos(t), y2 + r2 * sin(t), 0.0);
t += 2 * PI / numVertices;
}
glEnd();
glFlush();
glBegin(GL_POLYGON);
glColor3f(1.0, 0.7, 0.0);
for(int i = 0; i < numVertices; ++i)
{
glVertex3f(x3 + r3 * cos(t), y3 + r3 * sin(t), 0.0);
t += - PI / numVertices;
}
glEnd();
glFlush();
}
void main(int argc,char *argv[])
{
glutInit(&argc,argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (1000, 1000);
glutInitWindowPosition (0, 0);
glutCreateWindow ("joker");
myinit();
glutDisplayFunc(display);
glutMainLoop();
}
thanks in advance, please help me