View frustum culling

Blitz3D Forums/Blitz3D Programming/View frustum culling

Is there a way of turning off Blitz view culling? I decribe my problem, I am setting a transform matrix with Tomspeed's DX7 dll, so that the perspective is off-center, now if I move the camera the 3d models are disappearing (by the effect of blitz automatic view culling) in correspondence to the original non-off-center matrix, so sometimes when they are supposed to be still "in view".

I even tried Tomspeed DX7 dll with SetCullMode(1) , so cull mode set to none, but nothing does Blitz do culling, but if I set cullmode to 2 or 3 (CW and CCW) there it takes it ...

Did somebody experimented more with view matrix and blitz?

You're confusing view culling with backface culling (which is what the CW and CCW settings are referring to).

But I don't think you can tell Blitz to stop frustum culling in any case.

You are right, and what I am trying to disable or to transform is view culling.

Any idea what blitz uses to check if it has to hide the model? It is not entitybox or entityradius, is it somekind of Bounding Box?

Adding some distant vertices to the model, does the trick (entity is in view all the time). Then I have to do my own view culling...

Quote from 1.97 update:

"Added MeshCullBox for manual mesh culling. This allows you to correct some situations where an
animated mesh extends beyond the guesstimated bounding box."

MeshCullBox x#,y#,z#,width#,height#,depth#

maybe this helps? don't know if this only works with anims...

Oops this MeshCullBox meshhandle,x#,y#,z#,width#,height#,depth# does something, but not nice. It makes my models flickering, appearing and disappearing even at location (relative to the camera) where it didn't previously.

Is there somewhere a description of what the function does exactly?

Thanks for the suggestion.

I doubt MeshCullBox will help, and I'm not sure there is a solution to this problem without more hacking.

Ok here is some code, if someone has a suggestion... it requires tom's DX7 dll as found in DevilChild's Shadow system.

Use key 3 and 4 to move the perspective left/right, 1 and 2 change the aspect ratio, use the arrow keys to move the camera.


Graphics3D 640,480,32,2

If DX7_SetSystemProperties(SystemProperty$("Direct3D7"), SystemProperty$("Direct3DDevice7"), SystemProperty$("DirectDraw7"), SystemProperty$("AppHWND"), SystemProperty$("AppHINSTANCE")) Then RuntimeError "Error initializing dx7."

Global mymat.mat = New mat
Global mymat2.mat = New mat

Global inputratio#=1.33
Global movex#=0.0
InfiniteFarClipPlane(mymat,mymat2)
cam=CreateCamera()
CameraClsColor cam,255,255,255
CameraProjMode cam,1
;CameraRange cam,1,99
PositionEntity cam,0,0,-1000

;AmbientLight 255,255,255

cube=CreateCube()
;MeshCullBox cube,0,0,0,1000,1000,1000
ScaleEntity cube,100,100,100
EntityColor cube,0,255,0

lines=createline(-150,150,-1000,-150,150,100000,0)
lines=createline(-150,150,100000,150,150,100000,lines)
lines=createline(150,150,100000,150,150,-1000,lines)
lines2=createline(-150,-150,-1000,-150,-150,100000,lines2)
lines2=createline(-150,-150,100000,150,-150,100000,lines2)
lines2=createline(150,-150,100000,150,-150,-1000,lines2)

EntityColor lines,255,0,0
EntityColor lines2,255,0,0
;CameraZoom cam, 3.0
light=CreateLight()
PositionEntity light,50,50,-50
TurnEntity light,45,45,0

Global cullmode=1

;workaround for visibility
;surf=GetSurface(cube,1)
;AddVertex (surf,0,0,1000)
;AddVertex (surf,0,0,-1000)
;AddVertex (surf,-1000,0,0)
;AddVertex (surf,1000,0,0)


