Entity dimensions

Blitz3D Forums/Blitz3D Programming/Entity dimensions

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

You could just use this code ;o) mesh.b3d is the mesh you want to measure :o)

I use these functions to calculate my bounding boxes for my editor.

Graphics3D 800,600
SetBuffer BackBuffer()

Global mesh = LoadMesh("mesh.b3d")

Global camera = CreateCamera()
PositionEntity camera,0,0,-10




Global mesh_width = find_rightmost_vertex(mesh) - find_leftmost_vertex(mesh)
Global mesh_height = find_highest_vertex(mesh) - find_lowest_vertex(mesh)
Global mesh_depth = find_zmost_vertex(mesh) - find_zleast_vertex(mesh)


While Not KeyHit(1)



	UpdateWorld
	RenderWorld
	Text 0,0," mesh width = "+mesh_width
	Text 0,10," mesh height = "+mesh_height
	Text 0,20," mesh depth = "+mesh_depth
	Flip
Wend
End

Function find_lowest_vertex#(mesh)

	lowest# = 999999.0
	no_surfaces = CountSurfaces(mesh)
	
	For sloop = 1 To no_surfaces

		Surface_Handle = GetSurface(mesh, sloop)
		
			For loop = 0 To CountVertices(surface_handle)-1
			
				TFormPoint VertexX(surface_handle,loop),VertexY(surface_handle,loop),VertexZ(surface_handle,loop),mesh,0
				If TFormedY#() < lowest Then
					lowest = TFormedY#()
				End If
			Next
	Next
	Return lowest
	
End Function

Function find_highest_vertex#(mesh)

	highest# = -999999.0
	no_surfaces = CountSurfaces(mesh)
	
	For sloop = 1 To no_surfaces

		Surface_Handle = GetSurface(mesh, sloop)
		
			For loop = 0 To CountVertices(surface_handle)-1
			
				TFormPoint VertexX(surface_handle,loop),VertexY(surface_handle,loop),VertexZ(surface_handle,loop),mesh,0
				If TFormedY#() > highest Then
					highest = TFormedY#()
				End If
			Next
	Next
	Return highest
	
End Function

Function find_leftmost_vertex#(mesh)

	leftmost# = 999999.0
	no_surfaces = CountSurfaces(mesh)
	
	For sloop = 1 To no_surfaces

		Surface_Handle = GetSurface(mesh, sloop)
		
			For loop = 0 To CountVertices(surface_handle)-1
			
				TFormPoint VertexX(surface_handle,loop),VertexY(surface_handle,loop),VertexZ(surface_handle,loop),mesh,0
				If TFormedX#() < leftmost Then
					leftmost = TFormedX#()
				End If
			Next
	Next
	Return leftmost
	
End Function


Function find_rightmost_vertex#(mesh)

	rightmost# = -999999.0
	no_surfaces = CountSurfaces(mesh)
	
	For sloop = 1 To no_surfaces

		Surface_Handle = GetSurface(mesh, sloop)
		
			For loop = 0 To CountVertices(surface_handle)-1
			
				TFormPoint VertexX(surface_handle,loop),VertexY(surface_handle,loop),VertexZ(surface_handle,loop),mesh,0
				If TFormedX#() > rightmost Then
					rightmost = TFormedX#()
				End If
			Next
	Next
	Return rightmost
	
End Function

Function find_zmost_vertex#(mesh) ; the furthest away on the Z axis

	zmost# = -999999.0
	no_surfaces = CountSurfaces(mesh)
	
	For sloop = 1 To no_surfaces

		Surface_Handle = GetSurface(mesh, sloop)
		
			For loop = 0 To CountVertices(surface_handle)-1
			
				TFormPoint VertexX(surface_handle,loop),VertexY(surface_handle,loop),VertexZ(surface_handle,loop),mesh,0
				If TFormedZ#() > zmost Then
					zmost = TFormedZ#()
				End If
			Next
	Next
	Return zmost
	
End Function

Function find_zleast_vertex#(mesh) ; the closest on the Z axis

	zleast# = 999999.0
	no_surfaces = CountSurfaces(mesh)
	
	For sloop = 1 To no_surfaces

		Surface_Handle = GetSurface(mesh, sloop)
		
			For loop = 0 To CountVertices(surface_handle)-1
			
				TFormPoint VertexX(surface_handle,loop),VertexY(surface_handle,loop),VertexZ(surface_handle,loop),mesh,0
				If TFormedZ#() < zleast Then
					zleast = TFormedZ#()
				End If
			Next
	Next
	Return zleast
	
End Function