Always-in-front entity?

Blitz3D Forums/Blitz3D Programming/Always-in-front entity?

Jeroen(Posted 2003) [#1]
Hi,

Is it possible to "overrule" an entity by saying: "you are always in front of the other objects"

Thanks,

Jeroen


fredborg(Posted 2003) [#2]
Have a look at EntityOrder!


Shambler(Posted 2003) [#3]
Yes, use EntityOrder with a negative value

i.e. EntityOrder MyEntity,-1

the lower the number the more in front the entity becomes so

EntityOrder ent1,-1
EntityOrder ent2,-2

means both ent1 and ent2 will be in front of everything else plus ent2 will also always be draw in front of ent1.

This is useful for things like a 3D on screen HUD.


Jeroen(Posted 2003) [#4]
woooah I never spotted that command: how useful!

thanks!


Zethrax(Posted 2003) [#5]
Using EntityOrder for meshes turns off z-buffering for the mesh, though, so it will cause problems with non-convex meshes. A better solution is to use a second camera, with an EntityOrder value of -1 to force it to render last.

Just stick the second camera and whatever you want to render with it outside the range of the main camera and make sure the background screen color is black, so that the background is not rendered. Once you have the second camera set up you shouldn't need to do anything else to it, beyond changing the graphics displayed whenever your program needs them changed.

Here's the function I use for setting up a second camera for displaying a heads-up-display. I'm not sure why I've got CameraClsMode set to false values (it's been a while since I've worked on the game this is from) but I think there's a good reason for it.

Function create_hud()
hud_camera = CreateCamera()
CameraRange hud_camera, 1.0, 100.0
CameraClsMode hud_camera, False, False
EntityOrder hud_camera, -1

; -- Setup HUD status display.
hud_info = LoadSprite ( "..\media\sprites\display info2.png" )
EntityOrder hud_info, -1
SpriteViewMode hud_info, 2
EntityParent hud_info, hud_camera
MoveEntity hud_info, -3.55, 2.4, 4.5

; -- Setup crosshair.
crosshair = LoadSprite ( "..\media\sprites\crosshair7.png" )
EntityOrder crosshair, 1
ScaleSprite crosshair, 0.1, 0.1
EntityParent crosshair, hud_camera
PositionEntity crosshair, 0.0, 0.0, 5.0
PositionEntity hud_camera, 0.0, 5000.0, .0
End Function


Rottbott(Posted 2003) [#6]
Axeman, why bother with a second camera just for a HUD? Surely that's all flat surfaces (i.e. quads or sprites) anyway, so Z-order shouldn't matter..


Al Mackey(Posted 2003) [#7]
Axeman, your CameraCLSMode function isn't clearing the Z-Buffer, AND you're using a negative EntityOrder on your crosshairs and hud. So when the second camera renders, it's still not using the Z-buffer that you were setting up all this second camera stuff just to use. You might as well just be using one camera with the HUD and crosshairs parented to it. I bet it would give you a noticable speed increace.


FlameDuck(Posted 2003) [#8]
Axeman, why bother with a second camera just for a HUD? Surely that's all flat surfaces (i.e. quads or sprites) anyway, so Z-order shouldn't matter..
While his example is probably not the best in the world, his reasoning is still perfectly valid. He explained in his post that the reason for doing this is to get non-convex shapes to work. It is unfortunate that his example code doesn't contain any, but that wasn't the point of setting up a second camera.


GfK(Posted 2003) [#9]
While his example is probably not the best in the world, his reasoning is still perfectly valid.
Absolutely. For instance, try setting your game and your HUD up on the same camera, then apply CameraZoom.

You'll begin to see the point of rendering a HUD with a separate, dedicated camera.


Al Mackey(Posted 2003) [#10]
True, but my policy is to avoid multiple rendering passes whenever possible, especially if they require using HideEntity() and ShowEntity() on dozens of objects every frame. For the HUD, if you apply 1/Zoom to ScaleEntity, it will stay perfectly in place as the camera zooms (assuming its origin is in the middle of the screen).


poopla(Posted 2003) [#11]
I thought mark made hideentity() and showentity() inconsequential a while back. As in, they wouldnt eat any resources at all. *shrug*


Neo Genesis10(Posted 2003) [#12]
Nice method... but does anyone know of a workaround to do the opposite - ie, farther in the distance while retaining Z buffering?


GfK(Posted 2003) [#13]
I thought mark made hideentity() and showentity() inconsequential a while back. As in, they wouldnt eat any resources at all. *shrug*
In the case of a HUD camera, you can just position it away from the game world and point it in the opposite direction. That way you don't have to mess about hiding and showing entities.

I don't think I'd recommend it as an alternative to EntityOrder though where in-game objects are concerned.


Zethrax(Posted 2003) [#14]
As I said, it's been a while since I've worked on the game engine that code sample was taken from and I think I'd just started playing around with the second camera code. The main reason I think I went to a second camera routine was to display a gun model for the player without having it go through walls the player was up against, and also, so I could use a larger gun placed further away from the camera (to make it appear the correct size) to keep it out of the minimum camera range.

The 'CameraClsMode' is probably wrong for that though, as Al Mackey said.