| 1006 | } |
| 1007 | |
| 1008 | void UpdateEmitters() |
| 1009 | { |
| 1010 | float spin = DegToRad(15.0f); |
| 1011 | |
| 1012 | const Vec3 forward(-sinf(g_camAngle.x + spin)*cosf(g_camAngle.y), sinf(g_camAngle.y), -cosf(g_camAngle.x + spin)*cosf(g_camAngle.y)); |
| 1013 | const Vec3 right(Normalize(Cross(forward, Vec3(0.0f, 1.0f, 0.0f)))); |
| 1014 | |
| 1015 | g_emitters[0].mDir = Normalize(forward + Vec3(0.0, 0.4f, 0.0f)); |
| 1016 | g_emitters[0].mRight = right; |
| 1017 | g_emitters[0].mPos = g_camPos + forward*1.f + Vec3(0.0f, 0.2f, 0.0f) + right*0.65f; |
| 1018 | |
| 1019 | // process emitters |
| 1020 | if (g_emit) |
| 1021 | { |
| 1022 | int activeCount = NvFlexGetActiveCount(g_flex); |
| 1023 | |
| 1024 | size_t e = 0; |
| 1025 | |
| 1026 | // skip camera emitter when moving forward or things get messy |
| 1027 | if (g_camSmoothVel.z >= 0.025f) |
| 1028 | e = 1; |
| 1029 | |
| 1030 | for (; e < g_emitters.size(); ++e) |
| 1031 | { |
| 1032 | if (!g_emitters[e].mEnabled) |
| 1033 | continue; |
| 1034 | |
| 1035 | Vec3 emitterDir = g_emitters[e].mDir; |
| 1036 | Vec3 emitterRight = g_emitters[e].mRight; |
| 1037 | Vec3 emitterPos = g_emitters[e].mPos; |
| 1038 | |
| 1039 | float r; |
| 1040 | int phase; |
| 1041 | |
| 1042 | if (g_params.fluid) |
| 1043 | { |
| 1044 | r = g_params.fluidRestDistance; |
| 1045 | phase = NvFlexMakePhase(0, eNvFlexPhaseSelfCollide | eNvFlexPhaseFluid); |
| 1046 | } |
| 1047 | else |
| 1048 | { |
| 1049 | r = g_params.solidRestDistance; |
| 1050 | phase = NvFlexMakePhase(0, eNvFlexPhaseSelfCollide); |
| 1051 | } |
| 1052 | |
| 1053 | float numParticles = (g_emitters[e].mSpeed / r)*g_dt; |
| 1054 | |
| 1055 | // whole number to emit |
| 1056 | int n = int(numParticles + g_emitters[e].mLeftOver); |
| 1057 | |
| 1058 | if (n) |
| 1059 | g_emitters[e].mLeftOver = (numParticles + g_emitters[e].mLeftOver) - n; |
| 1060 | else |
| 1061 | g_emitters[e].mLeftOver += numParticles; |
| 1062 | |
| 1063 | // create a grid of particles (n particles thick) |
| 1064 | for (int k = 0; k < n; ++k) |
| 1065 | { |
no test coverage detected