Пример #1
0
        private void Render()
        {
            if (_world != null)
            {
                _world.OnUpdate();

                DrawingVisual view = new DrawingVisual();

                using (DrawingContext dc = view.RenderOpen())
                {
                    _world.OnRender(dc);
                }

                TransformGroup group = new TransformGroup();
                group.Children.Add(new TranslateTransform(ViewOffsetX, ViewOffsetY));
                group.Children.Add(new ScaleTransform()
                {
                    CenterX = ViewScaleOriginX, CenterY = ViewScaleOriginY, ScaleX = ViewScaleX, ScaleY = ViewScaleY
                });
                PlaneControl.SetTransfromOrigin(new Point(ViewScaleOriginX, ViewScaleOriginY));
                PlaneControl.SetTransfrom(group);

                PushVisual(view);
            }
        }
    // Ready function, called once at the beginning of the scene when all children are ready
    public override void _Ready()
    {
        // Assign required nodes
        objectBody      = GetNode <StaticBody>("ViewportContainer/Viewport/ObjectRoot/Object1");
        ray             = GetNode <RayCast>("ViewportContainer/Viewport/ObjectRoot/HiddenLineRay");
        freeCameraRoot  = GetNode <Spatial>("ViewportContainer/Viewport/ObjectRoot/CameraRoot");
        orthoCameraRoot = GetNode <Spatial>("ViewportContainer/Viewport/ObjectRoot/OrthoCameraRoot");

        // Populate the list of planes with the nodes of each BoxPlaneControl object
        planes = new Spatial[PLANE_COUNT] {
            GetNode <Spatial>("ViewportContainer/Viewport/ObjectRoot/FrontPlaneControl"), GetNode <Spatial>("ViewportContainer/Viewport/ObjectRoot/RightPlaneControl"), GetNode <Spatial>("ViewportContainer/Viewport/ObjectRoot/BackPlaneControl"), GetNode <Spatial>("ViewportContainer/Viewport/ObjectRoot/LeftPlaneControl"), GetNode <Spatial>("ViewportContainer/Viewport/ObjectRoot/TopPlaneControl"), GetNode <Spatial>("ViewportContainer/Viewport/ObjectRoot/BottomPlaneControl")
        };

        // All faces are hidden at first
        isFaceShown = new bool[PLANE_COUNT] {
            false, false, false, false, false, false
        };

        // Initialize the required static variables in the PlaneControl class
        PlaneControl.Initialize(objectBody.GetChild <MeshInstance>(0), ray, PlaneControl.ORTHOGRAPHIC);

        // Set the display size
        PlaneControl.SetScreenSize(PLANE_X_SCALE, PLANE_Y_SCALE, MAX_FOCUS);

        // Set the zoom of the PlaneControl class
        // A zoom value of 1 is set because this scene requires orthographic projection (without scaling to screen size)
        PlaneControl.SetZoom(MAX_FOCUS);

        // Set the projection colours
        ProjectionRoot.SetColours(true, false);
    }
Пример #3
0
    // The second half of the _on_ObjectList_item_selected function
    public void _on_ObjectList_item_selected_second_part()
    {
        // Initialize the PlaneControl class to use the new object
        PlaneControl.Initialize(objectBody.GetChild <MeshInstance>(0), ray, PlaneControl.projectionMode);

        // Set the display again in case the selected object was changed from the auxiliary object
        // ChangeDisplay is used instead of Display so that the controls values are still used and the new object is not completely reset
        SetDisplay();
        ChangeDisplay();
    }
Пример #4
0
    // Function to change (refresh) display when any of the controls have been changed
    // Controls are connected to this function through the editor
    // Note that the newValue parameter (given by slider signals) is not used
    public static void ChangeDisplay(float newValue = 0)
    {
        // Rotate the object according to sliders
        objectBody.RotationDegrees = new Vector3((float)ObjectXDegSlider.Value, (float)ObjectYDegSlider.Value, (float)ObjectZDegSlider.Value);

        // Force the body to transform (so calculations can be done) rather than waiting for the next frame
        objectBody.ForceUpdateTransform();

        // Set the zoom value
        PlaneControl.SetZoom((float)FocusZoomSlider.Value);

        // Display 2D screens
        Display();
    }
