History

indents

Philip Rosedale committed 13 years ago

Commit dd09d681 parent d8dcb6a1 file · +13 −20Browse files

Showing the changes to interface/src/Field.cpp (1 of 1 file). Show all

Unified · Split

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