Panda & C++ newbie questions

[size=59]And yet another noob enters the fray…[/size]
Hello all!

I decided to start learning about Panda3d and using it with C++, but it seems I hit a serious snag right from the start: how do (keyboard) events work in Panda when using C++?
The documentation is a bit…lacking in this regard and so I spent a long while struggling with the issue with pro-rsoft (thanks for your patience :stuck_out_tongue: ) without getting anywhere (we tried EventHandler::add_hook but couldn’t get it to work).

If anyone wants to share a sample code of some kind, it would be very much appreciated.

[size=59](I intend to post more pathetic questions into this thread if and when I get further, hence the name of the thread)[/size]

Indeed, any help concerning events is appreciated! I will later make some manual page about it or so.

I’ve looked into the source code, but I didn’t come very far, since the comments don’t contain the information about how to construct an event handler. We tried making the handler function of type EventHandler::EventFunction, and passing a pointer to it to add_hook, but that (unfortunately) didn’t work.
There is nothing on the manual or forum about this either.

There are examples of keyboard events in pview.cxx. If you use the PandaFramework library, you just hang hooks on the event handler it provides.

David

Thank you for your reply, but I encountered this error with the define_key in pview.cxx

error C2664: 'PandaFramework::define_key' : cannot convert parameter 3 from 'void (__cdecl *)(CPT_Event,void *)' to 'EventHandler::EventCallbackFunction (__cdecl *)'

Needless to say, it didn’t quite work out in my own test code either (same error obviously). Is this is a version 1.4.0 issue? I use VC8 for compiling.

The error message is telling you that the function you are trying to use as a callback function has the wrong kind of arguments. You have declared a function like this:

void my_callback_function(CPT_Event, void *);

But you need to declare it like this instead:

void my_callback_function(const Event *, void *);

David

Hmm, when using throw_event, is it possible to pass a typed object as argument to the event? I used an EventStoreValue(obj) but it doesn’t appear to work.

In what way doesn’t it work? But if you inherit from TypedWritableReferenceCount, you don’t even need to use EventStoreValue, you can use EventStoreTypedRefCount, which is even better. In any case, there should be examples within the Panda codebase for both cases.

David

Well, OdeGeom is the class in question, which just inherits from TypedObject. I want to pass an instance of it to a event (catched in Python code). How would I do that? I couldn’t find examples of that.

Hmm, well, the fact that it inherits from TypedObject and not TypedReferenceCount makes it problematic to pass it to Python; you’ll need to create a new instance to pass to Python or you risk early destruction. Do these Ode objects really only inherit from TypedObject? Trouble.

But you could do this:
throw_event(“foo”, new EventStoreValue<OdeGeom *>(my_ode_geom));

However, I don’t think Python would be able to decode that properly. The EventManager system is really designed to understand TypedWritableReferenceCount objects only, plus one regrettable special case for PandaNodes (which can’t inherit from TypedWritableReferenceCount).

To pass an OdeGeom, we’ll need to change its inheritance, which might be a good idea anyway. But that will involve major restructuring of the panda-ode layer. I’ll talk to the programmer who’s implemented this.

David

I’m actually trying to create a collision event system for ODE, a feature which has been requested over a dozen times.
Should I just make the OdeGeom class a TypedReferenceCount (and of course fix all the references to it)?
(I have no idea what Writable does, but I guess it’s not needed to pass it to Python?)

Um, maybe. Let me get back with you in a little bit on that.

(“Writable” classes may be written to a bam stream.)

David