History

Partial progress on new voxel model.

Philip Rosedale committed 13 years ago

Commit bd457401 parent b05909c6 files · +95 −101Browse files

Showing the changes to interface/src/VoxelSystem.cpp (1 of 6 files). Show all

Unified · Split

interface/src/VoxelSystem.cpp+68−0
@@ -0,0 +1,68 @@
1//
2// Cube.cpp
3// interface
4//
5// Created by Philip on 12/31/12.
6// Copyright (c) 2012 High Fidelity, Inc. All rights reserved.
7//
8
9#include "VoxelSystem.h"
10
11void VoxelSystem::init() {
12 root = new Voxel;
13}
14
15//
16// Recursively initialize the voxel tree
17//
18int VoxelSystem::initVoxels(Voxel * voxel, float scale) {
19 float childColor[3], averageColor[3];
20 int averageCount = 0;
21 int newVoxels = 0;
22 if (voxel == NULL) voxel = root;
23 averageColor[0] = averageColor[1] = averageColor[2] = 0.0;
24 for (unsigned char i = 0; i < NUM_CHILDREN; i++) {
25 if ((scale > 0.01) && (randFloat() < 0.5)) {
26 voxel->children[i] = new Voxel;
27 newVoxels += initVoxels(voxel->children[i], scale/2.0);
28 for (int j = 0; j < 3; j++) averageColor[j] += childColor[j];
29 averageCount++;
30 }
31 else {
32 voxel->children[i] = NULL;
33 }
34 }
35 if (averageCount == 0) {
36 // This is a leaf, so just pick a random color
37 voxel->color.x = voxel->color.y = voxel->color.z = randFloat();
38 } else {
39 voxel->color.x = averageColor[0]/averageCount;
40 voxel->color.y = averageColor[1]/averageCount;
41 voxel->color.z = averageColor[2]/averageCount;
42 }
43 newVoxels++;
44 return newVoxels;
45}
46
47void VoxelSystem::render(Voxel * voxel, float scale) {
48 if (voxel == NULL) voxel = root;
49 unsigned char i;
50 for (i = 0; i < NUM_CHILDREN; i++) {
51 if (voxel->children[i] != NULL) {
52 glTranslatef(scale/2.0*((i&4)>>2), scale/2.0*((i&2)>>1), scale/2.0*(i&1));
53 render(voxel->children[i], scale/2.0);
54 glTranslatef(-scale/2.0*((i&4)>>2), -scale/2.0*((i&2)>>1), -scale/2.0*(i&1));
55 }
56 }
57 glColor4f(voxel->color.x, voxel->color.y, voxel->color.z, 0.5);
58 glutSolidCube(scale);
59}
60
61void VoxelSystem::simulate(float deltaTime) {
62
63}
64
65
66
67
68