1 /* $Id: polyobj.c,v 1.11 2003-02-13 22:02:29 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.11 2003-02-13 22:02:29 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 #ifdef WORDS_BIGENDIAN
75 void short_swap(short *s)
82 *f = (fix)SWAPINT((int)*f);
85 void fixang_swap(fixang *f)
87 *f = (fixang)SWAPSHORT((short)*f);
90 void vms_vector_swap(vms_vector *v)
97 void vms_angvec_swap(vms_angvec *v)
105 void _pof_cfseek(int len,int type)
108 case SEEK_SET: Pof_addr = len; break;
109 case SEEK_CUR: Pof_addr += len; break;
111 Assert(len <= 0); // seeking from end, better be moving back.
112 Pof_addr = Pof_file_end + len;
116 if (Pof_addr > MODEL_BUF_SIZE)
120 #define pof_cfseek(_buf,_len,_type) _pof_cfseek((_len),(_type))
122 int pof_read_int(ubyte *bufp)
126 i = *((int *) &bufp[Pof_addr]);
130 // if (cfread(&i,sizeof(i),1,f) != 1)
131 // Error("Unexpected end-of-file while reading object");
136 size_t pof_cfread(void *dst, size_t elsize, size_t nelem, ubyte *bufp)
138 if (Pof_addr + nelem*elsize > Pof_file_end)
141 memcpy(dst, &bufp[Pof_addr], elsize*nelem);
143 Pof_addr += elsize*nelem;
145 if (Pof_addr > MODEL_BUF_SIZE)
151 // #define new_read_int(i,f) cfread(&(i),sizeof(i),1,(f))
152 #define new_pof_read_int(i,f) pof_cfread(&(i),sizeof(i),1,(f))
154 short pof_read_short(ubyte *bufp)
158 s = *((short *) &bufp[Pof_addr]);
160 return INTEL_SHORT(s);
161 // if (cfread(&s,sizeof(s),1,f) != 1)
162 // Error("Unexpected end-of-file while reading object");
167 void pof_read_string(char *buf,int max_char, ubyte *bufp)
171 for (i=0; i<max_char; i++) {
172 if ((*buf++ = bufp[Pof_addr++]) == 0)
176 // while (max_char-- && (*buf=cfgetc(f)) != 0) buf++;
180 void pof_read_vecs(vms_vector *vecs,int n,ubyte *bufp)
182 // cfread(vecs,sizeof(vms_vector),n,f);
184 memcpy(vecs, &bufp[Pof_addr], n*sizeof(*vecs));
185 Pof_addr += n*sizeof(*vecs);
187 #ifdef WORDS_BIGENDIAN
189 vms_vector_swap(&vecs[--n]);
192 if (Pof_addr > MODEL_BUF_SIZE)
196 void pof_read_angs(vms_angvec *angs,int n,ubyte *bufp)
198 memcpy(angs, &bufp[Pof_addr], n*sizeof(*angs));
199 Pof_addr += n*sizeof(*angs);
201 #ifdef WORDS_BIGENDIAN
203 vms_angvec_swap(&angs[--n]);
206 if (Pof_addr > MODEL_BUF_SIZE)
210 #define ID_OHDR 0x5244484f // 'RDHO' //Object header
211 #define ID_SOBJ 0x4a424f53 // 'JBOS' //Subobject header
212 #define ID_GUNS 0x534e5547 // 'SNUG' //List of guns on this object
213 #define ID_ANIM 0x4d494e41 // 'MINA' //Animation data
214 #define ID_IDTA 0x41544449 // 'ATDI' //Interpreter data
215 #define ID_TXTR 0x52545854 // 'RTXT' //Texture filename list
218 #define robot_info void
220 vms_angvec anim_angs[N_ANIM_STATES][MAX_SUBMODELS];
222 //set the animation angles for this robot. Gun fields of robot info must
224 void robot_set_angles(robot_info *r,polymodel *pm,vms_angvec angs[N_ANIM_STATES][MAX_SUBMODELS]);
227 #define DEBUG_LEVEL CON_NORMAL
229 #ifdef WORDS_NEED_ALIGNMENT
230 ubyte * old_dest(chunk o) // return where chunk is (in unaligned struct)
232 return o.old_base + INTEL_SHORT(*((short *)(o.old_base + o.offset)));
234 ubyte * new_dest(chunk o) // return where chunk is (in aligned struct)
236 return o.new_base + INTEL_SHORT(*((short *)(o.old_base + o.offset))) + o.correction;
239 * find chunk with smallest address
241 int get_first_chunks_index(chunk *chunk_list, int no_chunks)
243 int i, first_index = 0;
244 Assert(no_chunks >= 1);
245 for (i = 1; i < no_chunks; i++)
246 if (old_dest(chunk_list[i]) < old_dest(chunk_list[first_index]))
250 #define SHIFT_SPACE 500 // increase if insufficent
252 void align_polygon_model_data(polymodel *pm)
255 int total_correction = 0;
256 ubyte *cur_old, *cur_new;
258 chunk ch_list[MAX_CHUNKS];
260 int tmp_size = pm->model_data_size + SHIFT_SPACE;
261 ubyte *tmp = d_malloc(tmp_size); // where we build the aligned version of pm->model_data
264 //start with first chunk (is always aligned!)
265 cur_old = pm->model_data;
267 chunk_len = get_chunks(cur_old, cur_new, ch_list, &no_chunks);
268 memcpy(cur_new, cur_old, chunk_len);
269 while (no_chunks > 0) {
270 int first_index = get_first_chunks_index(ch_list, no_chunks);
271 cur_ch = ch_list[first_index];
272 // remove first chunk from array:
274 for (i = first_index; i < no_chunks; i++)
275 ch_list[i] = ch_list[i + 1];
276 // if (new) address unaligned:
277 if ((u_int32_t)new_dest(cur_ch) % 4L != 0) {
278 // calculate how much to move to be aligned
279 short to_shift = 4 - (u_int32_t)new_dest(cur_ch) % 4L;
280 // correct chunks' addresses
281 cur_ch.correction += to_shift;
282 for (i = 0; i < no_chunks; i++)
283 ch_list[i].correction += to_shift;
284 total_correction += to_shift;
285 Assert((u_int32_t)new_dest(cur_ch) % 4L == 0);
286 Assert(total_correction <= SHIFT_SPACE); // if you get this, increase SHIFT_SPACE
288 //write (corrected) chunk for current chunk:
289 *((short *)(cur_ch.new_base + cur_ch.offset))
290 = INTEL_SHORT(cur_ch.correction
291 + INTEL_SHORT(*((short *)(cur_ch.old_base + cur_ch.offset))));
292 //write (correctly aligned) chunk:
293 cur_old = old_dest(cur_ch);
294 cur_new = new_dest(cur_ch);
295 chunk_len = get_chunks(cur_old, cur_new, ch_list, &no_chunks);
296 memcpy(cur_new, cur_old, chunk_len);
297 //correct submodel_ptr's for pm, too
298 for (i = 0; i < MAX_SUBMODELS; i++)
299 if (pm->model_data + pm->submodel_ptrs[i] >= cur_old
300 && pm->model_data + pm->submodel_ptrs[i] < cur_old + chunk_len)
301 pm->submodel_ptrs[i] += (cur_new - tmp) - (cur_old - pm->model_data);
303 d_free(pm->model_data);
304 pm->model_data_size += total_correction;
305 pm->model_data = d_malloc(pm->model_data_size);
306 Assert(pm->model_data != NULL);
307 memcpy(pm->model_data, tmp, pm->model_data_size);
310 #endif //def WORDS_NEED_ALIGNMENT
312 //reads a binary file containing a 3d model
313 polymodel *read_model_file(polymodel *pm,char *filename,robot_info *r)
317 int id,len, next_chunk;
321 model_buf = (ubyte *)d_malloc( MODEL_BUF_SIZE * sizeof(ubyte) );
323 Error("Can't allocate space to read model %s\n", filename);
325 if ((ifile=cfopen(filename,"rb"))==NULL)
326 Error("Can't open file <%s>",filename);
328 Assert(ifile->size <= MODEL_BUF_SIZE);
331 Pof_file_end = cfread(model_buf, 1, cfilelength(ifile), ifile);
334 id = pof_read_int(model_buf);
336 if (id!=0x4f505350) /* 'OPSP' */
337 Error("Bad ID in model file <%s>",filename);
339 version = pof_read_short(model_buf);
341 if (version < PM_COMPATIBLE_VERSION || version > PM_OBJFILE_VERSION)
342 Error("Bad version (%d) in model file <%s>",version,filename);
344 if ( FindArg( "-bspgen" ))
345 printf( "bspgen -c1" );
347 while (new_pof_read_int(id,model_buf) == 1) {
349 //id = pof_read_int(model_buf);
350 len = pof_read_int(model_buf);
351 next_chunk = Pof_addr + len;
355 case ID_OHDR: { //Object header
356 vms_vector pmmin,pmmax;
358 //con_printf(DEBUG_LEVEL, "Got chunk OHDR, len=%d\n",len);
360 pm->n_models = pof_read_int(model_buf);
361 pm->rad = pof_read_int(model_buf);
363 Assert(pm->n_models <= MAX_SUBMODELS);
365 pof_read_vecs(&pmmin,1,model_buf);
366 pof_read_vecs(&pmmax,1,model_buf);
368 if ( FindArg( "-bspgen" )) {
372 vm_vec_sub(&v, &pmmax, &pmmin );
374 if ( v.y > l ) l = v.y;
375 if ( v.z > l ) l = v.z;
377 printf( " -l%.3f", f2fl(l) );
383 case ID_SOBJ: { //Subobject header
388 //con_printf(DEBUG_LEVEL, "Got chunk SOBJ, len=%d\n",len);
390 n = pof_read_short(model_buf);
392 Assert(n < MAX_SUBMODELS);
394 pm->submodel_parents[n] = pof_read_short(model_buf);
396 pof_read_vecs(&pm->submodel_norms[n],1,model_buf);
397 pof_read_vecs(&pm->submodel_pnts[n],1,model_buf);
398 pof_read_vecs(&pm->submodel_offsets[n],1,model_buf);
400 pm->submodel_rads[n] = pof_read_int(model_buf); //radius
402 pm->submodel_ptrs[n] = pof_read_int(model_buf); //offset
409 case ID_GUNS: { //List of guns on this object
411 //con_printf(DEBUG_LEVEL, "Got chunk GUNS, len=%d\n",len);
416 ubyte gun_used[MAX_GUNS];
418 r->n_guns = pof_read_int(model_buf);
423 Assert(r->n_guns <= MAX_GUNS);
425 for (i=0;i<r->n_guns;i++)
428 for (i=0;i<r->n_guns;i++) {
431 id = pof_read_short(model_buf);
432 Assert(id < r->n_guns);
433 Assert(gun_used[id] == 0);
435 r->gun_submodels[id] = pof_read_short(model_buf);
436 Assert(r->gun_submodels[id] != 0xff);
437 pof_read_vecs(&r->gun_points[id],1,model_buf);
440 pof_read_vecs(&gun_dir,1,model_buf);
444 pof_cfseek(model_buf,len,SEEK_CUR);
449 case ID_ANIM: //Animation data
450 //con_printf(DEBUG_LEVEL, "Got chunk ANIM, len=%d\n",len);
457 n_frames = pof_read_short(model_buf);
459 Assert(n_frames == N_ANIM_STATES);
461 for (m=0;m<pm->n_models;m++)
462 for (f=0;f<n_frames;f++)
463 pof_read_angs(&anim_angs[f][m], 1, model_buf);
466 robot_set_angles(r,pm,anim_angs);
470 pof_cfseek(model_buf,len,SEEK_CUR);
475 case ID_TXTR: { //Texture filename list
479 //con_printf(DEBUG_LEVEL, "Got chunk TXTR, len=%d\n",len);
481 n = pof_read_short(model_buf);
482 //con_printf(DEBUG_LEVEL, " num textures = %d\n",n);
484 pof_read_string(name_buf,128,model_buf);
485 //con_printf(DEBUG_LEVEL, "<%s>\n",name_buf);
491 case ID_IDTA: //Interpreter data
492 //con_printf(DEBUG_LEVEL, "Got chunk IDTA, len=%d\n",len);
494 pm->model_data = d_malloc(len);
495 pm->model_data_size = len;
497 pof_cfread(pm->model_data,1,len,model_buf);
502 //con_printf(DEBUG_LEVEL, "Unknown chunk <%c%c%c%c>, len = %d\n",id,id>>8,id>>16,id>>24,len);
503 pof_cfseek(model_buf,len,SEEK_CUR);
507 if ( version >= 8 ) // Version 8 needs 4-byte alignment!!!
508 pof_cfseek(model_buf,next_chunk,SEEK_SET);
511 // for (i=0;i<pm->n_models;i++)
512 // pm->submodel_ptrs[i] += (int) pm->model_data;
514 if ( FindArg( "-bspgen" )) {
515 char *p = strchr( filename, '.' );
521 printf( " %s.3ds\n", filename );
527 #ifdef WORDS_NEED_ALIGNMENT
528 align_polygon_model_data(pm);
530 #ifdef WORDS_BIGENDIAN
531 swap_polygon_model_data(pm->model_data);
533 //verify(pm->model_data);
538 //reads the gun information for a model
539 //fills in arrays gun_points & gun_dirs, returns the number of guns read
540 int read_model_guns(char *filename,vms_vector *gun_points, vms_vector *gun_dirs, int *gun_submodels)
548 model_buf = (ubyte *)d_malloc( MODEL_BUF_SIZE * sizeof(ubyte) );
550 Error("Can't allocate space to read model %s\n", filename);
552 if ((ifile=cfopen(filename,"rb"))==NULL)
553 Error("Can't open file <%s>",filename);
555 Assert(ifile->size <= MODEL_BUF_SIZE);
558 Pof_file_end = cfread(model_buf, 1, ifile->size, ifile);
561 id = pof_read_int(model_buf);
563 if (id!=0x4f505350) /* 'OPSP' */
564 Error("Bad ID in model file <%s>",filename);
566 version = pof_read_short(model_buf);
568 Assert(version >= 7); //must be 7 or higher for this data
570 if (version < PM_COMPATIBLE_VERSION || version > PM_OBJFILE_VERSION)
571 Error("Bad version (%d) in model file <%s>",version,filename);
573 while (new_pof_read_int(id,model_buf) == 1) {
575 //id = pof_read_int(model_buf);
576 len = pof_read_int(model_buf);
578 if (id == ID_GUNS) { //List of guns on this object
580 //con_printf(DEBUG_LEVEL, "Got chunk GUNS, len=%d\n",len);
584 n_guns = pof_read_int(model_buf);
586 for (i=0;i<n_guns;i++) {
589 id = pof_read_short(model_buf);
590 sm = pof_read_short(model_buf);
592 gun_submodels[id] = sm;
594 Error("Invalid gun submodel in file <%s>",filename);
595 pof_read_vecs(&gun_points[id],1,model_buf);
597 pof_read_vecs(&gun_dirs[id],1,model_buf);
602 pof_cfseek(model_buf,len,SEEK_CUR);
611 //free up a model, getting rid of all its memory
612 void free_model(polymodel *po)
614 d_free(po->model_data);
617 grs_bitmap *texture_list[MAX_POLYOBJ_TEXTURES];
618 bitmap_index texture_list_index[MAX_POLYOBJ_TEXTURES];
620 int Simple_model_threshhold_scale=5; //switch when this times radius far away
623 //draw a polygon model
625 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[])
629 PA_DFX (int save_light);
631 Assert(model_num < N_polygon_models);
633 po=&Polygon_models[model_num];
635 //check if should use simple model
636 if (po->simpler_model ) //must have a simpler model
637 if (flags==0) //can't switch if this is debris
638 //!!if (!alt_textures) { //alternate textures might not match
639 //alt textures might not match, but in the one case we're using this
640 //for on 11/14/94, they do match. So we leave it in.
645 depth = g3_calc_point_depth(pos); //gets 3d depth
647 while (po->simpler_model && depth > cnt++ * Simple_model_threshhold_scale * po->rad)
648 po = &Polygon_models[po->simpler_model-1];
653 for (i=0;i<po->n_textures;i++) {
654 texture_list_index[i] = alt_textures[i];
655 texture_list[i] = &GameBitmaps[alt_textures[i].index];
658 texture_list[i]->bm_handle = texture_list_index[i].index;
664 for (i=0;i<po->n_textures;i++) {
665 texture_list_index[i] = ObjBitmaps[ObjBitmapPtrs[po->first_texture+i]];
666 texture_list[i] = &GameBitmaps[ObjBitmaps[ObjBitmapPtrs[po->first_texture+i]].index];
669 texture_list[i]->bm_handle = texture_list_index[i].index;
674 #ifdef PIGGY_USE_PAGING
675 // Make sure the textures for this object are paged in...
676 piggy_page_flushed = 0;
677 for (i=0;i<po->n_textures;i++)
678 PIGGY_PAGE_IN( texture_list_index[i] );
679 // Hmmm... cache got flushed in the middle of paging all these in,
680 // so we need to reread them all in.
681 if (piggy_page_flushed) {
682 piggy_page_flushed = 0;
683 for (i=0;i<po->n_textures;i++)
684 PIGGY_PAGE_IN( texture_list_index[i] );
686 // Make sure that they can all fit in memory.
687 Assert( piggy_page_flushed == 0 );
690 g3_start_instance_matrix(pos,orient);
692 g3_set_interp_points(robot_points);
695 _3dfx_rendering_poly_obj = 1;
697 PA_DFX(save_light = Lighting_on);
698 PA_DFX(Lighting_on = 0);
700 if (flags == 0) //draw entire object
702 g3_draw_polygon_model(po->model_data,texture_list,anim_angles,light,glow_values);
707 for (i=0;flags;flags>>=1,i++)
711 Assert(i < po->n_models);
713 //if submodel, rotate around its center point, not pivot point
715 vm_vec_avg(&ofs,&po->submodel_mins[i],&po->submodel_maxs[i]);
717 g3_start_instance_matrix(&ofs,NULL);
719 g3_draw_polygon_model(&po->model_data[po->submodel_ptrs[i]],texture_list,anim_angles,light,glow_values);
728 _3dfx_rendering_poly_obj = 0;
731 PA_DFX (Lighting_on = save_light);
736 void free_polygon_models()
740 for (i=0;i<N_polygon_models;i++) {
741 free_model(&Polygon_models[i]);
746 void polyobj_find_min_max(polymodel *pm)
752 vms_vector *big_mn,*big_mx;
757 for (m=0;m<pm->n_models;m++) {
758 vms_vector *mn,*mx,*ofs;
760 mn = &pm->submodel_mins[m];
761 mx = &pm->submodel_maxs[m];
762 ofs= &pm->submodel_offsets[m];
764 data = (ushort *)&pm->model_data[pm->submodel_ptrs[m]];
768 Assert(type == 7 || type == 1);
773 data+=2; //skip start & pad
775 vp = (vms_vector *) data;
777 *mn = *mx = *vp++; nverts--;
780 *big_mn = *big_mx = *mn;
783 if (vp->x > mx->x) mx->x = vp->x;
784 if (vp->y > mx->y) mx->y = vp->y;
785 if (vp->z > mx->z) mx->z = vp->z;
787 if (vp->x < mn->x) mn->x = vp->x;
788 if (vp->y < mn->y) mn->y = vp->y;
789 if (vp->z < mn->z) mn->z = vp->z;
791 if (vp->x+ofs->x > big_mx->x) big_mx->x = vp->x+ofs->x;
792 if (vp->y+ofs->y > big_mx->y) big_mx->y = vp->y+ofs->y;
793 if (vp->z+ofs->z > big_mx->z) big_mx->z = vp->z+ofs->z;
795 if (vp->x+ofs->x < big_mn->x) big_mn->x = vp->x+ofs->x;
796 if (vp->y+ofs->y < big_mn->y) big_mn->y = vp->y+ofs->y;
797 if (vp->z+ofs->z < big_mn->z) big_mn->z = vp->z+ofs->z;
802 // printf("Submodel %d: (%8x,%8x) (%8x,%8x) (%8x,%8x)\n",m,mn->x,mx->x,mn->y,mx->y,mn->z,mx->z);
805 // 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);
809 extern short highest_texture_num; //from the 3d
811 char Pof_names[MAX_POLYGON_MODELS][FILENAME_LEN];
813 //returns the number of this model
815 int load_polygon_model(char *filename,int n_textures,int first_texture,robot_info *r)
817 int load_polygon_model(char *filename,int n_textures,grs_bitmap ***textures)
824 Assert(N_polygon_models < MAX_POLYGON_MODELS);
825 Assert(n_textures < MAX_POLYOBJ_TEXTURES);
827 // MK was real tired of those useless, slow mprintfs...
828 if (N_polygon_models > MAX_POLYGON_MODELS - 10)
829 mprintf(( 0, "Used %d/%d polygon model slots\n", N_polygon_models+1, MAX_POLYGON_MODELS ));
831 Assert(strlen(filename) <= 12);
832 strcpy(Pof_names[N_polygon_models],filename);
834 read_model_file(&Polygon_models[N_polygon_models],filename,r);
836 polyobj_find_min_max(&Polygon_models[N_polygon_models]);
838 g3_init_polygon_model(Polygon_models[N_polygon_models].model_data);
840 if (highest_texture_num+1 != n_textures)
841 Error("Model <%s> references %d textures but specifies %d.",filename,highest_texture_num+1,n_textures);
843 Polygon_models[N_polygon_models].n_textures = n_textures;
844 Polygon_models[N_polygon_models].first_texture = first_texture;
845 Polygon_models[N_polygon_models].simpler_model = 0;
847 // Assert(polygon_models[N_polygon_models]!=NULL);
851 return N_polygon_models-1;
856 void init_polygon_models()
858 N_polygon_models = 0;
860 atexit((void (*)())free_polygon_models);
864 //compare against this size when figuring how far to place eye for picture
865 #define BASE_MODEL_SIZE 0x28000
867 #define DEFAULT_VIEW_DIST 0x60000
869 //draws the given model in the current canvas. The distance is set to
870 //more-or-less fill the canvas. Note that this routine actually renders
871 //into an off-screen canvas that it creates, then copies to the current
873 void draw_model_picture(int mn,vms_angvec *orient_angles)
875 vms_vector temp_pos=ZERO_VECTOR;
876 vms_matrix temp_orient = IDENTITY_MATRIX;
877 grs_canvas *save_canv = grd_curcanv,*temp_canv;
879 Assert(mn>=0 && mn<N_polygon_models);
881 temp_canv = gr_create_canvas(save_canv->cv_bitmap.bm_w,save_canv->cv_bitmap.bm_h);
882 gr_set_current_canvas(temp_canv);
883 gr_clear_canvas( BM_XRGB(0,0,0) );
886 g3_set_view_matrix(&temp_pos,&temp_orient,0x9000);
888 if (Polygon_models[mn].rad != 0)
889 temp_pos.z = fixmuldiv(DEFAULT_VIEW_DIST,Polygon_models[mn].rad,BASE_MODEL_SIZE);
891 temp_pos.z = DEFAULT_VIEW_DIST;
893 vm_angles_2_matrix(&temp_orient, orient_angles);
895 PA_DFX(save_light = Lighting_on);
896 PA_DFX(Lighting_on = 0);
897 draw_polygon_model(&temp_pos,&temp_orient,NULL,mn,0,f1_0,NULL,NULL);
898 PA_DFX (Lighting_on = save_light);
900 gr_set_current_canvas(save_canv);
902 gr_bitmap(0,0,&temp_canv->cv_bitmap);
904 gr_free_canvas(temp_canv);
909 * reads a polymodel structure from a CFILE
911 extern void polymodel_read(polymodel *pm, CFILE *fp)
915 pm->n_models = cfile_read_int(fp);
916 pm->model_data_size = cfile_read_int(fp);
917 pm->model_data = (ubyte *) cfile_read_int(fp);
918 for (i = 0; i < MAX_SUBMODELS; i++)
919 pm->submodel_ptrs[i] = cfile_read_int(fp);
920 for (i = 0; i < MAX_SUBMODELS; i++)
921 cfile_read_vector(&(pm->submodel_offsets[i]), fp);
922 for (i = 0; i < MAX_SUBMODELS; i++)
923 cfile_read_vector(&(pm->submodel_norms[i]), fp);
924 for (i = 0; i < MAX_SUBMODELS; i++)
925 cfile_read_vector(&(pm->submodel_pnts[i]), fp);
926 for (i = 0; i < MAX_SUBMODELS; i++)
927 pm->submodel_rads[i] = cfile_read_fix(fp);
928 cfread(pm->submodel_parents, MAX_SUBMODELS, 1, fp);
929 for (i = 0; i < MAX_SUBMODELS; i++)
930 cfile_read_vector(&(pm->submodel_mins[i]), fp);
931 for (i = 0; i < MAX_SUBMODELS; i++)
932 cfile_read_vector(&(pm->submodel_maxs[i]), fp);
933 cfile_read_vector(&(pm->mins), fp);
934 cfile_read_vector(&(pm->maxs), fp);
935 pm->rad = cfile_read_fix(fp);
936 pm->n_textures = cfile_read_byte(fp);
937 pm->first_texture = cfile_read_short(fp);
938 pm->simpler_model = cfile_read_byte(fp);
942 * reads n polymodel structs from a CFILE
944 extern int polymodel_read_n(polymodel *pm, int n, CFILE *fp)
948 for (i = 0; i < n; i++) {
949 pm[i].n_models = cfile_read_int(fp);
950 pm[i].model_data_size = cfile_read_int(fp);
951 pm[i].model_data = (ubyte *) cfile_read_int(fp);
952 for (j = 0; j < MAX_SUBMODELS; j++)
953 pm[i].submodel_ptrs[j] = cfile_read_int(fp);
954 for (j = 0; j < MAX_SUBMODELS; j++)
955 cfile_read_vector(&(pm[i].submodel_offsets[j]), fp);
956 for (j = 0; j < MAX_SUBMODELS; j++)
957 cfile_read_vector(&(pm[i].submodel_norms[j]), fp);
958 for (j = 0; j < MAX_SUBMODELS; j++)
959 cfile_read_vector(&(pm[i].submodel_pnts[j]), fp);
960 for (j = 0; j < MAX_SUBMODELS; j++)
961 pm[i].submodel_rads[j] = cfile_read_fix(fp);
962 cfread(pm[i].submodel_parents, MAX_SUBMODELS, 1, fp);
963 for (j = 0; j < MAX_SUBMODELS; j++)
964 cfile_read_vector(&(pm[i].submodel_mins[j]), fp);
965 for (j = 0; j < MAX_SUBMODELS; j++)
966 cfile_read_vector(&(pm[i].submodel_maxs[j]), fp);
967 cfile_read_vector(&(pm[i].mins), fp);
968 cfile_read_vector(&(pm[i].maxs), fp);
969 pm[i].rad = cfile_read_fix(fp);
970 pm[i].n_textures = cfile_read_byte(fp);
971 pm[i].first_texture = cfile_read_short(fp);
972 pm[i].simpler_model = cfile_read_byte(fp);
980 * routine which allocates, reads, and inits a polymodel's model_data
982 void polygon_model_data_read(polymodel *pm, CFILE *fp)
984 pm->model_data = d_malloc(pm->model_data_size);
985 Assert(pm->model_data != NULL);
986 cfread(pm->model_data, sizeof(ubyte), pm->model_data_size, fp );
987 #ifdef WORDS_NEED_ALIGNMENT
988 align_polygon_model_data(pm);
990 #ifdef WORDS_BIGENDIAN
991 swap_polygon_model_data(pm->model_data);
993 //verify(pm->model_data);
994 g3_init_polygon_model(pm->model_data);