How to make my objects move to the middle and stop using OpenGL in Visual Studio

  2d, c++, graphics, opengl, visual-studio-code

I’m developing a very simple 2D animation using C++ with OpenGL and I’m practically new to coding. I wonder how can I make the male character moves to the red dot image for reference. This is my code snippet for the male character so far.

male character:

void maleChar(int x, int y, int w) {

//draw body shaped like an egg
glColor3ub(244, 177, 131);
ellipse(200, x, y, 100);

glColor3ub(68, 114, 196);
glBegin(GL_POLYGON);
glVertex2i(1000, 300);
glVertex2i(1200, 300);
glVertex2i(1200, 350);
glVertex2i(1170, 350);
glVertex2i(1150, 400);
glVertex2i(1050, 400);
glVertex2i(1050, 350);
glVertex2i(1000, 350);
glEnd();

//draw eyes
glColor3ub(255, 255, 255); //white
circle(100, x - 40, y + 40, 23);  //outer LEFT eye

glColor3ub(0, 0, 0); //black
circle(100, x - 40, y + 40, 10);  //inner LEFT eye

glColor3ub(255, 255, 255);
circle(100, x + 40, y + 40, 23);  //outer RIGHT eye

glColor3ub(0, 0, 0);
circle(100, x + 40, y + 40, 10);  //inner RIGHT eye

//draw nose (small triangle in the middle of face)
glColor3ub(237, 125, 49);
glBegin(GL_POLYGON);
glVertex2i(1080, 170);
glVertex2i(1120, 170);
glVertex2i(1100, 205);
glEnd();


// draw mouth (long, thin rectangle)
glColor3ub(109, 12, 12);
glBegin(GL_POLYGON);
glVertex2i(1060, 130);
glVertex2i(1140, 130);
glVertex2i(1140, 140);
glVertex2i(1060, 140);
glEnd(); }

display scene:

void display() {
glClear(GL_COLOR_BUFFER_BIT);

scene1();               
maleChar(1100, 200, 200);     
femaleChar(450, 330, 90);  

glFlush();
glutSwapBuffers(); }

Initialization:

void initGL() {
glClearColor(0.0, 0.0, 0.0, 0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, SCREEN_WIDTH, 0, SCREEN_HEIGHT); }

Main:

int main(int argc, char** argv) {
glutInitDisplayMode(GLUT_DOUBLE);
glutInit(&argc, argv);
glutInitWindowSize(SCREEN_WIDTH, SCREEN_HEIGHT);
glutCreateWindow("LIFT LOVE");
glutDisplayFunc(display);
initGL();

glutMainLoop(); }

Source: Windows Questions C++

LEAVE A COMMENT