Пример #1
0
 // Update is called once per frame
 void Update()
 {
     applyTorque();
     if (forcetype == forcegen.Gravity)
     {
         AddForce(ForceGenerator.GenerateForce_Gravity(Mass, kGravity, Vector2.up));
     }
     if (forcetype == forcegen.Normal)
     {
         AddForce(ForceGenerator.GenerateForce_Normal(ForceGenerator.GenerateForce_Gravity(Mass, kGravity, Vector2.up), surfaceNormalUnit));
     }
     if (forcetype == forcegen.Sliding)
     {
         AddForce(ForceGenerator.GenerateForce_Sliding(ForceGenerator.GenerateForce_Gravity(Mass, kGravity, Vector2.up), ForceGenerator.GenerateForce_Normal(ForceGenerator.GenerateForce_Gravity(Mass, kGravity, Vector2.up), surfaceNormalUnit)));
     }
     if (forcetype == forcegen.Friction_Static)
     {
         AddForce(ForceGenerator.GenerateForce_Friction_Static(ForceGenerator.GenerateForce_Normal(ForceGenerator.GenerateForce_Gravity(Mass, kGravity, Vector2.up), surfaceNormalUnit), f_opposing, frictionCoefficientStatic));
     }
     if (forcetype == forcegen.Friction_Kinetic)
     {
         AddForce(ForceGenerator.GenerateForce_Friction_Kinetic(ForceGenerator.GenerateForce_Normal(ForceGenerator.GenerateForce_Gravity(Mass, kGravity, Vector2.up), surfaceNormalUnit), velocity, frictionCoefficientKinetic));
     }
     if (forcetype == forcegen.Drag)
     {
         AddForce(ForceGenerator.GenerateForce_Sliding(ForceGenerator.GenerateForce_Gravity(Mass, kGravity, Vector2.up), ForceGenerator.GenerateForce_Normal(ForceGenerator.GenerateForce_Gravity(Mass, kGravity, Vector2.up), surfaceNormalUnit)));
         AddForce(ForceGenerator.GenerateForce_Drag(velocity, fluidVelocity, fluidDensity, objectAreaCrossSection, objectDragCoefficient));
     }
     if (forcetype == forcegen.Spring)
     {
         //AddForce(ForceGenerator.GenerateForce_Spring(position, anchorPosition, springRestingLength,springStiffnessCoefficient));
         AddForce(ForceGenerator.GenerateForce_Gravity(Mass, kGravity, Vector2.up));
         AddForce(ForceGenerator.GenerateForce_Spring(position, -position, springRestingLength, springStiffnessCoefficient));
     }
     if (forcetype == forcegen.None)
     {
     }
     if (forcetype == forcegen.SphereRoll)
     {
         AddForce(ForceGenerator.GenerateForce_Gravity(Mass, kGravity, Vector2.up));
         AddForce(ForceGenerator.GenerateForce_Normal(ForceGenerator.GenerateForce_Gravity(Mass, kGravity, Vector2.up), surfaceNormalUnit));
         AddForce(ForceGenerator.GenerateForce_Friction_Static(ForceGenerator.GenerateForce_Normal(ForceGenerator.GenerateForce_Gravity(Mass, kGravity, Vector2.up), surfaceNormalUnit), f_opposing, frictionCoefficientStatic));
     }
 }
Пример #2
0
    void UpdateForce()
    {
        // Lab 2 Step 3
        //f_gravity = f = mg = ma
        Vector3 f_gravity = forces.mass * new Vector3(0.0f, -9.8f);

        Vector3 f_normal = ForceGenerator.GenerateForce_Normal(f_gravity, transform.up);

        // AddForce(f_gravity); // works
        if (forces.generateGravity)
        {
            AddForce(ForceGenerator.GenerateForce_Gravity(forces.mass, -9.8f, Vector3.up));
        }

        if (forces.generateNormal)
        {
            AddForce(ForceGenerator.GenerateForce_Normal(f_gravity, forces.surfaceNormal_unit)); // works? more testing (surface normal is 0, 1)
        }
        if (forces.generateSliding)
        {
            AddForce(ForceGenerator.GenerateForce_Sliding(f_gravity, f_normal));  // (surface normal is 0,1)
        }
        if (forces.generateStaticsFriction)
        {
            AddForce(ForceGenerator.GenerateForce_Friction_Static(f_normal, forces.frictionOpposingForce, forces.frictionCoeff_static)); // works (surface normal is 1,1) FOF = (-3,0) FCS = 0.9
        }
        if (forces.generateKineticFriction)
        {
            AddForce(ForceGenerator.GenerateForce_Friction_Kinetic(f_normal, particle3DTransform.velocity, forces.frictionCoeff_kinetic));  // works surface = (1,1) initVel = 15 FCK = 0.3
        }
        if (forces.generateDrag)
        {
            AddForce(ForceGenerator.GenerateForce_Drag(particle3DTransform.velocity, forces.fluidVelocity, forces.fluidDensity, forces.objArea_CrossSection, forces.objDragCoeff));  // not sure if this works ask dan... IV = 1, FV = 1, FD = 1, OACS = 1.5, ODC=1.05
        }
        if (forces.generateSpring && particle3DTransform.position.magnitude != 0)
        {
            AddForce(ForceGenerator.GenerateForce_Spring(particle3DTransform.position, forces.anchorPos, forces.springRestingLength, forces.springStiffnesCoeff)); // pos = 0,100 , AP = 0,0 , SRL = 0.1, SSC = 3 , fricCoKin = 0.15 (turn on gravity and kin fric
        }
        AddForce(forces.basicForce);
    }
