1 /* $Id: polyobj.c,v 1.14 2003-03-29 22:35:00 btb 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.
20 static char rcsid[] = "$Id: polyobj.c,v 1.14 2003-03-29 22:35:00 btb Exp $";
27 // -- I hate this warning in make depend! -- #ifdef DRIVE
28 // -- I hate this warning in make depend! -- #include "drive.h"
29 // -- I hate this warning in make depend! -- #else
31 // -- I hate this warning in make depend! -- #endif
59 polymodel Polygon_models[MAX_POLYGON_MODELS]; // = {&bot11,&bot17,&robot_s2,&robot_b2,&bot11,&bot17,&robot_s2,&robot_b2};
61 int N_polygon_models = 0;
63 #define MAX_POLYGON_VECS 1000
64 g3s_point robot_points[MAX_POLYGON_VECS];
66 #define PM_COMPATIBLE_VERSION 6
67 #define PM_OBJFILE_VERSION 8
72 #define MODEL_BUF_SIZE 32768
74 void _pof_cfseek(int len,int type)
77 case SEEK_SET: Pof_addr = len; break;
78 case SEEK_CUR: Pof_addr += len; break;
80 Assert(len <= 0); // seeking from end, better be moving back.
81 Pof_addr = Pof_file_end + len;
85 if (Pof_addr > MODEL_BUF_SIZE)
89 #define pof_cfseek(_buf,_len,_type) _pof_cfseek((_len),(_type))
91 int pof_read_int(ubyte *bufp)
95 i = *((int *) &bufp[Pof_addr]);
99 // if (cfread(&i,sizeof(i),1,f) != 1)
100 // Error("Unexpected end-of-file while reading object");
105 size_t pof_cfread(void *dst, size_t elsize, size_t nelem, ubyte *bufp)
107 if (Pof_addr + nelem*elsize > Pof_file_end)
110 memcpy(dst, &bufp[Pof_addr], elsize*nelem);
112 Pof_addr += elsize*nelem;
114 if (Pof_addr > MODEL_BUF_SIZE)
120 // #define new_read_int(i,f) cfread(&(i),sizeof(i),1,(f))
121 #define new_pof_read_int(i,f) pof_cfread(&(i),sizeof(i),1,(f))
123 short pof_read_short(ubyte *bufp)
127 s = *((short *) &bufp[Pof_addr]);
129 return INTEL_SHORT(s);
130 // if (cfread(&s,sizeof(s),1,f) != 1)
131 // Error("Unexpected end-of-file while reading object");
136 void pof_read_string(char *buf,int max_char, ubyte *bufp)
140 for (i=0; i<max_char; i++) {
141 if ((*buf++ = bufp[Pof_addr++]) == 0)
145 // while (max_char-- && (*buf=cfgetc(f)) != 0) buf++;
149 void pof_read_vecs(vms_vector *vecs,int n,ubyte *bufp)
151 // cfread(vecs,sizeof(vms_vector),n,f);
153 memcpy(vecs, &bufp[Pof_addr], n*sizeof(*vecs));
154 Pof_addr += n*sizeof(*vecs);
156 #ifdef WORDS_BIGENDIAN
158 vms_vector_swap(&vecs[--n]);
161 if (Pof_addr > MODEL_BUF_SIZE)
165 void pof_read_angs(vms_angvec *angs,int n,ubyte *bufp)
167 memcpy(angs, &bufp[Pof_addr], n*sizeof(*angs));
168 Pof_addr += n*sizeof(*angs);
170 #ifdef WORDS_BIGENDIAN
172 vms_angvec_swap(&angs[--n]);
175 if (Pof_addr > MODEL_BUF_SIZE)
179 #define ID_OHDR 0x5244484f // 'RDHO' //Object header
180 #define ID_SOBJ 0x4a424f53 // 'JBOS' //Subobject header
181 #define ID_GUNS 0x534e5547 // 'SNUG' //List of guns on this object
182 #define ID_ANIM 0x4d494e41 // 'MINA' //Animation data
183 #define ID_IDTA 0x41544449 // 'ATDI' //Interpreter data
184 #define ID_TXTR 0x52545854 // 'RTXT' //Texture filename list
187 #define robot_info void
189 vms_angvec anim_angs[N_ANIM_STATES][MAX_SUBMODELS];
191 //set the animation angles for this robot. Gun fields of robot info must
193 void robot_set_angles(robot_info *r,polymodel *pm,vms_angvec angs[N_ANIM_STATES][MAX_SUBMODELS]);
196 #define DEBUG_LEVEL CON_NORMAL
198 #ifdef WORDS_NEED_ALIGNMENT
199 ubyte * old_dest(chunk o) // return where chunk is (in unaligned struct)
201 return o.old_base + INTEL_SHORT(*((short *)(o.old_base + o.offset)));
203 ubyte * new_dest(chunk o) // return where chunk is (in aligned struct)
205 return o.new_base + INTEL_SHORT(*((short *)(o.old_base + o.offset))) + o.correction;
208 * find chunk with smallest address
210 int get_first_chunks_index(chunk *chunk_list, int no_chunks)
212 int i, first_index = 0;
213 Assert(no_chunks >= 1);
214 for (i = 1; i < no_chunks; i++)
215 if (old_dest(chunk_list[i]) < old_dest(chunk_list[first_index]))
219 #define SHIFT_SPACE 500 // increase if insufficent
221 void align_polygon_model_data(polymodel *pm)
224 int total_correction = 0;
225 ubyte *cur_old, *cur_new;
227 chunk ch_list[MAX_CHUNKS];
229 int tmp_size = pm->model_data_size + SHIFT_SPACE;
230 ubyte *tmp = d_malloc(tmp_size); // where we build the aligned version of pm->model_data
233 //start with first chunk (is always aligned!)
234 cur_old = pm->model_data;
236 chunk_len = get_chunks(cur_old, cur_new, ch_list, &no_chunks);
237 memcpy(cur_new, cur_old, chunk_len);
238 while (no_chunks > 0) {
239 int first_index = get_first_chunks_index(ch_list, no_chunks);
240 cur_ch = ch_list[first_index];
241 // remove first chunk from array:
243 for (i = first_index; i < no_chunks; i++)
244 ch_list[i] = ch_list[i + 1];
245 // if (new) address unaligned:
246 if ((u_int32_t)new_dest(cur_ch) % 4L != 0) {
247 // calculate how much to move to be aligned
248 short to_shift = 4 - (u_int32_t)new_dest(cur_ch) % 4L;
249 // correct chunks' addresses
250 cur_ch.correction += to_shift;
251 for (i = 0; i < no_chunks; i++)
252 ch_list[i].correction += to_shift;
253 total_correction += to_shift;
254 Assert((u_int32_t)new_dest(cur_ch) % 4L == 0);
255 Assert(total_correction <= SHIFT_SPACE); // if you get this, increase SHIFT_SPACE
257 //write (corrected) chunk for current chunk:
258 *((short *)(cur_ch.new_base + cur_ch.offset))
259 = INTEL_SHORT(cur_ch.correction
260 + INTEL_SHORT(*((short *)(cur_ch.old_base + cur_ch.offset))));
261 //write (correctly aligned) chunk:
262 cur_old = old_dest(cur_ch);
263 cur_new = new_dest(cur_ch);
264 chunk_len = get_chunks(cur_old, cur_new, ch_list, &no_chunks);
265 memcpy(cur_new, cur_old, chunk_len);
266 //correct submodel_ptr's for pm, too
267 for (i = 0; i < MAX_SUBMODELS; i++)
268 if (pm->model_data + pm->submodel_ptrs[i] >= cur_old
269 && pm->model_data + pm->submodel_ptrs[i] < cur_old + chunk_len)
270 pm->submodel_ptrs[i] += (cur_new - tmp) - (cur_old - pm->model_data);
272 d_free(pm->model_data);
273 pm->model_data_size += total_correction;
274 pm->model_data = d_malloc(pm->model_data_size);
275 Assert(pm->model_data != NULL);
276 memcpy(pm->model_data, tmp, pm->model_data_size);
279 #endif //def WORDS_NEED_ALIGNMENT
281 //reads a binary file containing a 3d model
282 polymodel *read_model_file(polymodel *pm,char *filename,robot_info *r)
286 int id,len, next_chunk;
290 model_buf = (ubyte *)d_malloc( MODEL_BUF_SIZE * sizeof(ubyte) );
292 Error("Can't allocate space to read model %s\n", filename);
294 if ((ifile=cfopen(filename,"rb"))==NULL)
295 Error("Can't open file <%s>",filename);
297 Assert(ifile->size <= MODEL_BUF_SIZE);
300 Pof_file_end = cfread(model_buf, 1, cfilelength(ifile), ifile);
303 id = pof_read_int(model_buf);
305 if (id!=0x4f505350) /* 'OPSP' */
306 Error("Bad ID in model file <%s>",filename);
308 version = pof_read_short(model_buf);
310 if (version < PM_COMPATIBLE_VERSION || version > PM_OBJFILE_VERSION)
311 Error("Bad version (%d) in model file <%s>",version,filename);
313 if ( FindArg( "-bspgen" ))
314 printf( "bspgen -c1" );
316 while (new_pof_read_int(id,model_buf) == 1) {
318 //id = pof_read_int(model_buf);
319 len = pof_read_int(model_buf);
320 next_chunk = Pof_addr + len;
324 case ID_OHDR: { //Object header
325 vms_vector pmmin,pmmax;
327 //con_printf(DEBUG_LEVEL, "Got chunk OHDR, len=%d\n",len);
329 pm->n_models = pof_read_int(model_buf);
330 pm->rad = pof_read_int(model_buf);
332 Assert(pm->n_models <= MAX_SUBMODELS);
334 pof_read_vecs(&pmmin,1,model_buf);
335 pof_read_vecs(&pmmax,1,model_buf);
337 if ( FindArg( "-bspgen" )) {
341 vm_vec_sub(&v, &pmmax, &pmmin );
343 if ( v.y > l ) l = v.y;
344 if ( v.z > l ) l = v.z;
346 printf( " -l%.3f", f2fl(l) );
352 case ID_SOBJ: { //Subobject header
357 //con_printf(DEBUG_LEVEL, "Got chunk SOBJ, len=%d\n",len);
359 n = pof_read_short(model_buf);
361 Assert(n < MAX_SUBMODELS);
363 pm->submodel_parents[n] = pof_read_short(model_buf);
365 pof_read_vecs(&pm->submodel_norms[n],1,model_buf);
366 pof_read_vecs(&pm->submodel_pnts[n],1,model_buf);
367 pof_read_vecs(&pm->submodel_offsets[n],1,model_buf);
369 pm->submodel_rads[n] = pof_read_int(model_buf); //radius
371 pm->submodel_ptrs[n] = pof_read_int(model_buf); //offset
378 case ID_GUNS: { //List of guns on this object
380 //con_printf(DEBUG_LEVEL, "Got chunk GUNS, len=%d\n",len);
385 ubyte gun_used[MAX_GUNS];
387 r->n_guns = pof_read_int(model_buf);
392 Assert(r->n_guns <= MAX_GUNS);
394 for (i=0;i<r->n_guns;i++)
397 for (i=0;i<r->n_guns;i++) {
400 id = pof_read_short(model_buf);
401 Assert(id < r->n_guns);
402 Assert(gun_used[id] == 0);
404 r->gun_submodels[id] = pof_read_short(model_buf);
405 Assert(r->gun_submodels[id] != 0xff);
406 pof_read_vecs(&r->gun_points[id],1,model_buf);
409 pof_read_vecs(&gun_dir,1,model_buf);
413 pof_cfseek(model_buf,len,SEEK_CUR);
418 case ID_ANIM: //Animation data
419 //con_printf(DEBUG_LEVEL, "Got chunk ANIM, len=%d\n",len);
426 n_frames = pof_read_short(model_buf);
428 Assert(n_frames == N_ANIM_STATES);
430 for (m=0;m<pm->n_models;m++)
431 for (f=0;f<n_frames;f++)
432 pof_read_angs(&anim_angs[f][m], 1, model_buf);
435 robot_set_angles(r,pm,anim_angs);
439 pof_cfseek(model_buf,len,SEEK_CUR);
444 case ID_TXTR: { //Texture filename list
448 //con_printf(DEBUG_LEVEL, "Got chunk TXTR, len=%d\n",len);
450 n = pof_read_short(model_buf);
451 //con_printf(DEBUG_LEVEL, " num textures = %d\n",n);
453 pof_read_string(name_buf,128,model_buf);
454 //con_printf(DEBUG_LEVEL, "<%s>\n",name_buf);
460 case ID_IDTA: //Interpreter data
461 //con_printf(DEBUG_LEVEL, "Got chunk IDTA, len=%d\n",len);
463 pm->model_data = d_malloc(len);
464 pm->model_data_size = len;
466 pof_cfread(pm->model_data,1,len,model_buf);
471 //con_printf(DEBUG_LEVEL, "Unknown chunk <%c%c%c%c>, len = %d\n",id,id>>8,id>>16,id>>24,len);
472 pof_cfseek(model_buf,len,SEEK_CUR);
476 if ( version >= 8 ) // Version 8 needs 4-byte alignment!!!
477 pof_cfseek(model_buf,next_chunk,SEEK_SET);
480 // for (i=0;i<pm->n_models;i++)
481 // pm->submodel_ptrs[i] += (int) pm->model_data;
483 if ( FindArg( "-bspgen" )) {
484 char *p = strchr( filename, '.' );
490 printf( " %s.3ds\n", filename );
496 #ifdef WORDS_NEED_ALIGNMENT
497 align_polygon_model_data(pm);
499 #ifdef WORDS_BIGENDIAN
500 swap_polygon_model_data(pm->model_data);
502 //verify(pm->model_data);
507 //reads the gun information for a model
508 //fills in arrays gun_points & gun_dirs, returns the number of guns read
509 int read_model_guns(char *filename,vms_vector *gun_points, vms_vector *gun_dirs, int *gun_submodels)
517 model_buf = (ubyte *)d_malloc( MODEL_BUF_SIZE * sizeof(ubyte) );
519 Error("Can't allocate space to read model %s\n", filename);
521 if ((ifile=cfopen(filename,"rb"))==NULL)
522 Error("Can't open file <%s>",filename);
524 Assert(ifile->size <= MODEL_BUF_SIZE);
527 Pof_file_end = cfread(model_buf, 1, ifile->size, ifile);
530 id = pof_read_int(model_buf);
532 if (id!=0x4f505350) /* 'OPSP' */
533 Error("Bad ID in model file <%s>",filename);
535 version = pof_read_short(model_buf);
537 Assert(version >= 7); //must be 7 or higher for this data
539 if (version < PM_COMPATIBLE_VERSION || version > PM_OBJFILE_VERSION)
540 Error("Bad version (%d) in model file <%s>",version,filename);
542 while (new_pof_read_int(id,model_buf) == 1) {
544 //id = pof_read_int(model_buf);
545 len = pof_read_int(model_buf);
547 if (id == ID_GUNS) { //List of guns on this object
549 //con_printf(DEBUG_LEVEL, "Got chunk GUNS, len=%d\n",len);
553 n_guns = pof_read_int(model_buf);
555 for (i=0;i<n_guns;i++) {
558 id = pof_read_short(model_buf);
559 sm = pof_read_short(model_buf);
561 gun_submodels[id] = sm;
563 Error("Invalid gun submodel in file <%s>",filename);
564 pof_read_vecs(&gun_points[id],1,model_buf);
566 pof_read_vecs(&gun_dirs[id],1,model_buf);
571 pof_cfseek(model_buf,len,SEEK_CUR);
580 //free up a model, getting rid of all its memory
581 void free_model(polymodel *po)
583 d_free(po->model_data);
586 grs_bitmap *texture_list[MAX_POLYOBJ_TEXTURES];
587 bitmap_index texture_list_index[MAX_POLYOBJ_TEXTURES];
589 int Simple_model_threshhold_scale=5; //switch when this times radius far away
592 //draw a polygon model
594 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[])
598 PA_DFX (int save_light);
600 Assert(model_num < N_polygon_models);
602 po=&Polygon_models[model_num];
604 //check if should use simple model
605 if (po->simpler_model ) //must have a simpler model
606 if (flags==0) //can't switch if this is debris
607 //!!if (!alt_textures) { //alternate textures might not match
608 //alt textures might not match, but in the one case we're using this
609 //for on 11/14/94, they do match. So we leave it in.
614 depth = g3_calc_point_depth(pos); //gets 3d depth
616 while (po->simpler_model && depth > cnt++ * Simple_model_threshhold_scale * po->rad)
617 po = &Polygon_models[po->simpler_model-1];
622 for (i=0;i<po->n_textures;i++) {
623 texture_list_index[i] = alt_textures[i];
624 texture_list[i] = &GameBitmaps[alt_textures[i].index];
627 texture_list[i]->bm_handle = texture_list_index[i].index;
633 for (i=0;i<po->n_textures;i++) {
634 texture_list_index[i] = ObjBitmaps[ObjBitmapPtrs[po->first_texture+i]];
635 texture_list[i] = &GameBitmaps[ObjBitmaps[ObjBitmapPtrs[po->first_texture+i]].index];
638 texture_list[i]->bm_handle = texture_list_index[i].index;
643 #ifdef PIGGY_USE_PAGING
644 // Make sure the textures for this object are paged in...
645 piggy_page_flushed = 0;
646 for (i=0;i<po->n_textures;i++)
647 PIGGY_PAGE_IN( texture_list_index[i] );
648 // Hmmm... cache got flushed in the middle of paging all these in,
649 // so we need to reread them all in.
650 if (piggy_page_flushed) {
651 piggy_page_flushed = 0;
652 for (i=0;i<po->n_textures;i++)
653 PIGGY_PAGE_IN( texture_list_index[i] );
655 // Make sure that they can all fit in memory.
656 Assert( piggy_page_flushed == 0 );
659 g3_start_instance_matrix(pos,orient);
661 g3_set_interp_points(robot_points);
664 _3dfx_rendering_poly_obj = 1;
666 PA_DFX(save_light = Lighting_on);
667 PA_DFX(Lighting_on = 0);
669 if (flags == 0) //draw entire object
671 g3_draw_polygon_model(po->model_data,texture_list,anim_angles,light,glow_values);
676 for (i=0;flags;flags>>=1,i++)
680 Assert(i < po->n_models);
682 //if submodel, rotate around its center point, not pivot point
684 vm_vec_avg(&ofs,&po->submodel_mins[i],&po->submodel_maxs[i]);
686 g3_start_instance_matrix(&ofs,NULL);
688 g3_draw_polygon_model(&po->model_data[po->submodel_ptrs[i]],texture_list,anim_angles,light,glow_values);
697 _3dfx_rendering_poly_obj = 0;
700 PA_DFX (Lighting_on = save_light);
705 void free_polygon_models()
709 for (i=0;i<N_polygon_models;i++) {
710 free_model(&Polygon_models[i]);
715 void polyobj_find_min_max(polymodel *pm)
721 vms_vector *big_mn,*big_mx;
726 for (m=0;m<pm->n_models;m++) {
727 vms_vector *mn,*mx,*ofs;
729 mn = &pm->submodel_mins[m];
730 mx = &pm->submodel_maxs[m];
731 ofs= &pm->submodel_offsets[m];
733 data = (ushort *)&pm->model_data[pm->submodel_ptrs[m]];
737 Assert(type == 7 || type == 1);
742 data+=2; //skip start & pad
744 vp = (vms_vector *) data;
746 *mn = *mx = *vp++; nverts--;
749 *big_mn = *big_mx = *mn;
752 if (vp->x > mx->x) mx->x = vp->x;
753 if (vp->y > mx->y) mx->y = vp->y;
754 if (vp->z > mx->z) mx->z = vp->z;
756 if (vp->x < mn->x) mn->x = vp->x;
757 if (vp->y < mn->y) mn->y = vp->y;
758 if (vp->z < mn->z) mn->z = vp->z;
760 if (vp->x+ofs->x > big_mx->x) big_mx->x = vp->x+ofs->x;
761 if (vp->y+ofs->y > big_mx->y) big_mx->y = vp->y+ofs->y;
762 if (vp->z+ofs->z > big_mx->z) big_mx->z = vp->z+ofs->z;
764 if (vp->x+ofs->x < big_mn->x) big_mn->x = vp->x+ofs->x;
765 if (vp->y+ofs->y < big_mn->y) big_mn->y = vp->y+ofs->y;
766 if (vp->z+ofs->z < big_mn->z) big_mn->z = vp->z+ofs->z;
771 // printf("Submodel %d: (%8x,%8x) (%8x,%8x) (%8x,%8x)\n",m,mn->x,mx->x,mn->y,mx->y,mn->z,mx->z);
774 // 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);
778 extern short highest_texture_num; //from the 3d
780 char Pof_names[MAX_POLYGON_MODELS][FILENAME_LEN];
782 //returns the number of this model
784 int load_polygon_model(char *filename,int n_textures,int first_texture,robot_info *r)
786 int load_polygon_model(char *filename,int n_textures,grs_bitmap ***textures)
793 Assert(N_polygon_models < MAX_POLYGON_MODELS);
794 Assert(n_textures < MAX_POLYOBJ_TEXTURES);
796 // MK was real tired of those useless, slow mprintfs...
797 if (N_polygon_models > MAX_POLYGON_MODELS - 10)
798 mprintf(( 0, "Used %d/%d polygon model slots\n", N_polygon_models+1, MAX_POLYGON_MODELS ));
800 Assert(strlen(filename) <= 12);
801 strcpy(Pof_names[N_polygon_models],filename);
803 read_model_file(&Polygon_models[N_polygon_models],filename,r);
805 polyobj_find_min_max(&Polygon_models[N_polygon_models]);
807 g3_init_polygon_model(Polygon_models[N_polygon_models].model_data);
809 if (highest_texture_num+1 != n_textures)
810 Error("Model <%s> references %d textures but specifies %d.",filename,highest_texture_num+1,n_textures);
812 Polygon_models[N_polygon_models].n_textures = n_textures;
813 Polygon_models[N_polygon_models].first_texture = first_texture;
814 Polygon_models[N_polygon_models].simpler_model = 0;
816 // Assert(polygon_models[N_polygon_models]!=NULL);
820 return N_polygon_models-1;
825 void init_polygon_models()
827 N_polygon_models = 0;
829 atexit((void (*)())free_polygon_models);
833 //compare against this size when figuring how far to place eye for picture
834 #define BASE_MODEL_SIZE 0x28000
836 #define DEFAULT_VIEW_DIST 0x60000
838 //draws the given model in the current canvas. The distance is set to
839 //more-or-less fill the canvas. Note that this routine actually renders
840 //into an off-screen canvas that it creates, then copies to the current
842 void draw_model_picture(int mn,vms_angvec *orient_angles)
844 vms_vector temp_pos=ZERO_VECTOR;
845 vms_matrix temp_orient = IDENTITY_MATRIX;
846 grs_canvas *save_canv = grd_curcanv,*temp_canv;
848 Assert(mn>=0 && mn<N_polygon_models);
850 temp_canv = gr_create_canvas(save_canv->cv_bitmap.bm_w,save_canv->cv_bitmap.bm_h);
851 gr_set_current_canvas(temp_canv);
852 gr_clear_canvas( BM_XRGB(0,0,0) );
855 g3_set_view_matrix(&temp_pos,&temp_orient,0x9000);
857 if (Polygon_models[mn].rad != 0)
858 temp_pos.z = fixmuldiv(DEFAULT_VIEW_DIST,Polygon_models[mn].rad,BASE_MODEL_SIZE);
860 temp_pos.z = DEFAULT_VIEW_DIST;
862 vm_angles_2_matrix(&temp_orient, orient_angles);
864 PA_DFX(save_light = Lighting_on);
865 PA_DFX(Lighting_on = 0);
866 draw_polygon_model(&temp_pos,&temp_orient,NULL,mn,0,f1_0,NULL,NULL);
867 PA_DFX (Lighting_on = save_light);
869 gr_set_current_canvas(save_canv);
871 gr_bitmap(0,0,&temp_canv->cv_bitmap);
873 gr_free_canvas(temp_canv);
878 * reads a polymodel structure from a CFILE
880 extern void polymodel_read(polymodel *pm, CFILE *fp)
884 pm->n_models = cfile_read_int(fp);
885 pm->model_data_size = cfile_read_int(fp);
886 pm->model_data = (ubyte *) cfile_read_int(fp);
887 for (i = 0; i < MAX_SUBMODELS; i++)
888 pm->submodel_ptrs[i] = cfile_read_int(fp);
889 for (i = 0; i < MAX_SUBMODELS; i++)
890 cfile_read_vector(&(pm->submodel_offsets[i]), fp);
891 for (i = 0; i < MAX_SUBMODELS; i++)
892 cfile_read_vector(&(pm->submodel_norms[i]), fp);
893 for (i = 0; i < MAX_SUBMODELS; i++)
894 cfile_read_vector(&(pm->submodel_pnts[i]), fp);
895 for (i = 0; i < MAX_SUBMODELS; i++)
896 pm->submodel_rads[i] = cfile_read_fix(fp);
897 cfread(pm->submodel_parents, MAX_SUBMODELS, 1, fp);
898 for (i = 0; i < MAX_SUBMODELS; i++)
899 cfile_read_vector(&(pm->submodel_mins[i]), fp);
900 for (i = 0; i < MAX_SUBMODELS; i++)
901 cfile_read_vector(&(pm->submodel_maxs[i]), fp);
902 cfile_read_vector(&(pm->mins), fp);
903 cfile_read_vector(&(pm->maxs), fp);
904 pm->rad = cfile_read_fix(fp);
905 pm->n_textures = cfile_read_byte(fp);
906 pm->first_texture = cfile_read_short(fp);
907 pm->simpler_model = cfile_read_byte(fp);
911 * reads n polymodel structs from a CFILE
913 extern int polymodel_read_n(polymodel *pm, int n, CFILE *fp)
917 for (i = 0; i < n; i++) {
918 pm[i].n_models = cfile_read_int(fp);
919 pm[i].model_data_size = cfile_read_int(fp);
920 pm[i].model_data = (ubyte *) cfile_read_int(fp);
921 for (j = 0; j < MAX_SUBMODELS; j++)
922 pm[i].submodel_ptrs[j] = cfile_read_int(fp);
923 for (j = 0; j < MAX_SUBMODELS; j++)
924 cfile_read_vector(&(pm[i].submodel_offsets[j]), fp);
925 for (j = 0; j < MAX_SUBMODELS; j++)
926 cfile_read_vector(&(pm[i].submodel_norms[j]), fp);
927 for (j = 0; j < MAX_SUBMODELS; j++)
928 cfile_read_vector(&(pm[i].submodel_pnts[j]), fp);
929 for (j = 0; j < MAX_SUBMODELS; j++)
930 pm[i].submodel_rads[j] = cfile_read_fix(fp);
931 cfread(pm[i].submodel_parents, MAX_SUBMODELS, 1, fp);
932 for (j = 0; j < MAX_SUBMODELS; j++)
933 cfile_read_vector(&(pm[i].submodel_mins[j]), fp);
934 for (j = 0; j < MAX_SUBMODELS; j++)
935 cfile_read_vector(&(pm[i].submodel_maxs[j]), fp);
936 cfile_read_vector(&(pm[i].mins), fp);
937 cfile_read_vector(&(pm[i].maxs), fp);
938 pm[i].rad = cfile_read_fix(fp);
939 pm[i].n_textures = cfile_read_byte(fp);
940 pm[i].first_texture = cfile_read_short(fp);
941 pm[i].simpler_model = cfile_read_byte(fp);
949 * routine which allocates, reads, and inits a polymodel's model_data
951 void polygon_model_data_read(polymodel *pm, CFILE *fp)
953 pm->model_data = d_malloc(pm->model_data_size);
954 Assert(pm->model_data != NULL);
955 cfread(pm->model_data, sizeof(ubyte), pm->model_data_size, fp );
956 #ifdef WORDS_NEED_ALIGNMENT
957 align_polygon_model_data(pm);
959 #ifdef WORDS_BIGENDIAN
960 swap_polygon_model_data(pm->model_data);
962 //verify(pm->model_data);
963 g3_init_polygon_model(pm->model_data);