PDA

View Full Version : planets and gui / questions



largo_winch
28-04-2011, 10:47
hello.
1) petr, here a little attempt to include planets for my gui with openGL (tbgl). my question: if I push planet button I include they into scene. then you can pick up the planets (spheres objects) with mouse (grid spheres).
2) if I want to pick up a bigger sphere (planet, for example a sun) with my grid catcher how to do that for different size of planets?
3) my current problem: but I cannot see the data for this new planets send to listview. any help could be fine. source code into zip folder. project in works, not finished yet.
thanks, bye, largo

Simone
28-04-2011, 13:21
Ciao largo_winch,
For send information to the listiview control you have to send the handle of dialog window (hDlg) to the function RenderMyImage or you have to keep the global variable hDlg and remove local variable hdlg in TBMain function .

I Hope it works.

Ciao,
Simone

Petr Schreiber
28-04-2011, 19:15
Hi,



2) if I want to pick up a bigger sphere (planet, for example a sun) with my grid catcher how to do that for different size of planets?
You already have radius member in planetary objects user data. So to check if mouse points to given object, just check, whether the position is inside the object radius (with some safety offset). I would recommend to store all planet IDs in array, and then you can do something like:


FOR i = 1 to planetCount
TBGL_EntityGetPos(%sScene, planet(i), x, y, z)
data = TBGL_EntityGetUserDataPointer(%sScene, planet(i))

IF TBGL_PointInside3D(MouseX, MouseY, MouseZ, %TBGL_OBJ_SPHERE, x, y, z, data.radius) THEN
' -- This is our object, let's mark it and so on
...

EXIT FOR ' -- Stop searching
END IF
NEXT


