1 /* $Id: polyobj.c,v 1.21 2005-07-30 01:50:17 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.21 2005-07-30 01:50:17 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
68 polymodel Polygon_models[MAX_POLYGON_MODELS]; // = {&bot11,&bot17,&robot_s2,&robot_b2,&bot11,&bot17,&robot_s2,&robot_b2};
70 int N_polygon_models = 0;
72 #define MAX_POLYGON_VECS 1000
73 g3s_point robot_points[MAX_POLYGON_VECS];
75 #define PM_COMPATIBLE_VERSION 6
76 #define PM_OBJFILE_VERSION 8
81 #define MODEL_BUF_SIZE 32768
83 void _pof_cfseek(int len,int type)
86 case SEEK_SET: Pof_addr = len; break;
87 case SEEK_CUR: Pof_addr += len; break;
89 Assert(len <= 0); // seeking from end, better be moving back.
90 Pof_addr = Pof_file_end + len;
94 if (Pof_addr > MODEL_BUF_SIZE)
98 #define pof_cfseek(_buf,_len,_type) _pof_cfseek((_len),(_type))
100 int pof_read_int(ubyte *bufp)
104 i = *((int *) &bufp[Pof_addr]);
108 // if (cfread(&i,sizeof(i),1,f) != 1)
109 // Error("Unexpected end-of-file while reading object");
114 size_t pof_cfread(void *dst, size_t elsize, size_t nelem, ubyte *bufp)
116 if (Pof_addr + nelem*elsize > Pof_file_end)
119 memcpy(dst, &bufp[Pof_addr], elsize*nelem);
121 Pof_addr += elsize*nelem;
123 if (Pof_addr > MODEL_BUF_SIZE)
129 // #define new_read_int(i,f) cfread(&(i),sizeof(i),1,(f))
130 #define new_pof_read_int(i,f) pof_cfread(&(i),sizeof(i),1,(f))
132 short pof_read_short(ubyte *bufp)
136 s = *((short *) &bufp[Pof_addr]);
138 return INTEL_SHORT(s);
139 // if (cfread(&s,sizeof(s),1,f) != 1)
140 // Error("Unexpected end-of-file while reading object");
145 void pof_read_string(char *buf,int max_char, ubyte *bufp)
149 for (i=0; i<max_char; i++) {
150 if ((*buf++ = bufp[Pof_addr++]) == 0)
154 // while (max_char-- && (*buf=cfgetc(f)) != 0) buf++;
158 void pof_read_vecs(vms_vector *vecs,int n,ubyte *bufp)
160 // cfread(vecs,sizeof(vms_vector),n,f);
162 memcpy(vecs, &bufp[Pof_addr], n*sizeof(*vecs));
163 Pof_addr += n*sizeof(*vecs);
165 #ifdef WORDS_BIGENDIAN
167 vms_vector_swap(&vecs[--n]);
170 if (Pof_addr > MODEL_BUF_SIZE)
174 void pof_read_angs(vms_angvec *angs,int n,ubyte *bufp)
176 memcpy(angs, &bufp[Pof_addr], n*sizeof(*angs));
177 Pof_addr += n*sizeof(*angs);
179 #ifdef WORDS_BIGENDIAN
181 vms_angvec_swap(&angs[--n]);
184 if (Pof_addr > MODEL_BUF_SIZE)
188 #define ID_OHDR 0x5244484f // 'RDHO' //Object header
189 #define ID_SOBJ 0x4a424f53 // 'JBOS' //Subobject header
190 #define ID_GUNS 0x534e5547 // 'SNUG' //List of guns on this object
191 #define ID_ANIM 0x4d494e41 // 'MINA' //Animation data
192 #define ID_IDTA 0x41544449 // 'ATDI' //Interpreter data
193 #define ID_TXTR 0x52545854 // 'RTXT' //Texture filename list
196 #define robot_info void
198 vms_angvec anim_angs[N_ANIM_STATES][MAX_SUBMODELS];
200 //set the animation angles for this robot. Gun fields of robot info must
202 void robot_set_angles(robot_info *r,polymodel *pm,vms_angvec angs[N_ANIM_STATES][MAX_SUBMODELS]);
205 #define DEBUG_LEVEL CON_NORMAL
207 #ifdef WORDS_NEED_ALIGNMENT
208 ubyte * old_dest(chunk o) // return where chunk is (in unaligned struct)
210 return o.old_base + INTEL_SHORT(*((short *)(o.old_base + o.offset)));
212 ubyte * new_dest(chunk o) // return where chunk is (in aligned struct)
214 return o.new_base + INTEL_SHORT(*((short *)(o.old_base + o.offset))) + o.correction;
217 * find chunk with smallest address
219 int get_first_chunks_index(chunk *chunk_list, int no_chunks)
221 int i, first_index = 0;
222 Assert(no_chunks >= 1);
223 for (i = 1; i < no_chunks; i++)
224 if (old_dest(chunk_list[i]) < old_dest(chunk_list[first_index]))
228 #define SHIFT_SPACE 500 // increase if insufficent
230 void align_polygon_model_data(polymodel *pm)
233 int total_correction = 0;
234 ubyte *cur_old, *cur_new;
236 chunk ch_list[MAX_CHUNKS];
238 int tmp_size = pm->model_data_size + SHIFT_SPACE;
239 ubyte *tmp = d_malloc(tmp_size); // where we build the aligned version of pm->model_data
242 //start with first chunk (is always aligned!)
243 cur_old = pm->model_data;
245 chunk_len = get_chunks(cur_old, cur_new, ch_list, &no_chunks);
246 memcpy(cur_new, cur_old, chunk_len);
247 while (no_chunks > 0) {
248 int first_index = get_first_chunks_index(ch_list, no_chunks);
249 cur_ch = ch_list[first_index];
250 // remove first chunk from array:
252 for (i = first_index; i < no_chunks; i++)
253 ch_list[i] = ch_list[i + 1];
254 // if (new) address unaligned:
255 if ((u_int32_t)new_dest(cur_ch) % 4L != 0) {
256 // calculate how much to move to be aligned
257 short to_shift = 4 - (u_int32_t)new_dest(cur_ch) % 4L;
258 // correct chunks' addresses
259 cur_ch.correction += to_shift;
260 for (i = 0; i < no_chunks; i++)
261 ch_list[i].correction += to_shift;
262 total_correction += to_shift;
263 Assert((u_int32_t)new_dest(cur_ch) % 4L == 0);
264 Assert(total_correction <= SHIFT_SPACE); // if you get this, increase SHIFT_SPACE
266 //write (corrected) chunk for current chunk:
267 *((short *)(cur_ch.new_base + cur_ch.offset))
268 = INTEL_SHORT(cur_ch.correction
269 + INTEL_SHORT(*((short *)(cur_ch.old_base + cur_ch.offset))));
270 //write (correctly aligned) chunk:
271 cur_old = old_dest(cur_ch);
272 cur_new = new_dest(cur_ch);
273 chunk_len = get_chunks(cur_old, cur_new, ch_list, &no_chunks);
274 memcpy(cur_new, cur_old, chunk_len);
275 //correct submodel_ptr's for pm, too
276 for (i = 0; i < MAX_SUBMODELS; i++)
277 if (pm->model_data + pm->submodel_ptrs[i] >= cur_old
278 && pm->model_data + pm->submodel_ptrs[i] < cur_old + chunk_len)
279 pm->submodel_ptrs[i] += (cur_new - tmp) - (cur_old - pm->model_data);
281 d_free(pm->model_data);
282 pm->model_data_size += total_correction;
283 pm->model_data = d_malloc(pm->model_data_size);
284 Assert(pm->model_data != NULL);
285 memcpy(pm->model_data, tmp, pm->model_data_size);
288 #endif //def WORDS_NEED_ALIGNMENT
290 //reads a binary file containing a 3d model
291 polymodel *read_model_file(polymodel *pm,char *filename,robot_info *r)
295 int id,len, next_chunk;
299 model_buf = (ubyte *)d_malloc( MODEL_BUF_SIZE * sizeof(ubyte) );
301 Error("Can't allocate space to read model %s\n", filename);
303 if ((ifile=cfopen(filename,"rb"))==NULL)
304 Error("Can't open file <%s>",filename);
306 Assert(cfilelength(ifile) <= MODEL_BUF_SIZE);
309 Pof_file_end = cfread(model_buf, 1, cfilelength(ifile), ifile);
312 id = pof_read_int(model_buf);
314 if (id!=0x4f505350) /* 'OPSP' */
315 Error("Bad ID in model file <%s>",filename);
317 version = pof_read_short(model_buf);
319 if (version < PM_COMPATIBLE_VERSION || version > PM_OBJFILE_VERSION)
320 Error("Bad version (%d) in model file <%s>",version,filename);
322 if ( FindArg( "-bspgen" ))
323 printf( "bspgen -c1" );
325 while (new_pof_read_int(id,model_buf) == 1) {
327 //id = pof_read_int(model_buf);
328 len = pof_read_int(model_buf);
329 next_chunk = Pof_addr + len;
333 case ID_OHDR: { //Object header
334 vms_vector pmmin,pmmax;
336 //con_printf(DEBUG_LEVEL, "Got chunk OHDR, len=%d\n",len);
338 pm->n_models = pof_read_int(model_buf);
339 pm->rad = pof_read_int(model_buf);
341 Assert(pm->n_models <= MAX_SUBMODELS);
343 pof_read_vecs(&pmmin,1,model_buf);
344 pof_read_vecs(&pmmax,1,model_buf);
346 if ( FindArg( "-bspgen" )) {
350 vm_vec_sub(&v, &pmmax, &pmmin );
352 if ( v.y > l ) l = v.y;
353 if ( v.z > l ) l = v.z;
355 printf( " -l%.3f", f2fl(l) );
361 case ID_SOBJ: { //Subobject header
366 //con_printf(DEBUG_LEVEL, "Got chunk SOBJ, len=%d\n",len);
368 n = pof_read_short(model_buf);
370 Assert(n < MAX_SUBMODELS);
372 pm->submodel_parents[n] = pof_read_short(model_buf);
374 pof_read_vecs(&pm->submodel_norms[n],1,model_buf);
375 pof_read_vecs(&pm->submodel_pnts[n],1,model_buf);
376 pof_read_vecs(&pm->submodel_offsets[n],1,model_buf);
378 pm->submodel_rads[n] = pof_read_int(model_buf); //radius
380 pm->submodel_ptrs[n] = pof_read_int(model_buf); //offset
387 case ID_GUNS: { //List of guns on this object
389 //con_printf(DEBUG_LEVEL, "Got chunk GUNS, len=%d\n",len);
394 ubyte gun_used[MAX_GUNS];
396 r->n_guns = pof_read_int(model_buf);
401 Assert(r->n_guns <= MAX_GUNS);
403 for (i=0;i<r->n_guns;i++)
406 for (i=0;i<r->n_guns;i++) {
409 id = pof_read_short(model_buf);
410 Assert(id < r->n_guns);
411 Assert(gun_used[id] == 0);
413 r->gun_submodels[id] = pof_read_short(model_buf);
414 Assert(r->gun_submodels[id] != 0xff);
415 pof_read_vecs(&r->gun_points[id],1,model_buf);
418 pof_read_vecs(&gun_dir,1,model_buf);
422 pof_cfseek(model_buf,len,SEEK_CUR);
427 case ID_ANIM: //Animation data
428 //con_printf(DEBUG_LEVEL, "Got chunk ANIM, len=%d\n",len);
435 n_frames = pof_read_short(model_buf);
437 Assert(n_frames == N_ANIM_STATES);
439 for (m=0;m<pm->n_models;m++)
440 for (f=0;f<n_frames;f++)
441 pof_read_angs(&anim_angs[f][m], 1, model_buf);
444 robot_set_angles(r,pm,anim_angs);
448 pof_cfseek(model_buf,len,SEEK_CUR);
453 case ID_TXTR: { //Texture filename list
457 //con_printf(DEBUG_LEVEL, "Got chunk TXTR, len=%d\n",len);
459 n = pof_read_short(model_buf);
460 //con_printf(DEBUG_LEVEL, " num textures = %d\n",n);
462 pof_read_string(name_buf,128,model_buf);
463 //con_printf(DEBUG_LEVEL, "<%s>\n",name_buf);
469 case ID_IDTA: //Interpreter data
470 //con_printf(DEBUG_LEVEL, "Got chunk IDTA, len=%d\n",len);
472 pm->model_data = d_malloc(len);
473 pm->model_data_size = len;
475 pof_cfread(pm->model_data,1,len,model_buf);
480 //con_printf(DEBUG_LEVEL, "Unknown chunk <%c%c%c%c>, len = %d\n",id,id>>8,id>>16,id>>24,len);
481 pof_cfseek(model_buf,len,SEEK_CUR);
485 if ( version >= 8 ) // Version 8 needs 4-byte alignment!!!
486 pof_cfseek(model_buf,next_chunk,SEEK_SET);
489 // for (i=0;i<pm->n_models;i++)
490 // pm->submodel_ptrs[i] += (int) pm->model_data;
492 if ( FindArg( "-bspgen" )) {
493 char *p = strchr( filename, '.' );
499 printf( " %s.3ds\n", filename );
505 #ifdef WORDS_NEED_ALIGNMENT
506 align_polygon_model_data(pm);
508 #ifdef WORDS_BIGENDIAN
509 swap_polygon_model_data(pm->model_data);
511 //verify(pm->model_data);
516 //reads the gun information for a model
517 //fills in arrays gun_points & gun_dirs, returns the number of guns read
518 int read_model_guns(char *filename,vms_vector *gun_points, vms_vector *gun_dirs, int *gun_submodels)
526 model_buf = (ubyte *)d_malloc( MODEL_BUF_SIZE * sizeof(ubyte) );
528 Error("Can't allocate space to read model %s\n", filename);
530 if ((ifile=cfopen(filename,"rb"))==NULL)
531 Error("Can't open file <%s>",filename);
533 Assert(cfilelength(ifile) <= MODEL_BUF_SIZE);
536 Pof_file_end = cfread(model_buf, 1, cfilelength(ifile), ifile);
539 id = pof_read_int(model_buf);
541 if (id!=0x4f505350) /* 'OPSP' */
542 Error("Bad ID in model file <%s>",filename);
544 version = pof_read_short(model_buf);
546 Assert(version >= 7); //must be 7 or higher for this data
548 if (version < PM_COMPATIBLE_VERSION || version > PM_OBJFILE_VERSION)
549 Error("Bad version (%d) in model file <%s>",version,filename);
551 while (new_pof_read_int(id,model_buf) == 1) {
553 //id = pof_read_int(model_buf);
554 len = pof_read_int(model_buf);
556 if (id == ID_GUNS) { //List of guns on this object
558 //con_printf(DEBUG_LEVEL, "Got chunk GUNS, len=%d\n",len);
562 n_guns = pof_read_int(model_buf);
564 for (i=0;i<n_guns;i++) {
567 id = pof_read_short(model_buf);
568 sm = pof_read_short(model_buf);
570 gun_submodels[id] = sm;
572 Error("Invalid gun submodel in file <%s>",filename);
573 pof_read_vecs(&gun_points[id],1,model_buf);
575 pof_read_vecs(&gun_dirs[id],1,model_buf);
580 pof_cfseek(model_buf,len,SEEK_CUR);
589 //free up a model, getting rid of all its memory
590 void free_model(polymodel *po)
592 d_free(po->model_data);
595 grs_bitmap *texture_list[MAX_POLYOBJ_TEXTURES];
596 bitmap_index texture_list_index[MAX_POLYOBJ_TEXTURES];
598 int Simple_model_threshhold_scale=5; //switch when this times radius far away
601 //draw a polygon model
603 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[])
608 Assert(model_num < N_polygon_models);
610 po=&Polygon_models[model_num];
612 //check if should use simple model
613 if (po->simpler_model ) //must have a simpler model
614 if (flags==0) //can't switch if this is debris
615 //!!if (!alt_textures) { //alternate textures might not match
616 //alt textures might not match, but in the one case we're using this
617 //for on 11/14/94, they do match. So we leave it in.
622 depth = g3_calc_point_depth(pos); //gets 3d depth
624 while (po->simpler_model && depth > cnt++ * Simple_model_threshhold_scale * po->rad)
625 po = &Polygon_models[po->simpler_model-1];
630 for (i=0;i<po->n_textures;i++) {
631 texture_list_index[i] = alt_textures[i];
632 texture_list[i] = &GameBitmaps[alt_textures[i].index];
635 texture_list[i]->bm_handle = texture_list_index[i].index;
641 for (i=0;i<po->n_textures;i++) {
642 texture_list_index[i] = ObjBitmaps[ObjBitmapPtrs[po->first_texture+i]];
643 texture_list[i] = &GameBitmaps[ObjBitmaps[ObjBitmapPtrs[po->first_texture+i]].index];
646 texture_list[i]->bm_handle = texture_list_index[i].index;
651 #ifdef PIGGY_USE_PAGING
652 // Make sure the textures for this object are paged in...
653 piggy_page_flushed = 0;
654 for (i=0;i<po->n_textures;i++)
655 PIGGY_PAGE_IN( texture_list_index[i] );
656 // Hmmm... cache got flushed in the middle of paging all these in,
657 // so we need to reread them all in.
658 if (piggy_page_flushed) {
659 piggy_page_flushed = 0;
660 for (i=0;i<po->n_textures;i++)
661 PIGGY_PAGE_IN( texture_list_index[i] );
663 // Make sure that they can all fit in memory.
664 Assert( piggy_page_flushed == 0 );
667 g3_start_instance_matrix(pos,orient);
669 g3_set_interp_points(robot_points);
672 _3dfx_rendering_poly_obj = 1;
675 if (flags == 0) //draw entire object
677 g3_draw_polygon_model(po->model_data,texture_list,anim_angles,light,glow_values);
682 for (i=0;flags;flags>>=1,i++)
686 Assert(i < po->n_models);
688 //if submodel, rotate around its center point, not pivot point
690 vm_vec_avg(&ofs,&po->submodel_mins[i],&po->submodel_maxs[i]);
692 g3_start_instance_matrix(&ofs,NULL);
694 g3_draw_polygon_model(&po->model_data[po->submodel_ptrs[i]],texture_list,anim_angles,light,glow_values);
703 _3dfx_rendering_poly_obj = 0;
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);