Ejemplo n.º 1
0
/*------------------------------------------------------------------------------------------------------------------
 * -- FUNCTION: Update
 * --
 * -- DATE: January 11, 2018
 * --
 * -- DESIGNER:   Michael Goll
 * --
 * -- PROGRAMMER: Michael Goll
 * --
 * -- NOTES:
 * -- Calls helper functions that calculate various attributes.
 * -- Calls helper functions to load data arrays used to display the various attributes to the user.
 * -- Updates the COM Point material to move the com point shader around.
 * ----------------------------------------------------------------------------------------------------------------------*/
    void Update()
    {
        //------- LAB #6 Additions -------
        // acceleration = PhysicsCalculator.calculateAccelerationFromThrust(force, mass_com);

        if (Input.GetKeyDown(KeyCode.Space))
        {
            moving = !moving;
        }

        if (Input.GetKeyDown(KeyCode.W))
        {
            force  = 30000;
            moving = true;
        }

        if (Input.GetKeyUp(KeyCode.W) && dynamicControls)
        {
            force = 0;
        }

        if (Input.GetKeyDown(KeyCode.Q))
        {
            rotLeft  = true;
            rotRight = false;
        }

        if (Input.GetKeyDown(KeyCode.E))
        {
            rotRight = true;
            rotLeft  = false;
        }

        if (initial)
        {
            //------- LAB #1 Originals -------
            pilot  = p.GetComponent <Pilot>();
            boat   = b.GetComponent <Boat>();
            cannon = c.GetComponent <Cannon>();

            mass_boat   = boat.getMass();
            mass_pilot  = pilot.getMass();
            mass_cannon = cannon.getMass();
            mass_com    = PhysicsCalculator.calculateCombined(mass_boat, mass_pilot, mass_cannon);

            calculateMomentOfInertia();
            calculateComValues();
            calculateH();
            calculateMH();
            calculateInertiaTotals();

            comPoint.SetVector("_COMPosition", new Vector3(comX, 0, comZ));

            //------- LAB #6 Additions -------
            acceleration.x = PhysicsCalculator.calculateAccelerationFromThrust(thrust.x, mass_com);
            acceleration.z = PhysicsCalculator.calculateAccelerationFromThrust(thrust.z, mass_com);

            rLeft.x = 2 - comX;
            rLeft.y = 0;
            rLeft.z = -4 - comZ;

            rRight.x = -2 - comX;
            rRight.y = 0;
            rRight.z = -4 - comZ;

            torqueL = PhysicsCalculator.calculateCrossProd(new Vector3(thrustAngle.x, 0, thrustAngle.z), rLeft);
            torqueR = PhysicsCalculator.calculateCrossProd(new Vector3(thrustAngle.x, 0, thrustAngle.z), rRight);

            accelerationL = PhysicsCalculator.calculateAngularAcceleration(torqueL.y, it_com);
            accelerationR = PhysicsCalculator.calculateAngularAcceleration(torqueR.y, it_com);

            initial = false;
        }
    }