NTRT Simulator
 All Classes 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 
29 #include "tgUtil.h"
30 #include "core/tgTaggable.h"
31 
32 //Bullet Physics
33 #include "LinearMath/btVector3.h"
34 #include "LinearMath/btQuaternion.h"
35 
36 // NOTE: Should tgNode hold a quaternion to specify rotation/orientation?
37 
38 
43 class tgNode : public btVector3, public tgTaggable
44 {
45 public:
46 
47  tgNode(const btVector3& v = btVector3(),
48  const std::string& tags = "") :
49  btVector3(v), tgTaggable(tags)
50  {}
51 
52  tgNode(double x, double y, double z,
53  const std::string& tags = "") :
54  btVector3(x,y,z), tgTaggable(tags)
55  {}
56 
60  void addRotation(const btVector3& fixedPoint,
61  const btVector3& fromOrientation,
62  const btVector3& toOrientation)
63  {
64  // Note: there's likely a more efficient way to do this...
65  addRotation(fixedPoint,
66  tgUtil::getQuaternionBetween(fromOrientation,
67  toOrientation));
68  }
69 
73  void addRotation(const btVector3& fixedPoint,
74  const btVector3& axis,
75  double angle)
76  {
77  tgUtil::addRotation(*this, fixedPoint, axis, angle);
78  }
79 
80 
84  void addRotation(const btVector3& fixedPoint,
85  const btQuaternion& rotation)
86  {
87  addRotation(fixedPoint,
88  rotation.getAxis(),
89  rotation.getAngle());
90  }
91 
92  // Note: Required for extending tgTaggable
93  bool operator==(const tgNode& other) const
94  {
95  return (this->x() == other.x()) &&
96  (this->y() == other.y()) &&
97  (this->z() == other.z());
98  }
99 
100 };
101 
102 
103 
111 inline std::ostream&
112 operator<<(std::ostream& os, const tgNode& node)
113 {
114  os << "tgNode(" << node.x() << ", " << node.y() << ", " << node.z() << ", {" << node.getTagStr(", ") << "})";
115  return os;
116 }
117 
118 
119 #endif
void addRotation(const btVector3 &fixedPoint, const btVector3 &fromOrientation, const btVector3 &toOrientation)
Definition: tgNode.h:60
static btQuaternion getQuaternionBetween(btVector3 a, btVector3 b)
Definition: tgUtil.h:182
void addRotation(const btVector3 &fixedPoint, const btQuaternion &rotation)
Definition: tgNode.h:84
Definition: tgNode.h:43
Contains the definition of class tgTaggable $Id$.
std::ostream & operator<<(std::ostream &os, const tgNode &node)
Definition: tgNode.h:112
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:230
void addRotation(const btVector3 &fixedPoint, const btVector3 &axis, double angle)
Definition: tgNode.h:73