Entityvisible help?

Blitz3D Forums/Blitz3D Programming/Entityvisible help?

slenkar(Posted 2004) [#1]
Whenever I use entityvisible it always returns true.
I have tried exchanging the source and destination entity and it still always returns true.
; Entityvisible Example

; --------------------


Graphics3D 640,480

SetBuffer BackBuffer()


camera=CreateCamera()

PositionEntity camera,0,2,-10


light=CreateLight()

RotateEntity light,90,0,0


plane=CreatePlane()

;ground_tex=LoadTexture("media/Chorme-2.bmp")

;EntityTexture plane,ground_tex


cube=CreateCube()

;cube_tex=LoadTexture("media/b3dlogo.jpg")

;EntityTexture cube,cube_tex

PositionEntity cube,0,1,0


While Not KeyDown( 1 )


If KeyDown( 205 )=True Then TurnEntity camera,0,-1,0

If KeyDown( 203 )=True Then TurnEntity camera,0,1,0

If KeyDown( 208 )=True Then MoveEntity camera,0,0,-0.05

If KeyDown( 200 )=True Then MoveEntity camera,0,0,0.05




RenderWorld

Text 0,0,"Use cursor keys to move about"

Text 0,20,"ProjectedX: "+ProjectedX#()

Text 0,40,"ProjectedY: "+ProjectedY#()

Text 0,60,"ProjectedZ: "+ProjectedZ#()

Text 0,80,"EntityInView: "+EntityVisible(cube,camera)


Flip


Wend


End 
	




jfk EO-11110(Posted 2004) [#2]
the things between the two objects must be pickable. and also use entityinview to filter onscreen stuff.


slenkar(Posted 2004) [#3]
what does that mean?
sorry im a bit of a newb

There isnt anything in between the 2 objects

I also tried to use this command when I wasnt projecting text,

I have modified the above code just to include the bare bones of what is going on.


puki(Posted 2004) [#4]
Text 0,80,"EntityInView: "+EntityInView(cube,camera)


puki(Posted 2004) [#5]
Sorry "Slenkar" that was a bit of a short answer

With EntityVisible they will always see each other (doesn't relate to where you are looking)

EntityInView is working as the camera is "seeing" it - it's in the view of the camera


slenkar(Posted 2004) [#6]
o.k. thanks
how is entityvisible useful?


puki(Posted 2004) [#7]
You could be checking 2 game objects - such as 2 AI controlled characters - for example - nothing to do with the camera

EntityInView relates to the camera


Jeppe Nielsen(Posted 2004) [#8]
You could also check if an object is in another object´s view, by using a view angle:
;Obscurer example by Jeppe Nielsen 2004
;nielsen_jeppe@...

Graphics3D 800,600,16,2

viewangle#=45

CreateLight(2)

cam=CreateCamera()
PositionEntity cam,0,40,0
RotateEntity cam,90,0,0
CameraZoom cam,2

obj1=CreateCone()
RotateMesh obj1,-90,0,0

view=CreateCone(16,1,obj1)

RotateMesh view,-90,0,0
PositionMesh view,0,0,1
ScaleMesh view,0.5,0.5,0.5
EntityColor view,128,128,0
EntityAlpha view,0.8
UpdateViewCone(view,10,viewangle#)

obj2=CreateCube()

cube1=CreateCube()
EntityColor cube1,255,255,0
EntityPickMode cube1,3

cube2=CreateCube()
EntityColor cube2,255,255,0
EntityPickMode cube2,3

cube3=CreateCube()
EntityColor cube3,255,255,0
EntityPickMode cube3,3


Repeat

If KeyDown(203)

	TurnEntity obj1,0,2,0

EndIf

If KeyDown(205)

	TurnEntity obj1,0,-2,0

EndIf

If KeyDown(78)

	viewangle#=viewangle#+1
	If viewangle#>179
		viewangle#=179
	EndIf
	UpdateViewCone(view,10,viewangle#)	

EndIf

If KeyDown(74)

	viewangle#=viewangle#-1
	If viewangle#<15
		viewangle#=15
	EndIf
	UpdateViewCone(view,10,viewangle#)	

EndIf

an#=MilliSecs()/20
PositionEntity obj2,Sin(an#)*10,0,Cos(an#)*10

an#=MilliSecs()/50
PositionEntity cube1,Sin(an#)*6,0,Cos(an#)*6

PositionEntity cube2,Sin(an#+120)*6,0,Cos(an#+120)*6
PositionEntity cube3,Sin(an#+240)*6,0,Cos(an#+240)*6

RenderWorld

If CanSeeObject(obj1,obj2,viewangle)

	Color 255,255,255
	Text 400,200,"I see it :)",1
	CameraProject cam,EntityX(obj1),EntityY(obj1),EntityZ(obj1)
	x1=ProjectedX()
	y1=ProjectedY()
	CameraProject cam,EntityX(obj2),EntityY(obj2),EntityZ(obj2)
	x2=ProjectedX()
	y2=ProjectedY()	
	Color Rnd(255),Rnd(255),Rnd(255)
	Line x1,y1,x2,y2
	

EndIf

Color 255,255,255
Text 400,10,"Left/right to rotate observer",1
Text 400,30,"+ / - to change view angle",1
Text 400,50,"Yellow boxes obscurers the view",1
Text 400,70,"View angle : "+viewangle,1

Flip

Until KeyDown(1)
End

Function UpdateViewCone(cone,depth#,angle#)
	
	sc#=Tan(angle/2)*depth*2
	
	ScaleEntity cone,sc,sc,depth#
	
End Function

Function CanSeeObject(obj1,obj2,angle#=90)

dist#=EntityDistance(obj1,obj2)
dx#=(EntityX(obj2,1)-EntityX(obj1,1)) / dist
dy#=(EntityY(obj2,1)-EntityY(obj1,1)) / dist
dz#=(EntityZ(obj2,1)-EntityZ(obj1,1)) / dist

TFormVector 0,0,1,obj1,0

;dot product:
dot#=dx*TFormedX()+dy*TFormedY()+dz*TFormedZ()

If ACos(dot#)<angle/2
	
	Return EntityVisible(obj1,obj2)
	
EndIf

End Function



slenkar(Posted 2004) [#9]
ah I see entityvisible just checks if there are objects in the way or not


Zethrax(Posted 2004) [#10]
"ah I see entityvisible just checks if there are objects in the way or not"

Pretty much. I think it basically checks if a straight line can be picked between the centerpoints of the specified source and destination entities without any pick enabled objects getting in the way of that line.

If no objects in your game world are pick enabled (by setting their pickmode using EntityPickMode with the obscurer flag set to true) then it will always return true.


slenkar(Posted 2004) [#11]
o.k. thanks