Exemple #1
0
    //updates the pos, floating origin, child system shift
    public virtual void update()
    {
        //first calculate the new position and update the child system if needed
        if (!childBodyDependent())
        {
            pos = childRef + child.pos / SUtoChildSU;

            if (childOriginNeedsUpdate())
            {
                updateChildRef();
            }

            checkBodies();
        }
        else//we are on a planet
        {
            //the planet origin is the origin

            //the pos is the reference plus the child coordinates rotated around the ref body
            pos = child.getBodyReference().scaledPos + rotAroundLong(child.pos / SUtoChildSU, child.getBodyReference().Rotation);
            checkVoid();
        }

        //now update the tracker and floating origin
        updateTracker();
        updateTrackerRotation();
    }
Exemple #2
0
 protected override void checkVoid()
 {
     // Debug.Log(LongPos.Distance(pos, curPlanet.scaledPos) + " " + curPlanet.atmosRadius);
     if (LongPos.Distance(pos, curPlanet.scaledPos) > curPlanet.atmosRadius)
     {
         curPlanet = null;
         updateChildRef();
     }
 }
Exemple #3
0
 protected override void checkBodies()
 {
     foreach (Planet plan in curSystem.planets)
     {
         if (LongPos.Distance(pos, plan.scaledPos) < plan.atmosRadius)
         {
             curPlanet = plan;
             UniverseSystem.curPlanet = plan;//TODO: c'mon sam
             enterBody();
             break;
         }
     }
 }
Exemple #4
0
 void checkPlanet()
 {
     //if on a planet, check to see if you are far enough to leave it
     if (onPlanet)
     {
         //if the distance from the planet is greater than it's enter radius, remove
         if (curPlanet.atmosRadius < LongPos.Distance(curPlanet.scaledPos, stellarPos))
         {
             exitPlanet();
         }
     }
     else//check all planets to see if you are close enough to one to enter it
     {
     }
 }
Exemple #5
0
    //updates the poition of tracker and shifts it with everything else if out of the floating threshold
    protected virtual void updateTracker()
    {
        //if the stellar tracker/stellar pos is outside the threshold of the origin, recalculate the origin and shift everything back
        if (originNeedsUpdate(pos, floatingOrigin))
        {
            floatingOrigin = calcOrigin(pos);

            //shift all gameobjects
            if (getBodyReference() != null)
            {
                shiftItems();
            }
        }
        //move the stellar tracker to its appropriate position
        tracker.transform.position = getFloatingPos(pos);
    }
Exemple #6
0
    void updatePlanetTracker()
    {
        //set planetPos based on the player position
        planetPos.x = (long)(player.transform.position.x * SUperUU) + planetFloatOrigin.x;
        planetPos.y = (long)(player.transform.position.y * SUperUU) + planetFloatOrigin.y;
        planetPos.z = (long)(player.transform.position.z * SUperUU) + planetFloatOrigin.z;

        //print(player.transform.position.y+" "+player.transform.position.y*SUperUU+" "+planetPos.y+" "+planetFloatOrigin.y);
        //Debug.Log("{0} {1}",
        if (originNeedsUpdate(planetPos, planetFloatOrigin))
        {
            //calculate where the origin should now be
            LongPos newOrigin = calcOrigin(planetPos);

            //calcualte how much to shift the worldobjects
            Vector3 shift = ((planetFloatOrigin - newOrigin) / SUperUU).toVector3();
            foreach (KeyValuePair <WorldPos, List <WorldObject> > objectList in RequestSystem.builtObjects)
            {
                foreach (WorldObject wo in objectList.Value)
                {
                    wo.transform.position += shift;
                }
            }

            //move all terrain objects that are in planetary space (if the player is on a planet
            if (curPlanet != null)
            {
                foreach (KeyValuePair <LODPos, TerrainObject> chunk in UniverseSystem.curPlanet.lod.chunks)
                {
                    if (chunk.Key.level <= LODSystem.uniCutoff)
                    {
                        chunk.Value.gameObject.transform.position += shift;
                    }
                }
            }


            //ship.transform.position += shift;
            //also shift the player(should eventually not have to do this)
            //if(!Ship.playerOn)
            player.transform.position += shift;

            //now update the origin
            planetFloatOrigin = newOrigin;
        }
    }
