XNA Game Development Forums
2012/05/21 21:02:28 *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Search Calendar Login Register  
Pages: [1]
  Print  
Author Topic: extending the camera classes/cameramanager  (Read 2080 times)
Mikeske
Newbie
*
Offline Offline

Posts: 33


View Profile
« on: 2009/12/13 14:30:16 »

HI Folks,

How could multi-viewports been build in quickly? I want to keep it kinda object-like...
If ppl would add 2 viewports (cameras), then 2 viewports would be visible and so on and so on...

I know that the logic would be something like
Code:
Viewport original = graphics.GraphicsDevice.Viewport;
 
graphics.GraphicsDevice.Viewport = topViewport;
GraphicsDevice.Clear(Color.Black);
DrawModel(model, world, topView, projection);
 
graphics.GraphicsDevice.Viewport = sideViewport;
GraphicsDevice.Clear(Color.Black);
DrawModel(model, world, sideView, projection);
 
graphics.GraphicsDevice.Viewport = frontViewport;
GraphicsDevice.Clear(Color.Black);
DrawModel(model, world, frontView, projection);
 
graphics.GraphicsDevice.Viewport = perspectiveViewport;
GraphicsDevice.Clear(Color.Black);
DrawModel(model, world, perspectiveView, projection);
 
GraphicsDevice.Viewport = original;

But how could this be implemented in the hazymind engine?
Logged
mikeschuld
Administrator
Sr. Member
*****
Offline Offline

Posts: 389


View Profile WWW
« Reply #1 on: 2009/12/14 08:39:08 »

Essentially you just create the multiple cameras that you want to use and set them as the "Active" camera (there is already a method in the manager for doing so) before rendering whatever you want to use that camera's viewport. Everything else should be handled for you after that.

Let me know if you need more specifics and I'll try to work up a simple example.
Logged
Mikeske
Newbie
*
Offline Offline

Posts: 33


View Profile
« Reply #2 on: 2009/12/14 11:32:53 »

Hi Mike,

So far so good, same info I tried to explain but it came more intelligent from your side Wink
The thing is, how can I tell XNA to redraw everything again (in the same draw cycle) as the component manager is drawing every "renderable" item... thought of something like

Code:
        public override void Draw(GameTime gameTime)
        {
            foreach (IIcRenderable render in renderable.Values)
            {
                GraphicsDevice.VertexDeclaration = render.VertexDeclaration;

                IcCameraManager.SetActiveCamera("viewport1");

                IcEffectManager.SetActiveShader(render.Shader);
                IcEffectManager.ActiveShader.SetParameters(render);

                IcEffectManager.ActiveShader.Effect.Begin();
                foreach (EffectPass pass in IcEffectManager.ActiveShader.Effect.CurrentTechnique.Passes)
                {
                    pass.Begin();
                    render.Render(GraphicsDevice);
                    pass.End();
                }
                IcEffectManager.ActiveShader.Effect.End();
            }
            base.Draw(gameTime);
        }


but with an extra for loop whcih goes through every viewport...
But how could I keep it managable to be able to set for example...

Editor:
4-viewport
Game:
1-viewport

without having to rewrite the compomentmanager ...
Do you get my point where I'm going at, or is it totally insane to do it like this?

greetz
Logged
mikeschuld
Administrator
Sr. Member
*****
Offline Offline

Posts: 389


View Profile WWW
« Reply #3 on: 2009/12/15 12:36:33 »

How about switching the camera and then just calling the Render on the ObjectManager again? That shouls go down the whole tree and do everything it needs to.
Logged
Mikeske
Newbie
*
Offline Offline

Posts: 33


View Profile
« Reply #4 on: 2009/12/15 13:00:12 »

Hi there,

It was exactly what I meant... another for-loop, looping through each viewport...
But the question was more like, how could I keep it simple? in an editor you would need, 1..2...3...4...n - viewports, but for a game (single player-like) just 1 viewport for example... this would mean I would need something to designate as a Viewport in the for-loop...