Side note: Have a look at article "EntityDataSignature" (http://www.thinbasic.com/community/content.php?20-tbgl-entity-data-signature), it discusses approach on how to sign different objects in scene using unique value. This way, if you create planets even in random order, but with planetary signature, you can retrieve their complete list to array anytime later.

Other approach could be modification of your current one. You would store the biggest radius in scene and then use:


entity = TBGL_EntityFindNearestByPos(%sScene, %TBGL_DISPLAYLIST , MouseX, MouseY, MouseZ, biggestRadius, biggestRadius, biggestRadius)

But I guess this is not the best approach if you wish to include other objects than spheres in display lists later (could give false positives).


Petr

P.S. Ciao Simone, its great to see you more active on the forum lately!

ErosOlmi
28-04-2011, 21:39
Ciao largo_winch,
For send information to the listiview control you have to send the handle of dialog window (hDlg) to the function RenderMyImage or you have to keep the global variable hDlg and remove local variable hdlg in TBMain function .

I Hope it works.

Ciao,
Simone

To translate in English what Simone wrote :D
If you check inside function "RenderMyImage" you will see that handle of the main dialog is not defined because "hDlg" is always ZERO.
Why? If you check "TBMain" function hDlg is defined as LOCAL so outside TBMain function hDlg does not has any meaning.

I think the problem is that you adjusted this script from an old script made by Simone who used global variables (option to avoid wherever possible).

To fix the script either

remove "Local hDlg As DWord" in TBMain function (you have already it as global variable)
pass the handle of the window to "RenderMyImage" as parameter and use that parameter as window handle


Ciao
Eros

Simone
28-04-2011, 22:56
To translate in English what Simone wrote :D

yes sorry for my bad English. It's terrible what i've wrote

as Eros wrote the problem is the double declaration of hdlg(global and local in tbmain function).
if you don't want to change too much the program the solution it's to remove the local declaration of hdlg in tbmain function. But maybe is better don't use global variable and send the handle of dialog to REnderMyImage function.

hope this post it's more understandable.:D

Ciao,
Simone

P.s. Thanks Petr!

largo_winch
29-04-2011, 12:35
thank you all for fast replies and help (simone, petr, eros). I will check my example again and now I am seeing what's the problem with global and local hdlg. regards,
largo

largo_winch
17-05-2011, 21:31
here a new version of my planets-gui-example. have fun to use it. a lot of work, but good stuff to learn more about openGL and thinbasic. context menu included (thanks for help to eros).
all included in zip folder with tbasic file. next time I will try to use two different openGL windows as petr has shown good approach some days before.

regards, largo

zlatkoAB
18-05-2011, 13:23
Finaly someone who create interesting program...i like this astro stuff
program is ok but planets looks like bunch of molecules maby will be better
put smaller number of planets...just suggestion...

ErosOlmi
18-05-2011, 18:42
Finaly someone who create interesting program...

"Finally" is a little ... what to say ... not nice for the many hundreds of programs present into this forum developed by many users.

Maybe if you have some time you can check bonus pack at http://www.thinbasic.com/index.php?option=com_jdownloads&Itemid=95&task=viewcategory&catid=5
that is a collection of old (maybe some of them will not run due to thinBasic changes during the yars) but interesting applications developed by many users (for free).

Ciao
Eros

zlatkoAB
18-05-2011, 20:50
Hi Eros ...
I don't mean nothing bad ....
After all this mathematics experiments this program looks refreshing
-for me
of course i like Dan-s enthusiasm for programming :D

ErosOlmi
18-05-2011, 20:59
No problem zlatko :arms:

largo_winch
19-05-2011, 11:28
thanks eros and zlatko for feedback (no problem with your well mentioned sentences).

for petr or eros: can you test my last example? there is a little problem with sending three different data to listview (for object id's). two different objects you can see in listview but the third is going to stay in second row too :) / I have tried in my last example to take another approach for creating planet objects.
thanks, largo

ErosOlmi
19-05-2011, 14:29
for petr or eros: can you test my last example? there is a little problem with sending three different data to listview (for object id's). two different objects you can see in listview but the third is going to stay in second row too :) / I have tried in my last example to take another approach for creating planet objects.
thanks, largo

Largo

check code


Global hDlg As DWord

Function TBMain()
Local hDlg As DWord


hDlg is both global and local
You create DIALOG in fucntion TBMain, it means that when you later will use hDlg in other function (RenderMyImage) it will be ZERO because you are using the global variable that has never be assigned any value.

To resolve the problem, remove line


Local hDlg As DWord


from function TBMain

Ciao
Eros

largo_winch
20-05-2011, 14:51
To resolve the problem, remove line
? (http://www.thinbasic.com/community/)
1
Local hDlg As DWord




from function TBMain

yes, I have done and follow your advice (I took hDlg as global) but the very little problem still remains with listview control. I only see three different object-id numbers in two rows but there must be four rows ;) its not very important for me but would be nice to find better solution.
bye, largo

Petr Schreiber
20-05-2011, 18:18
Hi Largo,

I am sorry, but I am not sure I understand your code. What I see from tests is that conditions writing to row 3 and 4 are never satisfied, so that't why it does not get any update.

I am also not sure if it is good idea to continously insert and delete items - I would recommend to pre-create 4 rows on the beginning, and then write to them like:


ListView_SetItem(hDlg, %ListViewInfo, 1, 1, entity)
ListView_SetItem(hDlg, %ListViewInfo, 1, 2, Format$(pallet.pos.x, "0.0000"))
ListView_SetItem(hDlg, %ListViewInfo, 1, 3, Format$(pallet.pos.y, "0.0000"))
ListView_SetItem(hDlg, %ListViewInfo, 1, 4, Format$(pallet.pos.z, "0.0000"))
ListView_SetItem(hDlg, %ListViewInfo, 1, 5, Format$(pallet.pos.r))

' -- And so on...

Petr

largo_winch
23-05-2011, 14:47
I am also not sure if it is good idea to continously insert and delete items - I would recommend to pre-create 4 rows on the beginning, and then write to them like:

thank you petr. I followed your tipp, finally my example works fine. I satisfied two entities with new "listview setItem" and all four different objects were picked up in listview!

bye, largo

Petr Schreiber
24-05-2011, 07:43
I am happy it worked for you :D


Petr