NTRT Simulator  v1.1
 All Classes Namespaces 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 tgWorld::Config::Config(double g, double ws) :
36 gravity(g),
37 worldSize(ws)
38 {
39  if (ws <= 0.0)
40  {
41  throw std::invalid_argument("worldSize is not postive");
42  }
43 }
44 
50  m_config(),
51  m_pGround(new tgBoxGround()),
52  m_pImpl(new tgWorldBulletPhysicsImpl(m_config, (tgBulletGround*)m_pGround))
53 {
54  // Postcondition
55  assert(invariant());
56 }
57 
63  m_config(config),
64  m_pGround(new tgBoxGround()),
65  m_pImpl(new tgWorldBulletPhysicsImpl(m_config, (tgBulletGround*)m_pGround))
66 {
67  // Postcondition
68  assert(invariant());
69 }
70 
75 tgWorld::tgWorld(const tgWorld::Config& config, tgGround* ground) :
76  m_config(config),
77  m_pGround(ground),
78  m_pImpl(new tgWorldBulletPhysicsImpl(m_config, (tgBulletGround*)m_pGround))
79 {
80  // Postcondition
81  assert(invariant());
82 }
83 
85 {
86  delete m_pImpl;
87  delete m_pGround;
88 }
89 
91 {
92  delete m_pImpl;
93  m_pImpl = new tgWorldBulletPhysicsImpl(m_config, (tgBulletGround*)m_pGround);
94  // Postcondition
95  assert(invariant());
96 }
97 
98 void tgWorld::reset(const tgWorld::Config& config)
99 {
100  // Update the config
101  m_config = config;
102  // Reset as usual
103  reset();
104 
105  // Postcondition
106  assert(invariant());
107 }
108 
109 void tgWorld::step(double dt) const
110 {
111  if (dt <= 0.0)
112  {
113  throw std::invalid_argument("dt is not postive");
114  }
115  else
116  {
117  // Forward to the implementation
118  m_pImpl->step(dt);
119  }
120 }
121 
122 bool tgWorld::invariant() const
123 {
124  return m_pImpl != 0;
125 }
~tgWorld()
Definition: tgWorld.cpp:84
Contains the definition of class tgWorldBulletPhysicsImpl.
void step(double dt) const
Definition: tgWorld.cpp:109
Contains the definition of class tgWorld $Id$.
Contains the definition of class tgBoxGround.
tgWorld()
Definition: tgWorld.cpp:49
void reset()
Definition: tgWorld.cpp:90
virtual void step(double dt)=0