2016-04-10 5 views
0

Çalışmak için yoyo programımı almada sorun yaşıyorum; Hareketli ve dönen yoyo ile birlikte ilerlemek için gittikçe büyüyen ve küçülen bir dizim var, ama ben yoyo ile birlikte hareket eden iplerim var. Yoyo yukarı ve aşağı hareket ederken sabit kalan dizgiye ihtiyacım var. Bir tuşa da tahsis edilmiş dize ve yoyo hareketlerine sahip olmak zorundayım. Koduma yardım etmeme yardım eder misin? (Ayrıca cansız yoyo lütfen bağışlayın; bunu tasarlamadan önce programlamayı bitirmek istedi) benim sorun çözüldüOpenGL yoyo programı sorunları

#include "stdafx.h" 
#include <GL/glut.h> 
#include <GL/gl.h> 
#include <math.h> 

void firstDisplay(); 
void secondDisplay(); 
void movement(); 
void init(); 
void drawButton(); 
void handleButton(int button, int state, int x, int y); 

const int Width=720; 
const int Height = 480; 

static float PI = 3.14159; 
static float radius = 25; 
static float INC= (PI/30); 
static GLfloat spin = 0.0; 
static GLfloat deltaz = .001; 
static GLfloat deltax = 0.0; 
static GLfloat deltay = 0.0; 

//######################################################### Main ######################################################### 
void main(int argc, char** argv) 

{ 
    glutInit(&argc, argv); 

    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_MULTISAMPLE | GLUT_DEPTH); 
    glutInitWindowSize(Width,Height); 
    glutInitWindowPosition(0,0); 

    glutCreateWindow("Yoyo"); 

    glutDisplayFunc(firstDisplay); 
    glutMouseFunc(handleButton); 
    init(); 
    glutMainLoop(); 

    return; 
} 
//######################################################### Draw Button ######################################################### 
void drawButton() 
{ 
glBegin(GL_POLYGON); 
float theta; 
    for (theta = 0.0; theta <= 2 * PI; theta += INC) 
    { 
     glColor3f(1,0,1); 
     glVertex2f(40 + radius * cos(theta), 40 + radius*sin(theta)); 
    } 
glEnd(); 
} 
//######################################################### Second Display ######################################################### 
void secondDisplay() 
{ 
float theta; 

glClear(GL_COLOR_BUFFER_BIT); 

glBegin(GL_POLYGON); //Here is the yoyo 
    for (theta = 0.0; theta <= 2 * PI; theta += INC) 
    { 
     glColor3f(1,1,1); 
     float radius1 = 75; 
     glVertex2f(360 + radius1 * cos(theta), 80 + radius1*sin(theta)); 
    } 
glEnd(); 

glBegin(GL_POLYGON); //Here is the yoyo design 
    for (theta = 0.0; theta <= 2 * PI; theta += INC) 
    { 
     glColor3f(0,1,1); 
     float radius1 = 55; 
     glVertex2f(350 + radius1 * cos(theta), 90 + radius1*sin(theta)); 
    } 
glEnd(); 

glFlush(); 

return; 
} 
//######################################################### First Display ######################################################### 
void firstDisplay() 
{ 
glClear(GL_COLOR_BUFFER_BIT); 

float theta; 
glBegin(GL_POLYGON); //Here is the yoyo 
    for (theta = 0.0; theta <= 2 * PI; theta += INC) 
    { 
     glColor3f(1,1,1); 
     float radius1 = 75; 
     glVertex2f(360 + radius1 * cos(theta), 80 + radius1*sin(theta)); 
    } 
glEnd(); 

glBegin(GL_POLYGON); //Here is the yoyo 
    for (theta = 0.0; theta <= 2 * PI; theta += INC) 
    { 
     glColor3f(0,1,1); 
     float radius1 = 55; 
     glVertex2f(350 + radius1 * cos(theta), 90 + radius1*sin(theta)); 
    } 
glEnd(); 

drawButton(); 
glutSwapBuffers(); 
glFlush(); 
return; 
} 
//######################################################### Draw String ######################################################### 
void draw_string() 
{ 
glColor3f(1.0, 0.0, 0.0); 
glBegin(GL_POLYGON); 
glVertex3f(363, 8.25 - deltay, 0.0); 
glVertex3f(357, 8.25 - deltay, 0); 
glVertex3f(357, 6, 0); 
glVertex3f(363, 6, 0); 
glEnd(); 
} 
//######################################################### Button Controls ######################################################### 
void handleButton(int button, int state, int x, int y) 
{ 
    static int index =-1; 

    if(button == GLUT_LEFT_BUTTON) 
    { 
     if(y>= 10 && y<= 100) 
     { 
      if (state == GLUT_DOWN) 
      { 
       glutIdleFunc(movement); 
      } 
      if (state == GLUT_UP) 
      { 
       glutIdleFunc(NULL); 
      } 
     } 

     glutSwapBuffers(); 
    } 
} 
//######################################################### Yoyo Movement ######################################################### 
void movement() 
{ 
    static int goingup = 0; 

glClear(GL_COLOR_BUFFER_BIT); 

if(goingup==1) 
{ 
    deltay -= 6; 

    if(deltay <= 0) 
    { 
     goingup = 0; 
    } 

    spin = spin -5; 
    if(spin < 360) 
    { 
     spin = spin + 360; 
    } 
} 
if(goingup == 0) 
{ 
    deltay += 6; 

    if (deltay >= 315) 
    { 
     goingup = 1; 
    } 

    spin = spin +5; 
    if(spin < 360) 
    { 
     spin = spin + 360; 
    } 
} 

glPushMatrix(); 
glTranslatef(360+deltax, 80+deltay, 0.0); 
glRotatef(spin,0.0,0.0,1.0); 
glTranslatef(-360,-80, 0.0); 
secondDisplay(); 
draw_string(); 
glPopMatrix(); 
drawButton(); 
glutSwapBuffers(); 
} 

//######################################################### Init ######################################################### 
void init() 
{ 
    glClearColor(0, 0, 0, 0.0); 
    glColor3f(1, 1, 1); 

    glMatrixMode(GL_PROJECTION); 
    glLoadIdentity(); 
    gluOrtho2D(0,Width,Height,0); 

    return; 
} 

cevap

0

. Çok gibi hareket işlevi içinde draw_string() ve seconddisplay() işlev ayrıldı gitti:

} 

glPushMatrix(); 
glTranslatef(360+deltax, 80+deltay, 0.0); 
glRotatef(spin,0.0,0.0,1.0); 
glTranslatef(-360,-80, 0.0); 
secondDisplay(); 
glPopMatrix(); 
glPushMatrix(); 
glTranslatef(360+deltax, 80+deltay, 0.0); 
glRotatef(0,0.0,0.0,1.0); 
glTranslatef(-360,-80, 0.0); 
draw_string(); 
glPopMatrix(); 
drawButton(); 
glutSwapBuffers(); 
} 

I draw_string gelen sıkma kaldırıldı() 'in glRotatef.