Ejemplo n.º 1
0
 public static void MakeEventTrail(trackData track)
 {
     /* Vector3 tdir = new Vector3(Mathf.Sin(track.zen_rad) * Mathf.Cos(track.azi_rad), Mathf.Sin(track.zen_rad) * Mathf.Sin(track.azi_rad), Mathf.Cos(track.zen_rad));
      * Vector3 ipos = new Vector3(track.rec_x, track.rec_y, track.rec_z);
      * MuonTrack mtrack = new MuonTrack(ipos, tdir,5000, 0.299792458f / 1.00000001f, 20);
      * MultimeshObject meshes = mtrack.Simulate();
      * int cnt = 0;
      * foreach (Meshobject m in meshes.meshes)
      * {
      *   AssetDatabase.CreateAsset(m.ToMesh(), "Assets/Trailmesh/tmesh2_" + cnt.ToString() + ".asset");
      *   cnt += 1;
      * }*/
 }
Ejemplo n.º 2
0
    public void updateToSet(bool force = false)
    {
        if (EventRestAPI.Instance == null)
        {
            Debug.Log("Nyanya: no instance");
            return;
        }
        if (EventRestAPI.Instance.currentEvent == null)
        {
            //    Debug.Log("Nyanya: noevent");
            return;
        }
        float nsld = 0.0f;

        if (timeController != null)
        {
            nsld = timeController.value;
        }

        if (deltaController != null)
        {
            tgap = deltaController.value;
        }
        if (nsld == prevSld && beforeBalls != null && !force)
        {
            return;
        }

        if (beforeBalls != null)
        {
            foreach (ballIntegratedData id in beforeBalls)
            {
                ballArray[id.stId].balls[id.domId].setScale(baseScale);
                ballArray[id.stId].balls[id.domId].setColor(new Color(0.9f, 0.9f, 0.9f));
                if (force)
                {
                    ballArray[id.stId].balls[id.domId].resetSig();
                }
            }
        }

        List <ballIntegratedData> afterBalls = new List <ballIntegratedData>();
        float start = timeSpan.value;  //
        float end   = timeSpan.value2; //

        if (end > 1.0f)
        {
            end = 1.0f;
        }
        List <ballIntegratedData> collectedBalls = EventRestAPI.Instance.currentEvent.ballData;

        foreach (ballIntegratedData ball in collectedBalls)
        {
            if (ball.ballAffectedInTs(start, end))
            {
                afterBalls.Add(ball);
                float  tscl = 0.0f;
                double sig  = ball.getInSpan(start, end, tgap, nsld, ref tscl);
                if (sig != -1)
                {
                    float dsig = ballArray[ball.stId].balls[ball.domId].setAndCompareSig((float)sig);

                    if (dsig > 0 && playbackController != null && playbackController.IsPlaying)
                    {
                        //NoteSelector inst = NoteSelector.GetMainInstance();
                        // Debug.LogFormat("Sig :{0}", sig);
                        //if(inst)
                        //{
                        //   inst.PlayNote(ballArray[ball.stId].balls[ball.domId].transform.localPosition,(float) sig, 0.12f);
                        // }
                        int str = (int)(sig * 40);
                        if (str < 20)
                        {
                            str = 20;
                        }
                        if (str > 70)
                        {
                            str = 70;
                        }

                        stringArray[ball.stId - 1].HitBall(ball.domId, str);
                    }
                    double scale = (double)baseScale + (EventRestAPI.settings.scaleMul * Math.Pow((0.2 * sig), EventRestAPI.settings.scalePower));
                    ballArray[ball.stId].balls[ball.domId].setScale((float)scale);
                    ballArray[ball.stId].balls[ball.domId].setColor(colorFromBasicMap(tscl));
                }
                else
                {
                    ballArray[ball.stId].balls[ball.domId].resetSig();
                    ballArray[ball.stId].balls[ball.domId].setScale(baseScale);
                    ballArray[ball.stId].balls[ball.domId].setColor(new Color(0.9f, 0.9f, 0.9f));
                }
            }
        }
        // public float delay = 0.01f;
        //public float tgap = 0.1f;
        beforeBalls = afterBalls;
        //track
        trackData track = null;

        if (EventRestAPI.Instance.currentEvent.track == null)
        {
            EventRestAPI.Instance.currentEvent.track = EventRestAPI.Instance.currentEvent.description.track;
        }
        if (EventRestAPI.Instance.currentEvent.track != null)
        {
            track = EventRestAPI.Instance.currentEvent.track;
        }
        else
        {
            if (ftrack != null && EventRestAPI.Instance.currentEvent.description.run == ftrack.eid.Key &&
                EventRestAPI.Instance.currentEvent.description.evn == ftrack.eid.Value)
            {
                track = ftrack.frc;
                EventRestAPI.Instance.currentEvent.track = track;
                //EventRestAPI.Instance.currentEvent.sav
                //   Debug.Log("Forcing track ");
            }
        }
        if (force)
        {
            Debug.Log("Force updating");
        }
        float t1 = EventRestAPI.Instance.currentEvent.maxPureTime;
        float t0 = EventRestAPI.Instance.currentEvent.minPureTime;

        if (t0 > t1)
        {
            float tt = t0;
            t0 = t1; t1 = tt;
        }
        float atime = nsld * (t1 - t0) + t0;
        var   cdesc = EventRestAPI.Instance.currentEvent.description;
        var   ceid  = new KeyValuePair <long, long>(cdesc.run, cdesc.evn);

        if (track == null || track.rec_t0 > atime + 0.001f || EventRestAPI.Instance.eventTrackIsSuppressed(ceid))
        {
            pole.SetActive(false);
            cone.SetActive(false);
        }
        else
        {
            pole.SetActive(true);
            cone.SetActive(true);
        }
        if (track != null)
        {
            if (ref1 == null || ref2 == null || ref3 == null || ref4 == null)
            {
                Debug.Log("Need reference points");
                return;
            }
            if (cone == null || pole == null)
            {
                Debug.Log("Need cone and pole");
                return;
            }
            if (trackmesh != null)
            {
                if (EventRestAPI.Instance.currentEvent != null)
                {
                    var desc = EventRestAPI.Instance.currentEvent.description;
                    var eid  = new KeyValuePair <long, long>(desc.run, desc.evn);
                    if (EventRestAPI.Instance.eventHasSim(eid))
                    {
                        if (hairControl != null)
                        {
                            hairCover?.SetActive(true);
                        }
                    }
                    else
                    {
                        if (hairControl != null)
                        {
                            hairCover?.SetActive(false);
                        }
                    }
                }
            }
            // Debug.Log(atime);
            Debug.LogFormat("Trackt0 {0} atime: {1}", track.rec_t0, atime);
            if (track.rec_t0 > atime)
            {
                trackmesh?.Inactivate();
                return;
            }
            Vector3 tdir     = new Vector3(Mathf.Sin(track.zen_rad) * Mathf.Cos(track.azi_rad), Mathf.Sin(track.zen_rad) * Mathf.Sin(track.azi_rad), Mathf.Cos(track.zen_rad));
            float   vel      = 0.299792458f;/// ni;
            float   dt       = atime - track.rec_t0;
            Vector3 ice_offs = -tdir * vel * dt;
            Vector3 ice_pos  = new Vector3(track.rec_x, track.rec_y, track.rec_z) + ice_offs;
            if (trackmesh != null)
            {
                var             desc = EventRestAPI.Instance.currentEvent.description;
                MultimeshObject mesh = EventRestAPI.Instance.DemandMMesh(desc);
                Debug.LogFormat("DMesh {0}", mesh);
                if (mesh != null)
                {
                    trackmesh.UseMesh((int)desc.run, (int)desc.evn, mesh);
                }
                else
                {
                    trackmesh.Inactivate();
                }
                //trackmesh.MaybeRecreateMesh((int)desc.run, (int)desc.evn, new Vector3(track.rec_x, track.rec_y, track.rec_z), -tdir/tdir.magnitude, 5000, 10);
                //trackmesh.MaybeRecreateProperMesh((int)desc.run, (int)desc.evn, new Vector3(track.rec_x, track.rec_y, track.rec_z), -tdir / tdir.magnitude, 5000, 10, track.rec_t0);
                Debug.LogFormat("Tdir {0}", tdir);
            }
            //ref1.gameObject.transform.localPosition;
            Matrix4x4 trans = new Matrix4x4();
            Vector3   c1    = ref1.gameObject.transform.localPosition;
            Vector3   c2    = ref2.gameObject.transform.localPosition;
            Vector3   c3    = ref3.gameObject.transform.localPosition;
            Vector3   c4    = ref4.gameObject.transform.localPosition;
            trans.SetColumn(0, new Vector4(c1.x, c1.y, c1.z, 1));
            trans.SetColumn(1, new Vector4(c2.x, c2.y, c2.z, 1));
            trans.SetColumn(2, new Vector4(c3.x, c3.y, c3.z, 1));
            trans.SetColumn(3, new Vector4(c4.x, c4.y, c4.z, 1));
            Matrix4x4 ice = new Matrix4x4();

            Vector3 i1 = ref1.icecube_pt;
            Vector3 i2 = ref2.icecube_pt;
            Vector3 i3 = ref3.icecube_pt;
            Vector3 i4 = ref4.icecube_pt;
            ice.SetColumn(0, new Vector4(i1.x, i1.y, i1.z, 1));
            ice.SetColumn(1, new Vector4(i2.x, i2.y, i2.z, 1));
            ice.SetColumn(2, new Vector4(i3.x, i3.y, i3.z, 1));
            ice.SetColumn(3, new Vector4(i4.x, i4.y, i4.z, 1));

            Matrix4x4 inv     = trans * ice.inverse;
            Vector3   un_pos0 = inv.MultiplyPoint3x4(new Vector3(track.rec_x, track.rec_y, track.rec_z));
            if (trackmesh != null)
            {
                trackmesh.gameObject.transform.localPosition = un_pos0;
                float stime = start * (t1 - t0) + t0;
                float etime = end * (t1 - t0) + t0;
                trackmesh.SetTime(atime - track.rec_t0);
                trackmesh.SetTimeScale((etime - track.rec_t0));
                // Vector3 un = inv.MultiplyPoint3x4(new Vector3(track.rec_x, track.rec_y, track.rec_z-1)); lhs = m_Matrix.GetColumn(2),

                /* var lhs = inv.GetColumn(2);
                 * var rhs = inv.GetColumn(1);
                 * Quaternion rtt = Quaternion.identity;
                 * if (lhs == Vector4.zero && rhs == Vector4.zero)
                 *   rtt= Quaternion.identity;
                 * else
                 *   rtt= Quaternion.LookRotation(lhs, rhs);
                 * trackmesh.gameObject.transform.localRotation = rtt;// Quaternion.LookRotation(un_pos0 - un);
                 * trackmesh.gameObject.transform.localScale = new Vector3(0.1f,0.1f,0.1f);*/
                // Debug.LogFormat("Setting meshtimescale: {0} {1}", inv, (t1 - track.rec_t0));
            }
            Vector3    un_pos1 = inv.MultiplyPoint3x4(ice_pos);
            Quaternion rot     = Quaternion.LookRotation(un_pos0 - un_pos1);
            pole.transform.localRotation = rot;
            cone.transform.localRotation = rot;
            float sclen = (un_pos0 - un_pos1).magnitude;
            pole.transform.localScale    = new Vector3(1, 1, sclen / 10);
            pole.transform.localPosition = un_pos1;
            cone.transform.localPosition = un_pos1;
        }
        else
        {
            if (hairControl != null)
            {
                hairCover?.SetActive(false);
                hairCover?.SetActive(false);
            }
            if (trackmesh != null)
            {
                trackmesh.Inactivate();
            }
        }
    }
