Page 1 of 2

Adding a lifebar above a scenenode

Posted: Thu Apr 06, 2006 6:54 pm
by Ced666
Hello !

I am making a strategy game and I would like to add a lifebar just above my units. I think an option could be to use a billboard but I have no idea if it's possible to draw things on it (because of course the lifebar will depend of the life left of the unit :wink: ). Drawing 2D shapes is not really a solution because if the unit is far, the lifebar is smaller (of course, there is still a solution to calculate the size but it can be tricky).

Any idea ?
Thanks

Posted: Thu Apr 06, 2006 7:02 pm
by Aukecomps
...

Posted: Thu Apr 06, 2006 7:34 pm
by Ced666
:? I really don't understand what you wrote...


just give every bar the same distance to the camera
This is not what I want because they need to be just above the scenenode (the unit) which can be anywhere in the scene.

Posted: Thu Apr 06, 2006 7:38 pm
by Hirte
You could get the position of the node with getAbsolutePosition(), add a value to the y-axis and you have a vector where you can load your lifebar

Posted: Thu Apr 06, 2006 7:46 pm
by Xaron
I would use the draw2dImage method where you can define a target rectangle to scale the image.

Regards - Xaron

Posted: Thu Apr 06, 2006 7:47 pm
by Ced666
The problem with the lifebar is that it is like a billboard: it is a flat rectangle that always llok at the camera. So, knowing the position of where to put it is not the problem.
The problem is because I need to draw myself the bar (it depends of the life of the unit) so it can't be a billboard (or at least I don't know how to draw on a billboard). Another option is to draw a 2D rectangle (that's perfect for the lifebar itself) but then the problem is that the length of the bar needs to be adapted depending of the position of the node to the camera (and how to calulate this length ?).
I'm just wondering if there is not an easier way of doing it...

Posted: Thu Apr 06, 2006 7:50 pm
by hybrid
Yes, but you also need the billboard technique to have the lifebars always face the screen. So just add a billboard as a child node to your characters. Changing those lifebars can be done, e.g. by using a set of different textures, or by manually changing the pixels. Depends on the possible values and what will be possible. If only the length is important you might also scale the billboard on the X axis.

Posted: Thu Apr 06, 2006 7:50 pm
by Aukecomps
...

Posted: Fri Apr 07, 2006 11:29 am
by Ced666
@Aukecomps: sorry, but I still don't get you... (maybe my english is too bad).
so you know the proportion of the object (in x y z difference to the camera),
Yes, I know the proportions: it is for example (just an example) 10 on 1 for the Width/Height ratio. But it has nothing to do with 3D coordinates because it is a 2D shape (I cannot make it 3D because for example if the camera rotates, the bar will not face the camera anymore). And I don't see what you mean by x y z difference to the camera.
keep those proportions the same, but set one (or more) positions (x OR y OR z) different so that the absolute distance to the camera object becomes the constant distance you wish
Hum, welll :P .. Errr in fact I'm lost here (I simply don't understand at a language point of view, not for the math that are beyond this).

But ok, maybe I've found a solution: first, take a point (in 3D coordinates) above the center of the node (that's easy). Then convert this point in 2d coordinates. For this part, I have absolutely no idea how to do it. Does anybody know how to convert a 3D coordinate into a 2D point ? (This conversion should be possible directly, as opposed to the one in the other way).

Then, with this point, I know the center of my rectangle. I need then to calculate the distance between my node and the camera (easy) and apply a factor depending of this distance to the length and width of my bar (I think this can be found by trying several factors).

Do you think this is a good way to go ? And so, how to convert 3D coordinates into 2D screen coordinate ?
Thanks

Posted: Fri Apr 07, 2006 11:51 am
by Aukecomps
...

Posted: Fri Apr 07, 2006 12:02 pm
by Ced666
you know the x and y coordinates on the screen, of each bar, right?
Nope. What I know is the position of the node and I can deduce a 3D point just above the node. This point can be used as the center of the rectangle but it is still a 3D point and not a coordinate on the screen.

I think you are mixing a little bit everything. You cannot simply convert from a screen coordinate to a 3D coordinate (you can only convert to a ray that starts from the screen and goes out in the scene). You really know what you are speaking about ?

Do you really understand the problem ? The fact that I need to insert a 2D rectangle at a specific position in a 3D world.

Don't want to be rude but I don't think we are speaking about the same thing (or maybe I didn't understand your post correctly).

Posted: Fri Apr 07, 2006 12:20 pm
by Rohit
You Really need CEGUI (Crazy Eddies GUI) SDK and CEGUI Layout Editor.
CEGUI is specifically designed for "in game GUI" like LifeBar,HealthIndicator,
,TotalScore et cetera . You just need to design your GUI in the CEGUI layout editor.
Many game libraries like OGRE have there whole model so defined so
as to integrate CEGUI into them.

Posted: Fri Apr 07, 2006 12:30 pm
by Ced666
Ok, I'm also using CEGUI (no, I started to look at CEGUI and integrate it in my game, so I don't have I deep knowledge of it yet). But, I don't think this will solve the problem. I mean I want my life bar as part of the 3D scene and CEGUI is intended for everything that is GUI, which means 2D only. So still, the problem is there to specify where on the screen this *** lifebar needs to be drawn.
Or can you specify a 3D coordinate for your bar ? (I seriously doubt about this one).

The problem is not really the drawing of the bar itself but rather where to position it on the screen and size it depending of the distance between the node and the camera.

Posted: Fri Apr 07, 2006 12:34 pm
by hybrid
So what is the problem with using billboards then?
And there are methods to convert a 3d position into screen coordinates:

Code: Select all

core::position2d<s32> CSceneCollisionManager::getScreenCoordinatesFrom3DPosition
which would make it possible to draw images on the screen as overlays. But this would draw on top of all 3d entities, thus lifebars from objects far away would hide objects in front of them.

Posted: Fri Apr 07, 2006 12:41 pm
by Aukecomps
...