mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-29 18:22:55 +02:00
remove deadhead (of self) at origin. First commit of voxels with LOD, recursive test pattern.
This commit is contained in:
parent
fd151fb7bc
commit
15fd9638d6
4 changed files with 108 additions and 39 deletions
|
@ -79,9 +79,12 @@ void render_agents(int renderSelf, float * myLocation) {
|
||||||
glm::vec3 pos = agents[i].head.getPos();
|
glm::vec3 pos = agents[i].head.getPos();
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
if (!agents[i].isSelf || renderSelf) {
|
if (!agents[i].isSelf || renderSelf) {
|
||||||
|
if (!((pos.x == 0.0) && (pos.y == 0.0) && (pos.z == 0.0))) {
|
||||||
|
// ZERO ZERO ZERO means we are not getting data for this head, so don't render it
|
||||||
glTranslatef(-pos.x, -pos.y, -pos.z);
|
glTranslatef(-pos.x, -pos.y, -pos.z);
|
||||||
agents[i].head.render(0, myLocation);
|
agents[i].head.render(0, myLocation);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,47 +15,91 @@ void VoxelSystem::init() {
|
||||||
//
|
//
|
||||||
// Recursively initialize the voxel tree
|
// Recursively initialize the voxel tree
|
||||||
//
|
//
|
||||||
int VoxelSystem::initVoxels(Voxel * voxel, float scale) {
|
int VoxelSystem::initVoxels(Voxel * voxel, float scale, glm::vec3 * position) {
|
||||||
float childColor[3], averageColor[3];
|
glm::vec3 averageColor(0,0,0);
|
||||||
int averageCount = 0;
|
int childrenCreated = 0;
|
||||||
int newVoxels = 0;
|
int newVoxels = 0;
|
||||||
if (voxel == NULL) voxel = root;
|
if (voxel == NULL) voxel = root;
|
||||||
averageColor[0] = averageColor[1] = averageColor[2] = 0.0;
|
averageColor[0] = averageColor[1] = averageColor[2] = 0.0;
|
||||||
|
//
|
||||||
|
// First, decide whether I should be a leaf node and set/return if so
|
||||||
|
//
|
||||||
|
if ((randFloat() < 0.1) && (scale < 1.0))
|
||||||
|
{
|
||||||
|
voxel->color.x = voxel->color.y = voxel->color.z = 0.5 + randFloat()*0.5;
|
||||||
|
for (unsigned char i = 0; i < NUM_CHILDREN; i++) voxel->children[i] = NULL;
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
// Decide whether to make kids, recurse into them
|
||||||
for (unsigned char i = 0; i < NUM_CHILDREN; i++) {
|
for (unsigned char i = 0; i < NUM_CHILDREN; i++) {
|
||||||
if ((scale > 0.01) && (randFloat() < 0.5)) {
|
if ((scale > 0.01) && (randFloat() > 0.6))
|
||||||
|
{
|
||||||
|
// Make a new child
|
||||||
voxel->children[i] = new Voxel;
|
voxel->children[i] = new Voxel;
|
||||||
newVoxels += initVoxels(voxel->children[i], scale/2.0);
|
newVoxels++;
|
||||||
for (int j = 0; j < 3; j++) averageColor[j] += childColor[j];
|
childrenCreated++;
|
||||||
averageCount++;
|
glm::vec3 shift(scale/4.0*((i&4)>>2), scale/4.0*((i&2)>>1), scale/4.0*(i&1));
|
||||||
}
|
*position += shift;
|
||||||
else {
|
newVoxels += initVoxels(voxel->children[i], scale/2.0, position);
|
||||||
|
*position -= shift;
|
||||||
|
averageColor += voxel->children[i]->color;
|
||||||
|
} else {
|
||||||
|
// No child made: Set pointer to null, nothing to see here.
|
||||||
voxel->children[i] = NULL;
|
voxel->children[i] = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (averageCount == 0) {
|
if (childrenCreated > 0) {
|
||||||
// This is a leaf, so just pick a random color
|
// If there were children created, set this voxels color to the average of it's children
|
||||||
voxel->color.x = voxel->color.y = voxel->color.z = randFloat();
|
averageColor *= 1.0/childrenCreated;
|
||||||
} else {
|
voxel->color = averageColor;
|
||||||
voxel->color.x = averageColor[0]/averageCount;
|
|
||||||
voxel->color.y = averageColor[1]/averageCount;
|
|
||||||
voxel->color.z = averageColor[2]/averageCount;
|
|
||||||
}
|
|
||||||
newVoxels++;
|
|
||||||
return newVoxels;
|
return newVoxels;
|
||||||
|
} else {
|
||||||
|
// Tested and didn't make any children, so i've still got to be a leaf
|
||||||
|
voxel->color.x = voxel->color.y = voxel->color.z = 0.5 + randFloat()*0.5;
|
||||||
|
for (unsigned char i = 0; i < NUM_CHILDREN; i++) voxel->children[i] = NULL;
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void VoxelSystem::render(Voxel * voxel, float scale) {
|
const float RENDER_DISCARD = 0.01;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Returns the total number of voxels actually rendered
|
||||||
|
//
|
||||||
|
int VoxelSystem::render(Voxel * voxel, float scale, glm::vec3 * distance) {
|
||||||
|
// If null passed in, start at root
|
||||||
if (voxel == NULL) voxel = root;
|
if (voxel == NULL) voxel = root;
|
||||||
unsigned char i;
|
unsigned char i;
|
||||||
|
bool renderedChildren = false;
|
||||||
|
int vRendered = 0;
|
||||||
|
// Recursively render children
|
||||||
for (i = 0; i < NUM_CHILDREN; i++) {
|
for (i = 0; i < NUM_CHILDREN; i++) {
|
||||||
if (voxel->children[i] != NULL) {
|
glm::vec3 shift(scale/2.0*((i&4)>>2)-scale/4.0,
|
||||||
glTranslatef(scale/2.0*((i&4)>>2), scale/2.0*((i&2)>>1), scale/2.0*(i&1));
|
scale/2.0*((i&2)>>1)-scale/4.0,
|
||||||
render(voxel->children[i], scale/2.0);
|
scale/2.0*(i&1)-scale/4.0);
|
||||||
glTranslatef(-scale/2.0*((i&4)>>2), -scale/2.0*((i&2)>>1), -scale/2.0*(i&1));
|
if ((voxel->children[i] != NULL) && (scale / glm::length(*distance) > RENDER_DISCARD)) {
|
||||||
|
glTranslatef(shift.x, shift.y, shift.z);
|
||||||
|
//std::cout << "x,y,z: " << shift.x << "," << shift.y << "," << shift.z << "\n";
|
||||||
|
*distance += shift;
|
||||||
|
vRendered += render(voxel->children[i], scale/2.0, distance);
|
||||||
|
*distance -= shift;
|
||||||
|
glTranslatef(-shift.x, -shift.y, -shift.z);
|
||||||
|
renderedChildren = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
glColor4f(voxel->color.x, voxel->color.y, voxel->color.z, 0.5);
|
// Render this voxel if the children were not rendered
|
||||||
|
if (!renderedChildren)
|
||||||
|
{
|
||||||
|
//glColor4f(1,1,1,1);
|
||||||
|
glColor4f(voxel->color.x, voxel->color.y, voxel->color.z, 1.0);
|
||||||
|
//float bright = 1.0 - glm::length(*distance)/20.0;
|
||||||
|
//glColor3f(bright,bright,bright);
|
||||||
glutSolidCube(scale);
|
glutSolidCube(scale);
|
||||||
|
vRendered++;
|
||||||
|
}
|
||||||
|
return vRendered;
|
||||||
}
|
}
|
||||||
|
|
||||||
void VoxelSystem::simulate(float deltaTime) {
|
void VoxelSystem::simulate(float deltaTime) {
|
||||||
|
|
|
@ -25,10 +25,14 @@ struct Voxel {
|
||||||
class VoxelSystem {
|
class VoxelSystem {
|
||||||
public:
|
public:
|
||||||
void simulate(float deltaTime);
|
void simulate(float deltaTime);
|
||||||
void render(Voxel * voxel, float scale);
|
int render(Voxel * voxel, float scale, glm::vec3 * distance);
|
||||||
void init();
|
void init();
|
||||||
int initVoxels(Voxel * root, float scale);
|
int initVoxels(Voxel * root, float scale, glm::vec3 * position);
|
||||||
|
void setVoxelsRendered(int v) {voxelsRendered = v;};
|
||||||
|
int getVoxelsRendered() {return voxelsRendered;};
|
||||||
Voxel * root;
|
Voxel * root;
|
||||||
|
private:
|
||||||
|
int voxelsRendered;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -228,7 +228,7 @@ void Timer(int extra)
|
||||||
//
|
//
|
||||||
char output[100];
|
char output[100];
|
||||||
sprintf(output, "%c %f,%f,%f,%s %hd", 'I', location[0], location[1], location[2], localAddressBuffer, AGENT_UDP_PORT);
|
sprintf(output, "%c %f,%f,%f,%s %hd", 'I', location[0], location[1], location[2], localAddressBuffer, AGENT_UDP_PORT);
|
||||||
std::cout << "sending " << output << " to domain server\n";
|
//std::cout << "sending " << output << " to domain server\n";
|
||||||
int packet_size = strlen(output);
|
int packet_size = strlen(output);
|
||||||
agentSocket.send(DOMAIN_IP, DOMAINSERVER_PORT, output, packet_size);
|
agentSocket.send(DOMAIN_IP, DOMAINSERVER_PORT, output, packet_size);
|
||||||
|
|
||||||
|
@ -280,10 +280,16 @@ void display_stats(void)
|
||||||
}
|
}
|
||||||
drawtext(10,50,0.10, 0, 1.0, 0, (char *)pingTimes.str().c_str());
|
drawtext(10,50,0.10, 0, 1.0, 0, (char *)pingTimes.str().c_str());
|
||||||
|
|
||||||
|
std::stringstream voxelStats;
|
||||||
|
voxelStats << "Voxels Rendered: " << voxels.getVoxelsRendered();
|
||||||
|
drawtext(10,70,0.10, 0, 1.0, 0, (char *)voxelStats.str().c_str());
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
std::stringstream angles;
|
std::stringstream angles;
|
||||||
angles << "render_yaw: " << myHead.getRenderYaw() << ", Yaw: " << myHead.getYaw();
|
angles << "render_yaw: " << myHead.getRenderYaw() << ", Yaw: " << myHead.getYaw();
|
||||||
drawtext(10,50,0.10, 0, 1.0, 0, (char *)angles.str().c_str());
|
drawtext(10,50,0.10, 0, 1.0, 0, (char *)angles.str().c_str());
|
||||||
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
char adc[200];
|
char adc[200];
|
||||||
|
@ -315,7 +321,8 @@ void initDisplay(void)
|
||||||
void init(void)
|
void init(void)
|
||||||
{
|
{
|
||||||
voxels.init();
|
voxels.init();
|
||||||
int voxelsMade = voxels.initVoxels(NULL, 1.0);
|
glm::vec3 position(0,0,0);
|
||||||
|
int voxelsMade = voxels.initVoxels(NULL, 10.0, &position);
|
||||||
std::cout << voxelsMade << " voxels made. \n";
|
std::cout << voxelsMade << " voxels made. \n";
|
||||||
|
|
||||||
myHead.setRenderYaw(start_yaw);
|
myHead.setRenderYaw(start_yaw);
|
||||||
|
@ -559,13 +566,24 @@ void display(void)
|
||||||
glRotatef(myHead.getRenderYaw(), 0, 1, 0);
|
glRotatef(myHead.getRenderYaw(), 0, 1, 0);
|
||||||
glTranslatef(location[0], location[1], location[2]);
|
glTranslatef(location[0], location[1], location[2]);
|
||||||
|
|
||||||
|
glColor3f(1,0,0);
|
||||||
|
glutSolidSphere(0.25, 15, 15);
|
||||||
|
|
||||||
// Draw cloud of dots
|
// Draw cloud of dots
|
||||||
glDisable( GL_POINT_SPRITE_ARB );
|
glDisable( GL_POINT_SPRITE_ARB );
|
||||||
glDisable( GL_TEXTURE_2D );
|
glDisable( GL_TEXTURE_2D );
|
||||||
if (!display_head) cloud.render();
|
if (!display_head) cloud.render();
|
||||||
|
|
||||||
// Draw voxels
|
// Draw voxels
|
||||||
//voxels.render(NULL, 10.0);
|
glPushMatrix();
|
||||||
|
glTranslatef(WORLD_SIZE/2.0, WORLD_SIZE/2.0, WORLD_SIZE/2.0);
|
||||||
|
glm::vec3 distance(5.0 + location[0], 5.0 + location[1], 5.0 + location[2]);
|
||||||
|
//std::cout << "length: " << glm::length(distance) << "\n";
|
||||||
|
int voxelsRendered = voxels.render(NULL, 10.0, &distance);
|
||||||
|
voxels.setVoxelsRendered(voxelsRendered);
|
||||||
|
//glColor4f(0,0,1,0.5);
|
||||||
|
//glutSolidCube(10.0);
|
||||||
|
glPopMatrix();
|
||||||
|
|
||||||
// Draw field vectors
|
// Draw field vectors
|
||||||
if (display_field) field.render();
|
if (display_field) field.render();
|
||||||
|
|
Loading…
Reference in a new issue