This commit is contained in:
Philip Rosedale 2013-10-10 09:53:43 -07:00
parent d8dcb6aa44
commit dd09d686fc

View file

@ -11,17 +11,15 @@
int Field::value(float *value, float *pos) {
int index = (int)(pos[0] / _worldSize * 10.0) +
(int)(pos[1] / _worldSize * 10.0) * 10 +
(int)(pos[2] / _worldSize * 10.0) * 100;
(int)(pos[1] / _worldSize * 10.0) * 10 +
(int)(pos[2] / _worldSize * 10.0) * 100;
if ((index >= 0) && (index < FIELD_ELEMENTS))
{
if ((index >= 0) && (index < FIELD_ELEMENTS)) {
value[0] = _field[index].val.x;
value[1] = _field[index].val.y;
value[2] = _field[index].val.z;
return 1;
}
else {
} else {
return 0;
}
}
@ -30,8 +28,7 @@ Field::Field(float worldSize, float coupling) {
_worldSize = worldSize;
_coupling = coupling;
//float fx, fy, fz;
for (int i = 0; i < FIELD_ELEMENTS; i++)
{
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].center.x = ((float)(i % 10) + 0.5f);
@ -44,11 +41,10 @@ Field::Field(float worldSize, float coupling) {
void Field::add(float* add, float *pos) {
int index = (int)(pos[0] / _worldSize * 10.0) +
(int)(pos[1] / _worldSize * 10.0) * 10 +
(int)(pos[2] / _worldSize * 10.0) * 100;
(int)(pos[1] / _worldSize * 10.0) * 10 +
(int)(pos[2] / _worldSize * 10.0) * 100;
if ((index >= 0) && (index < FIELD_ELEMENTS))
{
if ((index >= 0) && (index < FIELD_ELEMENTS)) {
_field[index].val.x += add[0];
_field[index].val.y += add[1];
_field[index].val.z += add[2];
@ -58,8 +54,8 @@ void Field::add(float* add, float *pos) {
void Field::interact(float deltaTime, const glm::vec3& pos, glm::vec3& vel) {
int index = (int)(pos.x / _worldSize * 10.0) +
(int)(pos.y / _worldSize*10.0) * 10 +
(int)(pos.z / _worldSize*10.0) * 100;
(int)(pos.y / _worldSize*10.0) * 10 +
(int)(pos.z / _worldSize*10.0) * 100;
if ((index >= 0) && (index < FIELD_ELEMENTS)) {
vel += _field[index].val * deltaTime; // Particle influenced by field
_field[index].val += vel * deltaTime * _coupling; // Field influenced by particle
@ -69,8 +65,7 @@ void Field::interact(float deltaTime, const glm::vec3& pos, glm::vec3& vel) {
void Field::simulate(float deltaTime) {
glm::vec3 neighbors, add, diff;
for (int i = 0; i < FIELD_ELEMENTS; i++)
{
for (int i = 0; i < FIELD_ELEMENTS; i++) {
const float CONSTANT_DAMPING = 0.5f;
_field[i].val *= (1.f - CONSTANT_DAMPING * deltaTime);
}
@ -82,8 +77,7 @@ void Field::render() {
glDisable(GL_LIGHTING);
glBegin(GL_LINES);
for (i = 0; i < FIELD_ELEMENTS; i++)
{
for (i = 0; i < FIELD_ELEMENTS; i++) {
glColor3f(0, 1, 0);
glVertex3fv(&_field[i].center.x);
glVertex3f(_field[i].center.x + _field[i].val.x * scale_view,
@ -96,8 +90,7 @@ void Field::render() {
glPointSize(4.0);
glEnable(GL_POINT_SMOOTH);
glBegin(GL_POINTS);
for (i = 0; i < FIELD_ELEMENTS; i++)
{
for (i = 0; i < FIELD_ELEMENTS; i++) {
glVertex3fv(&_field[i].center.x);
}
glEnd();