how do you get a child entities location

Blitz3D Forums/Blitz3D Programming/how do you get a child entities location

MusicianKool(Posted 2010) [#1]
So i have a parent pivot at 0,0,0 and have many children scattered around the parent in every direction, but when I call getchild() then ask for the distance between the child and camera i get the distance between the camera and parent. if i use getchild() and ask for entityX , y , z with the global position relative to 0,0,0 on, i still get the parent to camera distance.

I am working on a tiled geosphere, it works, but i want to have only tiles that are in range to be rendered. So if a multi-million poly geosphere is created only a few thousand poly's need to be shown.

Function HideShowTiles(Source,Parent,Distance#)
	For i = 1 To CountChildren(Parent)
		ent = GetChild(Parent,i)
		eX# = EntityX#(ent,1):eY# = EntityY#(ent,1):eZ# = EntityZ#(ent,1)
		sX# = EntityX#(Source,1):sY# = EntityY#(Source,1):sZ# = EntityZ#(Source,1)
		Dist# = Sqr((eX#-sX#)*(eX#-sX#) + (eY#-sY#)*(eY#-sY#) + (eZ#-sZ#)*(eZ#-sZ#))
		If dist# < Distance# Then 
			ShowEntity (ent)
		Else
			HideEntity (ent)
		EndIf
	Next
End Function




Ross C(Posted 2010) [#2]
Are you parenting these entities in blitz, or are you loading a mesh containing child entities?


MusicianKool(Posted 2010) [#3]
I am generating the entities in Blitz. So yes parenting in Blitz.


_PJ_(Posted 2010) [#4]
TheWhjat sort of scales are you using? How far (should) the children be from the parent (roughly) in blitz units?

I think this line may be a root of the problem:
Sqr((eX#-sX#)*(eX#-sX#) + (eY#-sY#)*(eY#-sY#) + (eZ#-sZ#)*(eZ#-sZ#))



MusicianKool(Posted 2010) [#5]
Well right now the geosphere is scaled by 100, from a normal createsphere() size. the camera is 150 units from the parent
the parent is located at 0,0,0.
range to be rendered is 50.
but the moment a single tile is rendered all tiles are rendered.
plus the camera is inside the geosphere.

I'm starting to think that because all tiles are created relative to the global 0,0,0 that when the geosphere is scaled, Blitz uses the 0,0,0 location of the tiles created point, and because all are tiles created within the size of -.5 to .5 then when the camera is within the render range distance, then all the tiles are then rendered. I hope that explains it.

erm, is there a mesh distance, IE take the average of all the vertexes in a tile and use that scaled value to determine the distance to camera. that should work. or maybe a single vertex would work.


_PJ_(Posted 2010) [#6]
Oh right :)

I just realised... yoou're not Showing the parent after this function is called, are you?
Obviously when Show or Hide Entity is used on a parent, then it will affect the children too.


MusicianKool(Posted 2010) [#7]
Malice, Didn't work. I'm not hiding or showing the parent, just the children.


MusicianKool(Posted 2010) [#8]
oh yep, if I use a scaled vertex then it will show when within the distance range. but.... as the camera moves so does the vertex in opposite direction making visible tiles move opposing to the camera. not good, I'm guessing part of the Blitz3d engine. hmm...


MusicianKool(Posted 2010) [#9]
Here is the source. Fixed and works. sorry about the poor commenting.