From: "Anders Pedersen" Newsgroups: comp.os.msdos.djgpp Subject: Allegro program won't work Lines: 100 X-Newsreader: Microsoft Outlook Express 4.72.2106.4 X-MimeOLE: Produced By Microsoft MimeOLE V4.72.2106.4 Message-ID: Date: Sat, 10 Apr 1999 12:35:10 +0200 NNTP-Posting-Host: 129.142.195.151 X-Complaints-To: abuse AT get2 DOT net X-Trace: news.get2net.dk 923740595 129.142.195.151 (Sat, 10 Apr 1999 12:36:35 MET DST) NNTP-Posting-Date: Sat, 10 Apr 1999 12:36:35 MET DST Organization: get2net Internet Kunde To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com I'm trying to learn how to make 3d games. I've found an tutorial on the net and readed it. After that I wanted to do some research, and I've done this program that make an 3d rectangle (allmost there some lines in the rectangle missing) that you can move around with the keypads an zoom in and out with Z and X. The program work fine but when you try to zoom in so you can't se the rectangle more the program crashes. Anders Program: #include float x[4]={2,2,-2,-2}; // Here are the X and Y values float y[4]={2,-2,2,-2}; // for the rectangle float z=10; // And here are the z value int screenx1,screeny1,screenx2,screeny2; // Some integers to store the calculated points before they're blitted to the screen int i; // Just an integer for the loop int done=FALSE; BITMAP *temp; // A doublebuffer int main(void) { allegro_init(); set_gfx_mode(GFX_AUTODETECT,320,200,0,0); install_keyboard(); temp=create_bitmap(320,200); do { for (i=0; i!=4; i++) // we need to draw 4 lines { screenx1=160.0+256.0*( x[i] / z); // This algorithm screeny1=100.0+256.0*( y[i] / z); // calculate where screenx2=160.0+256.0*( x[i] / (z+5.0)); // I should draw screeny2=100.0+256.0*( y[i] / (z+5.0)); // the line line(temp, screenx1, screeny1, screenx2, screeny2, 6); // draw the line to the double buffer } blit(temp,screen,0,0,0,0,320,200); clear(temp); // getinput from keyboard if (key[KEY_UP]) { y[0]--; // Move rectangle up y[1]--; y[2]--; y[3]--; } if (key[KEY_DOWN]) { y[0]++; // Move rectangle down y[1]++; y[2]++; y[3]++; } if (key[KEY_LEFT]) { x[0]--; // move rectangle left x[1]--; x[2]--; x[3]--; } if (key[KEY_RIGHT]) { x[0]++; // move rectangle right x[1]++; x[2]++; x[3]++; } if (key[KEY_X]) { z++; // Zoom in } if (key[KEY_Z]) { z--; // Zoom out } if (key[KEY_ESC]) { done=TRUE; // exit program } clear_keybuf(); } while (done==FALSE); return 0; }