예제 #1
0
    // Called when the node enters the scene tree for the first time.
    public override void _Ready()
    {
        this.Connect(
            "UpdateVelocities",
            GetNode("/root/main/UI/AppWindow/LeftMenu/ObjectInspector/ObjectInspector/VBoxContainer/VelocityMenu"),
            "UpdateAllVels"
            );
        this.Connect(
            "UpdateTransform",
            GetNode("/root/main/UI/AppWindow/LeftMenu/ObjectInspector/ObjectInspector/VBoxContainer/TransformMenu"),
            "UpdateAllTrans"
            );
        this.Connect(
            "UpdateJointInfo",
            GetNode("/root/main/UI/AppWindow/LeftMenu/ObjectInspector/JointController"),
            "AddJointDetail"
            );

        GetNode("/root/main/UI/AppWindow/LeftMenu/TreeContainer/Environment").Connect("ObjectSelected", this, "TreeItemSelected");

        // Connect translation signals
        VBoxContainer TransformInspector = (VBoxContainer)GetNode("/root/main/UI/AppWindow/LeftMenu/ObjectInspector/ObjectInspector/VBoxContainer/TransformMenu");

        TransformInspector.Connect("XTrans", this, "TranslateX");
        TransformInspector.Connect("YTrans", this, "TranslateY");
        TransformInspector.Connect("ZTrans", this, "TranslateZ");
        TransformInspector.Connect("XRot", this, "RotX");
        TransformInspector.Connect("YRot", this, "RotY");
        TransformInspector.Connect("ZRot", this, "RotZ");

        Node temp = GetNode("SelectedObject");

        GD.Print(temp.GetType());
        marker = (Godot.Spatial)temp;

        // Connect tree update signal
        Connect(nameof(envUpdated), GetNode("/root/main/UI/AppWindow/LeftMenu/TreeContainer/Environment/"), "UpdateTree");

        gizmo = GetNode <Spatial>("/root/main/UI/AppWindow/EnvironmentContainer/4WayViewport/VerticalSplit/HSplit1/Viewport1/Viewport/gizmos");

        for (var i = 0; i < gizmo.GetChildCount(); ++i)
        {
            gizmo.GetChild(i).Connect("HandlePressed", this, "GizmoClicked");
            gizmo.GetChild(i).Connect("HandleUnpressed", this, "GizmoUnclicked");
        }

        simState         = false;
        GetTree().Paused = simState;

        // gizmo.Visible = false;
        GD.Print("ENV.CS: READY");
    }
예제 #2
0
    public override void InputEvent(Node camera, InputEvent @event, Vector3 click_position, Vector3 click_normal, int shape_idx)
    {
        GD.Print("GIZMO SCALE INPUT EVENT");
        if (@event is InputEventMouseButton)
        {
            GizmoPressed = @event.IsActionPressed("mouse_left_click");

            if (ActiveAxis != Axis.NONE)
            {
                EmitSignal("HandlePressed");
            }
            if (@event.IsActionReleased("mouse_left_click"))
            {
                EmitSignal("HandleUnpressed");
            }
        }
        if (@event is InputEventMouseMotion && GizmoPressed && ActiveAxis != Axis.NONE)
        {
            InputEventMouseMotion Event = (InputEventMouseMotion)@event;

            Godot.Spatial tempObj = GetObject();
            if (tempObj == null)
            {
                return;
            }
            if (CurrentObject == null)
            {
                CurrentObject = tempObj;
            }
            else if (CurrentObject.Name != tempObj.Name)
            {
                CurrentObject = tempObj;
            }
            if (CurrentObject.Name == "env")
            {
                return;
            }

            Vector3 PreviousObjectPosition = CurrentObject.GlobalTransform.origin;
            Vector3 CurrentObjectPosition  = PreviousObjectPosition;

            Vector2 MouseMoveDelta = Event.Relative * new Vector2((float)0.01, (float)0.01);

            CurrentObjectPosition += EditorViewport.GetCamera().GlobalTransform.basis.y * -MouseMoveDelta.y;
            CurrentObjectPosition += EditorViewport.GetCamera().GlobalTransform.basis.x *MouseMoveDelta.x;

            if (ActiveAxis == Axis.X)
            {
                CurrentObjectPosition.y = PreviousObjectPosition.y;
                CurrentObjectPosition.z = PreviousObjectPosition.z;
            }
            else if (ActiveAxis == Axis.Y)
            {
                CurrentObjectPosition.x = PreviousObjectPosition.x;
                CurrentObjectPosition.z = PreviousObjectPosition.z;
            }
            else
            {
                CurrentObjectPosition.x = PreviousObjectPosition.x;
                CurrentObjectPosition.y = PreviousObjectPosition.y;
            }

            CurrentObject.GlobalTranslate(CurrentObjectPosition - PreviousObjectPosition);
        }
    }
