NTRT Simulator
 All Classes Files Functions Variables Typedefs Friends Pages
tgWorld.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 
19 
26 // This module
27 #include "tgWorld.h"
28 // This application
30 #include "terrain/tgBoxGround.h"
31 // The C++ Standard Library
32 #include <cassert>
33 #include <stdexcept>
34 
35 namespace
36 {
37  // The default configuration to use if not supplied
38  const tgWorld::Config defaultConfig =
39  {
40  9.81 // gravity, g in m/sec^2
41  };
42 } // namespace
43 
49  m_config(defaultConfig),
50  m_pGround(new tgBoxGround()),
51  m_pImpl(new tgWorldBulletPhysicsImpl(m_config, (tgBulletGround*)m_pGround))
52 {
53  // Postcondition
54  assert(invariant());
55 }
56 
62  m_config(config),
63  m_pGround(new tgBoxGround()),
64  m_pImpl(new tgWorldBulletPhysicsImpl(m_config, (tgBulletGround*)m_pGround))
65 {
66  // Postcondition
67  assert(invariant());
68 }
69 
74 tgWorld::tgWorld(const tgWorld::Config& config, tgGround* ground) :
75  m_config(config),
76  m_pGround(ground),
77  m_pImpl(new tgWorldBulletPhysicsImpl(m_config, (tgBulletGround*)m_pGround))
78 {
79  // Postcondition
80  assert(invariant());
81 }
82 
84 {
85  delete m_pImpl;
86  delete m_pGround;
87 }
88 
90 {
91  delete m_pImpl;
92  m_pImpl = new tgWorldBulletPhysicsImpl(m_config, (tgBulletGround*)m_pGround);
93  // Postcondition
94  assert(invariant());
95 }
96 
97 void tgWorld::reset(const tgWorld::Config& config)
98 {
99  // Update the config
100  m_config = config;
101  // Reset as usual
102  reset();
103 
104  // Postcondition
105  assert(invariant());
106 }
107 
108 void tgWorld::step(double dt) const
109 {
110  if (dt <= 0.0)
111  {
112  throw std::invalid_argument("dt is not postive");
113  }
114  else
115  {
116  // Forward to the implementation
117  m_pImpl->step(dt);
118  }
119 }
120 
121 bool tgWorld::invariant() const
122 {
123  return m_pImpl != 0;
124 }
~tgWorld()
Definition: tgWorld.cpp:83
Contains the definition of class tgWorldBulletPhysicsImpl.
void step(double dt) const
Definition: tgWorld.cpp:108
Contains the definition of class tgWorld $Id$.
Contains the definition of class tgBoxGround.
tgWorld()
Definition: tgWorld.cpp:48
void reset()
Definition: tgWorld.cpp:89
virtual void step(double dt)=0