NTRT Simulator  v1.1
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
tgNode.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_NODE_H
20 #define TG_NODE_H
21 
30 #include "tgUtil.h"
31 #include "core/tgTaggable.h"
32 
33 //Bullet Physics
34 #include "LinearMath/btVector3.h"
35 #include "LinearMath/btQuaternion.h"
36 
37 // NOTE: Should tgNode hold a quaternion to specify rotation/orientation?
38 
39 
45 class tgNode : public btVector3, public tgTaggable
46 {
47 public:
48 
49  tgNode(const btVector3& v = btVector3(),
50  const std::string& tags = "") :
51  btVector3(v), tgTaggable(tags)
52  {}
53 
54  tgNode(double x, double y, double z,
55  const std::string& tags = "") :
56  btVector3(x,y,z), tgTaggable(tags)
57  {}
58 
62  void addRotation(const btVector3& fixedPoint,
63  const btVector3& fromOrientation,
64  const btVector3& toOrientation)
65  {
66  // Note: there's likely a more efficient way to do this...
67  addRotation(fixedPoint,
68  tgUtil::getQuaternionBetween(fromOrientation,
69  toOrientation));
70  }
71 
75  void addRotation(const btVector3& fixedPoint,
76  const btVector3& axis,
77  double angle)
78  {
79  tgUtil::addRotation(*this, fixedPoint, axis, angle);
80  }
81 
82 
86  void addRotation(const btVector3& fixedPoint,
87  const btQuaternion& rotation)
88  {
89  addRotation(fixedPoint,
90  rotation.getAxis(),
91  rotation.getAngle());
92  }
93 
94  // Note: Required for extending tgTaggable
95  bool operator==(const tgNode& other) const
96  {
97  return (this->x() == other.x()) &&
98  (this->y() == other.y()) &&
99  (this->z() == other.z());
100  }
101 
102 };
103 
104 
105 
113 inline std::ostream&
114 operator<<(std::ostream& os, const tgNode& node)
115 {
116  os << "tgNode(" << node.x() << ", " << node.y() << ", " << node.z() << ", {" << node.getTagStr(", ") << "})";
117  return os;
118 }
119 
120 
121 #endif
void addRotation(const btVector3 &fixedPoint, const btVector3 &fromOrientation, const btVector3 &toOrientation)
Definition: tgNode.h:62
static btQuaternion getQuaternionBetween(btVector3 a, btVector3 b)
Definition: tgUtil.h:196
void addRotation(const btVector3 &fixedPoint, const btQuaternion &rotation)
Definition: tgNode.h:86
Definition: tgNode.h:45
Contains the definition of class tgTaggable.
std::ostream & operator<<(std::ostream &os, const tgNode &node)
Definition: tgNode.h:114
Contains the definition of class tgUtil and overloaded operator<<() free functions.
static void addRotation(btVector3 &v, const btVector3 &fixedPoint, const btVector3 &axis, double angle)
Definition: tgUtil.h:252
void addRotation(const btVector3 &fixedPoint, const btVector3 &axis, double angle)
Definition: tgNode.h:75