Esempio n. 1
0
    // Update is called once per frame
    void Update()
    {
        for (short z = 0; z < 30; z++)
        {
            Vector3 topRight    = myCamera.ViewportToWorldPoint(new Vector3(1, 1, z));
            Vector3 topLeft     = myCamera.ViewportToWorldPoint(new Vector3(0, 1, z));
            Vector3 bottomRight = myCamera.ViewportToWorldPoint(new Vector3(1, 0, z));
            Vector3 bottomLeft  = myCamera.ViewportToWorldPoint(new Vector3(0, 0, z));

            // short startX = (short)topLeft.x;
            // short startY = (short)bottomLeft.y;
            // short endX = (short)topRight.x;
            // short endY = (short)topLeft.y;

            // short cameraWidth = MathF.abs(endX - startX);
            // short cameraHeight = MathF.abs(endY - startY);



            /*print(topRight);
             * print(topLeft);
             * print(bottomRight);
             * print(bottomLeft);*/
            for (short x = (short)topLeft.x; x < topRight.x; x++)
            {
                for (short y = (short)bottomLeft.y; y < topLeft.y; y++)
                {
                    // for (short z = i; z < 21; z++)
                    // {
                    if (x % sectorWidth == 0 && y % sectorWidth == 0)
                    {
                        ushort posY = (ushort)y;
                        ushort posZ = (ushort)topRight.z;
                        long   seed = (long)x << 32 | (long)posY << 16 | (long)posZ;
                        randGen = new Lehmer(seed);

                        long rand = randGen.randomInt(1, 1000);

                        bool starExists = rand == 1;

                        if (starExists && !Physics.CheckSphere(new Vector3(x, y, (short)topRight.z), sectorWidth / 2f))
                        {
                            GameObject planet = Instantiate(myPrefab, new Vector3(x, y, (short)topRight.z), Quaternion.identity);
                            float      scale  = randGen.randomInt(1, 100) / 100f;
                            planet.transform.localScale = new Vector3(scale * sectorWidth, scale * sectorWidth, scale * sectorWidth);
                            // print(planet.transform.localScale);
                        }
                    }
                    // }
                }
            }
        }
    }
Esempio n. 2
0
    void Start()
    {
        minMoonMass = (int)(minPlanetMass * moonMassSacle);
        maxMoonMass = (int)(maxPlanetMass * moonMassSacle);

        x = gameInfoObject.GetComponent <GameInfo>().x;
        y = gameInfoObject.GetComponent <GameInfo>().y;
        z = gameInfoObject.GetComponent <GameInfo>().z;
        GameObject star = Instantiate(starPrefab, starPoisiton, Quaternion.identity);

        ushort posY = (ushort)y;
        ushort posZ = (ushort)z;

        nLehmer       = (long)x << 32 | (long)posY << 16 | (long)posZ;
        randGenerator = new Lehmer(nLehmer);

        bool starExists = randGenerator.randomInt(0, 15) == 1;

        scale      = randGenerator.randomInt(1, 100) / 100f;
        numPlanets = (int)randGenerator.randomInt(0, maxNumPlanets);
        // numPlanets = 1;

        planetsGameObjects = new GameObject[numPlanets];
        rigidBodies        = new Rigidbody[numPlanets];
        planets            = new Planet[numPlanets];
        moons            = new Moon[numPlanets, maxNumMoons];
        moonsGameObjects = new GameObject[numPlanets, maxNumMoons];
        orbits           = new EllipseOrbit[numPlanets, maxNumMoons];



        for (int i = 0; i < numPlanets; i++)
        {
            int     maxPlanetScaleToInt = (int)(maxPlanetScale * 100);
            float   planetScale         = (maxPlanetScaleToInt - 1 - (uint)randGenerator.randomInt(1, maxPlanetScaleToInt - 1)) / 100f;
            Vector3 planetPosition      = new Vector3(randGenerator.randomInt(-maxPlanetRadiusDistance, maxPlanetRadiusDistance),
                                                      randGenerator.randomInt(-maxPlanetRadiusDistance, maxPlanetRadiusDistance),
                                                      randGenerator.randomInt(-maxPlanetRadiusDistance, maxPlanetRadiusDistance));

            GameObject planet = Instantiate(planetPrefab, planetPosition, Quaternion.identity);
            planetsGameObjects[i] = planet;
            planets[i]            = new Planet();
            // startVelocity = (starPoisiton - planetPosition).normalized;
            // planets[i].setVelocity(startVelocity);
            planets[i].setMass((float)randGenerator.randomInt(minPlanetMass, maxPlanetMass));

            //MOOOOOOOOOOOOOOOOOOOOON
            numMoons = (int)randGenerator.randomInt(0, maxNumMoons);
            planets[i].setNumMoons(numMoons);



            for (int j = 0; j < numMoons; j++)
            {
                Vector3 moondistance = new Vector3(randGenerator.randomInt(-maxMoonRadiusDistance, maxMoonRadiusDistance),
                                                   randGenerator.randomInt(-maxMoonRadiusDistance, maxMoonRadiusDistance),
                                                   randGenerator.randomInt(-maxMoonRadiusDistance, maxMoonRadiusDistance));

                Vector3 moonPosition = moondistance + planetPosition;

                float minMagnitude = moonPosition.magnitude + planetRadius + 1;
                float maxMagnitude = minMagnitude + maxVectorMagFromPlanet;
                float mag          = (float)randGenerator.randomInt((int)minMagnitude, (int)maxMagnitude);
                float b            = mag / 2;

                Vector3 ellipseEndpoint = (mag * -1 * moondistance) + moonPosition;
                Vector3 midPoint        = (b * -1 * moonPosition) + moonPosition;

                Vector3 normal = moondistance;
                Vector3 tangent;
                Vector3 t1 = Vector3.Cross(normal, Vector3.forward);
                Vector3 t2 = Vector3.Cross(normal, Vector3.up);
                if (t1.magnitude > t2.magnitude)
                {
                    tangent = t1;
                }
                else
                {
                    tangent = t2;
                }

                float a = (float)randGenerator.randomInt((int)minMagnitude, (int)maxMagnitude);
                orbits[i, j] = new EllipseOrbit(a * .2f, b * .2f, midPoint);
                orbits[i, j].setTheta((float)randGenerator.randomInt(0, 90));



                GameObject moon = Instantiate(moonPrefab, moonPosition, Quaternion.identity);
                moonsGameObjects[i, j] = moon;
                moons[i, j]            = new Moon();
                //moons[i, j].setVelocity(startVelocity);
                moons[i, j].setMass((float)randGenerator.randomInt(minMoonMass, maxMoonMass));
            }
        }
    }