Пример #5
0
 public void Init()
 {
     pc = new PlaneControl();
 }
Пример #6
0
    // Start is called before the first frame update
    void Start()
    {
        soundSource = GameObject.Find("SoundControl").GetComponent <AudioSource>();

        musicEnabled = PlayerPrefs.GetInt("musicEnabled", 1);
        soundEnabled = PlayerPrefs.GetInt("soundEnabled", 1);

        if (SceneManager.GetActiveScene().buildIndex == 0)
        {
            checkReturnToLevelSelect();
            musicEnabled = 1;
            soundEnabled = 1;
            PlayerPrefs.SetInt("musicEnabled", 1);
            PlayerPrefs.SetInt("soundEnabled", 1);
        }
        else
        {
            plane  = FindObjectOfType <PlaneControl>();
            star1C = GameObject.Find("endScreen").transform.GetChild(1).gameObject;
            star2C = GameObject.Find("endScreen").transform.GetChild(3).gameObject;
            star3C = GameObject.Find("endScreen").transform.GetChild(5).gameObject;
            endScreen.gameObject.SetActive(false);
            sC           = FindObjectOfType <StarCollector>();
            engineSource = GameObject.Find("Plane").GetComponent <AudioSource>();

            nextLevelStarDisplay = GameObject.Find("currentPlayerStar");

            nextLevelStarDisplay.transform.parent = nextLevelButton.gameObject.transform;
            nextLevelStarDisplay.GetComponent <RectTransform>().localPosition = new Vector3(-296, -105, 0);


            Image[] images1 = GameObject.Find("Sound Button").GetComponentsInChildren <Image>();
            foreach (Image image in images1)
            {
                if (image.gameObject.transform.parent.name == "Sound Button")
                {
                    soundAnim = image;
                }
            }

            Image[] images2 = GameObject.Find("Music Button").GetComponentsInChildren <Image>();
            foreach (Image image in images2)
            {
                if (image.gameObject.transform.parent.name == "Music Button")
                {
                    musicAnim = image;
                }
            }

            if (musicEnabled == 1)
            {
                musicAnim.sprite = Resources.Load <Sprite>("music_icon_on");
            }
            else
            {
                musicAnim.sprite = Resources.Load <Sprite>("music_icon_off");
            }


            if (soundEnabled == 1)
            {
                soundAnim.sprite = Resources.Load <Sprite>("sound_icon_on");
            }
            else
            {
                soundAnim.sprite = Resources.Load <Sprite>("sound_icon_off");
            }
        }


        musicSource = GameObject.Find("BackGroundSound").GetComponent <AudioSource>();


        if (soundEnabled == 1)
        {
            soundSource.enabled = true;
            if (SceneManager.GetActiveScene().buildIndex > 0)
            {
                engineSource.enabled = true;
            }
        }
        else
        {
            soundSource.enabled = false;
            if (SceneManager.GetActiveScene().buildIndex > 0)
            {
                engineSource.enabled = false;
            }
        }

        if (musicSource != null)
        {
            if (musicEnabled == 1)
            {
                musicSource.enabled = true;
            }
            else
            {
                musicSource.enabled = false;
            }
        }
    }
