NTRT Simulator  Version: Master
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
tgBox.cpp
Go to the documentation of this file.
1 /*
2  * Copyright © 2012, United States Government, as represented by the
3  * Administrator of the National Aeronautics and Space Administration.
4  * All rights reserved.
5  *
6  * The NASA Tensegrity Robotics Toolkit (NTRT) v1 platform is licensed
7  * under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * http://www.apache.org/licenses/LICENSE-2.0.
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
15  * either express or implied. See the License for the specific language
16  * governing permissions and limitations under the License.
17 */
18 
26 // This module
27 #include "tgBox.h"
28 #include "core/tgModelVisitor.h"
29 // The Bullet Physics library
30 #include "BulletDynamics/Dynamics/btRigidBody.h"
31 #include "btBulletDynamicsCommon.h"
32 // The C++ Standard Library
33 #include <cassert>
34 #include <stdexcept>
35 
36 tgBox::Config::Config(double w, double h, double d,
37  double f, double rf, double res) :
38  width(w),
39  height(h),
40  density(d),
41  friction(f),
42  rollFriction(rf),
43  restitution(res)
44 {
45  if (density < 0.0) { throw std::range_error("Negative density"); }
46  if (width < 0.0) { throw std::range_error("Negative width"); }
47  if (height < 0.0) { throw std::range_error("Negative height"); }
48  if (friction < 0.0) { throw std::range_error("Negative friction"); }
49  if (rollFriction < 0.0) { throw std::range_error("Negative roll friction"); }
50  if (restitution < 0.0) { throw std::range_error("Negative restitution"); }
51  if (restitution > 1.0) { throw std::range_error("Restitution > 1"); }
52  // Postcondition
53  assert(density >= 0.0);
54  assert(width >= 0.0);
55  assert(height >= 0.0);
56  assert(friction >= 0.0);
57  assert(rollFriction >= 0.0);
58  assert((restitution >= 0.0) && (restitution <= 1.0));
59 }
60 
61 tgBox::tgBox(btRigidBody* pRigidBody,
62  const tgTags& tags,
63  const double length) :
64  tgBaseRigid(pRigidBody, tags),
65  m_length(length)
66 {
67  if (pRigidBody == NULL)
68  {
69  throw std::invalid_argument("Pointer to btRigidBody is NULL");
70  }
71 
72  // Postcondition
73  assert(invariant());
74  assert(m_pRigidBody == pRigidBody);
75 }
76 
78 
79 void tgBox::onVisit(const tgModelVisitor& v) const
80 {
81  v.render(*this);
82  // Do we need to render the base class?
83 }
84 
86 {
87  // Sets body to NULL, calls teardown on children
89 
90  // Postcondition
91  // This does not preserve the invariant
92 }
93 
94 bool tgBox::invariant() const
95 {
96  return
97  (m_length >= 0.0);
98 }
const double restitution
Definition: tgBox.h:86
const double height
Definition: tgBox.h:71
const double rollFriction
Definition: tgBox.h:82
Create a box shape as an obstacle or add it to your tensegrity.
virtual void teardown()
Definition: tgBox.cpp:85
btRigidBody * m_pRigidBody
Definition: tgBaseRigid.h:102
double length() const
Definition: tgBox.h:104
const double density
Definition: tgBox.h:74
virtual ~tgBox()
Definition: tgBox.cpp:77
virtual void render(const tgRod &rod) const
Contains the definition of interface class tgModelVisitor.
Config(double w=1.0, double h=1.0, double d=1.0, double f=1.0, double rf=0.0, double res=0.2)
Definition: tgBox.cpp:36
virtual void teardown()
Definition: tgBaseRigid.cpp:65
const double width
Definition: tgBox.h:68
virtual void onVisit(const tgModelVisitor &v) const
Definition: tgBox.cpp:79
Definition: tgTags.h:44
const double friction
Definition: tgBox.h:78