示例#1
0
    public void ScaleNonUniform(GameObject pointOfCollision, Vector3 direction)
    {
        connectedModelingObject.CalculateBoundingBox();
        connectedModelingObject.boundingBox.DrawBoundingBox();

        //	Vector3 normalizedDirection = direction.normalized;

        float input = CalculateInputFromPoint(pointOfCollision.transform.position, transform.position, transform.position + transform.forward);

        // get current distance
        switch (typeOfHandle)
        {
        case handle.handleType.ScaleX:
            centerOfScaling      = connectedModelingObject.transform.InverseTransformPoint(connectedModelingObject.GetBoundingBoxLeftCenter());
            touchPointForScaling = connectedModelingObject.transform.InverseTransformPoint(connectedModelingObject.GetBoundingBoxRightCenter());
            break;

        case handle.handleType.ScaleY:
            centerOfScaling      = connectedModelingObject.transform.InverseTransformPoint(connectedModelingObject.GetBoundingBoxBottomCenter());
            touchPointForScaling = connectedModelingObject.transform.InverseTransformPoint(connectedModelingObject.GetBoundingBoxTopCenter());
            break;

        case handle.handleType.ScaleZ:
            centerOfScaling      = connectedModelingObject.transform.InverseTransformPoint(connectedModelingObject.GetBoundingBoxFrontCenter());
            touchPointForScaling = connectedModelingObject.transform.InverseTransformPoint(connectedModelingObject.GetBoundingBoxBackCenter());
            break;

        case handle.handleType.ScaleMinusX:
            centerOfScaling      = connectedModelingObject.transform.InverseTransformPoint(connectedModelingObject.GetBoundingBoxRightCenter());
            touchPointForScaling = connectedModelingObject.transform.InverseTransformPoint(connectedModelingObject.GetBoundingBoxLeftCenter());
            break;

        case handle.handleType.ScaleMinusY:
            centerOfScaling      = connectedModelingObject.transform.InverseTransformPoint(connectedModelingObject.GetBoundingBoxTopCenter());
            touchPointForScaling = connectedModelingObject.transform.InverseTransformPoint(connectedModelingObject.GetBoundingBoxBottomCenter());
            break;

        case handle.handleType.ScaleMinusZ:
            centerOfScaling      = connectedModelingObject.transform.InverseTransformPoint(connectedModelingObject.GetBoundingBoxBackCenter());
            touchPointForScaling = connectedModelingObject.transform.InverseTransformPoint(connectedModelingObject.GetBoundingBoxFrontCenter());
            break;
        }

        if (newScaling)
        {
            prevScalingAmount = input;
            newScaling        = false;
        }

        //input = Mathf.SmoothDamp(prevScalingAmount, input, ref velocity, smoothTime);

        // check if we can also raster just the touchpoint
        centerOfScaling = RasterManager.Instance.Raster(centerOfScaling);

        //touchPointForScaling = RasterManager.Instance.Raster(touchPointForScaling);

        float RasteredDistanceCenters = Mathf.Max(RasterManager.Instance.Raster((centerOfScaling - touchPointForScaling).magnitude * Mathf.Abs(1f + (input - prevScalingAmount))), RasterManager.Instance.rasterLevel * 2);

        input = (RasteredDistanceCenters / ((centerOfScaling - touchPointForScaling).magnitude)) - 1f + prevScalingAmount;

        float adjustedInput = Mathf.Abs(1f + (input - prevScalingAmount));

        connectedModelingObject.ScaleNonUniform(adjustedInput, direction.normalized, typeOfHandle, centerOfScaling);

        // correct center if object is off grid
        // check how far off grid
        //Vector3 center = connectedModelingObject.transform.InverseTransformPoint(connectedModelingObject.GetBoundingBoxCenter());
        //Vector3 correctedCenter = RasterManager.Instance.Raster(center);

        //connectedModelingObject.transform.localPosition = connectedModelingObject.transform.localPosition + (correctedCenter-center);

        prevScalingAmount = input;
    }