Recovered from microbel
This commit is contained in:
100
common/lib/srvcli/bsdtree.C
Normal file
100
common/lib/srvcli/bsdtree.C
Normal file
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* 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 <iostream.h>
|
||||
#include <stdio.h>
|
||||
#include "bsdtree.H"
|
||||
|
||||
CBSDTreeNode::CBSDTreeNode(double a, double b, double c, double d){
|
||||
this->a = a;
|
||||
this->b = b;
|
||||
this->c = c;
|
||||
this->d = d;
|
||||
inNode = NULL;
|
||||
outNode = NULL;
|
||||
}
|
||||
|
||||
int CBSDTreeNode::inside(double x, double y, double z){
|
||||
if ( (a*x + b*y + c*z + d ) >= 0.0){
|
||||
if (inNode != NULL) return inNode->inside(x,y,z);
|
||||
else return TRUE;
|
||||
} else {
|
||||
if (outNode != NULL) return outNode->inside(x,y,z);
|
||||
else return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
CBSDTree::CBSDTree(){
|
||||
BSDTree = NULL;
|
||||
}
|
||||
|
||||
int CBSDTree::load(char * fileName){
|
||||
FILE * bsdFile;
|
||||
|
||||
if ((bsdFile = fopen(fileName,"r")) == NULL){
|
||||
cdebug << "Failed to open bsdFile " << fileName << "\n";
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BSDTree = loadNode(bsdFile);
|
||||
|
||||
fclose(bsdFile);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
CBSDTreeNode * CBSDTree::loadNode(FILE * bsdFile){
|
||||
|
||||
CBSDTreeNode * node;
|
||||
char nodeType[256];
|
||||
double a,b,c,d;
|
||||
|
||||
if (fscanf(bsdFile,"%s",nodeType) == 1){
|
||||
|
||||
if (strcmp(nodeType,"NODE") == 0){
|
||||
if (fscanf(bsdFile,"%lf %lf %lf %lf",&a,&b,&c,&d) == 4){
|
||||
node = new CBSDTreeNode(a,b,c,d);
|
||||
} else {
|
||||
cdebug << "File format error in BSDTree file:"
|
||||
<< " Error in parameters to NODE\n";
|
||||
return NULL;
|
||||
}
|
||||
} else if (strcmp(nodeType,"IN") == 0){
|
||||
return NULL;
|
||||
} else if (strcmp(nodeType,"OUT") == 0){
|
||||
return NULL;
|
||||
} else {
|
||||
cdebug << "File format error in BSDTree file: Unknown identifyer\n";
|
||||
return FALSE;
|
||||
}
|
||||
node->setInChild( loadNode(bsdFile) );
|
||||
node->setOutChild( loadNode(bsdFile) );
|
||||
return node;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int CBSDTree::inside(double x, double y, double z){
|
||||
if (BSDTree != NULL) return BSDTree->inside(x,y,z);
|
||||
else return FALSE;
|
||||
}
|
||||
|
||||
int CBSDTree::inside(const CPosition & position){
|
||||
return inside(position.getX(),position.getY(),position.getZ());
|
||||
}
|
||||
Reference in New Issue
Block a user