Custom Camera

Apr 5, 2013 at 1:25 AM
Hi, in the older versions of Nine (using modelbatch), it was ok to pass in the view/projection parameters to draw objects. Using Nine 1.4 (scene.Draw()), there isn't a way to pass in the view/projection in order to draw - I ask because I have a series of already built cameras that'd I'd like to use with Nine 1.4 as the rendering engine, but not sure how to pass in those parameters. Is it possible to do so?

Apr 5, 2013 at 4:23 AM
Sure, there is an ICamera interface that exposes View/Projection matrices. Implement that interface on your camera and then add the camera to the scene using Scene.Add(). If your camera needs to receive frame update event, implement Nine.IUpdateable interface.
Apr 5, 2013 at 12:18 PM
Great, thank you!

Also, rather than start a new thread, what is the code based (non-XAML) process of adding the physics objects, both dynamic and static meshes, and tieing certain drawable models to them? I use my own implementation of BEPU right now and would love to give a shot using yours :)
Apr 6, 2013 at 3:08 AM
We haven't yet implemented a solid physics integration with our graphics system, so I recommend to continue using your own implementation.
Apr 25, 2013 at 2:11 AM
Edited Apr 25, 2013 at 2:31 AM
Hi, I'm sorry this is so late, but I'm finally getting around to implementing ICamera and have a few questions. I have a camera class called "Camera" and it is defined as this:
public class CustomCamera : ICamera
where ICamera is your interface. It requires the TryGetViewFrustum, so I created this as per what I saw in your Camera2D file in the 1.4 source:
        public bool TryGetViewFrustum(out Matrix view, out Matrix projection)
            view = this.ViewMatrix;
            projection = this.ProjectionMatrix;
            return true;
I then add my camera that implements your interface to the scene:
            // Set up the FPS Camera
            fpsCamera = new CameraComponents.CustomCamera(...
and call scene.Draw(...)
            scene.Draw(this.GraphicsDevice, gameTime.ElapsedGameTime);
I see some items on the screen, but it is obviously not my camera matrices and I never even see the TryGetViewFrustum get called. I also see my camera class added as a component when I step into debug mode, and it DOES inherit ICamera. Do I need to call TryGetViewFrustum it somewhere? With what parameters? I had thought the scene would replace its camera with my own.

Apr 25, 2013 at 2:39 AM
To complicate this further, on noticing that a FreeCamera is added if no other camera is found, I put a debug point in the following code:
            scene.Draw(this.GraphicsDevice, gameTime.ElapsedGameTime);

            Nine.Graphics.Camera c = scene.Find<Nine.Graphics.Camera>();
            CameraComponents.CustomCamera c2 = scene.Find<CameraComponents.CustomCamera>();
Both c and c2 have values. So obviously, I am adding my own camera at the start, but it is still adding a free camera... any ideas?
Apr 25, 2013 at 2:43 AM
Ok, I THINK I found the method. Can you verify this is close? It seems to get me closer:

            DrawingContext d = scene.GetDrawingContext();
            d.Camera = fpsCamera;
Apr 25, 2013 at 3:09 AM
Yeah, the scene is not intelligent enough to set the custom camera as an active camera. Mannually set the DrawingContext.Camara property.