案例位置:examples/Cuda/HeigthField/Qt_Buoyancy
功能介绍:该案例展示了 Coupling 类的基本使用。浸在流体内的物体受到流体竖直向上的作用力,与重力的方向相反。物体在液体中所受浮力的大小,只跟它排开液体体积和液体的密度有关,与物体本身的密度、运动状态、浸没在液体中的深度等因素无关。此场景为高度场技术的综合应用,模拟测试浮力仿真效果。
案例说明:案例主要展示物体在浮力的作用下漂浮在水面的效果。该案例通过Ocean节点模拟海面,使用RigidMesh类模拟刚体,最后通过Coupling节点对两者进行耦合,从而实现帆船浮在水面的效果。
案例中使用的是Qt框架,用户可以点击节点调整节点的属性。例如可以点击OceanPatch节点,通过更改Wind Type属性来设置不同的海浪等级。
std::shared_ptr<SceneGraph> scn = std::make_shared<SceneGraph>();
auto ocean = scn->addNode(std::make_shared<Ocean<DataType3f>>());
auto patch = scn->addNode(std::make_shared<OceanPatch<DataType3f>>());
patch->varWindType()->setValue(3);
patch->connect(ocean->importOceanPatch());
auto mapper = std::make_shared<HeightFieldToTriangleSet<DataType3f>>();
ocean->stateHeightField()->connect(mapper->inHeightField());
ocean->graphicsPipeline()->pushModule(mapper);
auto sRender = std::make_shared<GLSurfaceVisualModule>();
sRender->setColor(Vec3f(0, 0.2, 1.0));
sRender->varUseVertexNormal()->setValue(true);
sRender->varAlpha()->setValue(0.6);
mapper->outTriangleSet()->connect(sRender->inTriangleSet());
ocean->graphicsPipeline()->pushModule(sRender);
auto boat = scn->addNode(std::make_shared<RigidMesh<DataType3f>>());
boat->varScale()->setValue(Vec3f(5));
boat->varDensity()->setValue(150.0f);
boat->stateVelocity()->setValue(Vec3f(10, 0, 0));
boat->varEnvelopeName()->setValue(getAssetPath() + "obj/boat_boundary.obj");
boat->varMeshName()->setValue(getAssetPath() + "obj/boat_mesh.obj");
auto dragging = std::make_shared<DragBoat<DataType3f>>();
boat->stateVelocity()->connect(dragging->inVelocity());
boat->stateQuaternion()->connect(dragging->inQuaternion());
boat->animationPipeline()->pushModule(dragging);
auto rigidMeshRender = std::make_shared<GLSurfaceVisualModule>();
rigidMeshRender->setColor(Vec3f(0.8, 0.8, 0.8));
boat->stateMesh()->promoteOuput()->connect(rigidMeshRender->inTriangleSet());
boat->graphicsPipeline()->pushModule(rigidMeshRender);
auto coupling = scn->addNode(std::make_shared<Coupling<DataType3f>>());
boat->connect(coupling->importRigidMesh());
ocean->connect(coupling->importOcean());