routines for converting to/from variable length octal codes

This commit is contained in:
Philip Rosedale 2013-02-05 15:13:14 -08:00
parent 367fcaf840
commit 2dda03f7d9
2 changed files with 31 additions and 2 deletions

View file

@ -8,12 +8,14 @@
// Various subroutines for converting between X,Y,Z coords and octree coordinates.
//
#include "util.h"
#include "octal.h"
const int X = 0;
const int Y = 1;
const int Z = 2;
#include "util.h"
#include "octal.h"
domainNode rootNode;
// Given a position vector between zero and one (but less than one), and a voxel scale 1/2^scale,
// returns the smallest voxel at that scale which encloses the given point.
@ -24,3 +26,21 @@ void getVoxel(float * pos, int scale, float * vpos) {
vpos[Z] = floor(pos[Z]*vscale)/vscale;
}
domainNode* createNode(int lengthInBits, char * octalData,
char * hostname, char * nickname, int domain_id) {
domainNode * currentNode = &rootNode;
for (int i = 0; i < lengthInBits; i+=3) {
char octet = 0;
if (i%8 < 6) octet = octalData[i/8] << (i%8);
else {
octet = octalData[i/8] << (i%8) && ((octalData[i/8 + 1] >> (i%8)) << (8 - i%8));
}
if (currentNode->child[octet] == NULL) currentNode->child[octet] = new domainNode;
currentNode = currentNode->child[octet];
}
// Copy in the new node info...
strcpy(currentNode->hostname, hostname);
strcpy(currentNode->nickname, nickname);
currentNode->domain_id = domain_id;
return currentNode;
}

View file

@ -11,4 +11,13 @@
#include <iostream>
struct domainNode {
domainNode * child[8];
char * hostname;
char * nickname;
int domain_id;
};
#endif /* defined(__interface__octal__) */