Recovered from microbel
This commit is contained in:
160
common/lib/geometry/readbog.C
Normal file
160
common/lib/geometry/readbog.C
Normal file
@@ -0,0 +1,160 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
/******************************************************************************
|
||||
*
|
||||
* Utilities for reading BOG file format
|
||||
*
|
||||
* Standard: Useing standard suggested in bogfileformat.html with
|
||||
* rcs version 1.2 from the pvvmud web pages
|
||||
*
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#include "pvvmud.H"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <iostream.h>
|
||||
|
||||
#include "geometry.H"
|
||||
#include "bogfile.H"
|
||||
#include "exception.H"
|
||||
|
||||
//void CGeometry::load(int objId, char * name) {
|
||||
// setId(objId);
|
||||
// load(name);
|
||||
//}
|
||||
|
||||
void CGeometry::load(char * name) {
|
||||
FILE * bog;
|
||||
bog = fopen(name,"r");
|
||||
if (bog == NULL){
|
||||
cdebug << "Error: Failed to open BOG file " << name << "\n";
|
||||
throw new CException();
|
||||
}
|
||||
readBOG(bog);
|
||||
fclose(bog);
|
||||
}
|
||||
|
||||
|
||||
int CGeometry::readBOGCore(FILE * bog, int numV, int numN,
|
||||
int numTC, int numP){
|
||||
int ii,jj;
|
||||
int type,gltype,materialId,index;
|
||||
double d1,d2,d3;
|
||||
CPolygon * poly;
|
||||
|
||||
for (ii = 0; ii < numV; ii++){
|
||||
fscanf(bog,"%lf %lf %lf",&d1,&d2,&d3);
|
||||
addVertex(d1,d2,d3);
|
||||
}
|
||||
|
||||
for (ii = 0; ii < numN; ii++){
|
||||
fscanf(bog,"%lf %lf %lf",&d1,&d2,&d3);
|
||||
addNormal(d1,d2,d3);
|
||||
}
|
||||
|
||||
for (ii = 0; ii < numTC; ii++){
|
||||
fscanf(bog,"%lf %lf",&d1,&d2);
|
||||
addTexCoord(d1,d2);
|
||||
}
|
||||
|
||||
for (ii = 0; ii < numP; ii++){
|
||||
fscanf(bog,"%i %i %i %i %i",&type,&materialId,&numV,&numN,&numTC);
|
||||
|
||||
switch (type){
|
||||
case PT_Polygon: gltype = POLYGON_POLYGON; break;
|
||||
case PT_Triangles: gltype = POLYGON_TRIANGLES; break;
|
||||
case PT_Quads: gltype = POLYGON_QUADS; break;
|
||||
case PT_Quad_strip: gltype = POLYGON_QUAD_STRIP; break;
|
||||
case PT_Triangle_strip: gltype = POLYGON_TRIANGLE_STRIP; break;
|
||||
case PT_Triangle_fan: gltype = POLYGON_TRIANGLE_FAN; break;
|
||||
}
|
||||
|
||||
poly = new CPolygon(gltype,materialId,numV,numN,numTC);
|
||||
|
||||
for (jj = 0; jj < numV; jj++){
|
||||
fscanf(bog,"%i",&index);
|
||||
poly->addVertexIndex(index);
|
||||
}
|
||||
|
||||
for (jj = 0; jj < numN; jj++){
|
||||
fscanf(bog,"%i",&index);
|
||||
poly->addNormalIndex(index);
|
||||
}
|
||||
|
||||
for (jj = 0; jj < numTC; jj++){
|
||||
fscanf(bog,"%i",&index);
|
||||
poly->addTexCoordIndex(index);
|
||||
}
|
||||
|
||||
addPolygon(poly);
|
||||
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
void CGeometry::readBOG(FILE * bog ){
|
||||
|
||||
CGeometry *geo=NULL,*lastgeo=NULL;
|
||||
int version,numSub,subid;
|
||||
int numV,numN,numTC,numP;
|
||||
int ii;
|
||||
char name[5];
|
||||
|
||||
// Read header : BOG <version> <numSubObjects>
|
||||
|
||||
fscanf(bog,"%s",name);
|
||||
|
||||
if (strcmp(name,"BOG") != 0){
|
||||
throw new CException();
|
||||
} else {
|
||||
fscanf(bog,"%i %i",&version,&numSub);
|
||||
if (version != 1) throw new CException();
|
||||
}
|
||||
|
||||
geo = this;
|
||||
|
||||
for (ii = 0; ii < numSub; ii++){
|
||||
|
||||
fscanf(bog,"%i",&subid);
|
||||
|
||||
fscanf(bog,"%i %i %i %i",&numV,&numN,&numTC,&numP);
|
||||
|
||||
if (ii != 0){
|
||||
geo = newGeometry(getId());
|
||||
}
|
||||
|
||||
geo->setSize(numV,numN,numTC,numP);
|
||||
|
||||
if (lastgeo != NULL){
|
||||
lastgeo->setNext(geo);
|
||||
}
|
||||
|
||||
geo->setSubId(subid);
|
||||
geo->readBOGCore(bog,numV,numN,numTC,numP);
|
||||
lastgeo = geo;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user