Inheritance: MonoBehaviour
Ejemplo n.º 1
0
        public double observedUniverseTime(double universe_time, RelativisticObject camera)
        {
            double t;

            t = (universe_time - RMS(referencePositionDifference(camera, this)));
            return(t);
        }
Ejemplo n.º 2
0
    //Returns the relative position difference as seen by the observer RelativisticObject
    //public static double[] observedPositionDifference(RelativisticObject observer, RelativisticObject actor)

    //Returns the position difference based on the reference frame (includes lorentz transform for observer)
    public static double[] referencePositionDifference(RelativisticObject observer, RelativisticObject actor)
    {
        double[] answer = new double[observer.x.Length];
        for (int i = 0; i < observer.x.Length; i++)
        {
            answer[i] = actor.x[i] - observer.x[i];
        }
        //Assumption that the time is based on distance (true if observer sees actor in terms of a photon path)
        answer = LorenzTransform(answer, observer.v, -RMS(answer));
        return(answer);
    }
Ejemplo n.º 3
0
    public static double calculateRedshiftZ(RelativisticObject relative_emitter, double[] observer_position)
    {
        //Requires the observer to be stationary at a given position
        double[] v = relative_emitter.v;

        double velocity_rms = relative_emitter.vrms;
        double mygamma = relative_emitter.gamma;
        double[] position_difference = difference(observer_position,relative_emitter.x);
        double v_parallel_component = dotProduct(v,position_difference)/RMS (position_difference);

        double answer = -1.0 + mygamma * (1+v_parallel_component);
        return answer;
    }
Ejemplo n.º 4
0
    public static double calculateRedshiftZ(RelativisticObject relative_emitter, double[] observer_position)
    {//Requires the observer to be stationary at a given position
        double[] v = relative_emitter.v;

        double velocity_rms = relative_emitter.vrms;
        double mygamma      = relative_emitter.gamma;

        double[] position_difference  = difference(observer_position, relative_emitter.x);
        double   v_parallel_component = dotProduct(v, position_difference) / RMS(position_difference);

        double answer = -1.0 + mygamma * (1 + v_parallel_component);

        return(answer);
    }
Ejemplo n.º 5
0
    public static double calculateRedshiftZ(RelativisticObject emitter, RelativisticObject observer)
    {
        double[] velocity_difference = velocityDifference(emitter,observer);

        //all velocities below are implicitly from the difference
        //which gamma do we care about?  v parallel or v total?
        //Arguably v total, actually.  Think time dilation
        double velocity_rms = RMS (velocity_difference);
        double mygamma = computeGamma(velocity_rms);
        double[] position_difference = referencePositionDifference(observer,emitter);
        double v_parallel_component = dotProduct(velocity_difference,position_difference)/RMS (position_difference);

        double answer = -1.0 + mygamma * (1+v_parallel_component);
        return answer;
    }
Ejemplo n.º 6
0
    public static double calculateRedshiftZ(RelativisticObject emitter, RelativisticObject observer)
    {
        double[] velocity_difference = velocityDifference(emitter, observer);

        //all velocities below are implicitly from the difference
        //which gamma do we care about?  v parallel or v total?
        //Arguably v total, actually.  Think time dilation
        double velocity_rms = RMS(velocity_difference);
        double mygamma      = computeGamma(velocity_rms);

        double[] position_difference  = referencePositionDifference(observer, emitter);
        double   v_parallel_component = dotProduct(velocity_difference, position_difference) / RMS(position_difference);

        double answer = -1.0 + mygamma * (1 + v_parallel_component);

        return(answer);
    }