Пример #7
0
    // Ready function, called once at the beginning of the scene when all children are ready
    public override void _Ready()
    {
        // Assignment of required nodes
        // ObjectRoot (root of all 3D nodes)
        objectRoot = GetNode <Spatial>("HorizontalViewContainer/ObjectViewContainter/ObjectViewport/ObjectRoot");

        // PlaneControl Objects
        topViewPlane       = GetNode <Spatial>("HorizontalViewContainer/ObjectViewContainter/ObjectViewport/ObjectRoot/TopViewPlane");
        frontViewPlane     = GetNode <Spatial>("HorizontalViewContainer/ObjectViewContainter/ObjectViewport/ObjectRoot/FrontViewPlane");
        sideViewPlane      = GetNode <Spatial>("HorizontalViewContainer/ObjectViewContainter/ObjectViewport/ObjectRoot/RightViewPlane");
        auxiliaryViewPlane = GetNode <Spatial>("HorizontalViewContainer/ObjectViewContainter/ObjectViewport/ObjectRoot/AuxiliaryViewPlane");

        // ProjectionRoot Objects
        mainDisplayRoot   = GetNode <Node2D>("HorizontalViewContainer/MainProjectionDisplayContainer/MainProjectionViewport/ProjectionRoot");
        topViewRoot       = GetNode <Node2D>("HorizontalViewContainer/MainProjectionDisplayContainer/ViewGridContainer/TopViewportContainer/TopViewport/TopViewRoot");
        frontViewRoot     = GetNode <Node2D>("HorizontalViewContainer/MainProjectionDisplayContainer/ViewGridContainer/FrontViewportContainer/FrontViewport/FrontViewRoot");
        sideViewRoot      = GetNode <Node2D>("HorizontalViewContainer/MainProjectionDisplayContainer/ViewGridContainer/SideViewportContainer/SideViewport/SideViewRoot");
        auxiliaryViewRoot = GetNode <Node2D>("HorizontalViewContainer/MainProjectionDisplayContainer/ViewGridContainer/AuxiliaryViewportContainer/AuxiliaryViewport/AuxiliaryViewRoot");

        // UI Control Nodes
        ControlsNode     = GetNode <Control>("HorizontalViewContainer/ObjectViewContainter/ObjectViewport/Controls");
        FocusZoomSlider  = GetNode <HSlider>("HorizontalViewContainer/ObjectViewContainter/ObjectViewport/Controls/ControlsPanel/ViewControl/FocusZoomSlider");
        ObjectXDegSlider = GetNode <HSlider>("HorizontalViewContainer/ObjectViewContainter/ObjectViewport/Controls/ControlsPanel/ObjectControl/HBoxContainer/SlidersVBoxContainer/ObjectXDegSlider");
        ObjectYDegSlider = GetNode <HSlider>("HorizontalViewContainer/ObjectViewContainter/ObjectViewport/Controls/ControlsPanel/ObjectControl/HBoxContainer/SlidersVBoxContainer/ObjectYDegSlider");
        ObjectZDegSlider = GetNode <HSlider>("HorizontalViewContainer/ObjectViewContainter/ObjectViewport/Controls/ControlsPanel/ObjectControl/HBoxContainer/SlidersVBoxContainer/ObjectZDegSlider");
        viewList         = GetNode <OptionButton>("HorizontalViewContainer/ObjectViewContainter/ObjectViewport/Controls/ControlsPanel/ViewControl/ViewSelectList");
        viewGrid         = GetNode <GridContainer>("HorizontalViewContainer/MainProjectionDisplayContainer/ViewGridContainer");

        // RayCast Node
        ray = GetNode <RayCast>("HorizontalViewContainer/ObjectViewContainter/ObjectViewport/ObjectRoot/HiddenLineRayCast");

        // Populate the objects array with the required NodePaths
        for (int index = 0; index < OBJECT_COUNT; index++)
        {
            objects[index] = objectRoot.GetChild <StaticBody>(index + FIRST_OBJECT_INDEX).GetPath();
        }

        // The second object is initially selected
        currentObjectIndex = 1;

        // Get the object's static body from the selected NodePath in the objects array
        objectBody = GetNode <StaticBody>(objects[currentObjectIndex]);

        // Initialize the required static variables in the PlaneControl class
        PlaneControl.Initialize(objectBody.GetChild <MeshInstance>(0), ray, PlaneControl.ORTHOGRAPHIC);

        // Set the screen size so that the projection is properly scaled
        PlaneControl.SetScreenSize(LARGE_PLANE_X_SCALE, LARGE_PLANE_Y_SCALE, MAX_FOCUS);

        // Set the zoom value of the PlaneControl class according to the focus/zoom slider's value
        PlaneControl.SetZoom((float)FocusZoomSlider.Value);

        // Set the colours that the projection is to be displayed in, by specifying whether the projection is on the cube, and whether the colours have been switched
        ProjectionRoot.SetColours(false, false);

        // Auxiliary view is disabled at first
        isAuxEnabled = false;

        // Set the display nodes and display onto the screen
        SetDisplay();
        Display();
    }