I can add like 10 cameras (10 viewports if you like) but only 1...2...3 are viewports how can I designate the camera as being a viewport to be rendered, the other cameras could just be a first-person like camera, another could be an image of a surveillance camera that would be rendered on a tv-screen in-game... you catch my drift?

greetz
Logged
Mikeske
Newbie
*
Offline Offline

Posts: 33


View Profile
« Reply #5 on: 2009/12/15 13:03:16 »

just to be clear... didn't you mean the "render"-function of the component manager... as it calls every object or items which are "renderable"...
Logged
mikeschuld
Administrator
Sr. Member
*****
Offline Offline

Posts: 389


View Profile WWW
« Reply #6 on: 2009/12/15 16:02:53 »

That's what I meant Smiley I'm at the office so wasn't looking at my code at the time.

I would probably either use a Dictionary of cameras (which is already there in the camera manager) or just a List<> ArrayList<> etc. and use a foreach to set the active camera and then call the code like this:

Code:
foreach(HMCamera in WhateverCameraListYouUse) {
    HMComponentMananger.Draw(gameTime)
}

You'd probably want to do that in the Game class. This may be the method I use later on to implement multiple viewports for multiplayer on one screen setups, but we'll get to that when we get to that Wink
« Last Edit: 2009/12/15 16:17:40 by mikeschuld » Logged
Mikeske
Newbie
*
Offline Offline

Posts: 33


View Profile
« Reply #7 on: 2009/12/16 01:46:28 »

Wouldn't it be easier to call it in the draw override in the componentmanager itself?

Code:
        public override void Draw(GameTime gameTime)
        {
            foreach(HMCamera Viewportcamera in HMCameraManager.WhateverCameraListYouUse)
            {
            foreach (IIcRenderable render in renderable.Values)
            {
                GraphicsDevice.VertexDeclaration = render.VertexDeclaration;

                IcCameraManager.SetActiveCamera(Viewportcamera.name);

                IcEffectManager.SetActiveShader(render.Shader);
                IcEffectManager.ActiveShader.SetParameters(render);

                IcEffectManager.ActiveShader.Effect.Begin();
                foreach (EffectPass pass in IcEffectManager.ActiveShader.Effect.CurrentTechnique.Passes)
                {
                    pass.Begin();
                    render.Render(GraphicsDevice);
                    pass.End();
                }
                IcEffectManager.ActiveShader.Effect.End();
            }
            }
            base.Draw(gameTime);
        }

And an extention of the cameramanager class with your "WhateverCameraListYouUse"-idea?
and an extra bool "enabled" with it would solve my problem.
Going to try this one out tonight when I get home, will post the extended code for it if wanted Wink
Thankx for the patience with my idiotic reasoning  Cool

greetz,
Logged
Pages: [1]
  Print  
 
Jump to:  

Related Topics
Subject Started by Replies Views Last post
Tutorial 12 :: Adding in Advanced Camera Functionality Tutorial Discussion « 1 2 3 » mikeschuld 30 11116 Last post 2007/08/01 07:00:20
by Suzume
Parenting Camera to an Object Hazy Mind XNA Engine Requests rstackhouse 4 3098 Last post 2007/03/14 06:13:57
by 5parrowhawk
Camera Issues Hazy Mind XNA Engine minich21 6 3047 Last post 2007/08/14 21:27:30
by mikeschuld
Camera Issues Hazy Mind XNA Engine Trano 3 2811 Last post 2008/09/17 08:27:25
by mikeschuld
Camera Tracking Hazy Mind XNA Engine muchrejoicing 4 2007 Last post 2007/05/29 19:50:23
by daenris
Camera problem Hazy Mind XNA Engine Montynis 2 1686 Last post 2007/08/02 09:54:14
by Montynis
extending ObjectManager? Hazy Mind XNA Engine Wally 5 2297 Last post 2008/09/05 15:40:31
by Wally
Camera rotation issues (z-axis drift solved!) Hazy Mind XNA Engine ppardee 10 4272 Last post 2008/11/19 11:22:49
by inbreed
Powered by MySQL Powered by PHP Powered by SMF 1.1.12 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 0.18 seconds with 18 queries.