Collision Detection 2.0

Hello! In C++ Panda3D, what should I assign a CollisionTraverser class instance to? There is not much in the manuals about traversers, so is there anything like base.cTrav in C++. If no, what is there?

Assign it to whatever you’d like. You need to just call traverse() on it every frame.

So like this?:

// Global:
CollisionTraverser *cTrav = new CollisionTraverser;

// In main:
taskMg->add(new GenericAsyncTask("Traverses collision", &collTraverse, nullptr))

// Somewhere else:
AsyncTaskManager::DoneStatus collTraverse(GenericAsyncTask *task, void *data) {
  return AsyncTaskManager::DS_cont;

Yes, that’s the idea, though of course you need to do cTrav-> and CollisionTraverser *cTrav if you are allocating it on the heap as you are, but I assume those were typos.

1 Like

Yeah, I meant to do that. :slight_smile: :slight_smile:

Should I use:



CollisionTraverser *

You said that the former does reference counting while the latter doesn’t. Does a traverser need to have a reference count or not?

Look in the API reference. Does the class inherit from ReferenceCount? If so, use PT() to manage the reference counts automatically. If not, its lifetime is not managed by Panda, so you can use a regular pointer and manage it yourself using new/delete, or use automatic storage duration, or std::unique_ptr, or std::shared_ptr, or whatever you like.

So basically, anything that extends ReferenceCount (or its subclasses) should be used with PT while the others shouldn’t, right?

Yes, that is what I tried to say in my previous post.