예제 #3
0
    public override void InputEvent(Node camera, InputEvent @event, Vector3 click_position, Vector3 click_normal, int shape_idx)
    {
        GD.Print("GIZMO SCALE INPUT EVENT");
        Godot.Camera cam = (Godot.Camera)camera;
        if (shape_idx != 0)
        {
            LatestAngle      = shape_idx;
            LatestClickStart = click_position;
        }
        if (@event is InputEventMouseButton)
        {
            GizmoPressed = @event.IsActionPressed("mouse_left_click");
            ClickStart   = cam.UnprojectPosition(click_position);

            if (ActiveAxis != Axis.NONE)
            {
                EmitSignal("HandlePressed");
            }
            if (@event.IsActionReleased("mouse_left_click"))
            {
                StartTrans = CurrentObject.GlobalTransform;
                EmitSignal("HandleUnpressed");
            }
        }
        if (@event is InputEventMouseMotion && GizmoPressed && ActiveAxis != Axis.NONE)
        {
            GD.Print(LatestAngle);
            InputEventMouseMotion Event = (InputEventMouseMotion)@event;

            Godot.Spatial tempObj = GetObject();
            if (tempObj == null)
            {
                return;
            }
            if (CurrentObject == null)
            {
                CurrentObject = tempObj;
                StartTrans    = CurrentObject.GlobalTransform;
            }
            else if (CurrentObject.Name != tempObj.Name)
            {
                CurrentObject = tempObj;
                StartTrans    = CurrentObject.GlobalTransform;
            }
            if (CurrentObject.Name == "env")
            {
                return;
            }

            Vector2 Origin2d = cam.UnprojectPosition(CurrentObject.GlobalTransform.origin);
            Vector2 MousePos = Event.Position;

            Vector2 StartVector = ClickStart - Origin2d;
            Vector2 CurrVector  = MousePos - Origin2d;

            // float AngleCurr = (float) (180 / Math.PI) * StartVector.AngleTo(CurrVector);
            float AngleCurr = StartVector.AngleTo(CurrVector);


            Vector3 PreviousObjectRotation = CurrentObject.RotationDegrees;
            Vector3 CurrentObjectRotation  = PreviousObjectRotation;

            Transform rotTrans = StartTrans;

            Vector3 rotation = rotTrans.basis.GetEuler();

            if (ActiveAxis == Axis.X)
            {
                rotTrans.basis = StartTrans.basis.Rotated(new Vector3(1, 0, 0), AngleCurr);
            }
            else if (ActiveAxis == Axis.Y)
            {
                rotation.y     = -1 * AngleCurr;
                rotTrans.basis = StartTrans.basis.Rotated(new Vector3(0, 1, 0), -1 * AngleCurr);
            }
            else
            {
                rotation.z     = AngleCurr;
                rotTrans.basis = StartTrans.basis.Rotated(new Vector3(0, 0, 1), AngleCurr);
            }

            // rotTrans.basis = new Basis(rotation);
            CurrentObject.GlobalTransform = rotTrans;
        }
    }