Example #1
0
    // Update is called once per frame
    void Update()
    {
        // on a deferred add (while running) may get an OP update before actually added to GE. This would be bad.
        if (nbody.engineRef == null)
        {
            return;
        }

        // TODO: optimize/accuracy: if on rails could use orbitU (or KS) directly
        // Now there is MapToRender MUST use physics and not transform position
        Vector3 centerPos = GravityEngine.Instance().GetPhysicsPosition(aroundNBody);

        // Is the resulting orbit and ellipse or hyperbola?
        bool     mapToScene = true;
        Vector3d pos        = ge.GetPositionDoubleV3(nbody);
        Vector3d vel;

        if (velocityFromScript)
        {
            vel = new Vector3d(velocity);
        }
        else
        {
            vel = ge.GetVelocityDoubleV3(nbody);
        }

        orbitU.InitFromRVT(pos, vel, ge.GetPhysicalTimeDouble(), aroundNBody, false);

        // Add lines to the inclination=0 plane of the orbit
        Vector3[] points      = orbitU.OrbitPositions(numPoints, centerPos, mapToScene, hyperDisplayRadius);
        int       totalPoints = numPoints + 2 * numPlaneProjections;

        if (numPlaneProjections > 0)
        {
            Vector3[] pointsWithProj = new Vector3[totalPoints];
            int       projEvery      = numPoints / numPlaneProjections;
            int       p      = 0;
            int       orbitP = 0;
            while (p < totalPoints)
            {
                pointsWithProj[p++] = points[orbitP];
                if ((orbitP % projEvery) == 0)
                {
                    // add a line to plane and back
                    pointsWithProj[p++] = Vector3.ProjectOnPlane(points[orbitP], planeNormal);
                    pointsWithProj[p++] = points[orbitP];
                }
                orbitP++;
            }
            lineR.SetPositions(pointsWithProj);
        }
        else
        {
            lineR.SetPositions(points);
        }
    }