From b8ce7b7639a019dc2b48795f4791224782eb343a Mon Sep 17 00:00:00 2001 From: Jeongseok Lee Date: Mon, 25 Mar 2024 18:22:37 -0700 Subject: [PATCH] [example] Update hello world --- examples/hello_world/main.cpp | 42 +++++++++++++++++++++++++++++------ pixi.toml | 3 +++ 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/examples/hello_world/main.cpp b/examples/hello_world/main.cpp index b58b25a948dbf..20a64bb0aabac 100644 --- a/examples/hello_world/main.cpp +++ b/examples/hello_world/main.cpp @@ -34,26 +34,45 @@ #include +#include + using namespace dart; int main() { - auto shape - = std::make_shared(Eigen::Vector3d(0.3, 0.3, 0.3)); - // Create a box-shaped rigid body auto skeleton = dynamics::Skeleton::create(); auto jointAndBody = skeleton->createJointAndBodyNodePair(); auto body = jointAndBody.second; - body->createShapeNodeWith< + Eigen::Isometry3d tf = Eigen::Isometry3d::Identity(); + tf.translation() << 0, 0, 1; + tf.linear() = math::expMapRot(Eigen::Vector3d::Random()); + body->getParentJoint()->setTransformFromParentBodyNode(tf); + auto shapeNode = body->createShapeNodeWith< + dynamics::VisualAspect, + dynamics::CollisionAspect, + dynamics::DynamicsAspect>( + std::make_shared(Eigen::Vector3d(0.3, 0.3, 0.3))); + body->setInertia(dynamics::Inertia( + 1, Eigen::Vector3d::Zero(), shapeNode->getShape()->computeInertia(1.0))); + shapeNode->getVisualAspect()->setColor(dart::Color::Blue()); + + // Create ground + auto ground = dynamics::Skeleton::create("ground"); + auto groundBody + = ground->createJointAndBodyNodePair().second; + auto groundShapeNode = groundBody->createShapeNodeWith< dynamics::VisualAspect, dynamics::CollisionAspect, - dynamics::DynamicsAspect>(shape); + dynamics::DynamicsAspect>( + std::make_shared(Eigen::Vector3d(10.0, 10.0, 0.1))); + groundShapeNode->getVisualAspect()->setColor(dart::Color::LightGray()); - // Create a world and add the rigid body + // Create a world and add the rigid body and ground to the world auto world = simulation::World::create(); world->addSkeleton(skeleton); + world->addSkeleton(ground); // Wrap a WorldNode around it ::osg::ref_ptr node @@ -63,6 +82,15 @@ int main() auto viewer = gui::osg::Viewer(); viewer.addWorldNode(node); + // Enable shadow + auto shadow + = dart::gui::osg::WorldNode::createDefaultShadowTechnique(&viewer); + if (auto sm = dynamic_cast<::osgShadow::ShadowMap*>(shadow.get())) { + auto mapResolution = static_cast(std::pow(2, 12)); + sm->setTextureSize(::osg::Vec2s(mapResolution, mapResolution)); + } + node->setShadowTechnique(shadow); + viewer.addInstructionText("Press space to start free falling the box.\n"); std::cout << viewer.getInstructions() << std::endl; @@ -72,7 +100,7 @@ int main() // Adjust the viewpoint of the Viewer viewer.getCameraManipulator()->setHomePosition( ::osg::Vec3(2.57f, 3.14f, 1.64f), - ::osg::Vec3(0.00f, 0.00f, 0.00f), + ::osg::Vec3(0.00f, 0.00f, 0.50f), ::osg::Vec3(-0.24f, -0.25f, 0.94f)); // We need to re-dirty the CameraManipulator by passing it into the viewer diff --git a/pixi.toml b/pixi.toml index 07c625269c2cf..68663b9ae38cd 100644 --- a/pixi.toml +++ b/pixi.toml @@ -13,6 +13,9 @@ install-local = { cmd = "cmake --install build --prefix $CONDA_PREFIX", depends_ "configure_local", "build", ] } +example-hello-world = { cmd = "cmake --build build --target hello_world --parallel && ./build/bin/hello_world", depends_on = [ + "configure", +] } example-atlas-puppet = { cmd = "cmake --build build --target atlas_puppet --parallel && ./build/bin/atlas_puppet", depends_on = [ "configure", ] }