Пример #3
0
    private void FixedUpdate()
    {
        switch (positionType)
        {
        case PosIntegrationType.EulerExplicit:
            UpdatePositionEulerExplicit(Time.fixedDeltaTime);
            break;

        default:
            UpdatePositionKinematic(Time.fixedDeltaTime);
            break;
        }

        switch (rotationType)
        {
        case RotIntegrationType.EulerExplicit:
            UpdateRotationEulerExplicit(Time.fixedDeltaTime);
            break;

        default:
            UpdateRotationKinematic(Time.fixedDeltaTime);
            break;
        }

        //lab03
        UpdateAngularAcceleration();
        UpdateAcceleration();

        transform.position = position;

        Vector2 gravitationalForce   = ForceGenerator.GenerateForce_Gravity(mass, -9.8f, Vector2.up);
        Vector2 normalForce          = ForceGenerator.GenerateForce_Normal(-gravitationalForce, testFloor.transform.up);
        Vector2 slideForce           = ForceGenerator.GenerateForce_Sliding(gravitationalForce, normalForce);
        Vector2 frictionForce        = ForceGenerator.GenerateForce_Friction(normalForce, slideForce, velocity, frictionStatic, frictionKinetic);
        Vector2 dragForce            = ForceGenerator.GenerateForce_Drag(velocity, new Vector2(0.2f, 0.0f), 10.0f, 10.0f, 4.0f);
        Vector2 springForce          = ForceGenerator.GenerateForce_Spring(transform.position, testSpringAnchor.position, springRestingLength, springStrength * springStrength);
        Vector2 springDampForce      = ForceGenerator.GenerateForce_SpringDamping(mass, velocity, springStrength, 5.0f);
        Vector2 springMaxLengthForce = ForceGenerator.GenerateForce_SpringWithMax(transform.position, testSpringAnchor.position, springRestingLength, springStrength * springStrength, maxSpringLength);

        switch (forceType)
        {
        case ForceType.gravity:
            AddForce(gravitationalForce);
            break;

        case ForceType.normal:
            AddForce(normalForce);
            break;

        case ForceType.slide:
            AddForce(slideForce);
            break;

        case ForceType.friction:
            AddForce(slideForce);
            AddForce(frictionForce);
            break;

        case ForceType.drag:
            AddForce(dragForce);
            break;

        case ForceType.spring:
            AddForce(springForce);
            break;

        case ForceType.springDamping:
            AddForce(springForce);
            AddForce(springDampForce);
            AddForce(gravitationalForce);
            break;

        case ForceType.springWithMaxLength:
            AddForce(springMaxLengthForce);
            AddForce(springDampForce);
            AddForce(gravitationalForce);
            break;

        case ForceType.none:
            //Debug.Log("We ain't movin chief.");
            break;

        default:
            AddForce(gravitationalForce);
            break;
        }

        //lab03
        ApplyTorque(pointApplied, forceApplied);

        //clamps rotation to 360
        SetRotation(rotation %= 360.0f);
        rotAcceleration       = angularAccel;
    }
Пример #4
0
    /*
     *  Lab 1
     *  Integrate user friendly menu.
     */
    // Get selectable items from the inspector menu.
    private void GetInspectorItems()
    {
        /*
         *  Lab 1 Step 3
         */

        // Integrate.
        if (positionType == PositionType.Euler)
        {
            UpdatePositionEulerExplicit(Time.fixedDeltaTime);
        }
        else if (positionType == PositionType.Kinematic)
        {
            UpdatePositionKinematic(Time.fixedDeltaTime);
        }

        if (rotationType == RotationType.Euler)
        {
            UpdateRotationEulerExplicit(Time.fixedDeltaTime);
        }
        else if (rotationType == RotationType.Kinematic)
        {
            UpdateRotationKinematic(Time.fixedDeltaTime);
        }

        if (gravityActive)
        {
            // Gravity force.
            AddForce(ForceGenerator.GenerateForce_Gravity(mass, GRAVITY, Vector2.up));
        }

        if (springActive)
        {
            // Spring force.
            AddForce(ForceGenerator.GenerateForce_Spring(springAnchor.position, transform.position, springRestLength, springStiffness));
        }

        if (staticFrictionActive)
        {
            // Static friction force.
            AddForce(ForceGenerator.GenerateForce_Friction_Static(staticFrictionNormal, staticFrictionOpposingForce, staticFrictionCoefficient));
        }

        if (kinematicFrictionActive)
        {
            // Kinematic friction force.
            AddForce(ForceGenerator.GenerateForce_Friction_Kinetic(kinematicNormalForce, velocity, kinematicFrictionCoefficient));
        }

        if (slidingActive)
        {
            // Sliding force.
            AddForce(ForceGenerator.GenerateForce_Sliding(ForceGenerator.GenerateForce_Gravity(mass, GRAVITY, worldUp), slidingNormalForce));
        }

        if (dragActive)
        {
            // Drag force.
            AddForce(ForceGenerator.GenerateForce_Drag(velocity, fluidVelocity, fluidDensity, objectCrossSection, dragCoefficient));
        }

        if (normalActive)
        {
            // Normal force.
            AddForce(ForceGenerator.GenerateForce_Normal(ForceGenerator.GenerateForce_Gravity(mass, GRAVITY, worldUp), surfaceNormal));
        }

        if (dampingSpringActive)
        {
            // Damping spring force.
            AddForce(ForceGenerator.GenerateForce_Spring_Damping(position, springAnchor.position, springRestLength, springStiffness, springDamping, springConstant, velocity));
        }

        return;
    }