Exemple #7
0
    void updateStellarTracker()
    {
        //calculate the stellar position based on the player position
        stellarPos = curPlanet.scaledPos + planetPos / (int)(stellarSU / planetarySU);        //this last term should==10000
        //if the stellar tracker/stellar pos is outside the threshold of the origin, recalculate the origin and shift everything back
        if (originNeedsUpdate(stellarPos, stellarFloatOrigin))
        {
            stellarFloatOrigin = calcOrigin(stellarPos);

            //shift everything in stellar space
            foreach (Planet plan in curSystem.planets)
            {
                plan.scaledRep.transform.position = getStellarFloatingPos(plan.scaledPos);
            }
            curSystem.star.scaledRep.transform.position = getStellarFloatingPos(curSystem.star.scaledPos);
        }
        //move the stellar tracker to its appropriate position
        stellarTracker.transform.position = getStellarFloatingPos(stellarPos);
    }
Exemple #8
0
    public CelestialBody(int _seed, float r, LongPos pos)
    {
        radius = r;
        //this is only an approximation, which is suitable
        //radiusSU = (long)(r/PositionController.planetarySU);
        scaledRadius = r / CoordinateSystem.SUperUU;

        seed      = _seed;
        scaledPos = pos;

        atmosRadius = r + 200000;      //atmosphere is 200 km above surface
        //scaledAtmosRadius = atmosRadius/Unitracker.uniscale;

        buildHeight = r + 10000;      //build height is 10 km above surface

        //gravity = 9.8f;
        //TODO: use real gravity equations
        gravity = radius / 32000 - 1;
    }
Exemple #9
0
    public void generateStuff()
    {
        System.Random rand = new System.Random(Random.Range(int.MinValue, int.MaxValue));

        for (int i = 0; i < 50; i++)
        {
            LongPos pos;
            if (i == 0)
            {
                pos = new LongPos(0, 0, 0);
            }
            else
            {
                pos = new LongPos(rand.Next(-30000, 30000) * 10000L, rand.Next(-20000, 20000) * 10000L, rand.Next(-30000, 30000) * 10000L);
            }
            StarSystem sys = new StarSystem(pos);
            systems.Add(sys);
        }
    }
Exemple #10
0
    public override void update()
    {
        //calculate the pos based on the player's position in unityspace
        pos.x = floatingOrigin.x + (long)(tracker.transform.position.x * SUperUU);
        pos.y = floatingOrigin.y + (long)(tracker.transform.position.y * SUperUU);
        pos.z = floatingOrigin.z + (long)(tracker.transform.position.z * SUperUU);

        //Debug.Log(pos + " " + floatingOrigin);

        //if the origin needs updating, update it and shift everything
        if (originNeedsUpdate(pos, floatingOrigin))
        {
            //Debug.Log("origin updating.");
            //calculate where the origin should now be
            LongPos newOrigin = calcOrigin(pos);

            //shift all items if on a planet
            if (curPlanet != null)
            {
                shiftItems(newOrigin);
            }


            //ship.transform.position += shift;
            //also shift the player(should eventually not have to do this)
            //if(!Ship.playerOn)
            // tracker.transform.position = getFloatingPos(pos);

            //now update the origin
            floatingOrigin = newOrigin;

            if (!Ship.playerOn)
            {
                tracker.transform.position = getFloatingPos(pos);
            }
            else
            {
                ship.transform.position = getFloatingPos(pos);
            }
        }
    }
Exemple #11
0
    //later will have many parameters
    public Planet(float r, LongPos pos, int _seed) : base(_seed, r, pos)  //Vector3 sp, float r)
    {
        //generate the planet surface data
        ModuleBase       finalTerrain, finalTexture;
        List <Blueprint> blueprints;

        PlanetBuilder.genPlanetData(seed, out finalTerrain, out finalTexture, out blueprints);

        noise = new NoiseHandler(radius, finalTerrain, finalTexture);

        //terrain = new TerrainSystem(this, radius);
        //surface = new SurfaceSystem(radius, 400);
        surface = new SurfaceSystem(this, radius, (int)(radius / 50), blueprints);      //number of surface units per side is radius/50

        lod = new LODSystem(this);
        //TODO: does this 16 hold relavance?
        startLev = Mathf.CeilToInt(Mathf.Log(radius / TerrainObject.chunkWidth, 2)) - 1;



        createRep();
    }
