NTRT Simulator
 All Classes Files Functions Variables Typedefs Friends Pages
tgBulletRenderer.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 "tgBulletRenderer.h"
28 // This application
29 #include "Muscle2P.h"
30 #include "tgBulletUtil.h"
31 #include "tgLinearString.h"
32 #include "tgWorld.h"
34 // OpenGL_FreeGlut (patched Bullet)
35 #include "tgGLDebugDrawer.h"
36 // The Bullet Physics library
37 #include "BulletSoftBody/btSoftRigidDynamicsWorld.h"
38 // The C++ Standard Library
39 #include <cassert>
40 
41 
43 {
44 }
45 
46 void tgBulletRenderer::render(const tgRod& rod) const
47 {
48  // render the rod (change color, etc. if we want)
49 }
50 
51 void tgBulletRenderer::render(const tgLinearString& linString) const
52 {
53  // Fetch the btDynamicsWorld
54  btSoftRigidDynamicsWorld& dynamicsWorld =
56 
57  btIDebugDraw* const pDrawer = dynamicsWorld.getDebugDrawer();
58 
59  const Muscle2P* const pMuscle = linString.getMuscle();
60 
61  if (pDrawer && pMuscle)
62  {
63 
64  const btVector3 lineFrom =
65  pMuscle->anchor1->getWorldPosition();
66  const btVector3 lineTo =
67  pMuscle->anchor2->getWorldPosition();
68  const double stretch =
69  linString.getCurrentLength() - pMuscle->getRestLength();
70  const btVector3 color =
71  (stretch < 0.0) ?
72  btVector3(0.0, 0.0, 1.0) :
73  btVector3(0.5 + stretch / 3.0,
74  0.5 - stretch / 2.0,
75  0.0);
76  pDrawer->drawLine(lineFrom, lineTo, color);
77  }
78 }
79 
80 void tgBulletRenderer::render(const tgModel& model) const
81 {
82 }
83 
const Muscle2P * getMuscle() const
virtual void render(const tgLinearString &linString) const
Contains the definition of class tgWorldBulletPhysicsImpl.
static btSoftRigidDynamicsWorld & worldToDynamicsWorld(tgWorld &world)
tgBulletRenderer(tgWorld &world)
Definitions of classes Muscle2P and MuscleAnchor.
Contains the definition of class tgLinearString.
Contains the definition of class tgWorld $Id$.
Contains the definition of class tgBulletUtil.
Contains the definition of concrete class tgBulletRenderer.
Definition: tgRod.h:42