NTRT Simulator  Version: Master
 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 #include <iostream>
38 
39 tgBoxGround::Config::Config( btVector3 eulerAngles,
40  btScalar friction,
41  btScalar restitution,
42  btVector3 size,
43  btVector3 origin ) :
44 m_eulerAngles(eulerAngles),
45 m_friction(friction),
46 m_restitution(restitution),
47 m_size(size),
48 m_origin(origin)
49 {
50  assert((m_friction >= 0.0) && (m_friction <= 1.0));
51  assert((m_restitution >= 0.0) && (m_restitution <= 1.0));
52  assert((m_size[0] >= 0.0) && (m_size[1] >= 0.0) && (m_size[2] >= 0.0));
53 }
54 
56 m_config(Config())
57 {
58  // @todo make constructor aux to avoid repeated code
59  const btVector3 groundDimensions(m_config.m_size);
60  pGroundShape = new btBoxShape(groundDimensions);
61 
62 }
63 
65 m_config(config)
66 {
67  const btVector3 groundDimensions(m_config.m_size);
68  pGroundShape = new btBoxShape(groundDimensions);
69 
70 }
71 
72 
73 btRigidBody* tgBoxGround::getGroundRigidBody() const
74 {
75  std::cout << "Box Ground" << std::endl;
76  const btScalar mass = 0.0;
77 
78  btTransform groundTransform;
79  groundTransform.setIdentity();
80  groundTransform.setOrigin(m_config.m_origin);
81 
82  btQuaternion orientation;
83  orientation.setEuler(m_config.m_eulerAngles[0], // Yaw
84  m_config.m_eulerAngles[1], // Pitch
85  m_config.m_eulerAngles[2]); // Roll
86  groundTransform.setRotation(orientation);
87 
88  // Using motionstate is recommended
89  // It provides interpolation capabilities, and only synchronizes 'active' objects
90  btDefaultMotionState* const pMotionState =
91  new btDefaultMotionState(groundTransform);
92 
93  const btVector3 localInertia(0, 0, 0);
94 
95  btRigidBody::btRigidBodyConstructionInfo const rbInfo(mass, pMotionState, pGroundShape, localInertia);
96 
97  btRigidBody* const pGroundBody = new btRigidBody(rbInfo);
98 
99  return pGroundBody;
100 }
101 
virtual btRigidBody * getGroundRigidBody() const
Definition: tgBoxGround.cpp:73
btVector3 m_origin
Definition: tgBoxGround.h:82
Contains the definition of class tgBoxGround.
btVector3 m_eulerAngles
Definition: tgBoxGround.h:62