EntityOrder problem

Blitz3D Forums/Blitz3D Programming/EntityOrder problem

vibe37(Posted 2004) [#1]
I'm doing an FPS and I want to have the player's gun always visible, so I gave it EntityOrder -1. The problem is that the mesh now does not display correctly, as if the entity order "inside" the mesh didn't work. That is, some parts of the mesh are drawn atop others although they shouldn't. Sorry, I don't know how to describe this better... any ideas?

-kungfista


GfK(Posted 2004) [#2]
any ideas?
You really need to sort your sig out, its a mess.


vibe37(Posted 2004) [#3]
done :)


Regular K(Posted 2004) [#4]
I dont have B3D but try to set the guns order to 0 then go through every other entity and bump theres up 1 to make sure the gun is on top?


vibe37(Posted 2004) [#5]
Tried that and found out that I get the same problem with the other entities, i.e. the map in the first place. Buildings that are occluded by others now show through, making everything look like a Picasso painting ;) Must be a general problem with EntityOrder, I already double-checked everything...
Come on guys, someone must have had this problem before!?


Genexi2(Posted 2004) [#6]
As said in the docs :

Setting an entity's order to non-0 also disables z-buffering for the entity, so should be only used for simple, convex entities like skyboxes, sprites etc.



GfK(Posted 2004) [#7]
Could always render the player's gun to a separate, dedicated camera. That'd work.


vibe37(Posted 2004) [#8]
@Genexi2: Dammit, I must be blind! I overlooked that.

@GfK: How would that look like? I've never done such a thing before... perhaps you could post a little sample code? Thx! :)


Rob(Posted 2004) [#9]
Another trick is making the gun small yet close to the camera. It looks the same size and doesn't get stuck in walls (from your point of view).


vibe37(Posted 2004) [#10]
That's a neat trick BloodLocust, I did it that way and it works great. Btw, your FPS shell really helped me get started with my project... thanks!


D4NM4N(Posted 2004) [#11]
I had this problem with a clock dash, It liiked inside out, and i realised it was too near to the camera, try making tthe mesh really small and setting it near tio the camera and ensure your camera range near is outside the mesh


Ross C(Posted 2004) [#12]
Well, render your level first and hide the gun. Then make sure your not clearing the z buffer. Use "cameraclsmode" for this. Hide the level, then render the gun.


vibe37(Posted 2004) [#13]
@Ross
Sorry, I'm a miserable newb... What do you mean by "render the gun/level"? Could you give me a short code sample so that I can understand it?


Jeremy Alessi(Posted 2004) [#14]
HideEntity(Gun)
ShowEntity(Level)
Renderworld()
ShowEntity(Gun)
HideEntity(Level)
Renderworld()

flip()

Something like that ... I think he meant.


Ross C(Posted 2004) [#15]
Hey, check this out

Graphics3D 800,600
SetBuffer BackBuffer()


Global camera = CreateCamera()
CameraRange camera,0.1,1000

Global gun = CreateCylinder(8,True,camera) ; create a 8 seg cylinder, filled, and parented to the camera
PositionEntity gun,1,-0.2,0
ScaleEntity gun,0.3,2,0.3
RotateEntity gun,90,0,0


Global light = CreateLight()

Global world = CreatePivot() ; create a pivot called world

;just set up some cubes so there is something on screen. Parent these cubes to the world pivot, so
; you only need to hide the world pivot, to hide the level :o)

Dim cube(40)
For loop = 0 To 40
	cube(loop) = CreateCube(world) ; parent all the objects in the level to the world pivot, for easy hiding
	EntityColor cube(loop) , Rand(100,255), Rand(100,255), Rand(100,255)
	PositionEntity cube(loop) , Rnd(-15,15), 0, Rnd(5,35)
Next



While Not KeyHit(1)


	If KeyDown(203) Then TurnEntity camera,0,1,0
	If KeyDown(205) Then TurnEntity camera,0,-1,0
	If KeyDown(200) Then MoveEntity camera,0,0,0.2
	If KeyDown(208) Then MoveEntity camera,0,0,-0.2

	If KeyHit(2) Then HideEntity world
	
	HideEntity gun ; hide the gun. You don't really NEED to hide the gun, as the next render will render over it, but no point in rendering it twice :)
	CameraClsMode camera,True,True ; set the camera cls mode so the last renderworld gets cleared
	UpdateWorld
	RenderWorld ; render the world
	
	ShowEntity gun ; show the gun and
	HideEntity world ; hide the world
	CameraClsMode camera,False,True ; set the camera cls mode so the last render to the backbuffer won't be cleared, only written on top of
	RenderWorld ; render the gun

	Flip ; flip the back buffer so it can be seen
	
	ShowEntity world ; show the world again for the next time
	
Wend
End


Uses two renders. Firstly renders the world and hides the gun. Then shows the gun and hides the world. All the level objects are parented to the one pivot called "World", so to hide the world you just hide the pivot, and anything parented to the pivot will get hidden too. Hope that helps a little :o)


vibe37(Posted 2004) [#16]
Man, that's a really slick way of doing it! Plus your code didn't only solve my problem but also gave me an understanding of how rendering & z-buffering works. You should put this into the code archives or make a tutorial out of it, I think it might help a few other n00bs as well :) Many thanks!