Adding a lifebar above a scenenode

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Ced666
Posts: 86
Joined: Fri Jan 13, 2006 10:29 am
Location: Belgium

Adding a lifebar above a scenenode

Post 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
Aukecomps
Posts: 19
Joined: Wed Apr 05, 2006 7:53 pm

Post by Aukecomps »

...
Last edited by Aukecomps on Sun Dec 06, 2015 1:13 am, edited 1 time in total.
Ced666
Posts: 86
Joined: Fri Jan 13, 2006 10:29 am
Location: Belgium

Post 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.
Hirte
Posts: 73
Joined: Sat Apr 01, 2006 1:32 pm

Post 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
Xaron
Posts: 310
Joined: Sun Oct 16, 2005 7:39 am
Location: Germany
Contact:

Post by Xaron »

I would use the draw2dImage method where you can define a target rectangle to scale the image.

Regards - Xaron
Ced666
Posts: 86
Joined: Fri Jan 13, 2006 10:29 am
Location: Belgium

Post 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...
hybrid

Post 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.
Aukecomps
Posts: 19
Joined: Wed Apr 05, 2006 7:53 pm

Post by Aukecomps »

...
Last edited by Aukecomps on Sun Dec 06, 2015 1:14 am, edited 1 time in total.
Ced666
Posts: 86
Joined: Fri Jan 13, 2006 10:29 am
Location: Belgium

Post 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
Aukecomps
Posts: 19
Joined: Wed Apr 05, 2006 7:53 pm

Post by Aukecomps »

...
Last edited by Aukecomps on Sun Dec 06, 2015 1:14 am, edited 1 time in total.
Ced666
Posts: 86
Joined: Fri Jan 13, 2006 10:29 am
Location: Belgium

Post 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).
Rohit
Posts: 7
Joined: Tue Apr 04, 2006 5:37 pm
Location: Shimla , India
Contact:

Post 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.
O Draconian Devil ! O Lame Saint !
So Dark the Con of Man !
http://two.fsphost.com/irrlicht
Ced666
Posts: 86
Joined: Fri Jan 13, 2006 10:29 am
Location: Belgium

Post 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.
hybrid

Post 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.
Aukecomps
Posts: 19
Joined: Wed Apr 05, 2006 7:53 pm

Post by Aukecomps »

...
Last edited by Aukecomps on Sun Dec 06, 2015 1:15 am, edited 1 time in total.
Post Reply