1 /* $Id: polyobj.c,v 1.22 2005-07-30 07:46:03 chris Exp $ */
3 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
4 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
5 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
6 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
7 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
8 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
9 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
10 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
11 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
12 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
17 * Hacked-in polygon objects
27 static char rcsid[] = "$Id: polyobj.c,v 1.22 2005-07-30 07:46:03 chris Exp $";
34 // -- I hate this warning in make depend! -- #ifdef DRIVE
35 // -- I hate this warning in make depend! -- #include "drive.h"
36 // -- I hate this warning in make depend! -- #else
38 // -- I hate this warning in make depend! -- #endif
64 polymodel Polygon_models[MAX_POLYGON_MODELS]; // = {&bot11,&bot17,&robot_s2,&robot_b2,&bot11,&bot17,&robot_s2,&robot_b2};
66 int D1_Polymodel_map[] = {
76 110, 111, 112, 113, 114,
77 115, 116, 117, 118, 119,
78 120, 121, 122, 123, 124,
79 125, 126, 127, 128, 129,
80 130, 131, 132, 133, 134,
81 135, 136, 137, 138, 139,
82 140, 141, 142, -1, -1,
86 int N_polygon_models = 0;
88 #define MAX_POLYGON_VECS 1000
89 g3s_point robot_points[MAX_POLYGON_VECS];
91 #define PM_COMPATIBLE_VERSION 6
92 #define PM_OBJFILE_VERSION 8
97 #define MODEL_BUF_SIZE 32768
99 void _pof_cfseek(int len,int type)
102 case SEEK_SET: Pof_addr = len; break;
103 case SEEK_CUR: Pof_addr += len; break;
105 Assert(len <= 0); // seeking from end, better be moving back.
106 Pof_addr = Pof_file_end + len;
110 if (Pof_addr > MODEL_BUF_SIZE)
114 #define pof_cfseek(_buf,_len,_type) _pof_cfseek((_len),(_type))
116 int pof_read_int(ubyte *bufp)
120 i = *((int *) &bufp[Pof_addr]);
124 // if (cfread(&i,sizeof(i),1,f) != 1)
125 // Error("Unexpected end-of-file while reading object");
130 size_t pof_cfread(void *dst, size_t elsize, size_t nelem, ubyte *bufp)
132 if (Pof_addr + nelem*elsize > Pof_file_end)
135 memcpy(dst, &bufp[Pof_addr], elsize*nelem);
137 Pof_addr += elsize*nelem;
139 if (Pof_addr > MODEL_BUF_SIZE)
145 // #define new_read_int(i,f) cfread(&(i),sizeof(i),1,(f))
146 #define new_pof_read_int(i,f) pof_cfread(&(i),sizeof(i),1,(f))
148 short pof_read_short(ubyte *bufp)
152 s = *((short *) &bufp[Pof_addr]);
154 return INTEL_SHORT(s);
155 // if (cfread(&s,sizeof(s),1,f) != 1)
156 // Error("Unexpected end-of-file while reading object");
161 void pof_read_string(char *buf,int max_char, ubyte *bufp)
165 for (i=0; i<max_char; i++) {
166 if ((*buf++ = bufp[Pof_addr++]) == 0)
170 // while (max_char-- && (*buf=cfgetc(f)) != 0) buf++;
174 void pof_read_vecs(vms_vector *vecs,int n,ubyte *bufp)
176 // cfread(vecs,sizeof(vms_vector),n,f);
178 memcpy(vecs, &bufp[Pof_addr], n*sizeof(*vecs));
179 Pof_addr += n*sizeof(*vecs);
181 #ifdef WORDS_BIGENDIAN
183 vms_vector_swap(&vecs[--n]);
186 if (Pof_addr > MODEL_BUF_SIZE)
190 void pof_read_angs(vms_angvec *angs,int n,ubyte *bufp)
192 memcpy(angs, &bufp[Pof_addr], n*sizeof(*angs));
193 Pof_addr += n*sizeof(*angs);
195 #ifdef WORDS_BIGENDIAN
197 vms_angvec_swap(&angs[--n]);
200 if (Pof_addr > MODEL_BUF_SIZE)
204 #define ID_OHDR 0x5244484f // 'RDHO' //Object header
205 #define ID_SOBJ 0x4a424f53 // 'JBOS' //Subobject header
206 #define ID_GUNS 0x534e5547 // 'SNUG' //List of guns on this object
207 #define ID_ANIM 0x4d494e41 // 'MINA' //Animation data
208 #define ID_IDTA 0x41544449 // 'ATDI' //Interpreter data
209 #define ID_TXTR 0x52545854 // 'RTXT' //Texture filename list
212 #define robot_info void
214 vms_angvec anim_angs[N_ANIM_STATES][MAX_SUBMODELS];
216 //set the animation angles for this robot. Gun fields of robot info must
218 void robot_set_angles(robot_info *r,polymodel *pm,vms_angvec angs[N_ANIM_STATES][MAX_SUBMODELS]);
221 #define DEBUG_LEVEL CON_NORMAL
223 #ifdef WORDS_NEED_ALIGNMENT
224 ubyte * old_dest(chunk o) // return where chunk is (in unaligned struct)
226 return o.old_base + INTEL_SHORT(*((short *)(o.old_base + o.offset)));
228 ubyte * new_dest(chunk o) // return where chunk is (in aligned struct)
230 return o.new_base + INTEL_SHORT(*((short *)(o.old_base + o.offset))) + o.correction;
233 * find chunk with smallest address
235 int get_first_chunks_index(chunk *chunk_list, int no_chunks)
237 int i, first_index = 0;
238 Assert(no_chunks >= 1);
239 for (i = 1; i < no_chunks; i++)
240 if (old_dest(chunk_list[i]) < old_dest(chunk_list[first_index]))
244 #define SHIFT_SPACE 500 // increase if insufficent
246 void align_polygon_model_data(polymodel *pm)
249 int total_correction = 0;
250 ubyte *cur_old, *cur_new;
252 chunk ch_list[MAX_CHUNKS];
254 int tmp_size = pm->model_data_size + SHIFT_SPACE;
255 ubyte *tmp = d_malloc(tmp_size); // where we build the aligned version of pm->model_data
258 //start with first chunk (is always aligned!)
259 cur_old = pm->model_data;
261 chunk_len = get_chunks(cur_old, cur_new, ch_list, &no_chunks);
262 memcpy(cur_new, cur_old, chunk_len);
263 while (no_chunks > 0) {
264 int first_index = get_first_chunks_index(ch_list, no_chunks);
265 cur_ch = ch_list[first_index];
266 // remove first chunk from array:
268 for (i = first_index; i < no_chunks; i++)
269 ch_list[i] = ch_list[i + 1];
270 // if (new) address unaligned:
271 if ((u_int32_t)new_dest(cur_ch) % 4L != 0) {
272 // calculate how much to move to be aligned
273 short to_shift = 4 - (u_int32_t)new_dest(cur_ch) % 4L;
274 // correct chunks' addresses
275 cur_ch.correction += to_shift;
276 for (i = 0; i < no_chunks; i++)
277 ch_list[i].correction += to_shift;
278 total_correction += to_shift;
279 Assert((u_int32_t)new_dest(cur_ch) % 4L == 0);
280 Assert(total_correction <= SHIFT_SPACE); // if you get this, increase SHIFT_SPACE
282 //write (corrected) chunk for current chunk:
283 *((short *)(cur_ch.new_base + cur_ch.offset))
284 = INTEL_SHORT(cur_ch.correction
285 + INTEL_SHORT(*((short *)(cur_ch.old_base + cur_ch.offset))));
286 //write (correctly aligned) chunk:
287 cur_old = old_dest(cur_ch);
288 cur_new = new_dest(cur_ch);
289 chunk_len = get_chunks(cur_old, cur_new, ch_list, &no_chunks);
290 memcpy(cur_new, cur_old, chunk_len);
291 //correct submodel_ptr's for pm, too
292 for (i = 0; i < MAX_SUBMODELS; i++)
293 if (pm->model_data + pm->submodel_ptrs[i] >= cur_old
294 && pm->model_data + pm->submodel_ptrs[i] < cur_old + chunk_len)
295 pm->submodel_ptrs[i] += (cur_new - tmp) - (cur_old - pm->model_data);
297 d_free(pm->model_data);
298 pm->model_data_size += total_correction;
299 pm->model_data = d_malloc(pm->model_data_size);
300 Assert(pm->model_data != NULL);
301 memcpy(pm->model_data, tmp, pm->model_data_size);
304 #endif //def WORDS_NEED_ALIGNMENT
306 //reads a binary file containing a 3d model
307 polymodel *read_model_file(polymodel *pm,char *filename,robot_info *r)
311 int id,len, next_chunk;
315 model_buf = (ubyte *)d_malloc( MODEL_BUF_SIZE * sizeof(ubyte) );
317 Error("Can't allocate space to read model %s\n", filename);
319 if ((ifile=cfopen(filename,"rb"))==NULL)
320 Error("Can't open file <%s>",filename);
322 Assert(cfilelength(ifile) <= MODEL_BUF_SIZE);
325 Pof_file_end = cfread(model_buf, 1, cfilelength(ifile), ifile);
328 id = pof_read_int(model_buf);
330 if (id!=0x4f505350) /* 'OPSP' */
331 Error("Bad ID in model file <%s>",filename);
333 version = pof_read_short(model_buf);
335 if (version < PM_COMPATIBLE_VERSION || version > PM_OBJFILE_VERSION)
336 Error("Bad version (%d) in model file <%s>",version,filename);
338 if ( FindArg( "-bspgen" ))
339 printf( "bspgen -c1" );
341 while (new_pof_read_int(id,model_buf) == 1) {
343 //id = pof_read_int(model_buf);
344 len = pof_read_int(model_buf);
345 next_chunk = Pof_addr + len;
349 case ID_OHDR: { //Object header
350 vms_vector pmmin,pmmax;
352 //con_printf(DEBUG_LEVEL, "Got chunk OHDR, len=%d\n",len);
354 pm->n_models = pof_read_int(model_buf);
355 pm->rad = pof_read_int(model_buf);
357 Assert(pm->n_models <= MAX_SUBMODELS);
359 pof_read_vecs(&pmmin,1,model_buf);
360 pof_read_vecs(&pmmax,1,model_buf);
362 if ( FindArg( "-bspgen" )) {
366 vm_vec_sub(&v, &pmmax, &pmmin );
368 if ( v.y > l ) l = v.y;
369 if ( v.z > l ) l = v.z;
371 printf( " -l%.3f", f2fl(l) );
377 case ID_SOBJ: { //Subobject header
382 //con_printf(DEBUG_LEVEL, "Got chunk SOBJ, len=%d\n",len);
384 n = pof_read_short(model_buf);
386 Assert(n < MAX_SUBMODELS);
388 pm->submodel_parents[n] = pof_read_short(model_buf);
390 pof_read_vecs(&pm->submodel_norms[n],1,model_buf);
391 pof_read_vecs(&pm->submodel_pnts[n],1,model_buf);
392 pof_read_vecs(&pm->submodel_offsets[n],1,model_buf);
394 pm->submodel_rads[n] = pof_read_int(model_buf); //radius
396 pm->submodel_ptrs[n] = pof_read_int(model_buf); //offset
403 case ID_GUNS: { //List of guns on this object
405 //con_printf(DEBUG_LEVEL, "Got chunk GUNS, len=%d\n",len);
410 ubyte gun_used[MAX_GUNS];
412 r->n_guns = pof_read_int(model_buf);
417 Assert(r->n_guns <= MAX_GUNS);
419 for (i=0;i<r->n_guns;i++)
422 for (i=0;i<r->n_guns;i++) {
425 id = pof_read_short(model_buf);
426 Assert(id < r->n_guns);
427 Assert(gun_used[id] == 0);
429 r->gun_submodels[id] = pof_read_short(model_buf);
430 Assert(r->gun_submodels[id] != 0xff);
431 pof_read_vecs(&r->gun_points[id],1,model_buf);
434 pof_read_vecs(&gun_dir,1,model_buf);
438 pof_cfseek(model_buf,len,SEEK_CUR);
443 case ID_ANIM: //Animation data
444 //con_printf(DEBUG_LEVEL, "Got chunk ANIM, len=%d\n",len);
451 n_frames = pof_read_short(model_buf);
453 Assert(n_frames == N_ANIM_STATES);
455 for (m=0;m<pm->n_models;m++)
456 for (f=0;f<n_frames;f++)
457 pof_read_angs(&anim_angs[f][m], 1, model_buf);
460 robot_set_angles(r,pm,anim_angs);
464 pof_cfseek(model_buf,len,SEEK_CUR);
469 case ID_TXTR: { //Texture filename list
473 //con_printf(DEBUG_LEVEL, "Got chunk TXTR, len=%d\n",len);
475 n = pof_read_short(model_buf);
476 //con_printf(DEBUG_LEVEL, " num textures = %d\n",n);
478 pof_read_string(name_buf,128,model_buf);
479 //con_printf(DEBUG_LEVEL, "<%s>\n",name_buf);
485 case ID_IDTA: //Interpreter data
486 //con_printf(DEBUG_LEVEL, "Got chunk IDTA, len=%d\n",len);
488 pm->model_data = d_malloc(len);
489 pm->model_data_size = len;
491 pof_cfread(pm->model_data,1,len,model_buf);
496 //con_printf(DEBUG_LEVEL, "Unknown chunk <%c%c%c%c>, len = %d\n",id,id>>8,id>>16,id>>24,len);
497 pof_cfseek(model_buf,len,SEEK_CUR);
501 if ( version >= 8 ) // Version 8 needs 4-byte alignment!!!
502 pof_cfseek(model_buf,next_chunk,SEEK_SET);
505 // for (i=0;i<pm->n_models;i++)
506 // pm->submodel_ptrs[i] += (int) pm->model_data;
508 if ( FindArg( "-bspgen" )) {
509 char *p = strchr( filename, '.' );
515 printf( " %s.3ds\n", filename );
521 #ifdef WORDS_NEED_ALIGNMENT
522 align_polygon_model_data(pm);
524 #ifdef WORDS_BIGENDIAN
525 swap_polygon_model_data(pm->model_data);
527 //verify(pm->model_data);
532 //reads the gun information for a model
533 //fills in arrays gun_points & gun_dirs, returns the number of guns read
534 int read_model_guns(char *filename,vms_vector *gun_points, vms_vector *gun_dirs, int *gun_submodels)
542 model_buf = (ubyte *)d_malloc( MODEL_BUF_SIZE * sizeof(ubyte) );
544 Error("Can't allocate space to read model %s\n", filename);
546 if ((ifile=cfopen(filename,"rb"))==NULL)
547 Error("Can't open file <%s>",filename);
549 Assert(cfilelength(ifile) <= MODEL_BUF_SIZE);
552 Pof_file_end = cfread(model_buf, 1, cfilelength(ifile), ifile);
555 id = pof_read_int(model_buf);
557 if (id!=0x4f505350) /* 'OPSP' */
558 Error("Bad ID in model file <%s>",filename);
560 version = pof_read_short(model_buf);
562 Assert(version >= 7); //must be 7 or higher for this data
564 if (version < PM_COMPATIBLE_VERSION || version > PM_OBJFILE_VERSION)
565 Error("Bad version (%d) in model file <%s>",version,filename);
567 while (new_pof_read_int(id,model_buf) == 1) {
569 //id = pof_read_int(model_buf);
570 len = pof_read_int(model_buf);
572 if (id == ID_GUNS) { //List of guns on this object
574 //con_printf(DEBUG_LEVEL, "Got chunk GUNS, len=%d\n",len);
578 n_guns = pof_read_int(model_buf);
580 for (i=0;i<n_guns;i++) {
583 id = pof_read_short(model_buf);
584 sm = pof_read_short(model_buf);
586 gun_submodels[id] = sm;
588 Error("Invalid gun submodel in file <%s>",filename);
589 pof_read_vecs(&gun_points[id],1,model_buf);
591 pof_read_vecs(&gun_dirs[id],1,model_buf);
596 pof_cfseek(model_buf,len,SEEK_CUR);
605 //free up a model, getting rid of all its memory
606 void free_model(polymodel *po)
608 d_free(po->model_data);
611 grs_bitmap *texture_list[MAX_POLYOBJ_TEXTURES];
612 bitmap_index texture_list_index[MAX_POLYOBJ_TEXTURES];
614 int Simple_model_threshhold_scale=5; //switch when this times radius far away
617 //draw a polygon model
619 void draw_polygon_model(vms_vector *pos,vms_matrix *orient,vms_angvec *anim_angles,int model_num,int flags,fix light,fix *glow_values,bitmap_index alt_textures[])
624 Assert(model_num < N_polygon_models);
626 po=&Polygon_models[model_num];
628 //check if should use simple model
629 if (po->simpler_model ) //must have a simpler model
630 if (flags==0) //can't switch if this is debris
631 //!!if (!alt_textures) { //alternate textures might not match
632 //alt textures might not match, but in the one case we're using this
633 //for on 11/14/94, they do match. So we leave it in.
638 depth = g3_calc_point_depth(pos); //gets 3d depth
640 while (po->simpler_model && depth > cnt++ * Simple_model_threshhold_scale * po->rad)
641 po = &Polygon_models[po->simpler_model-1];
646 for (i=0;i<po->n_textures;i++) {
647 texture_list_index[i] = alt_textures[i];
648 texture_list[i] = &GameBitmaps[alt_textures[i].index];
653 for (i=0;i<po->n_textures;i++) {
654 texture_list_index[i] = ObjBitmaps[ObjBitmapPtrs[po->first_texture+i]];
655 texture_list[i] = &GameBitmaps[ObjBitmaps[ObjBitmapPtrs[po->first_texture+i]].index];
659 #ifdef PIGGY_USE_PAGING
660 // Make sure the textures for this object are paged in...
661 piggy_page_flushed = 0;
662 for (i=0;i<po->n_textures;i++)
663 PIGGY_PAGE_IN( texture_list_index[i] );
664 // Hmmm... cache got flushed in the middle of paging all these in,
665 // so we need to reread them all in.
666 if (piggy_page_flushed) {
667 piggy_page_flushed = 0;
668 for (i=0;i<po->n_textures;i++)
669 PIGGY_PAGE_IN( texture_list_index[i] );
671 // Make sure that they can all fit in memory.
672 Assert( piggy_page_flushed == 0 );
675 g3_start_instance_matrix(pos,orient);
677 g3_set_interp_points(robot_points);
679 if (flags == 0) //draw entire object
681 g3_draw_polygon_model(po->model_data,texture_list,anim_angles,light,glow_values);
686 for (i=0;flags;flags>>=1,i++)
690 Assert(i < po->n_models);
692 //if submodel, rotate around its center point, not pivot point
694 vm_vec_avg(&ofs,&po->submodel_mins[i],&po->submodel_maxs[i]);
696 g3_start_instance_matrix(&ofs,NULL);
698 g3_draw_polygon_model(&po->model_data[po->submodel_ptrs[i]],texture_list,anim_angles,light,glow_values);
707 void free_polygon_models()
711 for (i=0;i<N_polygon_models;i++) {
712 free_model(&Polygon_models[i]);
717 void polyobj_find_min_max(polymodel *pm)
723 vms_vector *big_mn,*big_mx;
728 for (m=0;m<pm->n_models;m++) {
729 vms_vector *mn,*mx,*ofs;
731 mn = &pm->submodel_mins[m];
732 mx = &pm->submodel_maxs[m];
733 ofs= &pm->submodel_offsets[m];
735 data = (ushort *)&pm->model_data[pm->submodel_ptrs[m]];
739 Assert(type == 7 || type == 1);
744 data+=2; //skip start & pad
746 vp = (vms_vector *) data;
748 *mn = *mx = *vp++; nverts--;
751 *big_mn = *big_mx = *mn;
754 if (vp->x > mx->x) mx->x = vp->x;
755 if (vp->y > mx->y) mx->y = vp->y;
756 if (vp->z > mx->z) mx->z = vp->z;
758 if (vp->x < mn->x) mn->x = vp->x;
759 if (vp->y < mn->y) mn->y = vp->y;
760 if (vp->z < mn->z) mn->z = vp->z;
762 if (vp->x+ofs->x > big_mx->x) big_mx->x = vp->x+ofs->x;
763 if (vp->y+ofs->y > big_mx->y) big_mx->y = vp->y+ofs->y;
764 if (vp->z+ofs->z > big_mx->z) big_mx->z = vp->z+ofs->z;
766 if (vp->x+ofs->x < big_mn->x) big_mn->x = vp->x+ofs->x;
767 if (vp->y+ofs->y < big_mn->y) big_mn->y = vp->y+ofs->y;
768 if (vp->z+ofs->z < big_mn->z) big_mn->z = vp->z+ofs->z;
773 // printf("Submodel %d: (%8x,%8x) (%8x,%8x) (%8x,%8x)\n",m,mn->x,mx->x,mn->y,mx->y,mn->z,mx->z);
776 // printf("Whole model: (%8x,%8x) (%8x,%8x) (%8x,%8x)\n",big_mn->x,big_mx->x,big_mn->y,big_mx->y,big_mn->z,big_mx->z);
780 extern short highest_texture_num; //from the 3d
782 char Pof_names[MAX_POLYGON_MODELS][FILENAME_LEN];
784 //returns the number of this model
786 int load_polygon_model(char *filename,int n_textures,int first_texture,robot_info *r)
788 int load_polygon_model(char *filename,int n_textures,grs_bitmap ***textures)
795 Assert(N_polygon_models < MAX_POLYGON_MODELS);
796 Assert(n_textures < MAX_POLYOBJ_TEXTURES);
798 // MK was real tired of those useless, slow mprintfs...
799 if (N_polygon_models > MAX_POLYGON_MODELS - 10)
800 mprintf(( 0, "Used %d/%d polygon model slots\n", N_polygon_models+1, MAX_POLYGON_MODELS ));
802 Assert(strlen(filename) <= 12);
803 strcpy(Pof_names[N_polygon_models],filename);
805 read_model_file(&Polygon_models[N_polygon_models],filename,r);
807 polyobj_find_min_max(&Polygon_models[N_polygon_models]);
809 g3_init_polygon_model(Polygon_models[N_polygon_models].model_data);
811 if (highest_texture_num+1 != n_textures)
812 Error("Model <%s> references %d textures but specifies %d.",filename,highest_texture_num+1,n_textures);
814 Polygon_models[N_polygon_models].n_textures = n_textures;
815 Polygon_models[N_polygon_models].first_texture = first_texture;
816 Polygon_models[N_polygon_models].simpler_model = 0;
818 // Assert(polygon_models[N_polygon_models]!=NULL);
822 return N_polygon_models-1;
827 void init_polygon_models()
829 N_polygon_models = 0;
831 atexit((void (*)())free_polygon_models);
835 //compare against this size when figuring how far to place eye for picture
836 #define BASE_MODEL_SIZE 0x28000
838 #define DEFAULT_VIEW_DIST 0x60000
840 //draws the given model in the current canvas. The distance is set to
841 //more-or-less fill the canvas. Note that this routine actually renders
842 //into an off-screen canvas that it creates, then copies to the current
844 void draw_model_picture(int mn,vms_angvec *orient_angles)
846 vms_vector temp_pos=ZERO_VECTOR;
847 vms_matrix temp_orient = IDENTITY_MATRIX;
849 grs_canvas *save_canv = grd_curcanv,*temp_canv;
852 Assert(mn>=0 && mn<N_polygon_models);
855 ogl_start_offscreen_render(0, 0, grd_curcanv->cv_bitmap.bm_w, grd_curcanv->cv_bitmap.bm_h);
857 temp_canv = gr_create_canvas(save_canv->cv_bitmap.bm_w,save_canv->cv_bitmap.bm_h);
858 gr_set_current_canvas(temp_canv);
860 gr_clear_canvas( BM_XRGB(0,0,0) );
863 g3_set_view_matrix(&temp_pos,&temp_orient,0x9000);
865 if (Polygon_models[mn].rad != 0)
866 temp_pos.z = fixmuldiv(DEFAULT_VIEW_DIST,Polygon_models[mn].rad,BASE_MODEL_SIZE);
868 temp_pos.z = DEFAULT_VIEW_DIST;
870 vm_angles_2_matrix(&temp_orient, orient_angles);
872 draw_polygon_model(&temp_pos,&temp_orient,NULL,mn,0,f1_0,NULL,NULL);
877 ogl_end_offscreen_render();
879 gr_set_current_canvas(save_canv);
881 gr_bitmap(0,0,&temp_canv->cv_bitmap);
883 gr_free_canvas(temp_canv);
889 * reads a polymodel structure from a CFILE
891 extern void polymodel_read(polymodel *pm, CFILE *fp)
895 pm->n_models = cfile_read_int(fp);
896 pm->model_data_size = cfile_read_int(fp);
897 pm->model_data = (ubyte *)cfile_read_int(fp); // garbage, read it anyway just for consistency
898 for (i = 0; i < MAX_SUBMODELS; i++)
899 pm->submodel_ptrs[i] = cfile_read_int(fp);
900 for (i = 0; i < MAX_SUBMODELS; i++)
901 cfile_read_vector(&(pm->submodel_offsets[i]), fp);
902 for (i = 0; i < MAX_SUBMODELS; i++)
903 cfile_read_vector(&(pm->submodel_norms[i]), fp);
904 for (i = 0; i < MAX_SUBMODELS; i++)
905 cfile_read_vector(&(pm->submodel_pnts[i]), fp);
906 for (i = 0; i < MAX_SUBMODELS; i++)
907 pm->submodel_rads[i] = cfile_read_fix(fp);
908 cfread(pm->submodel_parents, MAX_SUBMODELS, 1, fp);
909 for (i = 0; i < MAX_SUBMODELS; i++)
910 cfile_read_vector(&(pm->submodel_mins[i]), fp);
911 for (i = 0; i < MAX_SUBMODELS; i++)
912 cfile_read_vector(&(pm->submodel_maxs[i]), fp);
913 cfile_read_vector(&(pm->mins), fp);
914 cfile_read_vector(&(pm->maxs), fp);
915 pm->rad = cfile_read_fix(fp);
916 pm->n_textures = cfile_read_byte(fp);
917 pm->first_texture = cfile_read_short(fp);
918 pm->simpler_model = cfile_read_byte(fp);
922 * reads n polymodel structs from a CFILE
924 extern int polymodel_read_n(polymodel *pm, int n, CFILE *fp)
928 for (i = 0; i < n; i++) {
929 pm[i].n_models = cfile_read_int(fp);
930 pm[i].model_data_size = cfile_read_int(fp);
931 pm->model_data = (ubyte *)cfile_read_int(fp); // garbage, read it anyway just for consistency
932 for (j = 0; j < MAX_SUBMODELS; j++)
933 pm[i].submodel_ptrs[j] = cfile_read_int(fp);
934 for (j = 0; j < MAX_SUBMODELS; j++)
935 cfile_read_vector(&(pm[i].submodel_offsets[j]), fp);
936 for (j = 0; j < MAX_SUBMODELS; j++)
937 cfile_read_vector(&(pm[i].submodel_norms[j]), fp);
938 for (j = 0; j < MAX_SUBMODELS; j++)
939 cfile_read_vector(&(pm[i].submodel_pnts[j]), fp);
940 for (j = 0; j < MAX_SUBMODELS; j++)
941 pm[i].submodel_rads[j] = cfile_read_fix(fp);
942 cfread(pm[i].submodel_parents, MAX_SUBMODELS, 1, fp);
943 for (j = 0; j < MAX_SUBMODELS; j++)
944 cfile_read_vector(&(pm[i].submodel_mins[j]), fp);
945 for (j = 0; j < MAX_SUBMODELS; j++)
946 cfile_read_vector(&(pm[i].submodel_maxs[j]), fp);
947 cfile_read_vector(&(pm[i].mins), fp);
948 cfile_read_vector(&(pm[i].maxs), fp);
949 pm[i].rad = cfile_read_fix(fp);
950 pm[i].n_textures = cfile_read_byte(fp);
951 pm[i].first_texture = cfile_read_short(fp);
952 pm[i].simpler_model = cfile_read_byte(fp);
960 * routine which allocates, reads, and inits a polymodel's model_data
962 void polygon_model_data_read(polymodel *pm, CFILE *fp)
964 pm->model_data = d_malloc(pm->model_data_size);
965 Assert(pm->model_data != NULL);
966 cfread(pm->model_data, sizeof(ubyte), pm->model_data_size, fp );
967 #ifdef WORDS_NEED_ALIGNMENT
968 align_polygon_model_data(pm);
970 #ifdef WORDS_BIGENDIAN
971 swap_polygon_model_data(pm->model_data);
973 //verify(pm->model_data);
974 g3_init_polygon_model(pm->model_data);