Hooking Camera to TrackBar Control

Using C# / MDX 9.0c

I have a main form which contains controls (Textbox's) to set default settings for my camera. My MDX window is launched from a button on the main form.

Currently, I manually enter Matrix.PerspectiveFovLH, and Matrix.LookAtLH values into the controls on the main form to set the properties of my camera before I launch my MDX window.

I would like to hook my trackbar controls to each of the properties and have my MDX window move the camera position as the trackbar is scrolled (interactively ).

Is this possible, and if so, how might it best be done I currently have the trackbar converting int values to float before passing to Matrix.PerspectiveFovLH, and Matrix.LookAtLH.

Thank you in advance,

Owen



Answer this question

Hooking Camera to TrackBar Control

  • HuyN_MS

    I'm basing it on the early sample

    My SetupCamera routine looks like this:

    private void SetupCamera()

    {

    // Set projection transform to describe the view frustum of the scene

    device.Transform.Projection = Matrix.PerspectiveFovLH(fieldOfViewY, aspectRatio, ZnearPlane, ZfarPlane);

    // Describes the properties of the camera

    device.Transform.View = Matrix.LookAtLH(new Vector3(cameraPositionX, cameraPositionY, cameraPositionZ), new Vector3(cameraTargetX, cameraTargetY, cameraTargetZ), new Vector3(cameraUpVectorX, cameraUpVectorY, cameraUpVectorZ));

    // Disable Lighting

    device.RenderState.Lighting = false;

    }

    I added the Diagnostics to my Form and The SetupCamera() rountine is only getting values from the intial launch of the MDX form, it seems my problem is that the Form itself isn't updating the values from the trackbar inside the game loop.

    I'm going to make that change. If you have any suggestions, please let me know.

    Thank you for pushing me in the right direction.

    Owen


  • RAnderson14

    Sounds reasonable to me. Yes the OnPaint even is the game loop in those examples. After the form is painted in invalidates itself, otehr events (like your trackbars) will be processed and then paint will be called again.

    Which particlular kickstart sample did you base it on I can't remember exactly how the SetupCamera routine works. If it sets the view matrix for the device then everything should be working. Put some Debug.Print's inside SetupCamera() to make sure its being called, and with the correct values from the trackbars.



  • Graham Hay

    No reason why it can't be done - what problem are you having getting it to work.

    Expose some public properties for yout camera from your MDX class and update the camera using those inside your game loop. Then your trackbar can just modify these public values.



  • MetaDjinn

    Thank you for your reply ZMan.

    I have the SetupCamera() function called from the OnPaint event (Tom Millers Kickstart). Both exist on my MDX Form (frm2) which is shown by clicking a button on form1.

    I have the trackbars on form1 setting each property of the Camera.

    The problem I must be having to get this to work is the game loop. I was under the impression that the OnPaint event for form2 is the game loop.

    With the SetupCamera function being run from the game loop, shouldn't this be working


  • Hooking Camera to TrackBar Control