mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-03 23:33:10 +02:00
code review, added Doxygen style comments
This commit is contained in:
parent
27a892fa55
commit
632dd2fa7d
3 changed files with 19 additions and 28 deletions
|
@ -14,6 +14,7 @@
|
|||
|
||||
const int NUM_PARTICLES = 100000;
|
||||
const float FIELD_COUPLE = 0.001f;
|
||||
const bool RENDER_FIELD = false;
|
||||
|
||||
Cloud::Cloud() {
|
||||
// Create and initialize particles
|
||||
|
@ -34,7 +35,9 @@ Cloud::Cloud() {
|
|||
}
|
||||
|
||||
void Cloud::render() {
|
||||
//field->render();
|
||||
if (RENDER_FIELD) {
|
||||
_field->render();
|
||||
}
|
||||
|
||||
glPointSize(3.0f);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
|
|
|
@ -5,14 +5,11 @@
|
|||
// Created by Philip Rosedale on 8/23/12.
|
||||
// Copyright (c) 2012 High Fidelity, Inc. All rights reserved.
|
||||
//
|
||||
// A vector-valued field over an array of elements arranged as a 3D lattice
|
||||
|
||||
#include "Field.h"
|
||||
|
||||
// A vector-valued field over an array of elements arranged as a 3D lattice
|
||||
|
||||
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
|
||||
{
|
||||
int index = (int)(pos[0] / _worldSize * 10.0) +
|
||||
(int)(pos[1] / _worldSize * 10.0) * 10 +
|
||||
|
@ -31,30 +28,23 @@ int Field::value(float *value, float *pos)
|
|||
}
|
||||
|
||||
Field::Field(float worldSize, float coupling)
|
||||
// Initializes the field to some random values
|
||||
{
|
||||
_worldSize = worldSize;
|
||||
_coupling = coupling;
|
||||
float fx, fy, fz;
|
||||
//float fx, fy, fz;
|
||||
for (int i = 0; i < FIELD_ELEMENTS; i++)
|
||||
{
|
||||
const float FIELD_INITIAL_MAG = 0.0f;
|
||||
_field[i].val = randVector() * FIELD_INITIAL_MAG * _worldSize;
|
||||
_field[i].scalar = 0;
|
||||
// Record center point for this field cell
|
||||
fx = static_cast<float>(i % 10);
|
||||
fy = static_cast<float>(i % 100 / 10);
|
||||
fz = static_cast<float>(i / 100);
|
||||
_field[i].center.x = (fx + 0.5f);
|
||||
_field[i].center.y = (fy + 0.5f);
|
||||
_field[i].center.z = (fz + 0.5f);
|
||||
_field[i].center.x = ((float)(i % 10) + 0.5f);
|
||||
_field[i].center.y = ((float)(i % 100 / 10) + 0.5f);
|
||||
_field[i].center.z = ((float)(i / 100) + 0.5f);
|
||||
_field[i].center *= _worldSize / 10.f;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void Field::add(float* add, float *pos)
|
||||
// At location loc, add vector add to the field values
|
||||
{
|
||||
int index = (int)(pos[0] / _worldSize * 10.0) +
|
||||
(int)(pos[1] / _worldSize * 10.0) * 10 +
|
||||
|
@ -74,11 +64,8 @@ void Field::interact(float deltaTime, const glm::vec3& pos, glm::vec3& vel) {
|
|||
(int)(pos.y / _worldSize*10.0) * 10 +
|
||||
(int)(pos.z / _worldSize*10.0) * 100;
|
||||
if ((index >= 0) && (index < FIELD_ELEMENTS)) {
|
||||
//
|
||||
// Vector Coupling with particle velocity
|
||||
//
|
||||
vel += _field[index].val * deltaTime; // Particle influenced by field
|
||||
_field[index].val += vel * deltaTime * _coupling;
|
||||
vel += _field[index].val * deltaTime; // Particle influenced by field
|
||||
_field[index].val += vel * deltaTime * _coupling; // Field influenced by particle
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -87,15 +74,12 @@ void Field::simulate(float deltaTime) {
|
|||
|
||||
for (int i = 0; i < FIELD_ELEMENTS; i++)
|
||||
{
|
||||
const float CONSTANT_DAMPING = 0.5;
|
||||
const float CONSTANT_SCALAR_DAMPING = 2.5;
|
||||
const float CONSTANT_DAMPING = 0.5f;
|
||||
_field[i].val *= (1.f - CONSTANT_DAMPING * deltaTime);
|
||||
_field[i].scalar *= (1.f - CONSTANT_SCALAR_DAMPING * deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
void Field::render()
|
||||
// Render the field lines
|
||||
{
|
||||
int i;
|
||||
float scale_view = 0.05f * _worldSize;
|
||||
|
|
|
@ -15,24 +15,28 @@
|
|||
#include "world.h"
|
||||
#include "Util.h"
|
||||
|
||||
// Field is a lattice of vectors uniformly distributed FIELD_ELEMENTS^(1/3) on side
|
||||
const int FIELD_ELEMENTS = 1000;
|
||||
|
||||
/// Field is a lattice of vectors uniformly distributed in 3D with FIELD_ELEMENTS^(1/3) per side
|
||||
class Field {
|
||||
public:
|
||||
struct FieldElement {
|
||||
glm::vec3 val;
|
||||
glm::vec3 center;
|
||||
glm::vec3 fld;
|
||||
float scalar;
|
||||
} _field[FIELD_ELEMENTS];
|
||||
|
||||
Field(float worldSize, float coupling);
|
||||
|
||||
/// The field value at a position in space, given simply as the value of the enclosing cell
|
||||
int value(float *ret, float *pos);
|
||||
/// Visualize the field as vector lines drawn at each center
|
||||
void render();
|
||||
/// Add to the field value cell enclosing a location
|
||||
void add(float* add, float *loc);
|
||||
/// A particle with a position and velocity interacts with the field given the coupling
|
||||
/// constant passed when creating the field.
|
||||
void interact(float deltaTime, const glm::vec3& pos, glm::vec3& vel);
|
||||
/// Field evolves over timestep
|
||||
void simulate(float deltaTime);
|
||||
private:
|
||||
float _worldSize;
|
||||
|
|
Loading…
Reference in a new issue