Han-Get Bounding Box 3D

From Vectorlab
Jump to: navigation, search


Sets two variables storing the top left and bottom right points of an object, both in 2D and 3D. This overcomes the limit of {{{2}}} which will always return screen coordinates, also in 3D, thus leading to wrong results. By Orso B. Schmid


{ Orso ************************************************ }
{ returns 3D info of top-left and bot-right of a 3D obj bbox } 
{ if the object is 2D it returns the normal bounding box (which is screen based) and fails on 3D views }
PROCEDURE H_GetBBox3D(h: HANDLE; VAR topL3D, botR3D : VECTOR);
	VAR
		wid, hei, dep : REAL;
		cen3D : VECTOR;
		obj : HANDLE;
		
	BEGIN
		IF h <> NIL THEN
		
			{ check if this is a 3D object }
			IF GetObjectVariableBoo(h, 650) THEN BEGIN
				Get3DCntr(h, cen3D.x, cen3D.y, cen3D.z);
				
				{ 3D loci raise a warning with Get3DInfo, which is expectable }
				IF GetType(h) <> 9 THEN
					Get3DInfo(h, hei, wid, dep);
				
				topL3D.x := cen3D.x - wid/2;
				topL3D.y := cen3D.y + hei/2;
				topL3D.z := cen3D.z + dep/2;
				
				botR3D.x := cen3D.x + wid/2;
				botR3D.y := cen3D.y - hei/2;
				botR3D.z := cen3D.z - dep/2;
				
			{ otherwise is 2D }
			END ELSE
				GetBBox(h, topL3D.x, topL3D.y, botR3D.x, botR3D.y);
	END;