Uhm… i have another problem…
#include "pandaFramework.h"
#include "pandaSystem.h"
#include "aiCharacter.h"
#include "typeHandle.h"
#include "genericAsyncTask.h"
#include "asyncTaskManager.h"
#include <collisionRay.h>
#include <collisionHandlerQueue.h>
#include <collisionTraverser.h>
#include <collisionSphere.h>
#include <nodePathCollection.h>
PandaFramework framework;
WindowFramework* window;
PT(AsyncTaskManager) taskMgr = AsyncTaskManager::get_global_ptr();
CollisionTraverser trav;
CollisionHandlerQueue* queue;
CollisionRay* ray;
NodePathCollection coll;
class MyObject : public CollisionNode {
public:
AICharacter* c;
MyObject() : CollisionNode("MyObject") {
}
static TypeHandle get_class_type() {
return _type_handle;
}
static void init_type() {
TypedObject::init_type();
register_type(_type_handle, "MyObject", TypedObject::get_class_type());
}
virtual TypeHandle get_type() const {
return MyObject::get_class_type();
}
virtual TypeHandle force_init_type() {
init_type();
return MyObject::get_class_type();
}
private:
static TypeHandle _type_handle;
};
TypeHandle MyObject::_type_handle;
void select(const Event* ev, void* data) {
float x = (2 * window->get_graphics_window()->get_pointer(0).get_x()) / ((float) window->get_graphics_window()->get_x_size()) - 1;
float y = (2 * window->get_graphics_window()->get_pointer(0).get_y()) / ((float) window->get_graphics_window()->get_y_size()) - 1;
ray->set_from_lens(window->get_camera(0), x, -y);
trav.traverse(window->get_render());
coll.clear();
for (int i =0; i < queue->get_num_entries(); i++)
coll.add_path(queue->get_entry(i)->get_into_node_path());
cout << "num: " << queue->get_num_entries() << endl;
}
void print(const Event* ev, void* data) {
for(int i =0; i < coll.get_num_paths(); i++) {
cout << i << " " << coll[i] << endl;
if (coll[i].node()->is_of_type(MyObject::get_class_type())) {
cout << DCAST(MyObject, coll[i].node())->c << endl;
}
}
}
int main(int argc, char *argv[]) {
framework.open_framework(argc, argv);
framework.set_window_title("My Panda3D Window");
window = framework.open_window();
framework.get_window(0)->enable_keyboard();
PT(MyObject) obj = new MyObject();
obj->add_solid(new CollisionSphere(0, 0, 0, 3));
NodePath path (obj);
path.show();
obj->c = new AICharacter("char", path, 60, 0.05, 15);
path.reparent_to(window->get_render());
path.set_pos(-10, -10, -10);
window->get_camera_group().look_at(path);
ray = new CollisionRay();
queue = new CollisionHandlerQueue();
CollisionNode* n = new CollisionNode("ray");
n->add_solid(ray);
NodePath p = window->get_camera_group().attach_new_node(n);
trav.add_collider(p, queue);
framework.define_key("mouse1", "select", &select, (void*)NULL);
framework.define_key("mouse3", "print", &print, (void*)NULL);
framework.main_loop();
framework.close_framework();
return (0);
}
when i click on the collision sphere with the mouse1 button, it’s printed “num1”. but when i click with the mouse3 button it’s printed
0 render/MyObject
Type
and the program is blocked here. I must kill it with Ctrl+C…
Why?
Where am i wrong?
thanks a lot for your patience!