コード例 #1
0
 // Start is called before the first frame update
 void Start()
 {
     particles = new ParticleGPU[maxParticles];
     for (int i = 0; i < particles.Length; i++)
     {
         Vector3 randompos = new Vector3(Random.Range(-3, 3), Random.Range(-3, 3), Random.Range(-3, 3));
         particles[i] = new ParticleGPU(transform.position + randompos, -randompos, Random.Range(minMass, maxMass));
     }
 }
コード例 #2
0
    /// <summary>
    /// Assigns velocity to particle b from particle a's kinetic energy
    /// </summary>
    /// <param name="a">Query particle</param>
    /// <param name="b">Collided particle</param>
    void Collide(ParticleGPU a, ParticleGPU b)
    {
        Vector3 energyAone = (1 / 2) * a.mass * Vector3.Scale(a.velocity, a.velocity);
        Vector3 energyBtwo = (1 / 2) * b.mass * Vector3.Scale(b.velocity, b.velocity);
        Vector3 squaredVel = (a.mass / b.mass) * Vector3.Scale(a.velocity, a.velocity);

        b.velocity = new Vector3(Mathf.Sqrt(squaredVel.x), Mathf.Sqrt(squaredVel.y), Mathf.Sqrt(squaredVel.z));
        SolvedVel  = b.velocity;
    }
コード例 #3
0
    void Collide(ParticleGPU a, SurfaceCollider s)
    {
        Vector3 energyA = (1 / 2) * a.mass * -a.velocity;

        a.velocity = -a.velocity * 10;
    }