Ejemplo n.º 7
0
    void LaunchObject()
    {
        //Instantiate a new Object (You can find this object in the GameObjects folder, it's a prefab.
        GameObject launchedObject = (GameObject)Instantiate(Resources.Load("GameObjects/" + prefabName, typeof(GameObject)), transform.position, this.transform.rotation);

        //Translate it to our center, and put it so that it's just touching the ground
        launchedObject.transform.Translate((new Vector3(0, launchedObject.GetComponent <MeshFilter>().mesh.bounds.extents.y, 0)));
        //Make it a child of our transform.
        launchedObject.transform.parent = transform;
        //Determine if it has a Relativistic Object, Firework, or multiple RO's to set VIW on.
        RelativisticObject ro = launchedObject.GetComponent <RelativisticObject>();

        RelativisticObject [] ros = launchedObject.GetComponentsInChildren <RelativisticObject>();

        if (ro != null)
        {
            ro.viw = viwMax * this.transform.forward;
            //And let the object know when it was created, so that it knows when not to be seen by the player
            ro.SetStartTime();
        }
        else if (ros.Length > 0)
        {
            for (int i = 0; i < ros.Length; i++)
            {
                ros[i].viw = viwMax * this.transform.forward;
                //And let the object know when it was created, so that it knows when not to be seen by the player
                ros[i].SetStartTime();
            }
        }
        else if (launchedObject.GetComponent <Firework>() != null)
        {
            launchedObject.GetComponent <Firework>().viw = viwMax * transform.forward;
            //And let the object know when it was created, so that it knows when not to be seen by the player
            launchedObject.GetComponent <Firework>().SetStartTime();
        }
    }
        // Use this for initialization, before relativistic object CombineParent() starts.
        void Awake()
        {
            wasStatic         = isStatic;
            finishedCoroutine = true;
            dispatchedShader  = false;
            coroutineTimer    = new System.Diagnostics.Stopwatch();
            myRO = GetComponent <RelativisticObject>();
            myRB = GetComponent <Rigidbody>();
            //Grab the meshfilter, and if it's not null, keep going
            BoxCollider[] origBoxColliders = GetComponents <BoxCollider>();

            //Prepare a new list of colliders for our split collider
            change = new List <BoxCollider>();

            //Store a copy of our original mesh
            original      = origBoxColliders;
            totalBoxCount = 0;
            for (int i = 0; i < original.Length; i++)
            {
                original[i].enabled = false;
                //Split this collider until all of its dimensions have length less than our chosen value
                Subdivide(original[i], change);
            }
        }
Ejemplo n.º 9
0
        //Note that this method assumes that walls are locked at right angles to the world coordinate axes.
        private void OnTrigger(Collider collider)
        {
            if (collider.isTrigger)
            {
                return;
            }

            Rigidbody          otherRB = collider.GetComponent <Rigidbody>();
            GameObject         otherGO = collider.gameObject;
            RelativisticObject otherRO = otherGO.GetComponent <RelativisticObject>();

            if (otherRO != null && otherRB != null && otherRB.isKinematic)
            {
                Collider myColl  = GetComponent <Collider>();
                Vector3  extents = myColl.bounds.extents;
                //We assume that the world "down" direction is the direction of gravity.
                Vector3    playerPos  = state.playerTransform.position;
                Ray        rayDown    = new Ray(playerPos + extents.y * Vector3.up, Vector3.down);
                Ray        rayUp      = new Ray(playerPos + extents.y * Vector3.down, Vector3.up);
                Ray        rayLeft    = new Ray(playerPos + extents.x * Vector3.right, Vector3.left);
                Ray        rayRight   = new Ray(playerPos + extents.x * Vector3.left, Vector3.right);
                Ray        rayForward = new Ray(playerPos + extents.z * Vector3.back, Vector3.forward);
                Ray        rayBack    = new Ray(playerPos + extents.z * Vector3.forward, Vector3.back);
                RaycastHit hitInfo;
                float      dist;
                if (collider.Raycast(rayDown, out hitInfo, 2.0f * extents.y))
                {
                    isFalling = false;
                    Vector3 pVel     = state.PlayerVelocityVector;
                    Vector3 pVelPerp = new Vector3(pVel.x, 0, pVel.z);
                    if (pVel.y > 0.0f)
                    {
                        state.PlayerVelocityVector = state.PlayerVelocityVector.AddVelocity(new Vector3(0.0f, -pVel.y * pVelPerp.Gamma(), 0.0f));
                    }

                    otherRO.UpdateColliderPosition(collider);
                    Ray longDown = new Ray(playerPos + 8.0f * extents.y * Vector3.up, Vector3.down);
                    if (collider.Raycast(longDown, out hitInfo, 16.0f * extents.y))
                    {
                        Vector3 newPos = hitInfo.point + new Vector3(0.0f, extents.y - 0.1f, 0.0f);
                        dist = transform.position.y - newPos.y;
                        if (Mathf.Abs(dist) > 0.01f)
                        {
                            state.playerTransform.position = newPos;
                        }
                    }

                    bool foundCollider = false;
                    for (int i = 0; i < collidersBelow.Count; i++)
                    {
                        if (collidersBelow[i].Equals(collider))
                        {
                            foundCollider = true;
                        }
                    }

                    if (!foundCollider)
                    {
                        collidersBelow.Add(collider);
                    }
                }

                Vector3 direction = Vector3.zero;
                dist = 0.0f;
                if (collider.Raycast(rayForward, out hitInfo, 2.0f * extents.z))
                {
                    dist      = 2.0f * extents.z - hitInfo.distance;
                    direction = Vector3.forward;
                }
                else if (collider.Raycast(rayBack, out hitInfo, 2.0f * extents.z))
                {
                    dist      = 2.0f * extents.z - hitInfo.distance;
                    direction = Vector3.back;
                }
                else if (collider.Raycast(rayLeft, out hitInfo, 2.0f * extents.x))
                {
                    dist      = 2.0f * extents.x - hitInfo.distance;
                    direction = Vector3.left;
                }
                else if (collider.Raycast(rayRight, out hitInfo, 2.0f * extents.x))
                {
                    dist      = 2.0f * extents.x - hitInfo.distance;
                    direction = Vector3.right;
                }
                else if (collider.Raycast(rayUp, out hitInfo, 2.0f * extents.y))
                {
                    dist      = 2.0f * extents.y - hitInfo.distance;
                    direction = Vector3.up;
                }

                if (dist > 0.0f)
                {
                    Vector3 pVel = state.PlayerVelocityVector;
                    if (Vector3.Dot(pVel, direction) < 0.0f)
                    {
                        //Decompose velocity in parallel and perpendicular components:
                        Vector3 myParraVel = Vector3.Project(pVel, direction) * 2.0f;
                        //Vector3 myPerpVel = Vector3.Cross(direction, Vector3.Cross(direction, pVel));
                        //Relativistically cancel the downward velocity:
                        state.PlayerVelocityVector = state.PlayerVelocityVector - myParraVel;
                    }
                    state.playerTransform.position -= dist * direction;
                }
            }
        }
