rendering 3dScene in PlayingState of tutorial 26

Nov 11, 2009 at 2:37 PM

hi StatusUnknown

I am working on xen 1.7 tutorial 26 (game state).

I have a general comprehension problem understanding the usage of the DrawTargetScreen in the application (tutorial class).
It gets passed a camera (here: camera2D). If I want to have a 3d scene renderd during the PlayingState i need a camera3D.
where should I create this camera (in PlayingState or better in GameStateManager?) and how do I pass it to the DrawTargetScreen?

Or, should I render in a DrawTargetTexture2D and pass this texture to the DrawTargetScreen when the state is active?

The tutorials concerning render to texture (tutorials 7/8/9) always use the same camera in the DrawTargetScreen and DrawTargetTexture2D (they are also created in the same class).
How do I set up a DrawTargetTexture2D that uses its own camera (in a seperate class e.g.PlayingState)
and how do I add this DrawTargetTexture2D to the DrawTargetScreen (via a GameStateManager?).

It seems to me desirable to have class (e.g.PlayingState level1, level2 etc.) which "describes" my level, calls all necessary classes (Actor, PhysicsActor, AI ...)

and has its own update and draw methods that get called by GameStateManager when the state is active and is ultimately controlled

by the application class (by adding the GameStateManager to UpdateManager and draw to screen).

I am a beginner, please forgive my lack of experience.

Although I want to add that for simple applications (no Game State management involved, only one camera) I have easily managed to integrate JigLibX physics and BoxCollider Library, render and animate my models etc.

Therefore I am very fond of Xen and want to thank you for this very fine work. maybe you can shed some light on the above issues for me.

thank you

Nov 11, 2009 at 2:41 PM
Edited Nov 11, 2009 at 3:08 PM


Luckily, this problem has a very simple solution.
DrawState has PushCamera() and PopCamera(), which allow you to change the camera while drawing. Afterall, it's very rare you will use only one type of camera for the entire game. (All the 2D elements do exactly this when drawing).

Just remember the tutorials are guides to how something *could* be implemented, I'm not saying 'do it this way or else!'. :-)
It's quite difficult to balance flexibility, understandability with simplicity in a single file tutorial. Eventually some flexibility will be sacrificed. :-)

Nov 11, 2009 at 7:33 PM

Hi, thank you for your quick reply. I did come across push/popCamera and had actually tried these methods before (as it seems the simplest way) and had failed.
however your answer made me think again (harder I guess) and now I have found a way that works.

I have an Actor Class that loads the tiny model.

in PlayingState I create an Actor instance and a FirstPersonControlledCamera3D.


         private FirstPersonControlledCamera3D camera3D;

        public void Initalise(IGameStateManager stateManager)
            this.stateManager = stateManager;
            this.camera3D = new FirstPersonControlledCamera3D(this.stateManager.Application.UpdateManager, new Vector3(5, 5, 0), false);
            camera3D.LookAt(Vector3.Zero, new Vector3(0, 400, -400), Vector3.UnitY);

        public void DrawScreen(DrawState state)

this works now.

thanks again for the reply and for Xen.