Getting the size of an object in the viewport?

Blitz3D Forums/Blitz3D Programming/Getting the size of an object in the viewport?

sswift(Posted 2004) [#1]
Does anyone have any suggestions how one could determine how "large" an entity is in a camera view?

In order to do robust level of detail, one needs to take into account camera zoom when determining what level of detail to show at any particular location. I'm trying to think of a way to do this.

I suppose one could calculate distance from the camera the old fasioned way, and then modify it by zoom somehow, but I'm not sure what equations to use and that would require the user to pass the camera's current zoom value to the function since there's no command to get it any other way.


sswift(Posted 2004) [#2]
Hm... I just thought of one method that might work. I could transform points from the world to the camera view with the appropriate projection commands... But those commands if I'm not mistaken are kind of fidgety and don't return real values if the point ends up outside the screen if I remmeber correctly.

[edit]

Well maybe projecting will work. It seems more reliable than I remmeber it being. The only problem is it does not give you any coordinates if the projected points are behind the camera... Which presents an issue for entities which are very close to the camera, partially in front of it, partially behind it. I suppose I could do some math with tformpoint to flip those points on the wrong side of the camera around the camera's Z axis so that they are in front of the camera so the project function will tell me where they are... Hm...


Picklesworth(Posted 2004) [#3]
There's a bounding box function somewhere in the code archives I think. It may contain what you're looking for. Actually, here it is:
Function targetBox(ent)
	If ent=0 Return 0
	If EntityInView(ent,cam)=0 Return 0
	CameraProject cam,EntityX(ent),EntityY(ent),EntityZ(ent)
	leftmost#=ProjectedX()
	rightmost#=ProjectedX()
	topmost#=ProjectedY()
	bottommost#=ProjectedY()
	For i=1 To CountSurfaces(ent)
		s=GetSurface(ent,1)
		For v=0 To CountVertices(s)-1
			TFormPoint VertexX(s,v),VertexY(s,v),VertexZ(s,v),ent,0
			CameraProject cam,TFormedX(),TFormedY(),TFormedZ()
			If ProjectedX()<leftmost leftmost=ProjectedX()
			If ProjectedX()>rightmost rightmost=ProjectedX()
			If ProjectedY()<topmost topmost=ProjectedY()
			If ProjectedY()>bottommost bottommost=ProjectedY()
		Next
	Next
	color 200,200,200
	Rect leftmost,topmost,rightmost-leftmost,bottommost-topmost,0
End Function



sswift(Posted 2004) [#4]
Yeah just found that, but it doesn't work when the object is partially in front of the camera and partially behind. And it is more of a reticle style thing. I don't want to know the size of the bounding 2D region, I want to know the scale of the object. So I only want to check the size one axis.

I'll figure it out... I forgot about the cameraproject function when I was asking the question.