NTRT Simulator  v1.1
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
tgBoxGround.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 "tgBoxGround.h"
28 
29 //Bullet Physics
30 #include "BulletCollision/CollisionShapes/btBoxShape.h"
31 #include "BulletDynamics/Dynamics/btRigidBody.h"
32 #include "LinearMath/btDefaultMotionState.h"
33 #include "LinearMath/btTransform.h"
34 
35 // The C++ Standard Library
36 #include <cassert>
37 
38 tgBoxGround::Config::Config( btVector3 eulerAngles,
39  btScalar friction,
40  btScalar restitution,
41  btVector3 size,
42  btVector3 origin ) :
43 m_eulerAngles(eulerAngles),
44 m_friction(friction),
45 m_restitution(restitution),
46 m_size(size),
47 m_origin(origin)
48 {
49  assert((m_friction >= 0.0) && (m_friction <= 1.0));
50  assert((m_restitution >= 0.0) && (m_restitution <= 1.0));
51  assert((m_size[0] >= 0.0) && (m_size[1] >= 0.0) && (m_size[2] >= 0.0));
52 }
53 
55 m_config(Config())
56 {
57  // @todo make constructor aux to avoid repeated code
58  const btVector3 groundDimensions(m_config.m_size);
59  pGroundShape = new btBoxShape(groundDimensions);
60 
61 }
62 
64 m_config(config)
65 {
66  const btVector3 groundDimensions(m_config.m_size);
67  pGroundShape = new btBoxShape(groundDimensions);
68 
69 }
70 
71 
72 btRigidBody* tgBoxGround::getGroundRigidBody() const
73 {
74  const btScalar mass = 0.0;
75 
76  btTransform groundTransform;
77  groundTransform.setIdentity();
78  groundTransform.setOrigin(m_config.m_origin);
79 
80  btQuaternion orientation;
81  orientation.setEuler(m_config.m_eulerAngles[0], // Yaw
82  m_config.m_eulerAngles[1], // Pitch
83  m_config.m_eulerAngles[2]); // Roll
84  groundTransform.setRotation(orientation);
85 
86  // Using motionstate is recommended
87  // It provides interpolation capabilities, and only synchronizes 'active' objects
88  btDefaultMotionState* const pMotionState =
89  new btDefaultMotionState(groundTransform);
90 
91  const btVector3 localInertia(0, 0, 0);
92 
93  btRigidBody::btRigidBodyConstructionInfo const rbInfo(mass, pMotionState, pGroundShape, localInertia);
94 
95  btRigidBody* const pGroundBody = new btRigidBody(rbInfo);
96 
97  return pGroundBody;
98 }
99 
virtual btRigidBody * getGroundRigidBody() const
Definition: tgBoxGround.cpp:72
btVector3 m_origin
Definition: tgBoxGround.h:82
Contains the definition of class tgBoxGround.
btVector3 m_eulerAngles
Definition: tgBoxGround.h:62