Пример #8
0
    // This function sets which viewport/display to display to, as well as which view(s) is (are) visible
    public static void SetDisplay()
    {
        // Set grid view as invisible and main view as visible
        viewGrid.Visible        = false;
        mainDisplayRoot.Visible = true;

        // Set planeControl objects (in 3D view) as invisible
        topViewPlane.Visible       = false;
        frontViewPlane.Visible     = false;
        sideViewPlane.Visible      = false;
        auxiliaryViewPlane.Visible = false;

        // Set the display size to the main viewport size
        PlaneControl.SetScreenSize(LARGE_PLANE_X_SCALE, LARGE_PLANE_Y_SCALE, MAX_FOCUS);

        if (selectedView == (int)Views.ALL_VIEWS)
        {
            // If all views are visible, set the grid view to visible and main view to invisible
            viewGrid.Visible        = true;
            mainDisplayRoot.Visible = false;

            // Set the individual view display ndoes
            topViewPlane.Call("SetDisplayNode", topViewRoot.GetPath());
            frontViewPlane.Call("SetDisplayNode", frontViewRoot.GetPath());
            sideViewPlane.Call("SetDisplayNode", sideViewRoot.GetPath());
            auxiliaryViewPlane.Call("SetDisplayNode", auxiliaryViewRoot.GetPath());

            // Set all planeControl objects (in 3D view) as visible
            topViewPlane.Visible   = true;
            frontViewPlane.Visible = true;
            sideViewPlane.Visible  = true;

            // If auxiliary view is enabled for this object, make the auxiliary planeControl object visible
            if (isAuxEnabled)
            {
                auxiliaryViewPlane.Visible = true;
            }

            // If all views are selected, change the display size to the small viewport size
            PlaneControl.SetScreenSize(SMALL_PLANE_X_SCALE, SMALL_PLANE_Y_SCALE, MAX_FOCUS);
        }
        else if (selectedView == (int)Views.TOP_VIEW)
        {
            // If top view is selected, set top view display node and set 3D planeControl object as visible
            topViewPlane.Call("SetDisplayNode", mainDisplayRoot.GetPath());
            topViewPlane.Visible = true;
        }
        else if (selectedView == (int)Views.FRONT_VIEW)
        {
            // If front view is selected, set front view display node and set 3D planeControl object as visible
            frontViewPlane.Call("SetDisplayNode", mainDisplayRoot.GetPath());
            frontViewPlane.Visible = true;
        }
        else if (selectedView == (int)Views.SIDE_VIEW)
        {
            // If side view is selected, set side view display node and set 3D planeControl object as visible
            sideViewPlane.Call("SetDisplayNode", mainDisplayRoot.GetPath());
            sideViewPlane.Visible = true;
        }
        else if (selectedView == (int)Views.AUX_VIEW && isAuxEnabled)
        {
            // If auxiliary view is selected, set auxiliary view display node and set 3D planeControl object as visible
            auxiliaryViewPlane.Call("SetDisplayNode", mainDisplayRoot.GetPath());
            auxiliaryViewPlane.Visible = true;
        }
    }