3
0
Fork 0
mirror of https://github.com/lubosz/overte.git synced 2025-04-27 11:35:26 +02:00

make Field a proper class to avoid duplicate symbols

This commit is contained in:
Stephen Birarda 2013-02-08 13:11:56 -08:00
parent d75541bb69
commit cedb212597
6 changed files with 47 additions and 38 deletions

View file

@ -21,6 +21,7 @@ Cloud::Cloud(int num,
count = num;
wrapBounds = wrap;
particles = new Particle[count];
field = new Field();
for (i = 0; i < count; i++) {
float x = randFloat()*box.x;
@ -87,7 +88,7 @@ void Cloud::simulate (float deltaTime) {
// Interact with Field
const float FIELD_COUPLE = 0.005; //0.0000001;
field_interact(deltaTime, &particles[i].position, &particles[i].velocity, &particles[i].color, FIELD_COUPLE);
field->interact(deltaTime, &particles[i].position, &particles[i].velocity, &particles[i].color, FIELD_COUPLE);
// Update color to velocity
particles[i].color = (glm::normalize(particles[i].velocity)*0.5f);

View file

@ -24,9 +24,11 @@ private:
struct Particle {
glm::vec3 position, velocity, color;
} *particles;
unsigned int count;
glm::vec3 bounds;
bool wrapBounds;
Field *field;
};
#endif

View file

@ -7,7 +7,7 @@
//
#include "Field.h"
#include <glm/glm.hpp>
#define FIELD_SCALE 0.00050
#define COLOR_DRIFT_RATE 0.001f // per-frame drift of particle color towards field element color
#define COLOR_MIN 0.2f // minimum R/G/B value at 0,0,0 - also needs setting in cloud.cpp
@ -16,7 +16,7 @@
// A vector-valued field over an array of elements arranged as a 3D lattice
int field_value(float *value, float *pos)
int Field::value(float *value, float *pos)
// sets the vector value (3 floats) to field value at location pos in space.
// returns zero if the location is outside world bounds
{
@ -33,7 +33,7 @@ int field_value(float *value, float *pos)
else return 0;
}
void field_init()
Field::Field()
// Initializes the field to some random values
{
int i;
@ -60,7 +60,7 @@ void field_init()
}
}
void field_add(float* add, float *pos)
void Field::add(float* add, float *pos)
// At location loc, add vector add to the field values
{
int index = (int)(pos[0]/WORLD_SIZE*10.0) +
@ -74,7 +74,7 @@ void field_add(float* add, float *pos)
}
}
void field_interact(float dt, glm::vec3 * pos, glm::vec3 * vel, glm::vec3 * color, float coupling) {
void Field::interact(float dt, glm::vec3 * pos, glm::vec3 * vel, glm::vec3 * color, float coupling) {
int index = (int)(pos->x/WORLD_SIZE*10.0) +
(int)(pos->y/WORLD_SIZE*10.0)*10 +
@ -104,7 +104,7 @@ void field_interact(float dt, glm::vec3 * pos, glm::vec3 * vel, glm::vec3 * colo
}
}
void field_avg_neighbors(int index, glm::vec3 * result) {
void Field::avg_neighbors(int index, glm::vec3 * result) {
// Given index to field element i, return neighbor field values
glm::vec3 neighbors(0,0,0);
@ -129,14 +129,14 @@ void field_avg_neighbors(int index, glm::vec3 * result) {
}
void field_simulate(float dt) {
void Field::simulate(float dt) {
glm::vec3 neighbors, add, diff;
float size, distance;
int i, j;
for (i = 0; i < FIELD_ELEMENTS; i++)
{
if (0) { //(randFloat() > 0.01) {
field_avg_neighbors(i, &neighbors);
avg_neighbors(i, &neighbors);
size = powf(field[i].val.x*field[i].val.x +
field[i].val.y*field[i].val.y +
field[i].val.z*field[i].val.z, 0.5);
@ -174,7 +174,7 @@ void field_simulate(float dt) {
}
}
void field_render()
void Field::render()
// Render the field lines
{
int i;

View file

@ -9,32 +9,38 @@
#ifndef __interface__Field__
#define __interface__Field__
#include "InterfaceConfig.h"
#include <iostream>
#include <glm/glm.hpp>
#include "InterfaceConfig.h"
#include "world.h"
#include "Util.h"
#include <glm/glm.hpp>
// Field is a lattice of vectors uniformly distributed FIELD_ELEMENTS^(1/3) on side
const int FIELD_ELEMENTS = 1000;
struct FieldElement {
glm::vec3 val;
glm::vec3 center;
glm::vec3 fld;
float scalar;
} field[FIELD_ELEMENTS];
class Field {
public:
struct FieldElement {
glm::vec3 val;
glm::vec3 center;
glm::vec3 fld;
float scalar;
} field[FIELD_ELEMENTS];
// Pre-calculated RGB values for each field element
struct FieldColor {
glm::vec3 rgb;
} fieldcolors[FIELD_ELEMENTS];
Field();
int value(float *ret, float *pos);
void render();
void add(float* add, float *loc);
void interact(float dt, glm::vec3 * pos, glm::vec3 * vel, glm::vec3 * color, float coupling);
void simulate(float dt);
glm::vec3 hsv2rgb(glm::vec3 in);
private:
void avg_neighbors(int index, glm::vec3 * result);
};
// Pre-calculated RGB values for each field element
struct FieldColor {
glm::vec3 rgb;
} fieldcolors[FIELD_ELEMENTS];
void field_init();
int field_value(float *ret, float *pos);
void field_render();
void field_add(float* add, float *loc);
void field_interact(float dt, glm::vec3 * pos, glm::vec3 * vel, glm::vec3 * color, float coupling);
void field_simulate(float dt);
glm::vec3 hsv2rgb(glm::vec3 in);
#endif

View file

@ -8,10 +8,9 @@
#include "InterfaceConfig.h"
#include <iostream>
#include "world.h"
#include <glm/glm.hpp>
#include "util.h"
#include "world.h"
#include "Util.h"
//
// Standard Deviation Object

View file

@ -105,6 +105,7 @@ VoxelSystem voxels(0, box);
Lattice lattice(160,100);
Finger myFinger(WIDTH, HEIGHT);
Field field;
#define RENDER_FRAME_MSECS 8
#define SLEEP 0
@ -295,8 +296,8 @@ void init(void)
head_lean_x = WIDTH/2;
head_lean_y = HEIGHT/2;
// Initialize Field values
field_init();
// Initialize Field values
field = Field();
printf( "Field Initialized.\n" );
if (noise_on)
@ -555,7 +556,7 @@ void display(void)
voxels.render();
// Draw field vectors
if (display_field) field_render();
if (display_field) field.render();
// Render my own head
if (display_head) {
@ -739,7 +740,7 @@ void key(unsigned char k, int x, int y)
// Add to field vector
float pos[] = {5,5,5};
float add[] = {0.001, 0.001, 0.001};
field_add(add, pos);
field.add(add, pos);
}
if (k == '1')
{
@ -800,7 +801,7 @@ void idle(void)
// Simulation
update_pos(1.f/FPS);
if (simulate_on) {
field_simulate(1.f/FPS);
field.simulate(1.f/FPS);
myHead.simulate(1.f/FPS);
myHand.simulate(1.f/FPS);
balls.simulate(1.f/FPS);