basic pointer question
tigital
tigital at mac.com
Thu Dec 19 14:16:49 EST 2002
ok,
...it's time I need to admit I'm a self-taught hobby programmer, cuz
I've run into (perhaps) a basic problem that I can't seem to figure
out, having to do with pointers and such...
...here is the original version of the function:
void moff_defpoints(ubyte * p)
{
int n;
int nverts = w(p+8);
int offset = w(p+16);
ubyte * normcount = p+20;
vector *src = vp(p+offset);
Assert( nverts < MAX_POLYGON_VECS );
// Assert( nnorms < MAX_POLYGON_NORMS );
for (n=0; n<nverts; n++ ) {
Interp_verts[n] = src;
src += normcount[n]+1;
}
}
...this seems to step through a set of vertex vectors (xyz.x,y,z)and
assign them to an externally declared global vector
"Interp_verts[n]"...ByteSwapping needs to be done on all data coming
from the passed in pointer "p", so I initially tried swapping the
x,y, and z floats passed into the "src" vector by doing src->xyz.x =
LoadLEFloat( &src->xyz.x );
...then I noticed that by doing this, I'm actually changing the value
in the passed in pointer, and so future references get swapped
multiple times, which isn't good!
So, I tried to create a local "buffer" vector that would hold the
swapped floats, put them into a buffer vector, then pass that to the
global vector Interp_verts[n]...but this isn't happening, and I'm not
sure where I've gone wrong? Can someone get me straight on this?
void moff_defpoints(ubyte * p)
{
int n;
int nverts = SDL_SwapLE32( w(p+8));
int offset = SDL_SwapLE32( w(p+16));
//int nverts = w(p+8);
//int offset = w(p+16);
float srcx, srcy, srcz;
vector *tmp;
ubyte * normcount = p+20;
vector *src = vp(p+offset);
Assert( nverts < MAX_POLYGON_VECS );
// Assert( nnorms < MAX_POLYGON_NORMS );
for (n=0; n<nverts; n++ ) {
srcx = LoadLEFloat( &src->xyz.x );
srcy = LoadLEFloat( &src->xyz.y );
srcz = LoadLEFloat( &src->xyz.z );
tmp->xyz.x = srcx;
tmp->xyz.y = srcy;
tmp->xyz.z = srcz;
//Interp_verts[n] = src;
Interp_verts[n] = tmp;
normcount[n] = SDL_SwapLE16( normcount[n] );
src += normcount[n]+1;
}
}
Tanx,
jamie
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://icculus.org/pipermail/freespace2/attachments/20021219/88064c4b/attachment.htm>
More information about the freespace2
mailing list