mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 11:17:34 +02:00
Partial progress on new voxel model.
This commit is contained in:
parent
b05909cf00
commit
bd45740dc6
6 changed files with 97 additions and 103 deletions
|
@ -1,80 +0,0 @@
|
||||||
//
|
|
||||||
// Cube.cpp
|
|
||||||
// interface
|
|
||||||
//
|
|
||||||
// Created by Philip on 12/31/12.
|
|
||||||
// Copyright (c) 2012 High Fidelity, Inc. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "Cube.h"
|
|
||||||
|
|
||||||
#define MAX_CUBES 250000
|
|
||||||
#define SMALLEST_CUBE 0.2
|
|
||||||
|
|
||||||
float cubes_position[MAX_CUBES*3];
|
|
||||||
float cubes_scale[MAX_CUBES];
|
|
||||||
float cubes_color[MAX_CUBES*3];
|
|
||||||
int cube_count = 0;
|
|
||||||
|
|
||||||
void makeCubes2D(float location[3], float scale, int * index,
|
|
||||||
float * cubes_position, float * cubes_scale, float * cubes_color) {
|
|
||||||
int i;
|
|
||||||
float spot[3];
|
|
||||||
float distance = powf(location[0]*location[0] + location[2]*location[2], 0.5);
|
|
||||||
|
|
||||||
if (*index >= MAX_CUBES) return;
|
|
||||||
if ((scale <= SMALLEST_CUBE) || (scale/distance < 0.025) || ((scale < 0.1) && (randFloat()<0.01))) {
|
|
||||||
// Make a cube
|
|
||||||
for (i = 0; i < 3; i++) cubes_position[*index*3 + i] = location[i]+scale/2.0;
|
|
||||||
//glm::vec2 noisepoint(location[0], location[2]);
|
|
||||||
//float color = glm::noise(noisepoint);
|
|
||||||
float color = 0.3 + randFloat()*0.7;
|
|
||||||
cubes_scale[*index] = scale;
|
|
||||||
cubes_color[*index*3] = color;
|
|
||||||
cubes_color[*index*3 + 1] = color;
|
|
||||||
cubes_color[*index*3 + 2] = color;
|
|
||||||
*index += 1;
|
|
||||||
} else {
|
|
||||||
for (i = 0; i < 4; i++) {
|
|
||||||
spot[0] = location[0] + (i%2)*scale/2.0;
|
|
||||||
spot[2] = location[2] + ((i/2)%2)*scale/2.0;
|
|
||||||
spot[1] = sinf(location[0])*0.15 + cosf(location[2]/0.2)*0.10 + randFloat()*0.005;
|
|
||||||
makeCubes2D(spot, scale/2.0, index, cubes_position, cubes_scale, cubes_color);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
VoxelSystem::VoxelSystem(int num,
|
|
||||||
glm::vec3 box) {
|
|
||||||
|
|
||||||
float location[] = {0,0,0};
|
|
||||||
float scale = 10.0;
|
|
||||||
int j = 0;
|
|
||||||
int index = 0;
|
|
||||||
if (num > 0)
|
|
||||||
makeCubes2D(location, scale, &index, cubes_position, cubes_scale, cubes_color);
|
|
||||||
std::cout << "Run " << j << " Made " << index << " cubes\n";
|
|
||||||
cube_count = index;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void VoxelSystem::render() {
|
|
||||||
int i = 0;
|
|
||||||
while (i < cube_count) {
|
|
||||||
glPushMatrix();
|
|
||||||
glTranslatef(cubes_position[i*3], cubes_position[i*3+1], cubes_position[i*3+2]);
|
|
||||||
glColor3fv(&cubes_color[i*3]);
|
|
||||||
glutSolidCube(cubes_scale[i]);
|
|
||||||
glPopMatrix();
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void VoxelSystem::simulate(float deltaTime) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -216,7 +216,7 @@ void Head::render(int faceToFace, float * myLocation)
|
||||||
//std::cout << distanceToCamera << "\n";
|
//std::cout << distanceToCamera << "\n";
|
||||||
|
|
||||||
// Don't render a head if it is really close to your location, because that is your own head!
|
// Don't render a head if it is really close to your location, because that is your own head!
|
||||||
if ((distanceToCamera > 0.1) || faceToFace) {
|
if ((distanceToCamera > 1.0) || faceToFace) {
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
|
|
||||||
|
|
|
@ -203,7 +203,7 @@ void SerialInterface::readData() {
|
||||||
serial_buffer_pos = 0;
|
serial_buffer_pos = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
if (initialSamples == totalSamples) {
|
if (initialSamples == totalSamples) {
|
||||||
noReadCount++;
|
noReadCount++;
|
||||||
std::cout << "#" << noReadCount << " blank read from serial.\n";
|
std::cout << "#" << noReadCount << " blank read from serial.\n";
|
||||||
|
@ -212,6 +212,7 @@ void SerialInterface::readData() {
|
||||||
resetSerial();
|
resetSerial();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void SerialInterface::resetSerial() {
|
void SerialInterface::resetSerial() {
|
||||||
|
|
68
interface/src/VoxelSystem.cpp
Normal file
68
interface/src/VoxelSystem.cpp
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
//
|
||||||
|
// Cube.cpp
|
||||||
|
// interface
|
||||||
|
//
|
||||||
|
// Created by Philip on 12/31/12.
|
||||||
|
// Copyright (c) 2012 High Fidelity, Inc. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "VoxelSystem.h"
|
||||||
|
|
||||||
|
void VoxelSystem::init() {
|
||||||
|
root = new Voxel;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Recursively initialize the voxel tree
|
||||||
|
//
|
||||||
|
int VoxelSystem::initVoxels(Voxel * voxel, float scale) {
|
||||||
|
float childColor[3], averageColor[3];
|
||||||
|
int averageCount = 0;
|
||||||
|
int newVoxels = 0;
|
||||||
|
if (voxel == NULL) voxel = root;
|
||||||
|
averageColor[0] = averageColor[1] = averageColor[2] = 0.0;
|
||||||
|
for (unsigned char i = 0; i < NUM_CHILDREN; i++) {
|
||||||
|
if ((scale > 0.01) && (randFloat() < 0.5)) {
|
||||||
|
voxel->children[i] = new Voxel;
|
||||||
|
newVoxels += initVoxels(voxel->children[i], scale/2.0);
|
||||||
|
for (int j = 0; j < 3; j++) averageColor[j] += childColor[j];
|
||||||
|
averageCount++;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
voxel->children[i] = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (averageCount == 0) {
|
||||||
|
// This is a leaf, so just pick a random color
|
||||||
|
voxel->color.x = voxel->color.y = voxel->color.z = randFloat();
|
||||||
|
} else {
|
||||||
|
voxel->color.x = averageColor[0]/averageCount;
|
||||||
|
voxel->color.y = averageColor[1]/averageCount;
|
||||||
|
voxel->color.z = averageColor[2]/averageCount;
|
||||||
|
}
|
||||||
|
newVoxels++;
|
||||||
|
return newVoxels;
|
||||||
|
}
|
||||||
|
|
||||||
|
void VoxelSystem::render(Voxel * voxel, float scale) {
|
||||||
|
if (voxel == NULL) voxel = root;
|
||||||
|
unsigned char i;
|
||||||
|
for (i = 0; i < NUM_CHILDREN; i++) {
|
||||||
|
if (voxel->children[i] != NULL) {
|
||||||
|
glTranslatef(scale/2.0*((i&4)>>2), scale/2.0*((i&2)>>1), scale/2.0*(i&1));
|
||||||
|
render(voxel->children[i], scale/2.0);
|
||||||
|
glTranslatef(-scale/2.0*((i&4)>>2), -scale/2.0*((i&2)>>1), -scale/2.0*(i&1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
glColor4f(voxel->color.x, voxel->color.y, voxel->color.z, 0.5);
|
||||||
|
glutSolidCube(scale);
|
||||||
|
}
|
||||||
|
|
||||||
|
void VoxelSystem::simulate(float deltaTime) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -15,19 +15,20 @@
|
||||||
#include "InterfaceConfig.h"
|
#include "InterfaceConfig.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
class VoxelSystem {
|
const int NUM_CHILDREN = 8;
|
||||||
public:
|
|
||||||
VoxelSystem(int num,
|
struct Voxel {
|
||||||
glm::vec3 box);
|
glm::vec3 color;
|
||||||
void simulate(float deltaTime);
|
Voxel * children[NUM_CHILDREN];
|
||||||
void render();
|
|
||||||
private:
|
|
||||||
struct Voxel {
|
|
||||||
glm::vec3 color;
|
|
||||||
bool hasChildren;
|
|
||||||
Voxel * children;
|
|
||||||
} *voxels;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class VoxelSystem {
|
||||||
|
public:
|
||||||
|
void simulate(float deltaTime);
|
||||||
|
void render(Voxel * voxel, float scale);
|
||||||
|
void init();
|
||||||
|
int initVoxels(Voxel * root, float scale);
|
||||||
|
Voxel * root;
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -42,7 +42,7 @@
|
||||||
#include "Texture.h"
|
#include "Texture.h"
|
||||||
#include "Cloud.h"
|
#include "Cloud.h"
|
||||||
#include "Agent.h"
|
#include "Agent.h"
|
||||||
#include "Cube.h"
|
#include "VoxelSystem.h"
|
||||||
#include "Lattice.h"
|
#include "Lattice.h"
|
||||||
#include "Finger.h"
|
#include "Finger.h"
|
||||||
#include "Oscilloscope.h"
|
#include "Oscilloscope.h"
|
||||||
|
@ -104,7 +104,7 @@ Cloud cloud(0, // Particles
|
||||||
false // Wrap
|
false // Wrap
|
||||||
);
|
);
|
||||||
|
|
||||||
VoxelSystem voxels(1000, box);
|
VoxelSystem voxels;
|
||||||
|
|
||||||
Lattice lattice(160,100);
|
Lattice lattice(160,100);
|
||||||
Finger myFinger(WIDTH, HEIGHT);
|
Finger myFinger(WIDTH, HEIGHT);
|
||||||
|
@ -314,6 +314,10 @@ void initDisplay(void)
|
||||||
|
|
||||||
void init(void)
|
void init(void)
|
||||||
{
|
{
|
||||||
|
voxels.init();
|
||||||
|
int voxelsMade = voxels.initVoxels(NULL, 1.0);
|
||||||
|
std::cout << voxelsMade << " voxels made. \n";
|
||||||
|
|
||||||
myHead.setRenderYaw(start_yaw);
|
myHead.setRenderYaw(start_yaw);
|
||||||
|
|
||||||
head_mouse_x = WIDTH/2;
|
head_mouse_x = WIDTH/2;
|
||||||
|
@ -401,7 +405,7 @@ void update_pos(float frametime)
|
||||||
if (powf(measured_yaw_rate*measured_yaw_rate +
|
if (powf(measured_yaw_rate*measured_yaw_rate +
|
||||||
measured_pitch_rate*measured_pitch_rate, 0.5) > MIN_MOUSE_RATE)
|
measured_pitch_rate*measured_pitch_rate, 0.5) > MIN_MOUSE_RATE)
|
||||||
{
|
{
|
||||||
head_mouse_x -= measured_yaw_rate*MOUSE_SENSITIVITY;
|
head_mouse_x += measured_yaw_rate*MOUSE_SENSITIVITY;
|
||||||
head_mouse_y += measured_pitch_rate*MOUSE_SENSITIVITY*(float)HEIGHT/(float)WIDTH;
|
head_mouse_y += measured_pitch_rate*MOUSE_SENSITIVITY*(float)HEIGHT/(float)WIDTH;
|
||||||
}
|
}
|
||||||
head_mouse_x = max(head_mouse_x, 0);
|
head_mouse_x = max(head_mouse_x, 0);
|
||||||
|
@ -424,18 +428,18 @@ void update_pos(float frametime)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Update render direction (pitch/yaw) based on measured gyro rates
|
// Update render direction (pitch/yaw) based on measured gyro rates
|
||||||
const int MIN_YAW_RATE = 3000;
|
const int MIN_YAW_RATE = 100;
|
||||||
const float YAW_SENSITIVITY = 0.03;
|
const float YAW_SENSITIVITY = 0.08;
|
||||||
const int MIN_PITCH_RATE = 3000;
|
const int MIN_PITCH_RATE = 100;
|
||||||
|
|
||||||
const float PITCH_SENSITIVITY = 0.04;
|
const float PITCH_SENSITIVITY = 0.04;
|
||||||
|
|
||||||
if (fabs(measured_yaw_rate) > MIN_YAW_RATE)
|
if (fabs(measured_yaw_rate) > MIN_YAW_RATE)
|
||||||
{
|
{
|
||||||
if (measured_yaw_rate > 0)
|
if (measured_yaw_rate > 0)
|
||||||
render_yaw_rate -= (measured_yaw_rate - MIN_YAW_RATE) * YAW_SENSITIVITY * frametime;
|
render_yaw_rate += (measured_yaw_rate - MIN_YAW_RATE) * YAW_SENSITIVITY * frametime;
|
||||||
else
|
else
|
||||||
render_yaw_rate -= (measured_yaw_rate + MIN_YAW_RATE) * YAW_SENSITIVITY * frametime;
|
render_yaw_rate += (measured_yaw_rate + MIN_YAW_RATE) * YAW_SENSITIVITY * frametime;
|
||||||
}
|
}
|
||||||
if (fabs(measured_pitch_rate) > MIN_PITCH_RATE)
|
if (fabs(measured_pitch_rate) > MIN_PITCH_RATE)
|
||||||
{
|
{
|
||||||
|
@ -561,7 +565,7 @@ void display(void)
|
||||||
if (!display_head) cloud.render();
|
if (!display_head) cloud.render();
|
||||||
|
|
||||||
// Draw voxels
|
// Draw voxels
|
||||||
voxels.render();
|
//voxels.render(NULL, 10.0);
|
||||||
|
|
||||||
// Draw field vectors
|
// Draw field vectors
|
||||||
if (display_field) field.render();
|
if (display_field) field.render();
|
||||||
|
|
Loading…
Reference in a new issue