The Actor
class is for animated models. Note that we use loadModel()
for static models and Actor
only when they are
animated. The two constructor arguments for the Actor
class are the name of the file containing the model and a Python dictionary containing the names of
the files containing the animations.
The Program
Update the Code
Now that the scenery is in place, we will load an Actor
. Update your code to look like this:
#include "pandaFramework.h"
#include "pandaSystem.h"
#include "genericAsyncTask.h"
#include "asyncTaskManager.h"
// Global stuff
PandaFramework framework;
PT(AsyncTaskManager) taskMgr = AsyncTaskManager::get_global_ptr();
PT(ClockObject) globalClock = ClockObject::get_global_clock();
NodePath camera;
// 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
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
// 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());
// Load the walk animation
window->load_model(pandaActor, "panda-walk4");
window->loop_animations(0);
// Add our task do the main loop, then rest in peace.
taskMgr->add(new GenericAsyncTask("Spins the camera", &SpinCameraTask, (void*) NULL));
framework.main_loop();
framework.close_framework();
return (0);
}
We are first loading the model file and the animation file like ordinary models. Then, we are simply calling loop_animations(0) to loop all animations.
Run the Program
The result is a panda walking in place as if on a treadmill: