Files
2025-03-05 08:37:43 +01:00

123 lines
3.5 KiB
C

/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "pvvmud.H"
#include <stdio.h>
#include "geometry.H"
#include "bogfile.H"
#include "exception.H"
int CGeometry::writeBOG( FILE * bog ){
CGeometry * geo;
CPolygon * poly;
int numVertices,numNormals,numTexCoords,numPolygons,ii,jj,nn;
int type,materialId,index,subid,numSubobj;
double x,y,z,u,v;
numSubobj = getNumSubobjects();
fprintf(bog,"BOG 1 %i\n",numSubobj);
// Requrcive algo. done iterative
geo = this;
for (nn = 0; nn < numSubobj; nn++){
subid = geo->getSubId();
numVertices = geo->getNumVertices();
numNormals = geo->getNumNormals();
numTexCoords = geo->getNumTexCoords();
numPolygons = geo->getNumPolygons();
fprintf(bog,"%i %i %i %i %i\n",subid,numVertices,numNormals,
numTexCoords,numPolygons);
for (ii = 0; ii < numVertices; ii ++){
geo->getVertex(ii,&x,&y,&z);
fprintf(bog,"%f %f %f\n",x,y,z);
}
for (ii = 0; ii < numNormals; ii ++){
geo->getNormal(ii,&x,&y,&z);
fprintf(bog,"%f %f %f\n",x,y,z);
}
for (ii = 0; ii < numTexCoords; ii ++){
geo->getTexCoord(ii,&u,&v);
fprintf(bog,"%f %f\n",u,v);
}
for (ii = 0; ii < numPolygons; ii ++){
poly = geo->getPolygon(ii);
poly->get(&type,&materialId,&numVertices,&numNormals,&numTexCoords);
switch (type){
case POLYGON_POLYGON: type = PT_Polygon; break;
case POLYGON_TRIANGLES: type = PT_Triangles; break;
case POLYGON_QUADS: type = PT_Quads; break;
case POLYGON_QUAD_STRIP: type = PT_Quad_strip; break;
case POLYGON_TRIANGLE_STRIP: type = PT_Triangle_strip; break;
case POLYGON_TRIANGLE_FAN: type = PT_Triangle_fan; break;
}
fprintf(bog,"%i %i %i %i %i\n",
type, materialId, numVertices, numNormals, numTexCoords );
for (jj = 0; jj < numVertices; jj++){
index = poly->getVertexIndex(jj);
if (jj != (numVertices-1))
fprintf(bog,"%i ",index);
else
fprintf(bog,"%i\n",index);
}
for (jj = 0; jj < numNormals; jj++){
index = poly->getNormalIndex(jj);
if (jj != (numNormals-1))
fprintf(bog,"%i ",index);
else
fprintf(bog,"%i\n",index);
}
for (jj = 0; jj < numTexCoords; jj++){
index = poly->getTexCoordIndex(jj);
if (jj != (numTexCoords-1))
fprintf(bog,"%i ",index);
else
fprintf(bog,"%i\n",index);
}
}
geo = geo->getNext();
}
return TRUE;
}
void CGeometry::save(char * name){
FILE * bog;
int res;
bog = fopen(name,"w");
if (bog == NULL){
fprintf(stderr,"Error: Failed to open file %s\n",name);
throw new CException();
}
writeBOG(bog);
fclose(bog);
}