Exemple #1
0
    public override void FromXML(XmlNodeList nodes)
    {
        Clear();
        foreach (XmlNode node in nodes)
        {
            CameraPathFOV newCameraPathPoint = gameObject.AddComponent <CameraPathFOV>();//CreateInstance<CameraPathFOV>();
            newCameraPathPoint.hideFlags = HideFlags.HideInInspector;
            CameraPathPoint.PositionModes positionModes = (CameraPathPoint.PositionModes)Enum.Parse(typeof(CameraPathPoint.PositionModes), node["positionModes"].FirstChild.Value);
            switch (positionModes)
            {
            case CameraPathPoint.PositionModes.Free:
                CameraPathControlPoint cPointA = cameraPath[int.Parse(node["cpointA"].FirstChild.Value)];
                CameraPathControlPoint cPointB = cameraPath[int.Parse(node["cpointB"].FirstChild.Value)];
                float curvePercentage          = float.Parse(node["curvePercentage"].FirstChild.Value);
                AddPoint(newCameraPathPoint, cPointA, cPointB, curvePercentage);
                break;

            case CameraPathPoint.PositionModes.FixedToPoint:
                CameraPathControlPoint point = cameraPath[int.Parse(node["point"].FirstChild.Value)];
                AddPoint(newCameraPathPoint, point);
                break;
            }
            newCameraPathPoint.FromXML(node, cameraPath);
        }
    }
Exemple #2
0
    private float LinearInterpolation(float percentage)
    {
        int           index  = GetLastPointIndex(percentage);
        CameraPathFOV pointP = (CameraPathFOV)GetPoint(index);
        CameraPathFOV pointQ = (CameraPathFOV)GetPoint(index + 1);

//        if (percentage < pointP.percent)
//            return pointP.FOV;
//        if (percentage > pointQ.percent)
//            return pointQ.FOV;

        float startPercentage = pointP.percent;
        float endPercentage   = pointQ.percent;

        if (startPercentage > endPercentage)
        {
            endPercentage += 1;
        }

        float curveLength     = endPercentage - startPercentage;
        float curvePercentage = percentage - startPercentage;
        float ct = curvePercentage / curveLength;

        return(Mathf.Lerp(pointP.FOV, pointQ.FOV, ct));
    }
Exemple #3
0
    private float SmoothStepInterpolation(float percentage)
    {
        int           index  = GetLastPointIndex(percentage);
        CameraPathFOV pointP = (CameraPathFOV)GetPoint(index);
        CameraPathFOV pointQ = (CameraPathFOV)GetPoint(index + 1);

//        if (percentage < pointP.percent)
//            return pointP.FOV;
//        if (percentage > pointQ.percent)
//            return pointQ.FOV;

        float startPercentage = pointP.percent;
        float endPercentage   = pointQ.percent;

        if (startPercentage > endPercentage)
        {
            endPercentage += 1;
        }

        float curveLength     = endPercentage - startPercentage;
        float curvePercentage = percentage - startPercentage;
        float ct = curvePercentage / curveLength;

//        Debug.DrawLine(cameraPath.GetPathPosition(percentage, true), pointP.worldPosition, Color.blue);
//        Debug.DrawLine(cameraPath.GetPathPosition(percentage, true), pointQ.worldPosition, Color.red);

        return(Mathf.Lerp(pointP.FOV, pointQ.FOV, CPMath.SmoothStep(ct)));
    }
Exemple #4
0
    public void AddFOV(CameraPathControlPoint atPoint)
    {
        CameraPathFOV point = gameObject.AddComponent <CameraPathFOV>();//CreateInstance<CameraPathFOV>();

        point.FOV       = defaultFOV;
        point.hideFlags = HideFlags.HideInInspector;
        AddPoint(point, atPoint);
        RecalculatePoints();
    }
