maximum and minimum coordinates

Blitz3D Forums/Blitz3D Beginners Area/maximum and minimum coordinates

Moraldi(Posted 2008) [#1]
Please take a look to the following code:
Graphics3D 640,480 
SetBuffer BackBuffer() 

Global minx#, miny#, minz#
Global maxx#, maxy#, maxz#

camera=CreateCamera() 

light=CreateLight() 
RotateEntity light,90,0,0 

modelname$ = "mak_robotic.3ds"

staticmesh% = LoadMesh(modelname$)
If staticmesh <> 0 Then PositionEntity camera,0,MeshHeight(staticmesh)/2,-MeshDepth(staticmesh)*3
FreeEntity staticmesh

; Load mesh 

animmesh% = LoadAnimMesh(modelname$)

; alpha entity
ent = animmesh

notinit%=True

While ent
	If EntityClass(ent)="Mesh"
		For si=1 To CountSurfaces(ent)
			surf% = GetSurface(ent, si)
			For vi=0 To CountVertices(surf)-1
				x# = VertexX(surf, vi)
				y# = VertexY(surf, vi)
				z# = VertexZ(surf, vi)
				If notinit=True
					minx = x
					miny = y
					minz = z
					maxx = x
					maxy = y
					maxz = z
					notinit = False
				Else
					If x < minx Then minx = x
					If y < miny Then miny = y
					If z < minz Then minz = z
					If x > maxx Then maxx = x
					If y > maxy Then maxy = y
					If z > maxz Then maxz = z
				EndIf
			Next		; vi
		Next			; si
	EndIf
	ent = NextChild(ent)
Wend

Animate animmesh

While Not KeyDown( 1 ) 

	RenderWorld
	UpdateWorld
	If CameraPick(camera, MouseX(), MouseY()) Then Text 0,0, "Picked"
	Text 0,20,"min: "+minx+","+miny+","+minz
	Text 0,40,"max: "+maxx+","+maxy+","+maxz
	Flip 

Wend

FreeEntity animmesh

End


Function NextChild(ent)
	Local siblingcnt
	If CountChildren(ent)>0
		Return GetChild(ent,1)
	EndIf

	Local foundunused=False
	Local foundent = 0, parent,sibling
	While foundunused=False And ent<>0
		parent = GetParent(ent)
		If parent<>0
			If CountChildren(parent)>1
				If GetChild(parent,CountChildren(parent))<>ent
					For siblingcnt = 1 To CountChildren(parent)
						sibling = GetChild(parent,siblingcnt)
						If sibling=ent
							foundunused = True
							foundent = GetChild(parent,siblingcnt+1)
						EndIf
					Next
				EndIf
			EndIf
		EndIf
		ent = parent
	Wend
	Return foundent
End Function


Ultimate Unwrap3D gives me different values:
min: -11.717, -0.697, -9.948
max: 9.026, 47.521, 12.299

I suppose somewhere I make a mistake. But I don't know where


Danny(Posted 2008) [#2]
At first glance, your code to calculate the bounding box looks fine to me..

Perhaps it's got something to do with the different between a 'mesh' and an 'animmesh' ?! Not sure why you're loading a 3ds file as an animmesh? As far as I know, they don't support bones or anything like that anyway. See if it makes a difference if you load the file as a normal Mesh, in stead of an animmesh???

good luck,
Danny


Moraldi(Posted 2008) [#3]
Perhaps it's got something to do with the different between a 'mesh' and an 'animmesh'

That's the reason I am posting :)

There is no difference from mak_robotic.x


Ross C(Posted 2008) [#4]
Your calling the next child function after your checking the first time for vertices in an unknown child. I'm not sure what happens if you scan a meshes vertices, without first selecting a child. You may want to change this and see if you get different results.


Warner(Posted 2008) [#5]
After using:
				x# = VertexX(surf, vi)
				y# = VertexY(surf, vi)
				z# = VertexZ(surf, vi)

use:
TFormPoint x,y,z,ent,0
x#=tformedx()
y#=tformedy()
z#=tformedz()



Moraldi(Posted 2008) [#6]
@Warner: You are great man!
It works! But... how...and why?

I am using Blitz3D for about 5 years and I was thinking that I am an experienced Blitz3D guy. But after Warner's post I am back to first day ;)

Thank you very much :)


Warner(Posted 2008) [#7]
Vertices are part of the mesh, that is the original 3d data from the file. A mesh is wrapped by an entity. An entity is a matrix that transforms the mesh right before rendering it. The entity can be transformed/rotated/scaled without affecting the org. mesh data. When reading vertexx/y/z you get the original 3d coordinates, they still need to be transformed. Using TFormPoint like this converts the coordinates from mesh relative coords (=ent) into world relative coords (=0)


Moraldi(Posted 2008) [#8]
Oh. This clears all.
Thanks again