Hi,
I am trying to add a DirectGui element at a position on the scene. But when i set the position (pos) as (5,0,0) i do not see the object positioned there. Upon looking at the manual , i understood that the elements are by default parented to aspect2d and hence have no effect.
But when i tried to reparent it to render and then set the pos keyword or used setPos, i did not see any object on the screen.
Here is the program i tried:
import direct.directbase.DirectStart
from direct.gui.OnscreenText import OnscreenText
from direct.gui.DirectGui import *
#add some text
bk_text = "DirectOptionMenu Demo"
textObject = OnscreenText(text = bk_text, pos = (0.85,0.85),
scale = 0.07,fg=(1,0.5,0.5,1),align=TextNode.ACenter,mayChange=1)
#add some text
output = ""
textObject = OnscreenText(text = output, pos = (0.95,-0.95),
scale = 0.07,fg=(1,0.5,0.5,1),align=TextNode.ACenter,mayChange=1)
#callback function to set text
def itemSel(arg):
output = "Item Selected is: "+arg
textObject.setText(output)
#create a frame
menu = DirectOptionMenu(text="options", scale=0.1,items=["item1","item2","item3"],initialitem=2,
highlightColor=(0.65,0.65,0.65,1),command=itemSel)
menu.reparentTo(render)
menu.setPos(1,0,0)
base.camera.setPos(0,10,0)
#run the tutorial
run()
If there is no way i can set a direct UI object in a 3d world , then why does the pos parameter in the constructor take 3 parameters?
Also, when menu’s pos is set in the constructor as :
menu = DirectOptionMenu(text="options", scale=0.1,items=["item1","item2","item3"],initialitem=2,
highlightColor=(0.65,0.65,0.65,1),command=itemSel,
pos=(-1.5,2,1)
the menu is placed at that position in the corner of the screen. But i am unable to navigate to the node using the mouse beyond the value of 1 for the z in the pos parameter . The mouse does not work as it would for models. Is this an expected behaviour?
Am i missing something here about Direct Gui? Or is this a limitation of UI? I am using panda 1.1 ion debian.
Also, is it possible to place a direct ui element at a 3d position in the screen say at (50,0,0) like any other panda node?(Since it is a NodePath it should be, but it doesnot seem to work). Please advise me on how i can set a direct UI element at some point in a scene.