Jump to content

Testing multi-display


Xavier513

Recommended Posts

I'm trying to play KSP on more than one monitor, with different  content in each monitor.

I successfully achieved this on two monitors, but I encountered an issue, and I need some help: the vessel disappears in the first monitor.

This is how I enable the second monitor:

1, Connect another monitor to the PC running KSP (via HDMI port).

2, Compile following codes and start KSP, this addon will take effect in Flight scene.

	[KSPAddon(KSPAddon.Startup.Flight, false)]
    public class DisplayAddon : MonoBehaviour
    {
        private static bool bottonClicked;
        private static global::Vessel vessel;

        private static Camera galaxyCamera;
        private static Camera scaledSpaceCamera;
        private static Camera camera00;

        private static int SecondDisplay = 1;
        public void Start()
        {
            vessel = FlightGlobals.ActiveVessel;

            Display.displays[SecondDisplay].Activate(); // Activate the second display
				
				 // Copy in-game cameras
            galaxyCamera = new GameObject().AddComponent<Camera>();
            galaxyCamera.CopyFrom(Camera.allCameras.FirstOrDefault(cam => cam.name == "GalaxyCamera"));
            galaxyCamera.name = "GalaxyCameraCopy";

            scaledSpaceCamera = new GameObject().AddComponent<Camera>();
            scaledSpaceCamera.CopyFrom(Camera.allCameras.FirstOrDefault(cam => cam.name == "Camera ScaledSpace"));
            scaledSpaceCamera.name = "scaledSpaceCameraCopy";

            camera00 = new GameObject().AddComponent<Camera>();
            camera00.CopyFrom(Camera.allCameras.FirstOrDefault(cam => cam.name == "Camera 00"));
            camera00.name = "camera00Copy";
				 
           // New cameras render to the second display
            galaxyCamera.targetDisplay = SecondDisplay;
            scaledSpaceCamera.targetDisplay = SecondDisplay;
            camera00.targetDisplay = SecondDisplay;
        }

        public void FixedUpdate()
        {
            if (bottonClicked) 
            {
                camera00.transform.position = new Vector3(-5.5f, 0.7f, -2.0f); // Place the camera at somewhere near the vessel
                camera00.transform.LookAt(vessel.CoM);

                galaxyCamera.transform.rotation = camera00.transform.rotation;
                scaledSpaceCamera.transform.rotation = camera00.transform.rotation;
            }
        }
    }

3, Load a save, load a vessel, then enable addon.

Please take a look at these 4 images: https://imgur.com/a/uiOz9pn

The first 2 images are contents in two monitors when the addon IS NOT activated.

The last 2 images are contents in two monitors when the addon IS activated.

As you can see, in the third image, the vessel is not shown.

Does anyone know how to fix this? Thanks a lot!

 

 

 

 

Link to comment
Share on other sites

1 hour ago, Stone Blue said:

@Xavier513 do you happen to have a compiled dll of this?... I would be ineterested in testing it...

hi, @Stone Blue, thanks.

Sorry, I'm testing this function along with many other WIP features in my project, so it's not quite convenient to provide a DLL.

But the codes above are basicly all the codes needed for this feature, for now. 

You can

1, create a new project in Visual Studio,

2, create a C# file with those codes.

3, add references of Assembly-CSharp.dll and UnityEngine.dll to project.

4, then you can compile it to generate a DLL, 

 

Besides, you have to add a button somewhere(e.g. some part's right click menu) to set "bottonClicked" to true, or activate the addon in other ways.

Edited by Xavier513
Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...