void IJobParallelFor.Execute(int index) { var pR = pRPoints + index; if (pR->Weight <= EPSILON) { return; } var pRW = pRWPoints + index; Vector3 Force = Vector3.zero; Force += pR->Gravity; Force += WindForce; Force *= StepTime_x2_Half; Vector3 Displacement; Displacement = pRW->Position - pRW->OldPosition; Displacement += Force / pR->Mass; Displacement *= pR->Resistance; Displacement *= 1.0f - (pRW->Friction * pR->FrictionScale); pRW->OldPosition = pRW->Position; pRW->Position += Displacement; pRW->Friction = 0.0f; if (pR->Hardness > 0.0f) { var Target = RootMatrix.MultiplyPoint3x4(pR->InitialPosition); pRW->Position += (Target - pRW->Position) * pR->Hardness; } if (pRW->GrabberIndex != -1) { Grabber * pGR = pGrabbers + pRW->GrabberIndex; GrabberEx *pGRW = pGrabberExs + pRW->GrabberIndex; if (pGRW->IsEnabled == 0) { pRW->GrabberIndex = -1; return; } var Vec = pRW->Position - pGRW->Position; var Pos = pGRW->Position + Vec.normalized * pRW->GrabberDistance; pRW->Position += (Pos - pRW->Position) * pGR->Force; } else { int NearIndex = -1; float sqrNearRange = 1000.0f * 1000.0f; for (int i = 0; i < GrabberCount; ++i) { Grabber * pGR = pGrabbers + i; GrabberEx *pGRW = pGrabberExs + i; if (pGRW->IsEnabled == 0) { continue; } var Vec = pGRW->Position - pRW->Position; var sqrVecLength = Vec.sqrMagnitude; if (sqrVecLength < pGR->Radius * pGR->Radius) { if (sqrVecLength < sqrNearRange) { sqrNearRange = sqrVecLength; NearIndex = i; } } } if (NearIndex != -1) { pRW->GrabberIndex = NearIndex; pRW->GrabberDistance = Mathf.Sqrt(sqrNearRange) / 2.0f; } } }
void IJobParallelFor.Execute(int index) { var pR = pRPoints + index; if (pR->Weight == 0.0f) { return; } var pRW = pRWPoints + index; var Force = pR->Gravity; Force += WindForce; Force *= StepTime_x2_Half; var Displacement = pRW->Position - pRW->OldPosition; Displacement += Force / pR->Mass; Displacement *= pR->Resistance; Displacement *= 1.0f - (pRW->Friction * pR->FrictionScale); pRW->OldPosition = pRW->Position; pRW->Position += Displacement; pRW->Friction = 0.0f; if (pRW->GrabberIndex != -1) { Grabber * pGR = pGrabbers + pRW->GrabberIndex; GrabberEx *pGRW = pGrabberExs + pRW->GrabberIndex; if (pGRW->IsEnabled == 0) { pRW->GrabberIndex = -1; return; } var Vec = pRW->Position - pGRW->Position; var Pos = pGRW->Position + Vec.normalized * pRW->GrabberDistance; pRW->Position += (Pos - pRW->Position) * pGR->Force; } else { var NearIndex = -1; var sqrNearRange = float.PositiveInfinity; for (int i = 0; i < GrabberCount; ++i) { Grabber * pGR = pGrabbers + i; GrabberEx *pGRW = pGrabberExs + i; if (pGRW->IsEnabled == 0) { continue; } var Vec = pGRW->Position - pRW->Position; var sqrVecLength = Vec.sqrMagnitude; if (sqrVecLength < pGR->Radius * pGR->Radius && sqrVecLength < sqrNearRange) { sqrNearRange = sqrVecLength; NearIndex = i; } } if (NearIndex != -1) { pRW->GrabberIndex = NearIndex; pRW->GrabberDistance = Mathf.Sqrt(sqrNearRange) * 0.5f; } } }