案例位置:examples/Cuda/Tutorials/GL_MouseInteractionInGraphicsPipeline
功能介绍:主要用于测试鼠标交互功能。该案例展示了 CustomMouseInteraction 类的的基本使用。
案例说明:该功能主要用于响应鼠标事件,包括鼠标移动、点击和释放等。当鼠标发出不同指令时,程序会调用不同的接口,便于用户和仿真程序的交互。案例中展示了鼠标在仿真界面移动、点击时,程序打印出相应的状态、位置坐标等信息。
std::shared_ptr<SceneGraph> scn = std::make_shared<SceneGraph>();
auto triSet = std::make_shared<TriangleSet<DataType3f>>();
triSet->loadObjFile(getAssetPath() + "armadillo/armadillo.obj");
for (uint i = 0; i < 5; i++)
{
Transform3f tm;
tm.translation() = Vec3f(0.4 * i, 0, 0);
tm.scale() = Vec3f(1.0 + 0.1 * i, 1.0 - 0.1 * i, 1.0);
tm.rotation() = Quat<float>(i * (-0.2), Vec3f(1, 0, 0)).toMatrix3x3();
auto node = scn->addNode(std::make_shared<TransformNode>());
node->setName("TN-" + std::to_string(i));
//node->loadMesh("armadillo/armadillo.obj");
node->setMesh(triSet);
node->setTransform(tm);
auto sm = std::make_shared<GLInstanceVisualModule>();
sm->setColor(Vec3f(i * 0.2f, i * 0.2f, 1.f - i * 0.1f));
sm->setAlpha(0.8f);
node->setSurfaceVisualModule(sm);
}
scn->setUpperBound({ 4, 4, 4 });
//Create a CustomMouseInteraction object to handle the mouse event,
//Press/release the mouse button to show the information
auto mouseInterator = std::make_shared<CustomMouseInteraction>();
instanceNode->stateTopology()->connect(mouseInterator->inTopology());
instanceNode->graphicsPipeline()->pushModule(mouseInterator);
auto instanceRender = std::make_shared<GLInstanceVisualModule>();
instanceRender->setColor(Vec3f(0, 1, 0));
instanceNode->stateTopology()->connect(instanceRender->inTriangleSet());
instanceNode->stateTransforms()->connect(instanceRender->inTransform());
instanceNode->graphicsPipeline()->pushModule(instanceRender);
scn->setUpperBound({ 4, 4, 4 });