| 65 | #define G_CONST 9.8066f |
| 66 | |
| 67 | void ClothObject::Simulate(Matrix4Val pos, // world space position of fixed points |
| 68 | Vector3Val velocity, // world space velocity of fixed points |
| 69 | float time, Vector3Par wind, Vector3Par inertia, SimulationImportance importance) |
| 70 | { |
| 71 | if (!EnableVisualEffects(pos.Position(), importance)) |
| 72 | { |
| 73 | InitPos(pos, velocity); |
| 74 | return; |
| 75 | } |
| 76 | |
| 77 | // create acceleration array |
| 78 | int nKnots = _knots.W() * _knots.H(); |
| 79 | AUTO_STATIC_ARRAY(Vector3, accel, 64 * 64); |
| 80 | accel.Realloc(nKnots); |
| 81 | accel.Resize(nKnots); |
| 82 | // init acceleration of all knots with gravity |
| 83 | Vector3 grav(0, -G_CONST * _gravCoef, 0); |
| 84 | |
| 85 | struct Neighbourh |
| 86 | { |
| 87 | int dx, dy; |
| 88 | float factor; |
| 89 | int align; |
| 90 | }; |
| 91 | static const Neighbourh neighbourhs[] = {{-1, 0, 1.0f}, {+1, 0, 1.0f}, {0, -1, 1.0f}, {0, +1, 1.0f}, |
| 92 | {-1, -1, 0.5f}, {+1, +1, 0.5f}, {-1, +1, 0.5f}, {+1, -1, 0.5f}}; |
| 93 | // calculate stretch forces |
| 94 | const float xGrid = _xSize / (_knots.W() - 1); |
| 95 | const float yGrid = _ySize / (_knots.H() - 1); |
| 96 | const int nNeighbourhs = sizeof(neighbourhs) / sizeof(*neighbourhs); |
| 97 | |
| 98 | struct NormNeighbourh |
| 99 | { |
| 100 | int dx1, dy1; |
| 101 | int dx2, dy2; |
| 102 | }; |
| 103 | static const NormNeighbourh normNeighbourhs[] = { |
| 104 | {-1, 0, 0, +1}, |
| 105 | {0, +1, +1, 0}, |
| 106 | {+1, 0, 0, -1}, |
| 107 | {0, -1, -1, 0}, |
| 108 | }; |
| 109 | const int nNormNeighbourhs = sizeof(normNeighbourhs) / sizeof(*normNeighbourhs); |
| 110 | |
| 111 | while (time > 0) |
| 112 | { |
| 113 | float maxStep = _maxStep; |
| 114 | float step = floatMin(time, maxStep); |
| 115 | time -= maxStep; |
| 116 | |
| 117 | for (int i = 0; i < nKnots; i++) |
| 118 | { |
| 119 | accel[i] = grav; |
| 120 | } |
| 121 | |
| 122 | for (int y = 0; y < _knots.H(); y++) |
| 123 | { |
| 124 | for (int x = 0; x < _knots.W(); x++) |
nothing calls this directly
no test coverage detected