Exemple #1
0
/*------------------------------------------------------------------------------------------------------------------
 * -- FUNCTION: calculateInertiaTotals
 * --
 * -- DATE: January 11, 2018
 * --
 * -- DESIGNER:   Michael Goll
 * --
 * -- PROGRAMMER: Michael Goll
 * --
 * -- NOTES:
 * -- Calls the physics helper function that calculates the inertia totals for all the objects and
 * --     stores them in the appropriate data array.
 * ----------------------------------------------------------------------------------------------------------------------*/
    private void calculateInertiaTotals()
    {
        it_boat   = PhysicsCalculator.calculateInertiaTotal(moi_boat, mh_boat);
        it_pilot  = PhysicsCalculator.calculateInertiaTotal(moi_pilot, mh_pilot);
        it_cannon = PhysicsCalculator.calculateInertiaTotal(moi_cannon, mh_cannon);
        it_com    = PhysicsCalculator.calculateCombined(it_boat, it_pilot, it_cannon);
    }
Exemple #2
0
/*------------------------------------------------------------------------------------------------------------------
 * -- FUNCTION: calculateMH
 * --
 * -- DATE: January 11, 2018
 * --
 * -- DESIGNER:   Michael Goll
 * --
 * -- PROGRAMMER: Michael Goll
 * --
 * -- NOTES:
 * -- Calls the physics helper function that calculates the moment of inertia for all the objects and
 * --     stores them in the appropriate data array.
 * ----------------------------------------------------------------------------------------------------------------------*/
    private void calculateMomentOfInertia()
    {
        moi_boat   = PhysicsCalculator.calculateMOI(boat.getMass(), boat.getXDim(), boat.getZDim());
        moi_pilot  = PhysicsCalculator.calculateMOI(pilot.getMass(), pilot.getXDim(), pilot.getZDim());
        moi_cannon = PhysicsCalculator.calculateMOI(cannon.getMass(), cannon.getXDim(), cannon.getZDim());
        moi_com    = PhysicsCalculator.calculateCombined(moi_boat, moi_pilot, moi_cannon);
    }
Exemple #3
0
/*------------------------------------------------------------------------------------------------------------------
 * -- FUNCTION: calculateMH
 * --
 * -- DATE: January 11, 2018
 * --
 * -- DESIGNER:   Michael Goll
 * --
 * -- PROGRAMMER: Michael Goll
 * --
 * -- NOTES:
 * -- Calls the physics helper function that calculates the MH values for all the objects and
 * --     stores them in the appropriate data array.
 * ----------------------------------------------------------------------------------------------------------------------*/
    private void calculateMH()
    {
        mh_boat   = PhysicsCalculator.calculateMH(h_boat, mass_boat);
        mh_pilot  = PhysicsCalculator.calculateMH(h_pilot, mass_pilot);
        mh_cannon = PhysicsCalculator.calculateMH(h_cannon, mass_cannon);
        mh_com    = PhysicsCalculator.calculateCombined(mh_boat, mh_pilot, mh_cannon);
    }
Exemple #4
0
/*------------------------------------------------------------------------------------------------------------------
 * -- FUNCTION: calculateInertiaTotals
 * --
 * -- DATE: January 11, 2018
 * --
 * -- DESIGNER:   Michael Goll
 * --
 * -- PROGRAMMER: Michael Goll
 * --
 * -- NOTES:
 * -- Calls the physics helper function that calculates the inertia totals for all the objects and
 * --     stores them in the appropriate data array.
 * ----------------------------------------------------------------------------------------------------------------------*/
    private void calculateInertiaTotals()
    {
        it_boat   = PhysicsCalculator.calculateInertiaTotal(moi_boat, mh_boat);
        it_pilot  = PhysicsCalculator.calculateInertiaTotal(moi_pilot, mh_pilot);
        it_cannon = PhysicsCalculator.calculateInertiaTotal(moi_cannon, mh_cannon);
        it_com    = PhysicsCalculator.calculateCombined(it_boat, it_pilot, it_cannon);

        boatFloats[8]   = it_boat;
        pilotFloats[8]  = it_pilot;
        cannonFloats[8] = it_cannon;
        comFloats[8]    = it_com;
    }
Exemple #5
0
/*------------------------------------------------------------------------------------------------------------------
 * -- FUNCTION: calculateMH
 * --
 * -- DATE: January 11, 2018
 * --
 * -- DESIGNER:   Michael Goll
 * --
 * -- PROGRAMMER: Michael Goll
 * --
 * -- NOTES:
 * -- Calls the physics helper function that calculates the MH values for all the objects and
 * --     stores them in the appropriate data array.
 * ----------------------------------------------------------------------------------------------------------------------*/
    private void calculateMH()
    {
        mh_boat   = PhysicsCalculator.calculateMH(h_boat, mass_boat);
        mh_pilot  = PhysicsCalculator.calculateMH(h_pilot, mass_pilot);
        mh_cannon = PhysicsCalculator.calculateMH(h_cannon, mass_cannon);
        mh_com    = PhysicsCalculator.calculateCombined(mh_boat, mh_pilot, mh_cannon);

        boatFloats[3]   = mh_boat;
        pilotFloats[3]  = mh_pilot;
        cannonFloats[3] = mh_cannon;
        comFloats[3]    = mh_com;
    }
Exemple #6
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()
    {
        mass_boat   = boat.getMass();
        mass_pilot  = pilot.getMass();
        mass_cannon = cannon.getMass();
        mass_com    = PhysicsCalculator.calculateCombined(mass_boat, mass_pilot, mass_cannon);

        boatFloats[0]   = mass_boat;
        pilotFloats[0]  = mass_pilot;
        cannonFloats[0] = mass_cannon;
        comFloats[0]    = mass_com;

        loadBoatFloats();
        loadPilotFloats();
        loadCannonFloats();

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

        comPoint.SetVector("_COMPosition", new Vector3(comX, 0, comZ));
    }
Exemple #7
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;
        }
    }
Exemple #8
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()
    {
        //Pause/unpause simulation
        if (Input.GetKeyDown(KeyCode.Space))
        {
            moving = !moving;
        }

        //Forward Thrust
        if (Input.GetKeyDown(KeyCode.W))
        {
            force = 4000;
        }

        //Release forward thrust
        if (Input.GetKeyUp(KeyCode.W))
        {
            force = 0;
        }

        //Left torque
        if (Input.GetKeyDown(KeyCode.Q))
        {
            rotLeft  = true;
            rotRight = false;

            turnForce = -1000;
        }

        //Right torque
        if (Input.GetKeyDown(KeyCode.E))
        {
            rotRight = true;
            rotLeft  = false;

            turnForce = 1000;
        }

        //Release directional torque
        if (Input.GetKeyUp(KeyCode.E) || Input.GetKeyUp(KeyCode.Q))
        {
            rotRight = false;
            rotLeft  = false;

            turnForce = 0;
        }

        if (initial)
        {
            //Initialize objects to access attributes
            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));
            initial = false;
        }
    }