变化视角

1、变化视角

案例位置examples/Cuda/QtGUI/Qt_ViewTest

功能介绍:PeriDyno支持多视口仿真。每一个视口有一个渲染引擎窗口和移动相机。不同视口的渲染引擎和相机相互不影响。通过调用视口的相机setUnitScale的函数,来改变视口大小。

案例说明: 该案例主要测试视口相机视角变化。

2、程序实现

接下来介绍案例的实现过程:

  • 创建场景图及边界:
	std::shared_ptr<SceneGraph> scn = std::make_shared<SceneGraph>();

  • 创建刚体节点以及渲染节点:
	auto instanceNode = scn->addNode(std::make_shared<Instances>());

	auto surfaceRenderer = std::make_shared<GLSurfaceVisualModule>();

	//surfaceRenderer->setColor(Vec3f(0, 1, 0));
	//instanceNode->stateTopology()->connect(surfaceRenderer->inTriangleSet());
	//instanceNode->graphicsPipeline()->pushModule(surfaceRenderer);

	auto rigid = scn->addNode(std::make_shared<RigidBodySystem<DataType3f>>());
	RigidBodyInfo rigidBody;
	rigidBody.linearVelocity = Vec3f(0, 0, 0);
	BoxInfo box;

	box.center = 0.5f * Vec3f(0, 0.4, 0);
	box.halfLength = Vec3f(1.0, 1.0, 1.0);
	rigid->addBox(box, rigidBody);

	scn->setLowerBound(box.center - box.halfLength);
	scn->setUpperBound(box.center + box.halfLength);

	auto mapper = std::make_shared<DiscreteElementsToTriangleSet<DataType3f>>();
	rigid->stateTopology()->connect(mapper->inDiscreteElements());
	rigid->graphicsPipeline()->pushModule(mapper);

	auto sRender = std::make_shared<GLSurfaceVisualModule>();
	sRender->setColor(Vec3f(1, 1, 0));
	mapper->outTriangleSet()->connect(sRender->inTriangleSet());
	rigid->graphicsPipeline()->pushModule(sRender);

	scn->addNode(rigid);
  • 在main函数中调用视口相机,对视角进行修改:
	GlfwApp app;
	app.initialize(1024, 768);

	app.setSceneGraph(scn);

	//Set the distance unit for the camera, the fault unit is meter
	app.renderWindow()->getCamera()->setUnitScale(3.0f);

	app.mainLoop();