CollisionHandlerPusher

Hello!
I’m working with Panda3d to build a simple FPS. I put in the scene an environment and a camera. I want the camera doens’t travel into environment. Surfing on the web, I find CollisionHandlerPusher class that should stop two object when they intersect. It’s correct?
I don’t understand how to use CollisionHandlerPusher.
Where can i find an example?? possible in c++ please!

thanks!

The Panda3D manual is a good place to start for information about Panda’s collision system. There is also the Roaming Ralph sample program, which was oringinally written in Python, but which also has a C++ version that you can find by searching the forums.

David

I dont’t find the roaming ralph in c++ version:
in this topic [url]Roaming Ralph in C++] the link is broken
I try to do it by myself and i write this code:

#include "pandaFramework.h"
#include "pandaSystem.h"
#include "collisionTraverser.h"
#include "collisionNode.h"
#include "collisionPlane.h"
#include "collisionHandlerPusher.h"
#include "collisionSphere.h"
#include "nodePath.h"
#include "collisionHandlerEvent.h"
#include "plane.h"
#include "lpoint3.h"
#include "lvector3.h"
#include "boundingPlane.h"

#define ACCEL 200
float vel =0;

PandaFramework framework;
AsyncTaskManager* taskMgr = AsyncTaskManager::get_global_ptr();
WindowFramework *window;
NodePath smile;

AsyncTask::DoneStatus rotCamTask(GenericAsyncTask* task, void* data) {
	window->get_camera_group().look_at(smile);
	return AsyncTask::DS_cont;
}

AsyncTask::DoneStatus moveSmile(GenericAsyncTask* task, void* data) {
	vel += ACCEL*task->get_dt();
	smile.set_z(smile.get_z() - vel*task->get_dt());
	return AsyncTask::DS_cont;
}

int main(int argc, char *argv[]) {
	framework.open_framework(argc, argv);
	framework.set_window_title("My Panda3D Window");
	window = framework.open_window();
 	
	CollisionTraverser trav;
	trav.show_collisions(window->get_render());
	CollisionHandlerPusher* notifier = new CollisionHandlerPusher();
	notifier->add_in_pattern("%fn-in-%in");
	
	smile = window->load_model(framework.get_models(), "models/frowney");
	smile.reparent_to(window->get_render());
	smile.set_pos(0, 0, 10);
	
	CollisionSphere* col_solid = new CollisionSphere(0, 0, 0, 1);
	CollisionNode* col_node = new CollisionNode("Sphere");
	col_node->add_solid(col_solid);
	NodePath col = smile.attach_new_node(col_node);
	col.show();
    trav.add_collider(col, notifier);
    
    CollisionPlane* col_plane = new CollisionPlane(LPlane(LVector3f(0, 0, 1), LPoint3f(0, 0, 0)));
    col_node = new CollisionNode("Floor");
    col_node->add_solid(col_plane);
    NodePath floor = window->get_render().attach_new_node(col_node);
    floor.show();
    
 	NodePath cam = window->get_camera_group();
 	cam.set_pos(0, -10, 4);
 	cam.look_at(smile);
 	
 	// Add our task.
  	taskMgr->add(new GenericAsyncTask("Rotate camera", &rotCamTask, (void*) &smile));
  	taskMgr->add(new GenericAsyncTask("Move smile", &moveSmile, (void*) &smile));
 	
 
	framework.main_loop();
	framework.close_framework();
	return (0);
}

but when the smile touch the floor, the sphere crosses the plane.

Why?

ok… I write this.

#include "pandaFramework.h" 
#include "pandaSystem.h" 
#include "collisionTraverser.h" 
#include "collisionNode.h" 
#include "collisionPlane.h" 
#include "collisionHandlerPusher.h" 
#include "collisionSphere.h" 
#include "nodePath.h" 
#include "collisionHandlerEvent.h" 
#include "plane.h" 
#include "lpoint3.h" 
#include "lvector3.h" 
#include "boundingPlane.h" 

#define ACCEL 9.8 
float vel =20; 

PandaFramework framework; 
AsyncTaskManager* taskMgr = AsyncTaskManager::get_global_ptr(); 
WindowFramework *window; 
NodePath smile; 
CollisionTraverser trav; 

AsyncTask::DoneStatus rotCamTask(GenericAsyncTask* task, void* data) { 
   window->get_camera_group().look_at(smile); 
   return AsyncTask::DS_cont; 
} 

AsyncTask::DoneStatus moveSmile(GenericAsyncTask* task, void* data) { 
   trav.traverse(window->get_render());
   	vel += ACCEL*task->get_dt(); 
   	smile.set_z(smile.get_z() - vel*task->get_dt()); 
   return AsyncTask::DS_cont;
} 

int main(int argc, char *argv[]) { 
   framework.open_framework(argc, argv); 
   framework.set_window_title("My Panda3D Window"); 
   window = framework.open_window(); 
     
   
   trav.show_collisions(window->get_render()); 
   CollisionHandlerPusher* notifier = new CollisionHandlerPusher(); 
   notifier->add_in_pattern("%fn-in-%in"); 
    
   smile = window->load_model(framework.get_models(), "models/frowney"); 
   smile.reparent_to(window->get_render()); 
   smile.set_pos(0, 0, 10); 
    
   CollisionSphere* col_solid = new CollisionSphere(0, 0, 0, 1); 
   CollisionNode* col_node = new CollisionNode("Sphere"); 
   col_node->add_solid(col_solid); 
   NodePath col = smile.attach_new_node(col_node); 
   col.show(); 
    trav.add_collider(col, notifier); 
    
    NodePath floor = window->load_model(framework.get_models(), "plane");
    floor.reparent_to(window->get_render());
    floor.set_pos(0, 0, 0);
    
    CollisionPlane* col_plane = new CollisionPlane(LPlane(LVector3f(0, 0, 1), LPoint3f(0, 0, 0))); 
    col_node = new CollisionNode("Floor"); 
    col_node->add_solid(col_plane); 
    floor = floor.attach_new_node(col_node); 
    floor.show(); 
    
    NodePath cam = window->get_camera_group(); 
    cam.set_pos(0, -10, 4); 
    cam.look_at(smile); 
     
    // Add our task. 
     taskMgr->add(new GenericAsyncTask("Rotate camera", &rotCamTask, (void*) &smile));
     taskMgr->add(new GenericAsyncTask("Move smile", &moveSmile, (void*) &smile)); 
     
  
   framework.main_loop(); 
   framework.close_framework(); 
   return (0); 
}

but when the smile touch the plane, in the terminal it shows this message:

:collide(error): CollisionHandlerPusher doesn't know about render/frowney.egg/Sphere, disabling.

Why?

Ralf in c++
https://rapidshare.com/files/856878241/Roaming-Ralph-CXX.7z