From: Vic Newsgroups: comp.os.msdos.djgpp Subject: Re: 3d help for allegro..please Date: Fri, 26 Jun 1998 09:48:12 -0400 Organization: Communications Accessibles Montreal, Quebec Canada Lines: 122 Message-ID: <3593A69C.79B2@cam.org> References: <6muo12$503 AT news9 DOT noc DOT netcom DOT net> <2jX1PCA0b4k1Mw4w AT fluidcontrol DOT demon DOT co DOT uk> NNTP-Posting-Host: dialup-654.hip.cam.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Kevin Smith wrote: > its only got 4 verticies. not 8. just like a sqaure except using > allegros quad function to draw it. I hope you were requesting an example for that, it's attached ;) uses gouraud shading for a quad. use x,X,y,Y,z,Z keys to rotate #include int main(void) { V3D_f points[4]; //since we want a square, we have 4 vertices V3D_f Tpoints[4]; // 4 transformed vertices MATRIX_f rot; //the matrix we will construct for rotation MATRIX_f tr; //the matrix we will construct for translation float Xr=0,Yr=0,Zr=0; //rotations on 3 axis BITMAP* back; //backbuffer int i; //allegro init stuff allegro_init(); install_keyboard(); set_gfx_mode(GFX_AUTODETECT,640,480,0,0); //initialise our data //make a better palette for(i=0;i<64;i++) { desktop_palette[i].r=0; desktop_palette[i].g=0; desktop_palette[i].b=i; } for(i=64;i<128;i++) { desktop_palette[i].r=(i-64)/2; desktop_palette[i].g=0; desktop_palette[i].b=34; } for(i=128;i<192;i++) { desktop_palette[i].r=0; desktop_palette[i].g=(i-128)/2; desktop_palette[i].b=34; } for(i=192;i<256;i++) { desktop_palette[i].r=i-192; desktop_palette[i].g=i-192; desktop_palette[i].b=34; } //create buffers set_palette(desktop_palette); back=create_bitmap(SCREEN_W,SCREEN_H); rgb_map=malloc(sizeof(RGB_MAP)); create_rgb_table(rgb_map,desktop_palette,NULL); //create the square points[0].z=points[1].z=points[2].z=points[3].z=0; points[0].y=points[1].y=-100; points[2].y=points[3].y=100; points[0].x=points[3].x=-100; points[1].x=points[2].x=100; //color stuff for gouraud shading Tpoints[0].c=0xababcc; //some blue Tpoints[1].c=0x4421aa; Tpoints[2].c=0x222244; Tpoints[3].c=0xac11af; set_projection_viewport(0,0,SCREEN_W,SCREEN_H); while(!key[KEY_ESC]) { clear(back); if(key[KEY_X]) { if(key_shifts&KB_SHIFT_FLAG) Xr+=0.5; else Xr-=0.5; } if(key[KEY_Y]) { if(key_shifts&KB_SHIFT_FLAG) Yr+=0.5; else Yr-=0.5; } if(key[KEY_Z]) { if(key_shifts&KB_SHIFT_FLAG) Zr+=0.5; else Zr-=0.5; } get_rotation_matrix_f(&rot,Xr,Yr,Zr); //construct our transformation matrixes get_translation_matrix_f(&tr,0,0,200); for(i=0;i<4;i++) { //apply matrices and do a perspective projection apply_matrix_f(&rot,points[i].x,points[i].y,points[i].z,&Tpoints[i].x,&Tpoints[i].y,&Tpoints[i].z); apply_matrix_f(&tr,Tpoints[i].x,Tpoints[i].y,Tpoints[i].z,&Tpoints[i].x,&Tpoints[i].y,&Tpoints[i].z); persp_project_f(Tpoints[i].x,Tpoints[i].y,Tpoints[i].z,&Tpoints[i].x,&Tpoints[i].y); } //draw quad3d_f(back,POLYTYPE_GRGB,NULL,&Tpoints[0], &Tpoints[1],&Tpoints[2],&Tpoints[3]); blit(back,screen,0,0,0,0,SCREEN_W,SCREEN_H); } free(rgb_map); destroy_bitmap(back); return 0; }