Exemplo n.º 1
0
    public void updateForce(MyParticle particle, float duration)
    {
        // Calculate spring vector
        MyVector3 force;

        force = particle.getPosition();
        force.SubtractVectorFromThisVector(other.getPosition());

        //Check is the bungie is compressed
        // if bungie is compressed break out of the method without adding a force
        float magnitude = force.magnitude();


        if (magnitude < restLength)
        {
            return;
        }
        else if (magnitude > restLength)
        {
            //Everything after this comment will happen if the if condition isn't true
            //Calculate the magnitude of the force
            magnitude = springConstant * (restLength - magnitude);
            //magnitude = springConstant * (magnitude-restLength);

            //Calculate the final force and apply it
            force.normalize();
            force.multiplyVectorByScalar(magnitude);
            particle.addForce(force);
        }
        else
        {
            return;
        }
    }
    public void updateForce(MyParticle particle, float duration)
    {
        //checking if particle has infinite mass
        if (!particle.hasFiniteMass())
        {
            return;
        }

        //calculates position of the particle relative to the anchor
        MyVector3 position;

        position = particle.getPosition();
        position.SubtractVectorFromThisVector(this.anchor);

        //Calculate constants and check whether they are in bounds
        float gamma = 0.5f * Mathf.Sqrt(4 * springConstant - damping * damping);

        if (gamma == 0.0f)
        {
            return;
        }

        MyVector3 c = position.multiplyVectorByScalarVR(damping / (2.0f * gamma)).returnAddVectorToThisVector(particle.getVelocity().multiplyVectorByScalarVR(1.0f / gamma));

        //Calculate the target position
        MyVector3 target = position.multiplyVectorByScalarVR(Mathf.Cos(gamma * duration)).returnAddVectorToThisVector(c.multiplyVectorByScalarVR(Mathf.Sin(gamma * duration)));

        target.multiplyVectorByScalar(Mathf.Exp(-0.5f * duration * damping));

        //Calculate resulting acceration and force
        MyVector3 accel = (target.returnSubtractVectorFromThisVector(position)).multiplyVectorByScalarVR(1.0f / (duration * duration)).returnSubtractVectorFromThisVector(particle.getVelocity().multiplyVectorByScalarVR(duration));

        particle.addForce(accel.multiplyVectorByScalarVR(particle.getMass()));
    }
    void FixedUpdate()
    {
        float duration = Time.fixedUnscaledDeltaTime;

        testReg.updateForces(duration);
        //grav2.updateForce (part2, duration);
        part.integrate();
        part2.integrate();
        Debug.Log(_gobject.transform.position);

        _gobject.transform.position = part2.position.convertToVector3();
        GameObject.Find("Green Sphere(Clone)").transform.position = part.position.convertToVector3();
        Debug.Log(_gobject.transform.position);
        print("registry particle position: " + testReg.getParticleAtIndex(0).getPosition().getComponentY());
        print("particle position: " + part2.getPosition().getComponentY());
    }
Exemplo n.º 4
0
    public void updateForce(MyParticle particle, float duration)
    {
        // Calculate spring vector
        MyVector3 force;

        force = particle.getPosition();
        force.SubtractVectorFromThisVector(anchor);

        //Calculate the magnitude of the force
        float magnitude = force.magnitude();

        magnitude  = absValue(magnitude - this.restLength);
        magnitude *= springConstant;

        //Calculate the final force and apply it
        force.normalize();
        force.multiplyVectorByScalar(-1 * magnitude);
        particle.addForce(force);
    }
    //I might come back and add some get and set methods to modify volume and waterHeight

    public void updateForce(MyParticle particle, float duration)
    {
        float depth = particle.getPosition().getComponentY();

        //check is object is out of water
        //
        if (depth >= waterHeight + maxDepth)
        {
            return;
        }
        MyVector3 force = new MyVector3(0f, 0f, 0f);

        //check if we're at max depth
        if (depth <= waterHeight - maxDepth)
        {
            force.y = liquidDensity * volume;
            particle.addForce(force);
            return;
        }

        //if the other 2 aren't true we're partially submerged
        force.y = liquidDensity * volume * (depth - maxDepth - waterHeight);
        particle.addForce(force);
    }