[freespace2] a problem that has me stumped!
tigital
tigital at mac.com
Fri Aug 23 22:20:22 EDT 2002
>hiya,
>
>...after jumping the gun and releasing an OS X diff, I'm trying to
>move ahead with the port and get the byteswapping to work with model
>loading...fortunately, most of the that is done, but I'm now stuck
>on what to do with a coupla struct data fields...
>
>the polymodel struct has an element "*submodel" of type bsp_info,
>which is another struct...this bsp_info has a ubyte *bsp_data, which
>is specifically passed to many model functions, which then use a
>series of dereferencing define's to access certain fields:
>
>#define w(p) (*((int *) (p)))
>#define vp(p) ((vector *)(p))
>#define fl(p) (*((float *)(p)))
>
>
>...unfortunately, the fields are offsets from the beginning of the
>"ubyte *bsp_data", so, as an example, with Textured poly's the
>following offsets apply:
>
>+0 int id
>+4 int size
>+8 vector normal
>+20 vector center
>+32 float radius
>+36 int nverts
>+40 int tmap_num
>+44 nverts*(model_tmap_vert) vertlist (n,u,v)
>
>...so, the code uses vp(p+8) and vp(p+20) to access the vector
>fields...so far I've been able to byteswap the w(p) and fl(p)
>functions at the point of their calling(ex. chunk_size =
>SDL_SwapLE32( w(p+4));), but I'm unsure how to access the vector
>elements...a vector is as follows:
>
>typedef struct vector {
> union {
> struct{
> float x,y,z;
> }xyz;
> float a1d[3];
> };
>} vector;
>
>...anyone think they can shed some insight?
>
>tanx,
>
>jamie
Me again,
...the following compiles, but I don't know if trying to replace all
44 occurrences with code like this is the best way to do it; seems
like it should be done once, like at the model_read(), but there are
four different types of bsp_data: Point list, Flat Poly, Textured
Poly, and Sortnorms (these are found in modelinterp.cpp,
modeloctant.cpp, and modelcollide.cpp, just before the functions they
are used in)...
vector *tmp = vp(p+8);
vector *tmp2 = vp(p+20);
tmp->xyz.x = LoadLEFloat( &tmp->xyz.x );
tmp->xyz.y = LoadLEFloat( &tmp->xyz.y );
tmp->xyz.z = LoadLEFloat( &tmp->xyz.z );
tmp2->xyz.x = LoadLEFloat( &tmp2->xyz.x );
tmp2->xyz.y = LoadLEFloat( &tmp2->xyz.y );
tmp2->xyz.z = LoadLEFloat( &tmp2->xyz.z );
...Seems like this could really slow down model rendering if this
were done 44 times for each frame, but I don't know if that the
functions that use vp(p) are used only in model loading, or are
constantly called...
Help!
jamie
More information about the freespace2
mailing list