From: Matthew Heyman Newsgroups: comp.os.msdos.djgpp Subject: 3d engine help Date: Wed, 17 Mar 1999 21:10:58 +0000 Organization: Airnews.net! at Internet America Lines: 81 Message-ID: <3A89A2976D50E917.6E59E2959D5860B1.4DCF6A1A868E60C5@library-proxy.airnews.net> X-Orig-Message-ID: <36F01A62 DOT 6BD7 AT airmail DOT net> Abuse-Reports-To: abuse at airmail.net to report improper postings NNTP-Proxy-Relay: library2.iadfw.net NNTP-Posting-Time: Wed Mar 17 21:11:26 1999 NNTP-Posting-Host: !`Ya:1k-V\PfF;I (Encoded at Airnews!) Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 3.01C-KIT (Win95; U) To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Hello. I was looking at the Allegro example library and was wondering if anybody could walk me through what happens in this piece of code from example 25. I know its a tall order, but any help would be appreciated. Matthew Heyman void draw_square(BITMAP *bmp, MATRIX_f *camera, int x, int z) { V3D_f _v[4]; V3D_f _vout[8]; V3D_f _vtmp[8]; V3D_f *v[4] = { &_v[0], &_v[1], &_v[2], &_v[3] }; V3D_f *vout[8] = { &_vout[0], &_vout[1], &_vout[2], &_vout[3], &_vout[4],&_vout[5], &_vout[6], &_vout[7] }; V3D_f *vtmp[8] = { &_vtmp[0], &_vtmp[1], &_vtmp[2], &_vtmp[3], &_vtmp[4],&_vtmp[5], &_vtmp[6], &_vtmp[7] }; int out[8]; int flags[4]; int c, vc; /* set up four vertices with the world-space position of the tile */ v[0]->x = x - GRID_SIZE/2; v[0]->y = 0; v[0]->z = z - GRID_SIZE/2; v[1]->x = x - GRID_SIZE/2 + 1; v[1]->y = 0; v[1]->z = z - GRID_SIZE/2; v[2]->x = x - GRID_SIZE/2 + 1; v[2]->y = 0; v[2]->z = z - GRID_SIZE/2 + 1; v[3]->x = x - GRID_SIZE/2; v[3]->y = 0; v[3]->z = z - GRID_SIZE/2 + 1; /* apply the camera matrix, translating world space -> view space */ for (c=0; c<4; c++) { apply_matrix_f(camera, v[c]->x, v[c]->y, v[c]->z, &v[c]->x, &v[c]->y, &v[c]->z); flags[c] = 0; /* set flags if this vertex is off the edge of the screen */ if (v[c]->x < -v[c]->z) flags[c] |= 1; else if (v[c]->x > v[c]->z) flags[c] |= 2; if (v[c]->y < -v[c]->z) flags[c] |= 4; else if (v[c]->y > v[c]->z) flags[c] |= 8; if (v[c]->z < 0.1) flags[c] |= 16; } /* quit if all vertices are off the same edge of the screen */ if (flags[0] & flags[1] & flags[2] & flags[3]) return; if (flags[0] | flags[1] | flags[2] | flags[3]) { /* clip if any vertices are off the edge of the screen */ vc = clip3d_f(POLYTYPE_FLAT, 0.1, 0.1, 4, v, vout, vtmp, out); if (vc <= 0) return; } else { /* no need to bother clipping this one */ vout[0] = v[0]; vout[1] = v[1]; vout[2] = v[2]; vout[3] = v[3]; vc = 4; }