Exemple #12
0
    void shiftItems(LongPos newOrigin)
    {
        //calcualte how much to shift the worldobjects
        Vector3 shift = ((floatingOrigin - newOrigin) / SUperUU).toVector3();

        foreach (KeyValuePair <WorldPos, List <WorldObject> > objectList in RequestSystem.builtObjects)
        {
            foreach (WorldObject wo in objectList.Value)
            {
                wo.transform.position += shift;
            }
        }

        //move all terrain objects that are in planetary space (if the player is on a planet
        foreach (KeyValuePair <LODPos, TerrainObject> chunk in UniverseSystem.curPlanet.lod.chunks)
        {
            if (chunk.Key.level <= LODSystem.uniCutoff)
            {
                chunk.Value.gameObject.transform.position += shift;
            }
        }



        //Debug.Log(getFloatingPos(pos) + " " + (tracker.transform.position + shift));

        if (!Ship.playerOn)
        {
            ship.transform.position += shift;
        }



        // if(!Ship.playerOn)
        //   tracker.transform.position = getFloatingPos(pos);*/
    }
Exemple #13
0
 public StarSystem(LongPos pos)
 {
     scaledPos = pos;
     createRep();
     //generateStuff();
 }
Exemple #14
0
    //rotates a given longpos by a certain rotation
    //this compensates for rotation of a body and therefore of the entire child coordinate system
    private LongPos rotAroundLong(LongPos pos, Quaternion rot)
    {
        Vector3 rotated = rot * pos.toVector3();

        return(new LongPos((long)rotated.x, (long)rotated.y, (long)rotated.z));
    }
Exemple #15
0
 //converts scaled units to unity units
 public static Vector3 SUtoUU(LongPos pos)
 {
     return(pos.toVector3() / SUperUU);
 }
Exemple #16
0
 //takes a longpos and returns the floating pos in unity space
 public Vector3 getFloatingPos(LongPos _pos)
 {
     //finds relative position in su, divides by 10000 to convert to uu, converts to v3
     return((_pos - floatingOrigin).toVector3() / SUperUU);
 }
Exemple #17
0
 //calculates the floating origin of a space given the current position of the player/tracker in that space
 //it just rounds to the nearest 1000/whatever threshold is
 public LongPos calcOrigin(LongPos pos)
 {
     return(new LongPos(roundToNearest(pos.x, SUThreshold * 2),
                        roundToNearest(pos.y, SUThreshold * 2),
                        roundToNearest(pos.z, SUThreshold * 2)));
 }
Exemple #18
0
 //checks if the current pos is far away enough from the floating origin that it needs shifting/updating
 //can probably make this non static
 public static bool originNeedsUpdate(LongPos pos, LongPos origin)
 {
     return(System.Math.Abs(pos.x - origin.x) > SUThreshold || System.Math.Abs(pos.y - origin.y) > SUThreshold || System.Math.Abs(pos.z - origin.z) > SUThreshold);
 }
Exemple #19
0
 //shifts the child coordinate system
 protected void updateChildRef()
 {
     childRef  = calcReferenceOrigin();
     child.pos = (pos - childRef) * SUtoChildSU;
     child.updateTracker();
 }
Exemple #20
0
 public Star(int _seed, float r, LongPos pos) : base(_seed, r, pos)
 {
     createRep();
 }
Exemple #21
0
 //distance between two longpos using distance formula
 public static double Distance(LongPos p1, LongPos p2)
 {
     return(System.Math.Sqrt(System.Math.Pow(p1.x - p2.x, 2) + System.Math.Pow(p1.y - p2.y, 2) + System.Math.Pow(p1.y - p2.y, 2)));
 }
Exemple #22
0
 bool originNeedsUpdate(LongPos pos, LongPos origin)
 {
     //print(System.Math.Abs(pos.y-origin.y) + " " + floatThreshold);
     return(System.Math.Abs(pos.x - origin.x) > floatThreshold || System.Math.Abs(pos.y - origin.y) > floatThreshold || System.Math.Abs(pos.z - origin.z) > floatThreshold);
 }
Exemple #23
0
 //calculates the floating origin of a space given the current position of the player/tracker in that space
 //it just rounds to the nearest 1000/whatever threshold is
 LongPos calcOrigin(LongPos pos)
 {
     return(new LongPos(roundToNearest(pos.x, floatThresholddouble),
                        roundToNearest(pos.y, floatThresholddouble),
                        roundToNearest(pos.z, floatThresholddouble)));
 }
Exemple #24
0
 //TODO: condense these into 1 method/simplify
 //takes a longpos and returns the floating pos in unity space
 public static Vector3 getStellarFloatingPos(LongPos pos)
 {
     //finds relative position in su, divides by 10000 to convert to uu, converts to v3
     return((pos - stellarFloatOrigin).toVector3() / SUperUU);
 }