rendered paste bodysbVector::sbVector(float x, float y, float z){
this->x = x;
this->y = y;
this->z = z;
}
---
class sbFace {
public:
sbFace();
~sbFace();
std::vector<sbVector> vertex; /* Tirnangle Coordinates */
sbVector normal;
TEXTURE_INFO texture; /* Texture Coordinates */
int cntVertices; /* number of vertices */
float distance; /* Face Distance from Origin */
sbVector getOrigin(void);
void setOrigin(sbVector newo);
private:
sbVector origin;
};
---
int getData(void)
{
extern WORLD world;
extern GAME game;
int cntTextures=2, i=0, temp=0, groups=0, brushes=0, faces=0;
char thisline[100],
temp2[20],
**textureName=(char**)aalloc(2, 12*sizeof(char));
FILE *file=fopen(game.mainFile, "r");
if (file == NULL)
{
MessageBox(0,"Main game file not found.","Error 2",0);
exit(1); /* file does not exist */
}
/** load the textures **/
strcpy(textureName[0], "pic1.bmp");
strcpy(textureName[1], "pic2.bmp");
loadGLTextures(cntTextures, (char**)textureName);
for (i=0; i < cntTextures; i++)
{
// free(textureName[cntTextures]);
// textureName[cntTextures]=NULL;
}
// free(textureName);
// textureName=NULL;
/** read out first opening bracket **/
do
readLine(file, thisline);
while (thisline[0] != '{');
if (thisline[0] != '{')
return 1;
MessageBox(0,"getting data","Error 2",0);
while (readLine(file,thisline) != 0)
{
/** if end of brush... **/
if(thisline[0] == '}')
{
world.brush[brushes-1].cntFaces = faces;
faces = 0;
readLine(file,thisline); /* just for the sake of not looping thru again. faster. */
/** end of file **/
if(thisline[0] == '}')
break;
}
/** if new brush... **/
if (thisline[0] == '{')
{
brushes += 1;
/** make room for a new brush **/
if (brushes == 1)
world.brush = (sbPoly *) malloc(1 * sizeof(sbPoly));
else
world.brush = (sbPoly *) realloc(world.brush, brushes * sizeof(sbPoly)); /* allocate enough space to hold sizeof(BRUSH) */
/* origin always 0 for now */
world.brush[brushes-1].origin.x = 0;
world.brush[brushes-1].origin.y = 0;
world.brush[brushes-1].origin.z = 0;
}
/** if new face... **/
if (thisline[0] == '(')
{
faces += 1;
/** make room for a new face **/
if (faces == 1)
world.brush[brushes-1].face = (sbFace *) malloc(1 * sizeof(sbFace));
else
world.brush[brushes-1].face = (sbFace *) realloc(world.brush[brushes-1].face, faces * sizeof(sbFace));
/** initialize shit **/
world.brush[brushes-1].face[faces-1].cntVertices = 3; /* 404 */
MessageBox(0,"before","",0);//sprintf((char *)&str, "%i,%i,%i", world.brush[brushes-1].face[faces-1].vertex.at(0).x, world.brush[brushes-1].face[faces-1].vertex.at(0).y, world.brush[brushes-1].face[faces-1].vertex.at(0).z);
//world.brush[brushes-1].face[faces-1].vertex.resize(3);// = (sbVector *) malloc(3 * sizeof(sbVector));
world.brush[brushes-1].face[faces-1].vertex.push_back(sbVector::sbVector(0, 0, 0));// = (sbVector *) malloc(3 * sizeof(sbVector));
MessageBox(0,"after","",0);//sprintf((char *)&str, "%i,%i,%i", world.brush[brushes-1].face[faces-1].vertex.at(0).x, world.brush[brushes-1].face[faces-1].vertex.at(0).y, world.brush[brushes-1].face[faces-1].vertex.at(0).z);
world.brush[brushes-1].face[faces-1].texture.texID = 1; /* set texture to 0 because we only have one for now */
sscanf(thisline, "( %f %f %f ) ( %f %f %f ) ( %f %f %f ) %s [ %f %f %f %f ] [ %f %f %f %f ] %f %f %f \n",
&world.brush[brushes-1].face[faces-1].vertex.at(0).x,
&world.brush[brushes-1].face[faces-1].vertex.at(0).z,
&world.brush[brushes-1].face[faces-1].vertex.at(0).y,
&world.brush[brushes-1].face[faces-1].vertex.at(1).x,
&world.brush[brushes-1].face[faces-1].vertex.at(1).z,
&world.brush[brushes-1].face[faces-1].vertex.at(1).y,
&world.brush[brushes-1].face[faces-1].vertex.at(2).x,
&world.brush[brushes-1].face[faces-1].vertex.at(2).z,
&world.brush[brushes-1].face[faces-1].vertex.at(2).y, &temp2,
&world.brush[brushes-1].face[faces-1].texture.texU.x,
&world.brush[brushes-1].face[faces-1].texture.texU.z,
&world.brush[brushes-1].face[faces-1].texture.texU.y,
&world.brush[brushes-1].face[faces-1].texture.shiftU,
&world.brush[brushes-1].face[faces-1].texture.texV.x,
&world.brush[brushes-1].face[faces-1].texture.texV.z,
&world.brush[brushes-1].face[faces-1].texture.texV.y,
&world.brush[brushes-1].face[faces-1].texture.shiftV,
&world.brush[brushes-1].face[faces-1].texture.rotation,
&world.brush[brushes-1].face[faces-1].texture.scaleU,
&world.brush[brushes-1].face[faces-1].texture.scaleV);
for (i=0; i<3; i++)
{
/** scale world **/
world.brush[brushes-1].face[faces-1].vertex.at(i).x /= _WORLD_SCALE;
world.brush[brushes-1].face[faces-1].vertex.at(i).y /= _WORLD_SCALE;
world.brush[brushes-1].face[faces-1].vertex.at(i).z /= _WORLD_SCALE;
/** further translate from the right-hand coordinate system to the left **/
world.brush[brushes-1].face[faces-1].vertex.at(i).y = -world.brush[brushes-1].face[faces-1].vertex.at(i).y;
}
world.brush[brushes-1].face[faces-1].texture.texU.y = -world.brush[brushes-1].face[faces-1].texture.texU.y;
world.brush[brushes-1].face[faces-1].texture.texV.y = -world.brush[brushes-1].face[faces-1].texture.texV.y;
}
}
world.cntBrushes = brushes;
fclose(file);
return 0;
}