Hi,
Im learning Panda3D from official manual, and Im on Physics chapter. The problem is that codes here are in python even if you change to C++…
Here is the link to one of the pages: http://www.panda3d.org/manual/index.php/Enabling_physics_on_a_node
Whole chapter is bugged (or unfinished)…
rdb
2
Unfinished, you mean. However, the code should be easy enough to translate to C++ since the APIs are virtually the same.
Yup, I transladed quite fast I thought it’s bugged, so you could fix this :> It’s quite easy to make small mistake coding in PHP
Okay, translating was quite easy, but my code doesn’t work…
What else should I do to see my box falling?
My code (based on one of tutorials):
#include "pandaFramework.h"
#include "pandaSystem.h"
#include "actorNode.h"
#include "physicsManager.h"
#include "linearVectorForce.h"
#include "genericAsyncTask.h"
#include "asyncTaskManager.h"
#include "cIntervalManager.h"
#include "cLerpNodePathInterval.h"
#include "cMetaInterval.h"
// Global stuff
PT(AsyncTaskManager) taskMgr = AsyncTaskManager::get_global_ptr();
PT(ClockObject) globalClock = ClockObject::get_global_clock();
NodePath camera;
PhysicsManager physics;
// Task to move the camera
AsyncTask::DoneStatus SpinCameraTask(GenericAsyncTask* task, void* data) {
double time = globalClock->get_real_time();
double angledegrees = time * 6.0;
double angleradians = angledegrees * (3.14 / 180.0);
camera.set_pos(20*sin(angleradians),-20.0*cos(angleradians),3);
camera.set_hpr(angledegrees, 0, 0);
return AsyncTask::DS_cont;
}
int main(int argc, char *argv[]) {
// Open a new window framework and set the title
PandaFramework framework;
framework.open_framework(argc, argv);
framework.set_window_title("My Panda3D Window");
// Open the window
WindowFramework *window = framework.open_window();
camera = window->get_camera_group(); // Get the camera and store it
LinearVectorForce* gravityForce=new LinearVectorForce(0,0,-9.81);
physics.add_linear_force(gravityForce);
// Load the environment model
NodePath environ = window->load_model(framework.get_models(),"models/environment");
environ.reparent_to(window->get_render());
environ.set_scale(0.25 , 0.25, 0.25);
environ.set_pos(-8, 42, 0);
// Load our panda
NodePath pandaActor = window->load_model(framework.get_models(),
"panda-model");
pandaActor.set_scale(0.005);
pandaActor.reparent_to(window->get_render());
NodePath box("N-box");
box.set_scale(1);
box.set_pos(0, 0, 4);
box.reparent_to(window->get_render());
ActorNode* an=new ActorNode("A-box");
physics.attach_physical_node(an);
NodePath anp=box.attach_new_node(an);
NodePath Pbox = window->load_model(framework.get_models(),"box");
Pbox.reparent_to(anp);
an->get_physics_object()->set_mass(100);
// Load the walk animation
window->load_model(pandaActor, "panda-walk4");
window->loop_animations(0);
// Add our task.
taskMgr->add(new GenericAsyncTask("Spins the camera",
&SpinCameraTask, (void*) NULL));
// This is a simpler way to do stuff every frame,
// if you're too lazy to create a task.
Thread *current_thread = Thread::get_current_thread();
while(framework.do_frame(current_thread)) {
// Step the interval manager
CIntervalManager::get_global_ptr()->step();
physics.do_physics(10);
}
framework.close_framework();
return (0);
}