Exemple #5
0
    public CameraPathFOV AddFOV(CameraPathControlPoint curvePointA, CameraPathControlPoint curvePointB, float curvePercetage, float fov)
    {
        CameraPathFOV fovpoint = gameObject.AddComponent <CameraPathFOV>();//CreateInstance<CameraPathFOV>();

        fovpoint.hideFlags = HideFlags.HideInInspector;
        fovpoint.FOV       = fov;
        AddPoint(fovpoint, curvePointA, curvePointB, curvePercetage);
        RecalculatePoints();
        return(fovpoint);
    }
    public void AddFOV(CameraPathControlPoint atPoint)
    {
        CameraPathFOV fovpoint = gameObject.AddComponent <CameraPathFOV>();

        fovpoint.FOV       = defaultFOV;
        fovpoint.Size      = defaultSize;
        fovpoint.hideFlags = HideFlags.HideInInspector;
        AddPoint(fovpoint, atPoint);
        RecalculatePoints();
    }
    public void AddFOV(CameraPathControlPoint atPoint)
    {
        CameraPathFOV cameraPathFOV = base.get_gameObject().AddComponent <CameraPathFOV>();

        cameraPathFOV.FOV  = this.defaultFOV;
        cameraPathFOV.Size = this.defaultSize;
        cameraPathFOV.set_hideFlags(2);
        base.AddPoint(cameraPathFOV, atPoint);
        this.RecalculatePoints();
    }
    public CameraPathFOV AddFOV(CameraPathControlPoint curvePointA, CameraPathControlPoint curvePointB, float curvePercetage, float fov, float size)
    {
        CameraPathFOV cameraPathFOV = base.get_gameObject().AddComponent <CameraPathFOV>();

        cameraPathFOV.set_hideFlags(2);
        cameraPathFOV.FOV  = fov;
        cameraPathFOV.Size = size;
        cameraPathFOV.Size = this.defaultSize;
        base.AddPoint(cameraPathFOV, curvePointA, curvePointB, curvePercetage);
        this.RecalculatePoints();
        return(cameraPathFOV);
    }
    private static void SceneGUIFOVBased()
    {
        DisplayAtPoint();

        CameraPathFOVList fovList     = _cameraPath.fovList;
        Camera            sceneCamera = Camera.current;
        int pointCount = fovList.realNumberOfPoints;

        for (int i = 0; i < pointCount; i++)
        {
            CameraPathFOV fovPoint = fovList[i];
            if (_cameraPath.enableUndo)
            {
                Undo.RecordObject(fovPoint, "Modifying FOV Point");
            }
            if (Vector3.Dot(sceneCamera.transform.forward, fovPoint.worldPosition - sceneCamera.transform.position) < 0)
            {
                continue;
            }

            string pointLabel = fovPoint.displayName;
            pointLabel += "\nvalue: " + fovPoint.FOV.ToString("F1");
            if (fovPoint.positionModes == CameraPathPoint.PositionModes.FixedToPoint)
            {
                pointLabel += "\nat point: " + fovPoint.point.displayName;
            }
            else
            {
                pointLabel += "\nat percentage: " + fovPoint.percent.ToString("F3");
            }

            Handles.Label(fovPoint.worldPosition, pointLabel);
            float pointHandleSize = HandleUtility.GetHandleSize(fovPoint.worldPosition) * HANDLE_SCALE;
            Handles.color = (i == selectedPointIndex) ? _cameraPath.selectedPointColour : _cameraPath.unselectedPointColour;
            if (Handles.Button(fovPoint.worldPosition, Quaternion.identity, pointHandleSize, pointHandleSize, Handles.DotCap))
            {
                ChangeSelectedPointIndex(i);
                GUI.changed = true;
            }

            if (i == selectedPointIndex)
            {
                CPPSlider(fovPoint);
            }
        }
    }
    private float SmoothStepInterpolation(float percentage, CameraPathFOVList.ProjectionType projectionType)
    {
        int           lastPointIndex = base.GetLastPointIndex(percentage);
        CameraPathFOV cameraPathFOV  = (CameraPathFOV)base.GetPoint(lastPointIndex);
        CameraPathFOV cameraPathFOV2 = (CameraPathFOV)base.GetPoint(lastPointIndex + 1);
        float         percent        = cameraPathFOV.percent;
        float         num            = cameraPathFOV2.percent;

        if (percent > num)
        {
            num += 1f;
        }
        float num2 = num - percent;
        float num3 = percentage - percent;
        float val  = num3 / num2;
        float num4 = (projectionType != CameraPathFOVList.ProjectionType.FOV) ? cameraPathFOV.Size : cameraPathFOV.FOV;
        float num5 = (projectionType != CameraPathFOVList.ProjectionType.FOV) ? cameraPathFOV2.Size : cameraPathFOV2.FOV;

        return(Mathf.Lerp(num4, num5, CPMath.SmoothStep(val)));
    }
    private float LinearInterpolation(float percentage, ProjectionType projectionType)
    {
        int           index  = GetLastPointIndex(percentage);
        CameraPathFOV pointP = (CameraPathFOV)GetPoint(index);
        CameraPathFOV pointQ = (CameraPathFOV)GetPoint(index + 1);

        float startPercentage = pointP.percent;
        float endPercentage   = pointQ.percent;

        if (startPercentage > endPercentage)
        {
            endPercentage += 1;
        }

        float curveLength     = endPercentage - startPercentage;
        float curvePercentage = percentage - startPercentage;
        float ct     = curvePercentage / curveLength;
        float valueA = (projectionType == ProjectionType.FOV) ? pointP.FOV : pointP.Size;
        float valueB = (projectionType == ProjectionType.FOV) ? pointQ.FOV : pointQ.Size;

        return(Mathf.Lerp(valueA, valueB, ct));
    }
    private static void AddCPathPoints()
    {
        if (SceneView.focusedWindow != null)
        {
            SceneView.focusedWindow.wantsMouseMove = true;
        }

        Handles.color = _cameraPath.selectedPointColour;
        CameraPathPointList pointList = null;

        switch (_pointMode)
        {
        case CameraPath.PointModes.AddOrientations:
            pointList = _cameraPath.orientationList;
            break;

        case CameraPath.PointModes.AddFovs:
            pointList = _cameraPath.fovList;
            break;

        case CameraPath.PointModes.AddTilts:
            pointList = _cameraPath.tiltList;
            break;

        case CameraPath.PointModes.AddEvents:
            pointList = _cameraPath.eventList;
            break;

        case CameraPath.PointModes.AddSpeeds:
            pointList = _cameraPath.speedList;
            break;

        case CameraPath.PointModes.AddDelays:
            pointList = _cameraPath.delayList;
            break;
        }
        int numberOfPoints = pointList.realNumberOfPoints;

        for (int i = 0; i < numberOfPoints; i++)
        {
            CameraPathPoint point           = pointList[i];
            float           pointHandleSize = HandleUtility.GetHandleSize(point.worldPosition) * HANDLE_SCALE * 0.4f;
            Handles.DotCap(0, point.worldPosition, Quaternion.identity, pointHandleSize);
        }

        float   mousePercentage = NearestmMousePercentage();// _track.GetNearestPoint(mousePlanePoint);
        Vector3 mouseTrackPoint = _cameraPath.GetPathPosition(mousePercentage, true);

        Handles.Label(mouseTrackPoint, "Add New Point");
        float      newPointHandleSize = HandleUtility.GetHandleSize(mouseTrackPoint) * HANDLE_SCALE;
        Ray        mouseRay           = Camera.current.ScreenPointToRay(new Vector3(Event.current.mousePosition.x, Screen.height - Event.current.mousePosition.y - 30, 0));
        Quaternion mouseLookDirection = Quaternion.LookRotation(-mouseRay.direction);

        if (Handles.Button(mouseTrackPoint, mouseLookDirection, newPointHandleSize, newPointHandleSize, Handles.DotCap))
        {
            CameraPathControlPoint curvePointA = _cameraPath[_cameraPath.GetLastPointIndex(mousePercentage, false)];
            CameraPathControlPoint curvePointB = _cameraPath[_cameraPath.GetNextPointIndex(mousePercentage, false)];
            float curvePercentage = _cameraPath.GetCurvePercentage(curvePointA, curvePointB, mousePercentage);
            switch (_pointMode)
            {
            case CameraPath.PointModes.AddOrientations:
                Quaternion            pointRotation  = Quaternion.LookRotation(_cameraPath.GetPathDirection(mousePercentage));
                CameraPathOrientation newOrientation = ((CameraPathOrientationList)pointList).AddOrientation(curvePointA, curvePointB, curvePercentage, pointRotation);
                ChangeSelectedPointIndex(pointList.IndexOf(newOrientation));
                break;

            case CameraPath.PointModes.AddFovs:
                float         pointFOV    = _cameraPath.fovList.GetValue(mousePercentage, CameraPathFOVList.ProjectionType.FOV);
                float         pointSize   = _cameraPath.fovList.GetValue(mousePercentage, CameraPathFOVList.ProjectionType.Orthographic);
                CameraPathFOV newFOVPoint = ((CameraPathFOVList)pointList).AddFOV(curvePointA, curvePointB, curvePercentage, pointFOV, pointSize);
                ChangeSelectedPointIndex(pointList.IndexOf(newFOVPoint));
                break;

            case CameraPath.PointModes.AddTilts:
                float          pointTilt    = _cameraPath.GetPathTilt(mousePercentage);
                CameraPathTilt newTiltPoint = ((CameraPathTiltList)pointList).AddTilt(curvePointA, curvePointB, curvePercentage, pointTilt);
                ChangeSelectedPointIndex(pointList.IndexOf(newTiltPoint));
                break;

            case CameraPath.PointModes.AddEvents:
                CameraPathEvent newEventPoint = ((CameraPathEventList)pointList).AddEvent(curvePointA, curvePointB, curvePercentage);
                ChangeSelectedPointIndex(pointList.IndexOf(newEventPoint));
                break;

            case CameraPath.PointModes.AddSpeeds:
                _cameraPath.speedList.listEnabled = true;    //if we're adding speeds then we probable want to enable it
                CameraPathSpeed newSpeedPoint = ((CameraPathSpeedList)pointList).AddSpeedPoint(curvePointA, curvePointB, curvePercentage);
                newSpeedPoint.speed = _animator.pathSpeed;
                ChangeSelectedPointIndex(pointList.IndexOf(newSpeedPoint));
                break;

            case CameraPath.PointModes.AddDelays:
                CameraPathDelay newDelayPoint = ((CameraPathDelayList)pointList).AddDelayPoint(curvePointA, curvePointB, curvePercentage);
                ChangeSelectedPointIndex(pointList.IndexOf(newDelayPoint));
                break;
            }
            GUI.changed = true;
        }
    }