Como dersenhar peça de xadrez em opengl?

0 respostas
S

Boas, sou iniciante em computacão gráfica. O trabalho é fazer o tabuleiro de xadrez e as suas peças, apenas o tabuleiro e as peças, e não o jogo, nem é necessário colocar as peças no tabuleiro e nem é necessário programar os movimentos, apenas desenhar as peças em 3d. Ja consegui fazer o tabuleiro, no entanto estou com dificuldades em desenhar as peças, peço a vossa ajuda para desenhar pelo menos o peão para servir de base para eu desenhar o resto. Não é necessário a aplicaco de texturas, apenas o um desenho valido da peão em 3d. Isto e o que já fiz até agora…

include
ifdef APPLE
include
else
include
endif
using namespace std;

void drawTabuleiro(void) {

float x1 = 0.0, x2=15.0, x3=15.0, x4=0.0;
float y1=0.0, y2=0.0, y3=15.0, y4=15.0;

int coluna = 0, contador=0;

for(int linha=0; linha<8; linha++){

while(coluna < 8){

 if(contador%2==0){
        glColor3f(0.0, 0.0, 0.0);
    }
    else{
        glColor3f(0.0, 0.0, 1.0);
    }

    glVertex3f(x1, y1, 0.0);
    glVertex3f(x2, y2, 0.0);
    glVertex3f(x3, y3, 0.0);
    glVertex3f(x4, y4, 0.0);

    x1+=15;
    x2+=15;
    x3+=15;
    x4+=15;

    coluna++;
    contador++;
}

y1+=15;

y2+=15;

y3+=15;

y4+=15;

coluna=0;

x1 = 0.0;

x2=15.0;

x3=15.0;

x4=0.0;
contador+=1;

}
}

// Drawing (display) routine. void drawScene(void) { // Clear screen to background color. glClear(GL_COLOR_BUFFER_BIT);

// Set foreground (or drawing) color. glColor3f(0.0, 0.0, 0.0);

glRotatef(45, 0.0, 0.0, 0.0);
// Draw a polygon with specified vertices. glBegin(GL_QUADS);

drawTabuleiro();
glEnd();

// Flush created objects to the screen, i.e., force rendering. glFlush(); }

// Initialization routine. void setup(void) { // Set background (or clearing) color. glClearColor(1.0, 1.0, 1.0, 0.0); }

// OpenGL window reshape routine. void resize(int w, int h) { // Set viewport size to be entire OpenGL window. glViewport(0, 0, (GLsizei)w, (GLsizei)h);

// Set matrix mode to projection. glMatrixMode(GL_PROJECTION);

// Clear current projection matrix to identity. glLoadIdentity();

// Specify the orthographic (or perpendicular) projection, // i.e., define the viewing box. glOrtho(-100.0, 200.0, -100.0, 200.0, -1.0, 1.0);

// Set matrix mode to modelview. glMatrixMode(GL_MODELVIEW);

// Clear current modelview matrix to identity. glLoadIdentity(); }

// Keyboard input processing routine. void keyInput(unsigned char key, int x, int y) { switch(key) { // Press escape to exit. case 27: exit(0); break; default: break; } }

// Main routine: defines window properties, creates window, // registers callback routines and begins processing. int main(int argc, char **argv) { // Initialize GLUT. glutInit(&argc, argv);

// Set display mode as single-buffered and RGB color. glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);

// Set OpenGL window size. glutInitWindowSize(500, 500);

// Set position of OpenGL window upper-left corner. glutInitWindowPosition(100, 100);

// Create OpenGL window with title. glutCreateWindow(“square.cpp”);

// Initialize. setup();

// Register display routine. glutDisplayFunc(drawScene);

// Register reshape routine. glutReshapeFunc(resize);

// Register keyboard routine. glutKeyboardFunc(keyInput);

// Begin processing. glutMainLoop();

return 0; }

Criado 12 de abril de 2018
Respostas 0
Participantes 1