Showing the changes to interface/src/Field.cpp (1 of 1 file). Show all
Unified · Split
| @@ -11,17 +11,15 @@ · 10 unmodified lines | ||
| 11 | 11 | |
| 12 | 12 | int Field::value(float *value, float *pos) { |
| 13 | 13 | int index = (int)(pos[0] / _worldSize * 10.0) + |
| 14 | − (int)(pos[1] / _worldSize * 10.0) * 10 + | |
| 15 | − (int)(pos[2] / _worldSize * 10.0) * 100; | |
| 14 | + (int)(pos[1] / _worldSize * 10.0) * 10 + | |
| 15 | + (int)(pos[2] / _worldSize * 10.0) * 100; | |
| 16 | 16 | |
| 17 | − if ((index >= 0) && (index < FIELD_ELEMENTS)) | |
| 18 | − { | |
| 17 | + if ((index >= 0) && (index < FIELD_ELEMENTS)) { | |
| 19 | 18 | value[0] = _field[index].val.x; |
| 20 | 19 | value[1] = _field[index].val.y; |
| 21 | 20 | value[2] = _field[index].val.z; |
| 22 | 21 | return 1; |
| 23 | − } | |
| 24 | − else { | |
| 22 | + } else { | |
| 25 | 23 | return 0; |
| 26 | 24 | } |
| 27 | 25 | } |
| @@ -30,8 +28,7 @@ Field::Field(float worldSize, float coupling) { · 2 unmodified lines | ||
| 30 | 28 | _worldSize = worldSize; |
| 31 | 29 | _coupling = coupling; |
| 32 | 30 | //float fx, fy, fz; |
| 33 | − for (int i = 0; i < FIELD_ELEMENTS; i++) | |
| 34 | − { | |
| 31 | + for (int i = 0; i < FIELD_ELEMENTS; i++) { | |
| 35 | 32 | const float FIELD_INITIAL_MAG = 0.0f; |
| 36 | 33 | _field[i].val = randVector() * FIELD_INITIAL_MAG * _worldSize; |
| 37 | 34 | _field[i].center.x = ((float)(i % 10) + 0.5f); |
| @@ -44,11 +41,10 @@ Field::Field(float worldSize, float coupling) { · 6 unmodified lines | ||
| 44 | 41 | |
| 45 | 42 | void Field::add(float* add, float *pos) { |
| 46 | 43 | int index = (int)(pos[0] / _worldSize * 10.0) + |
| 47 | − (int)(pos[1] / _worldSize * 10.0) * 10 + | |
| 48 | − (int)(pos[2] / _worldSize * 10.0) * 100; | |
| 44 | + (int)(pos[1] / _worldSize * 10.0) * 10 + | |
| 45 | + (int)(pos[2] / _worldSize * 10.0) * 100; | |
| 49 | 46 | |
| 50 | − if ((index >= 0) && (index < FIELD_ELEMENTS)) | |
| 51 | − { | |
| 47 | + if ((index >= 0) && (index < FIELD_ELEMENTS)) { | |
| 52 | 48 | _field[index].val.x += add[0]; |
| 53 | 49 | _field[index].val.y += add[1]; |
| 54 | 50 | _field[index].val.z += add[2]; |
| @@ -58,8 +54,8 @@ void Field::add(float* add, float *pos) { · 3 unmodified lines | ||
| 58 | 54 | void Field::interact(float deltaTime, const glm::vec3& pos, glm::vec3& vel) { |
| 59 | 55 | |
| 60 | 56 | int index = (int)(pos.x / _worldSize * 10.0) + |
| 61 | − (int)(pos.y / _worldSize*10.0) * 10 + | |
| 62 | − (int)(pos.z / _worldSize*10.0) * 100; | |
| 57 | + (int)(pos.y / _worldSize*10.0) * 10 + | |
| 58 | + (int)(pos.z / _worldSize*10.0) * 100; | |
| 63 | 59 | if ((index >= 0) && (index < FIELD_ELEMENTS)) { |
| 64 | 60 | vel += _field[index].val * deltaTime; // Particle influenced by field |
| 65 | 61 | _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) { · 3 unmodified lines | ||
| 69 | 65 | void Field::simulate(float deltaTime) { |
| 70 | 66 | glm::vec3 neighbors, add, diff; |
| 71 | 67 | |
| 72 | − for (int i = 0; i < FIELD_ELEMENTS; i++) | |
| 73 | − { | |
| 68 | + for (int i = 0; i < FIELD_ELEMENTS; i++) { | |
| 74 | 69 | const float CONSTANT_DAMPING = 0.5f; |
| 75 | 70 | _field[i].val *= (1.f - CONSTANT_DAMPING * deltaTime); |
| 76 | 71 | } |
| @@ -82,8 +77,7 @@ void Field::render() { · 5 unmodified lines | ||
| 82 | 77 | |
| 83 | 78 | glDisable(GL_LIGHTING); |
| 84 | 79 | glBegin(GL_LINES); |
| 85 | − for (i = 0; i < FIELD_ELEMENTS; i++) | |
| 86 | − { | |
| 80 | + for (i = 0; i < FIELD_ELEMENTS; i++) { | |
| 87 | 81 | glColor3f(0, 1, 0); |
| 88 | 82 | glVertex3fv(&_field[i].center.x); |
| 89 | 83 | glVertex3f(_field[i].center.x + _field[i].val.x * scale_view, |
| @@ -96,8 +90,7 @@ void Field::render() { · 6 unmodified lines | ||
| 96 | 90 | glPointSize(4.0); |
| 97 | 91 | glEnable(GL_POINT_SMOOTH); |
| 98 | 92 | glBegin(GL_POINTS); |
| 99 | − for (i = 0; i < FIELD_ELEMENTS; i++) | |
| 100 | − { | |
| 93 | + for (i = 0; i < FIELD_ELEMENTS; i++) { | |
| 101 | 94 | glVertex3fv(&_field[i].center.x); |
| 102 | 95 | } |
| 103 | 96 | glEnd(); |