예제 #1
0
    virtual public MultimeshObject Simulate()
    {
        int                  emittedPhotons = Mathf.RoundToInt(emissionRate * duration);
        MultimeshObject      ret            = new MultimeshObject();
        List <ScatterPhoton> emitted        = new List <ScatterPhoton>();

        Debug.LogFormat("Emitted track photons: {0} ", emittedPhotons);
        for (int i = 0; i < emittedPhotons; i++)
        {
            float   emitTime = (float)RandomGen3.NextDouble() * duration;
            Vector3 ppos     = emitTime * speed * direction + initialPos;
            emitted.Add(EmitCherenkovPhoton(ppos, emitTime));
            if (emitted.Count >= 16384)
            {
                ret.meshes.AddRange(PhotonsToMesh(emitted).meshes);
                emitted.Clear();
            }
        }
        ret.meshes.AddRange(PhotonsToMesh(emitted).meshes);
        if (energyLosses != null)
        {
            foreach (CascadeData dat in energyLosses)
            {
                emitted = dat.Emit(0.02f);
                ret.meshes.AddRange(PhotonsToMesh(emitted).meshes);
            }
        }
        Debug.LogFormat("Total meshes: {0} ", ret.meshes.Count);
        return(ret);
    }
예제 #2
0
    public List <ScatterPhoton> Emit(float duration)
    {
        List <ScatterPhoton> ret = new List <ScatterPhoton>();

        // Debug.LogFormat("Emitting energy {0}",energy);
        for (int i = 0; i < energy; i++)
        {
            Vector3 emitPos = location + radius * TrailmeshMaker.onUnitSphere();
            Vector3 perp    = new Vector3(-directionPreference.y, directionPreference.x, 0);
            if (directionPreference.z > 0.9)
            {
                perp = new Vector3(0, directionPreference.z, -directionPreference.y);
            }
            Quaternion rt = Quaternion.AngleAxis((float)RandomGen3.NextDouble() * 360, directionPreference);
            perp = (rt * perp).normalized;
            float         angl = Mathf.PI * (1 - directionBias) * (float)RandomGen3.NextDouble();
            Vector3       dir  = (directionPreference * Mathf.Cos(angl) + perp * Mathf.Sin(angl)).normalized;
            ScatterPhoton pht  = new ScatterPhoton();
            // Debug.LogFormat("Derection:{0} {1}", dir, angl);
            pht.direction  = dir;
            pht.position   = emitPos;
            pht.timeOffset = timeOffset + duration * (float)RandomGen3.NextDouble();
            ret.Add(pht);
        }
        //  Debug.LogFormat("Emitted energy {0}", energy);
        return(ret);
    }
예제 #3
0
        /// <summary>
        /// 获取随机的姓名
        /// </summary>
        public static string NextSurName()
        {
            string xing   = Xings[Random(0, Xings.Length)];
            string name   = string.Empty;
            int    length = RandomGen3.NextDouble() > 0.3 ? 2 : 1;

            for (int i = 0; i < length; i++)
            {
                name += Mings[Random(0, Mings.Length)];
            }
            return(xing + name);
        }
예제 #4
0
    public static float DrawExp(float ilam)
    {
        if (ilam <= 0)
        {
            ilam = 0.01f;
        }
        float ran = (float)RandomGen3.NextDouble();

        float ret = -Mathf.Log(1.0f - ran) * ilam;

        if (ret > ilam * 10000)
        {
            return(ilam * 10000);
        }
        return(ret);
    }
예제 #5
0
 static public Vector3 onUnitSphere()
 {
     while (true)
     {
         double  theta = 2 * Math.PI * RandomGen3.NextDouble();
         double  phi   = Math.Acos(1 - 2 * RandomGen3.NextDouble());
         double  x     = Math.Sin(phi) * Math.Cos(theta);
         double  y     = Math.Sin(phi) * Math.Sin(theta);
         double  z     = Math.Cos(phi);
         Vector3 vct   = new Vector3((float)x, (float)y, (float)z);// (float)(rndgen.NextDouble() * 2 - 1), (float)(rndgen.NextDouble() * 2 - 1), (float)(rndgen.NextDouble() * 2 - 1));
         var     mag   = vct.magnitude;
         if (mag <= 1.000001 && mag > 0.0001f)
         {
             return(vct / mag);
         }
         // Debug.LogFormat("Rejected {0}", vct);
     }
 }
예제 #6
0
    public void Propagate(float absorbtion, float scatter)// scatter length
    {
        float distance = TrailmeshMaker.DrawExp(scatter);
        //Debug.LogFormat("Ran: {0} {1} {2}", distance, absorbtion, scatter);
        float dur       = distance / speed;
        float decayprob = 1.0f - Mathf.Exp(-distance / absorbtion);

        prevPosition = position;
        prevTime     = timeOffset;
        position     = position + direction * distance;
        timeOffset  += dur;
        if (RandomGen3.NextDouble() <= decayprob)
        {
            decayed = true;
            return;
        }
        direction = TrailmeshMaker.Scatter(direction);
    }
예제 #7
0
    // Start is called before the first frame update

    public static Vector3 Scatter(Vector3 inc)
    {
        int cnt = 0;

        while (true)
        {
            Vector3 rd   = onUnitSphere();
            float   prob = scatterdirprob(inc, rd);

            if (prob >= RandomGen3.NextDouble() * 40)
            {
                //Debug.LogFormat("Prob: {0}",prob);
                return(rd);
            }
            if (cnt > 100)
            {
                return(inc);
            }
            cnt += 1;
        }
    }
예제 #8
0
    ScatterPhoton EmitCherenkovPhoton(Vector3 pos, float timeOffset)
    {
        float   shift = (float)RandomGen3.NextDouble();
        Vector3 perp  = new Vector3(-direction.y, direction.x, 0);

        if (Mathf.Abs(direction.z) > 0.9)
        {
            perp = new Vector3(0, direction.z, -direction.y);
        }
        Quaternion rt = Quaternion.AngleAxis(shift * 360, direction);

        perp  = rt * perp;
        perp /= perp.magnitude;
        Vector3       photondir = direction * cos41 + perp * sin41;
        ScatterPhoton ret       = new ScatterPhoton();

        ret.direction  = photondir;
        ret.position   = pos;
        ret.timeOffset = timeOffset;
        //ret.Propagate(IcecubeDust.getAbsorption(pos), IcecubeDust.getScatter(pos));
        return(ret);
    }
예제 #9
0
 /// <summary>
 /// 获取随机的民族
 /// </summary>
 public static string NextNationName()
 {
     return(RandomGen3.NextDouble() > 0.5 ? "汉族" : NationNames[Random(0, NationNames.Length)]);
 }