i have trouble finding the path for Panda3D functions.
for example, if i want to call getForeground(), how do i know the path: showbase.showbase.win.getProperties().getForeground() ? - if i don’t search the forum or sample programs.
btw: i searched getForeground in Reference, it saids
how should i comprehense this path ?
If I’m not much mistaken, it means that “getForeground” is a method of the “WindowProperties” class, which is in the “panda3d.core” package (if I recall my Python nomenclature correctly).
If I may ask, why are you searching this way around? I would expect rather that you’d usually have an object that you wanted to do something with, and so would look at what methods it has available, rather than having a method that you want to find an object to apply to, which appears to be your case…
In short, your I find your situation and intent confusing – could you please clarify it?
I’m afraid that I’m still not confident that I understand what you’re asking, but let me attempt to answer anyway…
Hmm… Given that one could potentially have more than one window, I would imagine that you’d want to get hold of a specific instance in order to specify which window it is that you want information on. Based on what experience I have with Panda (and I may very well be incorrect here), this might be fetched from some global singleton instance somewhere.
In general I would expect to be dealing with instances of objects and methods belonging to them, rather than free-floating functions, in case that’s what you were expecting.
So… Given that you can find the class to which a method belongs and the module in which to find that class, both from the reference, is there anything more that is not answered?
WindowProperties::getForeground() does not need an EXPLICIT argument. It is an instance method, and thus needs the “self” argument. But this is added automatically by Python IF (!!!) you have an instance.
Is it possible that you didn’t type exactly what you are posting?
>>> if(WindowProperties().getForeground()==0): pass
>>> if(WindowProperties.getForeground()==0): pass
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: descriptor 'getForeground' of 'libpanda.WindowProperties' object needs an argument
is incorrect - an argument is actually being provided to it, as it desires: in Python, as enn0x indicated, instance methods – which getForeground is, I believe, and which it should be described as in the reference – are automatically provided as their first argument a reference to the object on which they are being called, often given the parameter name “self”.
That’s perhaps a little trickier – you essentially want to know what class “showbase.win” is. I imagine, however, that it’s mentioned somewhere in the manual, so a search of that might help. Knowing the class you should be able to simply look up its methods in the reference.
Are you trying to instantiate the WindowProperties class there? If so, why? How would it know which window it’s supposed to be describing?
i am not familiar with these objects,nodes,classes,methods,attributes and instances…
i was used to programming with pointers and addresses.
i found another example of how confused i am:
where does .node() come from?
why shouldn’t it be
base.cam.setLens(lenstype) or base.camera.setLens(lenstype) ?
why make it so complicated ?
if .cam and .camera are at the same level in base, why do they have different properties, yet they are named so similar?
Aaah, I think that this is the core of the problem. Panda is, I believe, a strongly object-oriented engine, and using it without at least some knowledge of object-orientation is likely to be painful. In short, I strongly recommend at least taking a look at a decent tutorial on object-oriented programming.
As to the base.cam, etc. issue, I hesitate to attempt an explanation before you’ve looked into object-orientation, but in short (and presuming that I have this all correct myself), “setLens” is a method contained by a sub-class of the PandaNode class (which is one of the fundamental classes in Panda), called “LensNode”. On the other hand, “base.cam” is likely a NodePath (one of the other fundamental classes in Panda), which essentially acts as a handle for PandaNodes. The “node()” method in NodePath fetches its associated PandaNode, I believe. As to why there is that separation, I’m afraid that I don’t know, offhand.
As for that I would recommend you read the entire python tutorial i linked earlier, take a look at chapter 6.4 which introduces modules.
IMHO Learning python from O’Reilly is another example of a good python book for people that already know programming.
as for base.win if you do print base.win you get …GraphicsWindow object…
Which tells you that base.win is a GraphicsWindow which i believe is set in ShowBase.py since print base gives you …ShowBase instance… so win is a object(The default window) automatically provided by ShowBase to you
(Which i believe is not productive to learning BTW)
from panda3d.core import WindowProperties
from panda3d.core import OrthographicLens
lens = OrthographicLens()
print "What is base"
print "What is base.cam"
print "What is base.cam.node"
print "What is base.cam.node()"
print "What is base.cam.node().setLens"
print "What is base.cam.node().setLens(lens)"
print "What is base.cam.node() now?"
From those results you should be able to figure out what happens and why, il give you the second one: base.cam tells you render is a parent of camera which is the parent of cam (Read scene graph manipulation for more info)