Ejemplo n.º 3
0
    void updateTrackRot()
    {
        if (EventRestAPI.Instance == null)
        {
            return;
        }
        if (EventRestAPI.Instance.currentEvent == null)
        {
            return;
        }
        if (EventRestAPI.Instance.currentEvent.track == null && EventRestAPI.Instance.currentEvent.description.track != null)
        {
            EventRestAPI.Instance.currentEvent.track = EventRestAPI.Instance.currentEvent.description.track;
        }
        if (EventRestAPI.Instance.currentEvent.track != null)
        {
            trackData dat = EventRestAPI.Instance.currentEvent.track;

            float dsin = Mathf.Sin(dat.zen_rad);
            float dcos = Mathf.Cos(dat.zen_rad);
            float rsin = Mathf.Sin(-dat.azi_rad);
            float rcos = Mathf.Cos(-dat.azi_rad);
            //Debug.LogFormat("ds:{0} dc:{1} rs:{2} rc:{3}",dsin,dcos,rsin,rcos);
            //////////////////////////////x/////////z//////////y/////
            Vector3 forw = new Vector3(dcos * rsin, -dcos * rcos, dsin);
            //earth-relative direction, i think ^^

            //south pole: 0 -2; 0;
            /// celestial sphere: radius 5 local
            float erad = 2.0f;
            float crad = 1.0f / earth.transform.localScale.x; //7.0f;
            // Debug.LogFormat("LocalScale: {0} ",crad);
            Vector3 spole = new Vector3(0, -erad, 0);
            float   a     = forw.sqrMagnitude;
            float   b     = 2 * (spole.x * forw.x + spole.y * forw.y + spole.z * forw.z);
            float   c     = spole.sqrMagnitude - crad * crad;
            float   det   = Mathf.Sqrt(b * b - 4 * a * c);
            float   sol   = (-b + det) / (2 * a);
            Vector3 from  = spole + forw * sol;

            float   cdsin = Mathf.Sin(dat.dec_rad);
            float   cdcos = Mathf.Cos(dat.dec_rad);
            float   crsin = Mathf.Sin((float)dat.ra_rad);
            float   crcos = Mathf.Cos((float)dat.ra_rad);
            Vector3 ft    = new Vector3(from.x, from.z, from.y);
            //dcos*rcos,dcos*rsin,dsin);
            Vector3 to = (new Vector3(cdcos * crcos, cdcos * crsin, cdsin)).normalized * crad;
            {
                // earth.gameObject.transform.localRotation = Quaternion.FromToRotation(from.normalized, to.normalized);
                Quaternion q;
                Vector3    a1 = Vector3.Cross(to.normalized, from.normalized);
                q.x = a1.x;
                q.y = a1.y;
                q.z = a1.z;
                q.w = 1 + Vector3.Dot(to.normalized, from.normalized);
            }
            epole.transform.localPosition     = spole;
            epole.transform.localRotation     = Quaternion.LookRotation(forw);
            indicator.transform.localRotation = Quaternion.LookRotation(from.normalized);
            indicator.transform.localScale    = new Vector3(0.05f, 0.05f, from.magnitude / 10f);
            epole.transform.localScale        = new Vector3(0.05f, 0.05f, sol / 10f);
            // Debug.LogFormat("Sol: {0}",sol);
            // Debug.LogFormat("From: {0}", from);
            // Debug.LogFormat("res: {0}", a *sol*sol+b*sol+c);
            // Debug.Log(forw);
            // Debug.Log(to);
            RotateAnim an   = earth.GetComponent <RotateAnim>();
            Quaternion erot = Quaternion.FromToRotation(from.normalized, to.normalized);
            if (an != null)
            {
                an.SetRotation(erot);
            }
            else
            {
                earth.gameObject.transform.localRotation = erot;
            }
            // Debug.Log("^^^^^^");
        }
        else
        {
            if (epole != null)
            {
                epole.transform.localPosition = Vector3.zero;
                epole.transform.localRotation = Quaternion.identity;
                epole.transform.localScale    = new Vector3(0.05f, 0.05f, 0.01f);
            }
            RotateAnim an   = earth.GetComponent <RotateAnim>();
            Quaternion erot = Quaternion.identity;
            if (an != null)
            {
                an.SetRotation(erot);
            }
            else
            {
                earth.gameObject.transform.localRotation = erot;
            }
        }
    }