Skip to main content
GameDev.net gamedev.net
🔒 Locked 🎮 Unity

implementing a hud

Started by wild_pointer Jan 9, 2007 at 12:56 AM 5 replies 1.5k views
Original Post
wild_pointer
wild_pointer
Is it neccessary to treat a hud completely differently from the 3d objects in your scene? I'm hoping to avoid having to treat them as a special case. I was also hoping to have the hud as children of the camera, so that I could easily swap cameras and not have to change the hud around, which would be greatly simplified by being able to treat them as standard game objects. My main problem I guess is deciding on a clean way to handle setting and resetting the projection matrix for 2d. Currently my rendering code looks something like this: Somewhere in initialization:

D3DXMATRIXA16 projection;
D3DXMatrixPerspectiveFovLH(&projection, ...);
device->SetTransform(D3DTS_PROJECTION, &projection);

device_->Transform(D3DTS_VIEW, camera_->ViewTransform());
for each Object o in scene:
  device->SetTransform(D3DTS_WORLD, o->WorldTransform());
  o->Draw();
Object's Draw method delegates to a Drawable member class: Object::Draw() { drawable->Draw(); } Any suggestions on how to handle overlays/2d elements in a generic way? Where should all those transform calls be? When and where should I set up the orthographic projection? I have some ideas but I'm not terribly happy with any of them, so I'd appreciate some input.
[size=2]
Endurion
Endurion
You might as well use pretransformed vertices so whatever matrices are currently set do not affect your GUI/HUD.

This has some downsides: In your system they should probably be the last objects to be rendered so they don't interfere with the 3d objects. It also deactives lighting.
Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>
waferthinninja
waferthinninja
The normal way to do it would be:

* Set up your camera for 3D, with z-buffer and lighting enabled
* Render your 3D objects
* Set up your camera for 2D (orthogonal projection), disable z-buffer and lighting
* Render your HUD

I dont really see that you gain much by trying to treat them like normal game objects.

I hope this is helpful

James
JasonBlochowiak
JasonBlochowiak
Trying to treat sprites as if they were full 3d objects will buy you more pain than benefit.
Ozymandias42
Ozymandias42
Unless you're doing billboarding or writing a particle engine of course.
RabblePants
RabblePants
I think you'll find that separating them from the 3D Objects in your scene will be much easier and painless than trying to make them all the same thing. A couple of considerations:

(1) HUD stuff is all 2D, so your rendering is usually drastically simplified. If you had the HUD and 3D Objects be the same thing, you'd have to turn of lighting, fog, z-buffer, and then change your camera to a 2D ortho projection camera. We do this anyway when rendering the HUD, but you would have to put a flag identifying which objects are "HUD" Objects to render them in this way .. thus dirtying up your regular 3D Scene objects.

(2) The regular 3D Objects tend to go through a lot of logic than rarely (if ever) coincides with the HUD. Physics, AI, networking, etc. You would have to selectively disable these components when processing a simple 2D button, for example.

(3) It's also much easier to keep your HUD separate from your game / objects in the interest of abstracting your "presentation" layer. Meaning, you can change out your HUD to use a completely different architecture, without trying to figure out how untangle it from your game logic.

So yeah .. separate your HUD and Game Logic :)

[Edited by - Grafalgar on January 11, 2007 12:55:12 AM]
wild_pointer
wild_pointer
You've convinced me =P Thanks guys.
[size=2]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.