Skip to content

Commit

Permalink
w
Browse files Browse the repository at this point in the history
  • Loading branch information
jslee02 committed Mar 26, 2024
1 parent b8ce7b7 commit aba9f87
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 0 deletions.
65 changes: 65 additions & 0 deletions dart/dynamics/RigidBody.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright (c) 2011-2024, The DART development contributors
* All rights reserved.
*
* The list of contributors can be found at:
* https://github.com/dartsim/dart/blob/main/LICENSE
*
* This file is provided under the following "BSD-style" License:
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

#include "dart/dynamics/RigidBody.hpp"

#include "dart/dynamics/BodyNode.hpp"
#include "dart/dynamics/BoxShape.hpp"
#include "dart/dynamics/FreeJoint.hpp"
#include "dart/dynamics/ShapeFrame.hpp"
#include "dart/dynamics/ShapeNode.hpp"

namespace dart::dynamics {

SkeletonPtr RigidBody::create(const Config& config)
{
return SkeletonPtr(new RigidBody(config));
}

RigidBody::RigidBody(const Config& config) : Skeleton(config.name)
{
auto jointAndBody = this->createJointAndBodyNodePair<dynamics::FreeJoint>();
auto body = jointAndBody.second;
auto shapeNode = body->createShapeNodeWith<
dynamics::VisualAspect,
dynamics::CollisionAspect,
dynamics::DynamicsAspect>(
std::make_shared<dynamics::BoxShape>(Eigen::Vector3d(0.3, 0.3, 0.3)));
(void)shapeNode;
}

RigidBody::~RigidBody()
{
// Do nothing
}

} // namespace dart::dynamics
66 changes: 66 additions & 0 deletions dart/dynamics/RigidBody.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright (c) 2011-2024, The DART development contributors
* All rights reserved.
*
* The list of contributors can be found at:
* https://github.com/dartsim/dart/blob/main/LICENSE
*
* This file is provided under the following "BSD-style" License:
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

#pragma once

#include <dart/dynamics/Skeleton.hpp>

namespace dart::dynamics {

struct RigidBodyConfig
{
std::string name = "RigidBody";
Eigen::Vector3d position = Eigen::Vector3d::Zero();

RigidBodyConfig(const std::string& name = "RigidBody") : name(name)
{
// Empty
}
};

class RigidBody : public Skeleton
{
public:
using Config = RigidBodyConfig;

static SkeletonPtr create(const Config& config = Config());

/// Constructor
explicit RigidBody(const Config& config = Config());

/// Destructor
~RigidBody() override;

void setPosition(const Eigen::Vector3d& position);
};

} // namespace dart::dynamics
2 changes: 2 additions & 0 deletions examples/hello_world/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ int main()
body->setInertia(dynamics::Inertia(
1, Eigen::Vector3d::Zero(), shapeNode->getShape()->computeInertia(1.0)));
shapeNode->getVisualAspect()->setColor(dart::Color::Blue());
auto body2 = dynamics::RigidBody::create();
(void)body2;

// Create ground
auto ground = dynamics::Skeleton::create("ground");
Expand Down

0 comments on commit aba9f87

Please sign in to comment.