NTRT Simulator
 All Classes Files Functions Variables Typedefs Friends Pages
tgSimView.h
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 #ifndef TG_SIM_VIEW_H
20 #define TG_SIM_VIEW_H
21 
28 // Forward declarations
29 class tgModelVisitor;
30 class tgSimulation;
31 class tgWorld;
32 
33 class tgSimView
34 {
35 
40  friend class tgSimulation;
41 
42 public:
43 
55  double stepSize = 1.0/120.0,
56  double renderRate = 1.0/60.0);
57 
58  ~tgSimView();
59 
64  tgWorld& world() { return m_world; }
65 
66  virtual void setup();
67 
68  virtual void teardown();
69 
73  virtual void run();
74 
78  virtual void run(int steps);
79 
80  virtual void render() const;
81 
82  virtual void render(const tgModelVisitor& r) const;
83 
84  // tgSimulation handles calling teardown and setup on this,
85  // since it knows when the new world is available
86  virtual void reset();
87 
95  void setRenderRate(double renderRate);
96 
101  double getRenderRate() const { return m_renderRate; }
102 
110  void setStepSize(double stepSize);
111 
116  double getStepSize() const { return m_stepSize; }
117 
118 protected:
119 
128  void bindToSimulation(tgSimulation& simulation);
129 
135  void releaseFromSimulation();
136 
142  void bindToWorld(tgWorld& world);
143 
145  bool isInitialzed() const { return m_initialized; }
146 
147 protected:
148 
156 
163 
169  double m_stepSize;
170 
175  double m_renderRate;
176 
181  double m_renderTime;
182 
183 private:
184 
186  bool invariant() const;
187 
188 private:
189 
191  tgWorld& m_world;
192 
194  bool m_initialized;
195 };
196 
197 #endif // TG_SIM_VIEW_H
void bindToWorld(tgWorld &world)
Definition: tgSimView.cpp:104
bool isInitialzed() const
Definition: tgSimView.h:145
double m_stepSize
Definition: tgSimView.h:169
double m_renderTime
Definition: tgSimView.h:181
void bindToSimulation(tgSimulation &simulation)
Definition: tgSimView.cpp:76
tgModelVisitor * m_pModelVisitor
Definition: tgSimView.h:162
double getStepSize() const
Definition: tgSimView.h:116
void releaseFromSimulation()
Definition: tgSimView.cpp:95
double getRenderRate() const
Definition: tgSimView.h:101
void setRenderRate(double renderRate)
Definition: tgSimView.cpp:189
void setStepSize(double stepSize)
Definition: tgSimView.cpp:197
double m_renderRate
Definition: tgSimView.h:175
tgSimulation * m_pSimulation
Definition: tgSimView.h:155
tgWorld & world()
Definition: tgSimView.h:64
virtual void run()
Definition: tgSimView.cpp:131
tgSimView(tgWorld &world, double stepSize=1.0/120.0, double renderRate=1.0/60.0)
Definition: tgSimView.cpp:35