2014-11-12 3 views
0

OpenGL과 C를 사용하여 2D 비디오 게임을 만들고 있는데 문제가 있습니다. 특정 숫자의 오브젝트를 만들려고합니다. 100이라고 가정 해 봅시다. 임의의 속도와 방향으로 돌아 다니다.하지만 작동하지 않으며 더 나은 방법이 있다고 확신 할 수 있습니다.하지만 알아낼 수는 없습니다.OpenGL - 임의 방향으로 움직이는 물체

는 지금까지 내가 100 번 그려하려는 것은 내 클래스입니다 :

#include "stdafx.h" 
#include <math.h> 
#ifndef _THING_H 
#define _THING_H 

class thingClase { 
public: 
    float ypos, xpos, zpos; 
    float count; 
    thingClase() { 
     xpos = rand()%80; 
     ypos = rand()%80; 
     zpos = 1; 
     count = 1; 
    } 
    }; 

thingClase thing[100]; 
int thingNum = 0; 
int thingTotal = 100; 
int width = 1; 
bool alive; 

#endif /* _THING_H */ 

그리고 내 주요 기능을하는이 포함되어 있습니다 : 그래서

void drawThing() { 
for (thingNum = 0; thingNum < thingTotal; thingNum++) { 
    glPushMatrix(); 
    glTranslated(thing[thingNum].xpos, thing[thingNum].ypos, thing[thingNum].zpos); 
    glPopMatrix(); 
} 
} 

답변

0

, 나는 당신이 설정하는 참조 무언가를 그리는 변형 :

void drawThing() { 

// EDIT: 
// 
// Set the matrix mode! 
glMatrixMode(GL_MODELVIEW); 

for (thingNum = 0; thingNum < thingTotal; thingNum++) { 

    // Yes, good, matrix is saved! 
    glPushMatrix(); 

    // Yes, translate to the thing's position 
    glTranslated(thing[thingNum].xpos, thing[thingNum].ypos, thing[thingNum].zpos); 

    // Draw the thing here! 
    // 
    // You know, like call a display list or something. 

    // Restore the matrix, also good! 
    glPopMatrix(); 
} 
} 

그리는 것이 필요합니다. 따라서 이전에 사용하기 쉬운 OpenGL을 사용하는 경우 디스플레이 목록을 만들거나 glBeginglEnd을 사용하십시오.

그런 다음 편한 마음으로 VBO와 쉐이더를 만들고 사용하십시오. 이것이 바로 오늘날 OpenGL의 방식입니다.

관련 문제