Ejemplo n.º 10
0
 //Returns the relative position difference as seen by the observer RelativisticObject
 //public static double[] observedPositionDifference(RelativisticObject observer, RelativisticObject actor)
 //Returns the position difference based on the reference frame (includes lorentz transform for observer)
 public static double[] referencePositionDifference(RelativisticObject observer, RelativisticObject actor)
 {
     double[] answer =  new double[observer.x.Length];
     for(int i=0;i<observer.x.Length;i++)
     {
         answer[i] = actor.x[i] - observer.x[i];
     }
     //Assumption that the time is based on distance (true if observer sees actor in terms of a photon path)
     answer = LorenzTransform(answer,observer.v,-RMS(answer));
     return answer;
 }
Ejemplo n.º 11
0
 //Functions that operate on at least one RelativisticObject
 //Returns the relative velocity of the actor from the observer's perspective
 public static double[] velocityDifference(RelativisticObject observer, RelativisticObject actor)
 {
     return velocityDifference(observer.v,actor.v);
 }
Ejemplo n.º 12
0
 public static double[] velocitySum(RelativisticObject observer, double[] u)
 {
     //Note: u is seen from observer's perspective, sum returns from the universe's perspective
     return velocitySum(observer.v,u);
 }
Ejemplo n.º 13
0
 public static double[] velocitySum(RelativisticObject observer, double[] u)
 {//Note: u is seen from observer's perspective, sum returns from the universe's perspective
     return(velocitySum(observer.v, u));
 }
Ejemplo n.º 14
0
 //Functions that operate on at least one RelativisticObject
 //Returns the relative velocity of the actor from the observer's perspective
 public static double[] velocityDifference(RelativisticObject observer, RelativisticObject actor)
 {
     return(velocityDifference(observer.v, actor.v));
 }
Ejemplo n.º 15
0
 //Returns a RO that is positioned relative to the observer in the observer's rest frame
 //More or less does a lorentz transform of that object in reference to the observer
 public RelativisticObject GetApparentObject(RelativisticObject observer)
 {
     return(GetApparentObject(observer.x, observer.v));
 }
Ejemplo n.º 16
0
 //Returns a RO that is positioned relative to the observer in the observer's rest frame
 //More or less does a lorentz transform of that object in reference to the observer
 public RelativisticObject GetApparentObject(RelativisticObject observer)
 {
     return GetApparentObject(observer.x,observer.v);
 }
Ejemplo n.º 17
0
 public double observedUniverseTime(double universe_time, RelativisticObject camera)
 {
     double t;
     t = (universe_time - RMS (referencePositionDifference (camera, this)));
     return t;
 }