コード例 #1
0
//  // Called every frame. 'delta' is the elapsed time since the previous frame.
    public override void _Process(float delta)
    {
        if (Visible)
        {
            GetNode <Node2D>("Node2D").Visible = true;
            Godot.Camera cam = GetTree().GetRoot().GetCamera();
            if (cam != null)
            {
                var target = GetParent <PhysicalEntity>();
                GetNode <Label>("Node2D/Info").SetText(target.GetTargettingInfoText());
                GetNode <Node2D>("Node2D").SetPosition(cam.UnprojectPosition(GetGlobalTransform().origin));

                Spatial player      = GetTree().GetRoot().GetNode <Spatial>("Spatial/Player");
                string  distanceStr = "";
                if (player != null)
                {
                    float distance = player.GetGlobalTransform().origin.DistanceTo(target.GetGlobalTransform().origin);
                    if (distance >= 1000)
                    {
                        distance   /= 1000;
                        distanceStr = string.Format("{0:0.0}km", distance);
                    }
                    else
                    {
                        distanceStr = string.Format("{0:0}m", distance);
                    }
                }
                GetNode <Label>("Node2D/Distance").SetText(distanceStr);
            }
        }
        else
        {
            GetNode <Node2D>("Node2D").Visible = false;
        }
    }
コード例 #2
0
    public override void _Ready()
    {
        // TODO: Find some way to make this dynamic instead of a static path
        var node = GetNode <Godot.Camera>("/root/main/UI/AppWindow/EnvironmentContainer/4WayViewport/VerticalSplit/HSplit1/Viewport1/Viewport/Camera/CameraObj");

        this.mainCam = node;
        GD.Print(node.GetPath());
        GD.Print("GIZMOS.CS: READY");
    }
コード例 #3
0
//  // Called every frame. 'delta' is the elapsed time since the previous frame.
//  public override void _Process(float delta)
//  {
//
//  }
    /// <summary>
    /// Sets the viewport's camera to the perspective specified by the button press id
    /// passed by the button connection signal.
    /// </summary>
    /// <param name = "id">The PerspectiveTypeEmun value for the camera perspective associated with the toolbar button</param>
    ///
    private void toolbarChangePerspective(int id)
    {
        currentPerspective = (PerspectiveType)id;
        Node tmp = this.GetNode("../Viewport/Camera/CameraObj");

        GD.Print(tmp.Name);
        GD.Print(tmp.GetType());
        Godot.Camera tmp2 = (Godot.Camera)tmp;

        Godot.Camera subCam  = (Godot.Camera)GetNode("../Viewport/Camera/CameraObj");
        Script       gdClass = ResourceLoader.Load("res://src/CameraObj.gd") as Script;
        Object       gdCam   = new Object();

        gdCam = (Godot.Object)gdClass.Call("new");
        gdCam.SetScript(gdClass);


        switch (currentPerspective)
        {
        case PerspectiveType.Front:

            //GD.Print(subCam.GetClass() + subCam.GetFilename());

            Vector3 newLook = new Vector3(5, 1, 0);
            subCam.LookAtFromPosition(newLook, new Vector3(0, 0, 0), new Vector3(0, 1, 0));
            gdCam.Call("_update_mouselook");
            gdCam.Call("_update_movement");
            break;

        case PerspectiveType.Back:
            //subCam = GetNode<Camera>("../Viewport/Camera/CameraObj");
            newLook = new Vector3(-5, 1, 0);
            subCam.LookAtFromPosition(newLook, new Vector3(0, 0, 0), new Vector3(0, 1, 0));
            gdCam.Call("_update_mouselook");
            gdCam.Call("_update_movement");
            break;

        case PerspectiveType.Orthogonal:
            //subCam = GetNode<Camera>("../Viewport/Camera/CameraObj");
            subCam.SetOrthogonal(3, 1, 10);
            gdCam.Call("_update_mouselook");
            gdCam.Call("_update_movement");
            break;

        case PerspectiveType.NOrthogonal:
            subCam.Projection = 0;
            gdCam.Call("_update_mouselook");
            gdCam.Call("_update_movement");
            break;

        default:
            GD.Print("Unrecognized Menu Item");
            break;
        }
    }
コード例 #4
0
ファイル: PlayerLabel.cs プロジェクト: tcmug/spacey
    // Called when the node enters the scene tree for the first time.
    public override void _Process(float delta)
    {
        t += delta;
        GetNode <Label>("Text").Visible = ((t * 1000) % 500) > 250;
        PhysicalEntity player = GetTree().GetRoot().GetNode <PhysicalEntity>("Spatial/Player");
        Spatial        target = player.GetLockedOnTarget();

        if (target != null)
        {
            Vector3      point = target.GetGlobalTransform().origin;
            Godot.Camera cam   = GetTree().GetRoot().GetCamera();
            if (cam == null)
            {
                return;
            }
            float distance = player.GetGlobalTransform().origin.DistanceTo(point);
            if (distance >= 1000)
            {
                distance /= 1000;
                GetNode <Label>("Distance").SetText(string.Format("{0:0.0}km", distance));
            }
            else
            {
                GetNode <Label>("Distance").SetText(string.Format("{0:0}m", distance));
            }
            if (!cam.IsPositionBehind(point))
            {
                Viewport vp   = cam.GetViewport();
                Vector2  pos  = cam.UnprojectPosition(point);
                Viewport vp2d = GetViewport();
                Vector2  posx = new Vector2(
                    pos.x / (vp.GetSize().x / vp2d.GetSize().x),
                    pos.y / (vp.GetSize().y / vp2d.GetSize().y)
                    );
                this.SetPosition(posx);
                this.Visible = true;
            }
            else
            {
                this.Visible = false;
            }
        }
    }
コード例 #5
0
ファイル: Camera.cs プロジェクト: johnfarrell/rr-godot
 /// <summary>
 /// Called when the node enters the scene tree for the first time.
 /// </summary>
 public override void _Ready()
 {
     this.cam         = this.GetNode <Godot.Camera>("CameraObj");
     this.cam.Current = true;
 }
コード例 #6
0
 public override void _Ready()
 {
     camera = GetNode("Camera") as Godot.Camera;
 }
コード例 #7
0
ファイル: GizmoRotate.cs プロジェクト: johnfarrell/rr-godot
    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;
        }
    }