1、panda3d使用了称为场景图(the Scene Graph)的树形数据结构,包括了所有需要渲染的对象,树根对象名为render。
2、通过window->get_render()得到render节点路径。
3、使用reparent_to()方法安装草地风景模型在场景图中。
4、 set_scale()和set_pos()调整大小和居中模型。
5、panda3d使用地理坐标系统, 比如,-28, 49, 0)表示(8, 42) 高度0.
地理坐标系(Geographic Coordinate
System),是使用三维球面来定义地球表面位置,以实现通过经纬度对地球表面点位引用的坐标系。
用 X 表示经度值并用 Y 表示纬度值
panda3d的forward改变了 Y坐标。
#include <iostream>
#include "pandaFramework.h"
#include "pandaSystem.h"using namespace std;
int main()
{PandaFramework framework;framework.open_framework();// Set the window title and open the windowframework.set_window_title("game2");WindowFramework* window = framework.open_window();// Load the environment model.NodePath scene = window->load_model(framework.get_models(), "models/environment");// Reparent the model to render.scene.reparent_to(window->get_render());// Apply scale and position transforms to the model.scene.set_scale(0.25f, 0.25f, 0.25f);scene.set_pos(-8, 42, 0);// Do the main loop, equal to run() in pythonframework.main_loop();framework.close_framework();return (0);
}
Panda3D 运行了一个任务,允许你移动摄像头使用鼠标。
通过下面命令启用它。
window->setup_trackball();
// panda3d-1.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//#include <iostream>
#include "pandaFramework.h"
#include "pandaSystem.h"using namespace std;
// The global task managerPT(AsyncTaskManager) taskMgr = AsyncTaskManager::get_global_ptr();// The global clockPT(ClockObject) globalClock = ClockObject::get_global_clock();// Here's what we'll store the camera in.NodePath camera;// This is our task - a global or static function that has to return DoneStatus.// The task object is passed as argument, plus a void* pointer, containing custom data.// For more advanced usage, we can subclass AsyncTask and override the do_task method.AsyncTask::DoneStatus spinCameraTask(GenericAsyncTask* task, void* data) {// Calculate the new position and orientation (inefficient - change me!)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);// Tell the task manager to continue this task the next frame.return AsyncTask::DS_cont;}int main()
{PandaFramework framework;framework.open_framework();// Set the window title and open the windowframework.set_window_title("game2");WindowFramework* window = framework.open_window();// Get the camera and store it in a variable.camera = window->get_camera_group();// Load the environment model.NodePath scene = window->load_model(framework.get_models(), "models/environment");// Reparent the model to render.scene.reparent_to(window->get_render());// Apply scale and position transforms to the model.scene.set_scale(0.25f, 0.25f, 0.25f);scene.set_pos(-8, 42, 0);// Add our task.// If we specify custom data instead of NULL, it will be passed as the second argument// to the task function.taskMgr->add(new GenericAsyncTask("Spins the camera", &spinCameraTask, nullptr));// Do the main loop, equal to run() in pythonframework.main_loop();framework.close_framework();return (0);
}