NTRT Simulator  Version: Master
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
tgSphere.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 "tgSphere.h"
28 #include "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 tgSphere::Config::Config(double r, double d,
37  double f, double rf, double res) :
38  radius(r),
39  density(d),
40  friction(f),
41  rollFriction(rf),
42  restitution(res)
43 {
44  if (density < 0.0) { throw std::range_error("Negative density"); }
45  if (radius < 0.0) { throw std::range_error("Negative radius"); }
46  if (friction < 0.0) { throw std::range_error("Negative friction"); }
47  if (rollFriction < 0.0) { throw std::range_error("Negative roll friction"); }
48  if (restitution < 0.0) { throw std::range_error("Negative restitution"); }
49  if (restitution > 1.0) { throw std::range_error("Restitution > 1"); }
50  // Postcondition
51  assert(density >= 0.0);
52  assert(radius >= 0.0);
53  assert(friction >= 0.0);
54  assert(rollFriction >= 0.0);
55  assert((restitution >= 0.0) && (restitution <= 1.0));
56 }
57 
58 tgSphere::tgSphere(btRigidBody* pRigidBody,
59  const tgTags& tags) :
60  tgBaseRigid(pRigidBody, tags)
61 {
62  if (pRigidBody == NULL)
63  {
64  throw std::invalid_argument("Pointer to btRigidBody is NULL");
65  }
66 
67  // Postcondition
68  assert(invariant());
69  assert(m_pRigidBody == pRigidBody);
70 }
71 
73 
74 void tgSphere::onVisit(const tgModelVisitor& v) const
75 {
76  v.render(*this);
77 
78 }
79 
81 {
82  // Set body to NULL, calls teardown on children
84 
85  // Postcondition
86  // This does not preserve the invariant
87 }
88 
89 bool tgSphere::invariant() const
90 {
91  return
92  (m_pRigidBody != NULL) &&
93  (m_mass >= 0.0);
94 }
btRigidBody * m_pRigidBody
Definition: tgBaseRigid.h:102
const double density
Definition: tgSphere.h:71
const double friction
Definition: tgSphere.h:75
virtual ~tgSphere()
Definition: tgSphere.cpp:72
Config(double r=0.5, double d=1.0, double f=1.0, double rf=0.0, double res=0.2)
Definition: tgSphere.cpp:36
Contains the definition of class tgSphere.
const double rollFriction
Definition: tgSphere.h:79
virtual void onVisit(const tgModelVisitor &v) const
Definition: tgSphere.cpp:74
virtual void render(const tgRod &rod) const
const double radius
Definition: tgSphere.h:68
Contains the definition of interface class tgModelVisitor.
tgSphere(btRigidBody *pRigidBody, const tgTags &tags)
Definition: tgSphere.cpp:58
virtual void teardown()
Definition: tgSphere.cpp:80
const double m_mass
Definition: tgBaseRigid.h:105
virtual void teardown()
Definition: tgBaseRigid.cpp:65
const double restitution
Definition: tgSphere.h:83
Definition: tgTags.h:44