Skip to content

Commit

Permalink
[example] Update hello world
Browse files Browse the repository at this point in the history
  • Loading branch information
jslee02 committed Mar 26, 2024
1 parent f22eb21 commit 94cf28a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
40 changes: 34 additions & 6 deletions examples/hello_world/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,45 @@

#include <dart/dart.hpp>

#include <osgShadow/ShadowMap>

using namespace dart;

int main()
{
auto shape
= std::make_shared<dynamics::BoxShape>(Eigen::Vector3d(0.3, 0.3, 0.3));

// Create a box-shaped rigid body
auto skeleton = dynamics::Skeleton::create();
auto jointAndBody
= skeleton->createJointAndBodyNodePair<dynamics::FreeJoint>();
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<dynamics::BoxShape>(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<dynamics::WeldJoint>().second;
auto groundShapeNode = groundBody->createShapeNodeWith<
dynamics::VisualAspect,
dynamics::CollisionAspect,
dynamics::DynamicsAspect>(shape);
dynamics::DynamicsAspect>(
std::make_shared<dynamics::BoxShape>(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<gui::osg::RealTimeWorldNode> node
Expand All @@ -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<short>(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;

Expand Down
3 changes: 3 additions & 0 deletions pixi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
] }
Expand Down

0 comments on commit 94cf28a

Please sign in to comment.