PDA

View Full Version : TBGL_EntityFind...-question



ReneMiner
02-11-2014, 09:59
a question about the various TBGL_EntityFind...-functions:
f.e.

TBGL_EntityFindNearestByPos( SceneID, EntityType, x, y, z, rangeX, rangeY, rangeZ [, GlobalCoordinates ] )

parameter-description:

Type of entity to search for, can take one of following values:

%TBGL_LIGHT
%TBGL_CAMERA
%TBGL_PIVOT

%TBGL_MODEL
%TBGL_DISPLAYLIST

%TBGL_BOX
%TBGL_SPHERE
%TBGL_TORUS
%TBGL_CYLINDER

what EntityType to specify for a function-slot?

Petr Schreiber
02-11-2014, 16:06
Hi Rene,

the function slot entities are not supported by this command at the moment.

What kind of functionality would be better for you: add %TBGL_FunctionSlot equate, or develop some smarter method, which would allow to perform filter like "all function slot entities which implement member x and function y"?


Petr

ReneMiner
02-11-2014, 18:00
the simplest i think is to add some equate for the already existing TBGL-functions so these are fully functional on all entity-types TBGL provides us with currently...

A function-slot does not mandatory need to have a user-type attached - does it? It sounds reasonable at first if it would work like:
"please TBGL, list all enemy-spaceships near that point xy" but i think then i would just go myself through the list of enemy-spaceships but not through all entities then and measure all theirs distances...

edit: it's thinkeable - if it were faster than in a tB-script- if TBGL would examine a scene and just go through a passed list of entities - and return what is left then.

So user sends a string, array or now possible too: variadic parameter-list (http://www.thinbasic.com/community/showthread.php?12481-unlimited-function-parameters#top) of entity-IDs that might be interesting, TBGL could probably be faster than the user to check for distances in a range to a certain point or entity and TBGL returns the closest entityID of the listed ones in range - or zero if none in range.
If getting closest listed entity by position it's pretty simple - but if the referred entity is also in the list... hmmm- return any other but itself nor any of its own children...



Function TBGL_EntityGetClosest( ByVal sceneID As Long, _
ByVal entityID As Long, _
ByVal listIDs(Any) As Long, _
Optional Byval maxRange As Double _
) As Long
'...
Function TBGL_EntityGetClosestPos( ByVal sceneID As Long, _
ByVal X As Double, _
ByVal Y As Double, _
ByVal Z As Double, _
ByVal listIDs(Any) As Long, _
Optional Byval maxRange As Double _
) As Long
'...



edit+

if we already on it, i have two and a half simple suggests that might be handy one day:



' - 1 -

Function TBGL_EntityIsChildOf( ByVal SceneID As Long, -
ByVal suspectedChildID As Long, _
ByVal suspectedParentID As Long _
) As Boolean

While TBGL_EntityExists(sceneID, suspectedChildID )
suspectedChildID = TBGL_EntityGetParent( SceneID, suspectedChildID )
If suspectedChildID = suspectedParentID Then Return TRUE
Wend

End Function

' - 1.5 - almost the same as above:
Function TBGL_EntityGetTopParent(ByVal SceneID As Long, _
ByVal EntityID As Long _
) As Long

While TBGL_EntityExists( SceneID, TBGL_EntityGetParent( SceneID, EntityID ))
EntityID = TBGL_EntityGetParent( SceneID, EntityID )
Wend

Function = EntityID

End Function


' - 2 -

Function TBGL_EntityExists( ByVal SceneID As Long, ByVal EntityID As Long) As Boolean

Function = ( TBGL_EntityGetFreeID( SceneID , EntityID ) <> EntityID )

End Function

Petr Schreiber
03-11-2014, 23:58
Hi Rene,

thanks for the inspiration - ideas noted, if time allows, I will try to add to next TBGL release!


Petr

ReneMiner
15-11-2014, 10:32
one more function to entities (especially bones-, parent- & child-stuff) that would be really helpful, in tB i have some VERY SLOW equivalent because Entity-enumeration is dynamic done to the script, at first I need the highest assigned EntityID in the current scene, (call it like %HighestID here) and then have to check all the numbers for theirs existance and if exist i need to check if it's a child of desired EntityID... really cumbersome:



Function TBGL_EntityListChildren( ByVal Scene As Long, Byval EntityID As Long ) As String

Local i As Long
Local sResult As String ' (returns Long-array)

For i = 1 to %HighestID
If TBGL_EntityExists( Scene, i ) Then
If TBGL_EntityGetParent(Scene, i ) = EntityID Then sResult += MKL$(i)
EndIf
Next
Function = sResult

End Function


optional there could be 2 switches to the function where the second switch only makes sense if the first one is used:
- list grandchilds etc. too
- list only childs that are in use (like in a collapsed tree it won't list hidden subchilds then)


Currently it forces me to store all information the entity already has stored somewhere in the depth of TBGL a second time at the user-data-slot. This can not be good...
it's like i would store positions of all entities - makes no sense- TBGL knows all the current positions exactly... while my stored data depends on continous refreshing it in the correct moment, which costs unnecessary resources and is not fool-proof