While KeyHit(1)=False

	If KeyDown(200)
		MoveEntity cam,0,0,10
	Else If KeyDown(208)
		MoveEntity cam,0,0,-10
	Else If KeyDown(205)
		MoveEntity cam,10,0,0
	Else If KeyDown(203)
		MoveEntity cam,-10,0,0
	EndIf
	If KeyDown(82) Then cullmode=-1
	If KeyDown(79) Then cullmode=1
	If KeyDown(80) Then cullmode=2
	If KeyDown(81) Then cullmode=3
	If KeyDown(75) Then cullmode=4
	If KeyDown(76) Then cullmode=5
	If KeyDown(77) Then cullmode=6
	If KeyDown(2) Then inputratio=inputratio-0.01
	If KeyDown(3) Then inputratio=inputratio+0.01
	
	If KeyDown(4) Then movex#=movex#-1
	If KeyDown(5) Then movex#=movex#+1
	
	TurnEntity cube,1,1,0

	InfiniteFarClipPlane(mymat,mymat2)

	DX7_SetFillMode(3)

	Cls()
	CameraClsMode(cam, 1, 1)
	RenderWorld()

	WireFrame(1)
	HideEntity(cube)	
	ShowEntity lines
	ShowEntity lines2

	CameraClsMode(cam, 0, 0)
	RenderWorld()
	
	WireFrame(0)
	ShowEntity(cube)
	HideEntity lines	
	HideEntity lines2


	Color 255,0,0
	Text 10,10,mymat\m1+","+mymat\m2+","+mymat\m3+","+mymat\m4
	Text 10,20,mymat\m5+","+mymat\m6+","+mymat\m7+","+mymat\m8
	Text 10,30,mymat\m9+","+mymat\m10+","+mymat\m11+","+mymat\m12
	Text 10,40,mymat\m13+","+mymat\m14+","+mymat\m15+","+mymat\m16
	
	Text 10,60,"trisrendered:"+TrisRendered()
	Text 10,70,"inview:"+EntityInView(cube,cam)
	
	Text 10,90,mymat2\m1+","+mymat2\m2+","+mymat2\m3+","+mymat2\m4
	Text 10,100,mymat2\m5+","+mymat2\m6+","+mymat2\m7+","+mymat2\m8
	Text 10,110,mymat2\m9+","+mymat2\m10+","+mymat2\m11+","+mymat2\m12
	Text 10,120,mymat2\m13+","+mymat2\m14+","+mymat2\m15+","+mymat2\m16
	
	Text 10,140,DX7_GetSrcBlendMode%()+"/"+DX7_GetDestBlendMode%()
	Flip()

Wend

EndGraphics

End

;D3DMATRIX
Type mat
 Field m1#,m2#,m3#,m4# ;m1 fov
 Field m5#,m6#,m7#,m8# ; m6 aspect ratio
 Field m9#,m10#,m11#,m12# ;m11 far clip plane, m12 if set to 0.0 (or under 1.0) ->ortho if set to 1.0->perspective
 Field m13#,m14#,m15#,m16# ;m15 near clip plane
End Type



Function InfiniteFarClipPlane(m.mat,m2.mat)
 ;Local m.mat = New mat
 DX7_GetTransform(3,m)
DX7_GetTransform(2,m2)
	m\m6=inputratio
 ;infinite far clip plane
 e#=0.00000001
 m\m11 = 1.0 - e ;far clip plane
 m\m15 = .1*(e - 1.0) ;.1 = camera near clip plane
	m\m9=movex#/100.0
	;m\m10=movex#/100.0
 DX7_SetTransform 3,m

End Function


Function createline(x1#,y1#,z1#, x2#,y2#,z2#, mesh=0)
	
	If mesh = 0 Then 
		mesh=CreateMesh()
		EntityFX(mesh,16)
		surf=CreateSurface(mesh)	
		verts = 0	
		AddVertex surf,x1#,y1#,z1#,0,0
	Else
		surf = GetSurface(mesh,1)
		verts = CountVertices(surf)-1
	End If
	
	AddVertex surf,(x1#+x2#)/2,(y1#+y2#)/2,(z1#+z2#)/2,0,0 
	; you could skip creating the above vertex and change the line below to
	; AddTriangle surf,verts,verts+1,verts+0
	; so your line mesh would use less vertices, the drawback is that some videocards (like the matrox g400)
	; aren't able to create a triangle with 2 vertices. so, it's your call :)
	AddVertex surf,x2#,y2#,z2#,1,0
	
	AddTriangle surf,verts,verts+2,verts+1
	
	Return mesh
End Function



Have you tried this?:
MeshCullBox cube,-1000,-1000,-1000,2000,2000,2000

No I thought the first 3 parameters were the Box center coordinates, and the 3 others the box size!

Thanks it works!