I wrote a function that will tell the program were to place the model and how much to scale the model. It works perfect with my MDL engine but when I put it into my MD2 engine it makes the model really big. The only diffrence in them is how they get the axis.
Here is the code from my MDL engine that works perfect
void Resize(float* scale, float* x, float* y, float* z)
{
float* av;
float minx = 0.0;
float maxx = 0.0;
float miny = 0.0;
float maxy = 0.0;
float minz = 0.0;
float maxz = 0.0;
float centerx;
float centery;
float centerz;
float scalex;
float scaley;
float scalez;
int i;
BYTE* vertbone;
vect3* studioverts;
SetUpBones();
for(int a=0;a<header->numbodyparts;a++)
{
SetupModel(a);
vertbone = ((BYTE*)header + model->vertinfoindex);
studioverts = (vect3*)((BYTE*)header + model->vertindex);
for(i=0;i<model->numverts;i++)
{
VectorTransform(studioverts[i], bonetransform[vertbone[i]], formverts[i]);
}
for(int j=0;j<model->nummesh;j++)
{
//set up the vars to get the info
Mesh* mesh = (Mesh*)((BYTE*)header + model->meshindex) + j;
short* tricmds = (short*)((BYTE*)header + mesh->triindex);
//start going threw the model
while(i = *(tricmds++))
{
if(i < 0)
{
i = -i;
}
//go threw each vertex
for(;i>0;i--,tricmds+=4)
{
av = formverts[tricmds[0]];
if((minx == 0) && (maxx == 0) && (miny == 0) && (maxy == 0) && (minz == 0) && (maxz == 0))
{
minx = maxx = av[0];
miny = maxy = av[1];
minz = maxz = av[2];
}else{
minx = min(minx, av[0]);
maxx = max(maxx, av[0]);
miny = min(miny, av[1]);
maxy = max(maxy, av[1]);
minz = min(minz, av[2]);
maxz = max(maxz, av[2]);
}
}
}
}
}
//get the center
centerx = (maxx + minx) / 2;
centery = (maxy + miny) / 2;
centerz = (maxz + minz) / 2;
//get the scale
scalex = 2 / (maxx - minx);
scaley = 2 / (maxy - miny);
scalez = 2 / (maxz - minz);
//get the min of all of them
float tmp1 = min(scalex, scaley);
float tmp2 = min(scalex, scalez);
float tmp3 = min(scaley, scalez);
//see which one is the smallest and sent it to scale
if(tmp1 < tmp2)
{
*scale = min(tmp2, tmp3);
}else{
*scale = min(tmp1, tmp3);
}
//set up the x y z var and give them there values
*x = (-centerx);
*y = (-centery);
*z = (-centerz);
}
Here is the broken MD2 funtion
void Resize(int Frame, float* scale, float* x, float* y, float* z)
{
float minx = 0.0;
float maxx = 0.0;
float miny = 0.0;
float maxy = 0.0;
float minz = 0.0;
float maxz = 0.0;
float centerx;
float centery;
float centerz;
float scalex;
float scaley;
float scalez;
MODELVERTEX vertlist[100];
FRAME_PNT currentframe;
long* command;
float texcoord[2];
int loop;
int vertindex;
int numvertex;
int index;
currentframe = (FRAME*)((char*)Frames + FrameSize * Frame);
command = glCommands;
while((*command) != 0)
{
if(*command > 0)
{
numvertex = *command;
command++;
}else{
numvertex = -*command;
command++;
}
if(numvertex < 0)
{
numvertex = -numvertex;
}
index = 0;
for(loop=0;loop<numvertex;loop++)
{
vertlist[index].U = *((float*)command);
command++;
vertlist[index].V = *((float*)command);
command++;
vertindex = *command;
command++;
vertlist[index].X = (currentframe->Vertices[vertindex].Vertex[0] * currentframe->Scale[0]) + currentframe->Translate[0];
vertlist[index].Z = -(currentframe->Vertices[vertindex].Vertex[1] * currentframe->Scale[1]) + currentframe->Translate[1];
vertlist[index].Y = (currentframe->Vertices[vertindex].Vertex[2] * currentframe->Scale[2]) + currentframe->Translate[2];
index++;
}
}
for(loop=0;loop<index;loop++)
{
if((minx == 0.0) && (maxx == 0.0) && (miny == 0.0) && (maxy == 0.0) && (minz == 0.0) && (maxz == 0.0))
{
minx = maxx = vertlist[loop].X;
miny = maxy = vertlist[loop].Y;
minz = maxz = vertlist[loop].Z;
}else{
minx = min(minx, vertlist[loop].X);
maxx = max(maxx, vertlist[loop].X);
miny = min(miny, vertlist[loop].Y);
maxy = max(maxy, vertlist[loop].Y);
minz = min(minz, vertlist[loop].Z);
maxz = max(maxz, vertlist[loop].Z);
}
}
//get the center
centerx = (maxx + minx) / 2;
centery = (maxy + miny) / 2;
centerz = (maxz + minz) / 2;
//get the scale
scalex = 2 / (maxx - minx);
scaley = 2 / (maxy - miny);
scalez = 2 / (maxz - minz);
//get the min of all of them
float tmp1 = min(scalex, scaley);
float tmp2 = min(scalex, scalez);
float tmp3 = min(scaley, scalez);
//see which one is the smallest and sent it to scale
if(tmp1 < tmp2)
{
*scale = min(tmp2, tmp3);
}else{
*scale = min(tmp1, tmp3);
}
//set up the x y z var and give them there values
*x = (-centerx);
*y = (-centery);
*z = (-centerz);
}
Can someone please help me?
Thanks
Nuke
--------------------------Nukemmsn: nukem996@hotmail.comaim: nukem996open source open mind