I am building a HUD system for an XNA project that uses some 3d rendering for some of the HUD components. I am using polymorphism, with each component having an ID assigned that identifies itself. For the 3D hud component, I have a pre-draw method that renders a scene to a texture, which is then used to display the frame in the HUD component after the main scene is rendered.
What I want to do is to setup some kind of delegate (or something) that can be setup at runtime, which will instruct the 3D hud object to call a draw method from another object, without hardcoded it in the 3D class. Hard to explain so I hope I am making sense...
public override void PreDraw()
{
_device.SetRenderTarget(_renderTarget);
_device.Clear(_clearColour);
//render scene
_scene.Draw(); <-- I want this to be setup as some form of delegate.
_device.SetRenderTarget(null);
base.PreDraw();
}---------- Post added at 11:45 AM ---------- Previous post was at 11:37 AM ----------
A better way of explaining the problem.
When I instantiate the 3D HUD object, I want to pass it a unique rendering scene object (a class) via the constructor, so I can use one 3D hud class only. The rendering class objects will all have a 'Draw()' method.
---------- Post added at 12:27 PM ---------- Previous post was at 11:45 AM ----------
Well, I got round the problem simply by using more polymorphism.
I have a set scene method in the 3D hud component that has the base class of the rendering object passed to it. The base class object was instantiated with one of its subclasses, which pretty much follows the same techniques as the hud system.
If anyone could suggest a better way of doing this without polymorphism it would be appreciated, as I'm concerned about any impacts on performance from using polymorphism.
Thanks.


Sign In
Create Account

Back to top









