View Full Version : Entitypos not working for me
Michael Clease
30-05-2008, 09:04
I am trying to get entityfindbypos to find an entity from the mouse position and it doesnt seem to be working for me i dont know if it is a scaling issue.
As an example I added it to Petr's tileforplatformer example and it did work there either.
Any Ideas?
Petr Schreiber
30-05-2008, 10:00
Hi Abraxas,
you almost gave me heart attack after waking up :)
The main problem is that you are calling:
TBGL_GetPixelInfo tbgl_MouseGetPosX, tbgl_MouseGetPosY, %TBGL_PINFO_XYZ, X,Y,Z
before you render anything, I recommend this order:
TBGL_SceneRender(%SCENE1)
TBGL_GetPixelInfo tbgl_MouseGetPosX, tbgl_MouseGetPosY, %TBGL_PINFO_XYZ, X,Y,Z
WinTitle = " Ent = " + TBGL_EntityFindByPos( %Scene1, %TBGL_DISPLAYLIST, X, Y, 0, %TRUE )
WinTitle += " X= " + X + " Y= " + Y + " Z= " + Z + " "
... but as TBGL_EntityFindByPos requires exact match ... the best thing for the job would be TBGL_EntityFindNearestByPos with some reasonable range, try this:
TBGL_SceneRender(%SCENE1)
TBGL_GetPixelInfo tbgl_MouseGetPosX, tbgl_MouseGetPosY, %TBGL_PINFO_XYZ, X,Y,Z
WinTitle = " Ent = " + TBGL_EntityFindNearestByPos( %SCENE1, %TBGL_DISPLAYLIST, X-0.5, Y-0.5, Z, 2, 2, 2, %TRUE )
WinTitle += " X= " + X + " Y= " + Y + " Z= " + Z + " "
... for the particular example ( -0.5 because those tiles are not centered ). But for this the x,y,z must be at least SINGLE, not LONGs ... please see solution in attachement :)
So the main problem was that you were comparing position unprojected from mysterious clipping volume and not the tiles ( because they were not yet rendered in the moment ).
Thanks,
Petr
Michael Clease
30-05-2008, 13:39
What a fool :-[
why didnt i see that ???
i do have one question why do i have to start my TBGL_EntityCreatedlslot from 2 or above and not 1???
thanks for your help as always
Petr Schreiber
30-05-2008, 14:47
Hi,
i do have one question why do i have to start my TBGL_EntityCreatedlslot from 2 or above and not 1???
Where do you see that? I can only guess that #1 is already occupied with camera entity ( not obligatory )?
If you do not like that, you can use TBGL camera instead, nasty but possible:
'
' *NASTY* entity sample, do not follow :D
'
Uses "TBGL"
' -- Create and show window
Dim hWnd As Dword = TBGL_CreateWindowEx("TBGL script - press ESC to quit", 640, 480, 32, %TBGL_WS_WINDOWED or %TBGL_WS_CLOSEBOX)
TBGL_ShowWindow
' -- Create scene
%SCENE1 = 1
TBGL_SceneCreate(%SCENE1)
%eMyList = 1
%lMyList = 1
tbgl_NewList %lMyList
tbgl_color 255,128,0
tbgl_Sphere 1
tbgl_EndList
' -- Create something to look at
TBGL_EntityCreateDLSlot(%SCENE1, %eMyList, 0, %lMyList)
DIM FrameRate AS DOUBLE
' -- Resets status of all keys
TBGL_GetAsyncKeyState(-1)
' -- Main loop
While TBGL_IsWindow(hWnd)
FrameRate = TBGL_GetFrameRate
TBGL_ClearFrame
' -- Camera from pure classic TBGL
tbgl_Camera 15, 15, 15, 0, 0, 0
' -- Rest of render using entities
TBGL_SceneRender(%SCENE1)
TBGL_DrawFrame
' -- ESCAPE key to exit application
If TBGL_GetWindowKeyState(hWnd, %VK_ESCAPE) Then Exit While
Wend
TBGL_DestroyWindow
Thanks,
Petr
Michael Clease
30-05-2008, 18:20
Oh dear my poor little brain cant cope at the moment :-[
For some reason I thought that each element of the entity system kept its own list. I will explain below.
so if i wanted serveral cameras i could start at number 1 to whatever...
then if i setup displaylists i could use numbers 1 to whatever again...
I thought that each type of entity had its own number system and not that all the entities are using the same number list.
Sorry to waste your time Petr.
Petr Schreiber
30-05-2008, 19:49
Hi Abrax,
you are right about the fact all types of entities share the one "number space".
Maybe it seems clumsy, but as there can be ( in theory ) over 2,000,000,000 entities in one scene + 2,000,000,000 separate scenes :D, I hope it is not big problem.
Sharing the same id space has the advantage that any type of entitiy can be parent/child of any type of entitity easily.
No time wasted, I am always happy when I can answer your questions.
Petr