예제 #1
0
    void takeStep(float dt)
    {
        hillRadius [0] = 0.0f;
        for (int j = 1; j < nb; j++)
        {
            if (m [j] > massThreshold)
            {
                double a = x [j].magnitude;
                hillRadius [j] = (float)(a * Mathd.Pow((double)m [j] / (3.0 * (double)m [0]), 0.33333));
            }
            else
            {
                hillRadius [j] = 0.0f;
            }
        }
        float captureMultiplier = 3.0f;

        if (!paused)
        {
            if (useDLL)
            {
                for (int j = 0; j < nb; j++)
                {
                    dx [j]  = x [j].x;
                    dy [j]  = x [j].y;
                    dz [j]  = x [j].z;
                    dvx [j] = v [j].x;
                    dvy [j] = v [j].y;
                    dvz [j] = v [j].z;
                    dm [j]  = m [j];
                    dhr [j] = captureMultiplier * hillRadius [j];
                }
                Wrappers.Wrapper_TakeStepDLL(itd, dx, dy, dz, dvx, dvy, dvz,
                                             dax, day, daz, dm, dhr, nb, (double)dt, (double)G, (double)shieldRadius, (double)massThreshold);
                for (int j = 0; j < nb; j++)
                {
                    x [j].x = (float)dx [j];
                    x [j].y = (float)dy [j];
                    x [j].z = (float)dz [j];
                    v [j].x = (float)dvx [j];
                    v [j].y = (float)dvy [j];
                    v [j].z = (float)dvz [j];
                    if (itd [j] > 0)
                    {
                        toBeRemoved [j] = true;
                    }
                }
            }
            else
            {
                for (int j = 0; j < nb; j++)
                {
                    a[j] = Vector3d.zero;
                }

                for (int j = 0; j < nb; j++)
                {
                    for (int k = j + 1; k < nb; k++)
                    {
                        if (m[k] > massThreshold || m[j] > massThreshold)
                        {
                            Vector3d dx  = (x[k] - x[j]);
                            double   dxm = dx.magnitude;
                            //float dx2 = dxm * dxm;
                            double dx3 = dxm * dxm * dxm;
                            if (m[j] <= massThreshold)
                            {
                                if (dxm < captureMultiplier * hillRadius[k])
                                {
                                    toBeRemoved[j] = true;
                                }
                            }
                            if (m[k] <= massThreshold)
                            {
                                if (dxm < captureMultiplier * hillRadius[j])
                                {
                                    toBeRemoved[k] = true;
                                }
                            }
                            if (dxm > shieldRadius)
                            {
                                if (m[k] > massThreshold)
                                {
                                    a[j] += G * m[k] / dx3 * dx;
                                }
                                if (m[j] > massThreshold)
                                {
                                    a[k] -= G * m[j] / dx3 * dx;
                                }
                            }
                        }
                    }
                }



                for (int j = 0; j < nb; j++)
                {
                    v[j] += a[j] * dt;
                    x[j] += v[j] * dt;
                }
            }

            /*
             * for (int j = 0; j < nb; j++)
             * {
             * bodyGos[j].GetComponent<PlanetBehaviour>().Push(x[j]);
             * }
             */
            t += dt;
        }
    }