Beispiel #1
0
    //call with the root celestial object and null in order to recursively instantiate a solar system
    private static void InstantiateSystem(Blueprint rootCelestial, CelestialObj parent)
    {
        CelestialObj newParent = BuildCelestial(parent, rootCelestial);

        foreach (Blueprint child in rootCelestial.children)
        {
            InstantiateSystem(child, newParent);
        }
    }
Beispiel #2
0
    public UVFKinetic(CelestialObj pObj, Vector3d pPos, Vector3d pVel)
    {
        if ((pPos == null) || (pVel == null))
        {
            throw new NullReferenceException("Must get mover instance after having set up position and velocity!");
        }

        if (pObj.parent == null)
        {
            throw new NullReferenceException("UVFKinetic type mover requires that a parent object be defined");
        }

        obj                 = pObj;
        startPosition       = new Vector3d(pPos);
        startVelocity       = new Vector3d(pVel);
        startRadialVelocity = Vector3d.Dot(pPos, pVel) / pPos.magnitude;

        recomputeParameters();
    }
Beispiel #3
0
 public Vector3d eulerVel(Vector3d mPos, Vector3d mVel, double deltaT, CelestialObj obj)
 {
     return(mVel + (getParentGravity(mPos, obj) * deltaT));
 }
Beispiel #4
0
 //helpers
 public Vector3d getParentGravity(Vector3d mPos, CelestialObj obj)
 {
     return((-1.0d * (mPos / mPos.magnitude)) * ((obj.parent.gravParam) / (mPos.magnitude * mPos.magnitude)));
 }
Beispiel #5
0
    /*may need this syntax later, hiding it here because im a lazy bum
     * private static T BuildCelestial<T>(CelestialObj parent, Blueprint bp)
     * where T : CelestialObj
     * {
     */


    //this is all a horrible mess of a procedure, move it into a generic under the hood method
    //if passed a null CelestialObj, this indicates that there is no parent (it also implicitly understands that it is creating the root object of the game world)
    private static CelestialObj BuildCelestial(CelestialObj parent, Blueprint bp)
    {
        GameObject gameObj = new GameObject();

        if (!(bp.type.IsSubclassOf(typeof(CelestialObj))))
        {
            throw new Exception("Celestial Blueprint class has improperly set up type!");
        }

        CelestialObj celestial = (CelestialObj)gameObj.AddComponent(bp.type);

        gameObj.name = bp.typeName;


        //slave the planet to its parent transform, tell the script who that is
        celestial.parent = parent;
        //if no parent, dont try to access components of parent
        if (parent != null)
        {
            gameObj.transform.parent = parent.transform;
        }

        //generate planets parameters
        //decide on which max mass to use
        celestial.mass    = bp.mass;
        celestial.density = bp.density;

        double xposition = bp.startAltitude * Mathd.Cos(bp.startAngle);
        double zposition = bp.startAltitude * Mathd.Sin(bp.startAngle);

        celestial.position = new Vector3d(xposition, 0.0d, zposition);

#warning should add a way to perturb the orbit, as in change its plane away from the ecliptic
        //put together the velocity vector
        double xvelocity = bp.startSpeed * Mathd.Cos(bp.startAngle + Mathd.PI / 4.0d);
        double zvelocity = bp.startSpeed * Mathd.Sin(bp.startAngle + Mathd.PI / 4.0d);
        celestial.velocity = new Vector3d(xvelocity, 0.0d, zvelocity);

        //set up the planets ability to move around
        celestial.SetupOrbit();

        //set up atmosphere

        /*
         *  double percent = Random.value;
         *
         *          double n = percent * 3619115000000.0d;
         *
         *          return n * gravity * gravity / (4.0d * Mathf.PI * radius * radius);
         */



        //set up visual representation
        GameObject modelObj = new GameObject();
        modelObj.transform.parent = gameObj.transform;
        modelObj.name             = "Model";

        //create a mesh and add it to the model object
        GameObject meshObj    = GameObject.CreatePrimitive(PrimitiveType.Sphere);
        Mesh       mesh       = meshObj.GetComponent <MeshFilter>().sharedMesh;
        MeshFilter meshFilter = modelObj.AddComponent <MeshFilter>();
        meshFilter.mesh = mesh;
        GameObject.Destroy(meshObj);

        //add mesh renderer
        GameObject materialObj = GameObject.CreatePrimitive(PrimitiveType.Plane);
        Material   diffuse     = materialObj.GetComponent <MeshRenderer>().sharedMaterial;
        GameObject.Destroy(materialObj);
        MeshRenderer renderer = modelObj.AddComponent <MeshRenderer>();
        renderer.sharedMaterial = diffuse;

        celestial.model = modelObj.AddComponent <CelestialIndicator>();

        addTrail(modelObj, bp.trailColor);

        //set up SOI indicator (should be part of the model object)

        /*
         *      //give it an SOI indicator
         * GameObject indicator = ((GameObject)Instantiate(SOIIndRef));
         * indicator.transform.localScale = new Vector3((float)(2.0d * planetBuffer.soi), (float)(2.0d * planetBuffer.soi), (float)(2.0d * planetBuffer.soi));
         * indicator.transform.parent = planetBuffer.transform;*/

        celestial.UpdateParameters();

        return(celestial);
    }