Example #1
0
    public override void handleDragEvent(DragEvent e)
    {
        if (e.state == DragState.DRAG)
        {
            float dBaseX = (float)e.getParam(ClickAndDragRotate.PARAM_D_ROTATION_X);
            float dBaseY = (float)e.getParam(ClickAndDragRotate.PARAM_D_ROTATION_Y);
            float dBaseZ = (float)e.getParam(ClickAndDragRotate.PARAM_D_ROTATION_Z);

            float dX = (dXPerDBaseX * dBaseX) + (dXPerDBaseY * dBaseY) + (dXPerDBaseZ * dBaseZ);
            float dY = (dYPerDBaseX * dBaseX) + (dYPerDBaseY * dBaseY) + (dYPerDBaseZ * dBaseZ);
            float dZ = (dZPerDBaseX * dBaseX) + (dZPerDBaseY * dBaseY) + (dZPerDBaseZ * dBaseZ);

            Vector3 newR = getNewRotation(dX, dY, dZ);
            toRotate.transform.localRotation = Quaternion.Euler(newR);
        }
    }
Example #2
0
    public override void handleDragEvent(DragEvent e)
    {
        if (e.state != DragState.DRAG || !isDrag)
        {
            return;
        }

        object o = e.getParam(ClickAndDragTranslate.PARAM_DRAG_STRENGTH);

        if (!(o is Vector3))
        {
            throw new Exception("Expected velocity to be of type Vector3");
        }

        Vector3 v = (Vector3)o;

        // This finds the length of the component of v which is parallel to maxVelocity
        float speed = Vector3.Dot(v, maxVelocity.normalized);

        Vector3 force = maxVelocity.normalized * speed;

        force = force * maxVelocity.magnitude;
        if (capForce > 0 && force.magnitude > capForce)
        {
            force = force.normalized * capForce;
        }
        child.constantForce.force = transform.TransformDirection(force);
    }
Example #3
0
    public override void handleDragEvent(DragEvent e)
    {
        if (e.state == DragState.DRAG)
        {
            if (handle.constantForce.force.x < 0 && prevForce.x > 0)
            {
                handleBang.Play();
            }

            prevForce = handle.constantForce.force;
        }

        Vector3 v = (Vector3)e.getParam(ClickAndDragTranslate.PARAM_VELOCITY);

        if (v.magnitude >= MIN_V_TRIGGER)
        {
            strengthenSlide();
        }

        if (v.magnitude == 0)
        {
            if (startRest == -1)
            {
                startRest = Time.time;
            }
            else if (Time.time - startRest >= MIN_REST_TRIGGER)
            {
                stopSlide();
            }
        }
        else
        {
            startRest = -1;

            // check for "impact" in the x direction
            Vector3 newP        = (Vector3)e.getParam(ClickAndDragTranslate.PARAM_NEW_P);
            Vector3 desiredNewP = (Vector3)e.getParam(ClickAndDragTranslate.PARAM_DESIRED_NEW_P);
            if (newP.x != desiredNewP.x)
            {
                drawerBang.volume = Mathf.Clamp(v.magnitude / 50, 0.0f, 1.0f);
                drawerBang.Play();
            }
        }
    }