Mail Archives: djgpp/1999/04/10/23:10:50
Hi,
Intrested in 3d games myself so I thought I would take a look at your
program.
I compiled and ran....No probs it never crashed me out ??? weird...
What errors if any do you get ?
Regards
Trip
On Sat, 10 Apr 1999 12:35:10 +0200, "Anders Pedersen"
<anders_p AT forum DOT dk> wrote:
>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 <allegro.h>
>
>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;
>}
>
>
- Raw text -